Examples#

Basic Usage#

To solve a simple LP problem using cuopt_cli:

basic_lp_example.sh

 1#!/bin/bash
 2# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 3# SPDX-License-Identifier: Apache-2.0
 4#
 5# Basic LP Example using cuopt_cli
 6#
 7# This example demonstrates how to solve a simple LP problem using cuopt_cli.
 8# cuopt_cli is a standalone command-line tool that solves LP/MILP problems
 9# from MPS files without requiring a server.
10#
11# Requirements:
12#   - cuopt_cli installed and available in PATH
13#
14
15# Create a sample MPS file
16echo "* optimize
17*  cost = -0.2 * VAR1 + 0.1 * VAR2
18* subject to
19*  3 * VAR1 + 4 * VAR2 <= 5.4
20*  2.7 * VAR1 + 10.1 * VAR2 <= 4.9
21NAME          SAMPLE
22ROWS
23 N  COST
24 L  ROW1
25 L  ROW2
26COLUMNS
27 VAR1      COST                -0.2
28 VAR1      ROW1                3.0
29 VAR1      ROW2                2.7
30 VAR2      COST                0.1
31 VAR2      ROW1                4.0
32 VAR2      ROW2               10.1
33RHS
34 RHS1      ROW1                5.4
35 RHS1      ROW2                4.9
36ENDATA" > sample.mps
37
38# Solve using default settings
39cuopt_cli sample.mps
40
41# Clean up
42rm -f sample.mps

This should give you the following output:

Output#
Running file sample.mps
Solving a problem with 2 constraints 2 variables (0 integers) and 4 nonzeros
Objective offset 0.000000 scaling_factor 1.000000
Running concurrent

Dual simplex finished in 0.00 seconds
   Iter    Primal Obj.      Dual Obj.    Gap        Primal Res.  Dual Res.   Time
      0 +0.00000000e+00 +0.00000000e+00  0.00e+00   0.00e+00     2.00e-01   0.033s
PDLP finished
Concurrent time:  0.036s
Solved with dual simplex
Status: Optimal   Objective: -3.60000000e-01  Iterations: 1  Time: 0.036s

Mixed Integer Programming Example#

Here’s an example of solving a Mixed Integer Programming (MIP) problem using the CLI:

basic_milp_example.sh

 1#!/bin/bash
 2# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 3# SPDX-License-Identifier: Apache-2.0
 4#
 5# Basic MILP Example using cuopt_cli
 6#
 7# This example demonstrates how to solve a Mixed Integer Programming (MIP)
 8# problem using cuopt_cli. The main difference from LP is that variables
 9# are marked as integers in the MPS file.
10#
11# Requirements:
12#   - cuopt_cli installed and available in PATH
13#
14
15# Create MILP problem MPS file
16echo "* Optimal solution -28
17NAME          MIP_SAMPLE
18ROWS
19 N  OBJ
20 L  C1
21 L  C2
22 L  C3
23COLUMNS
24 MARK0001  'MARKER'                 'INTORG'
25   X1        OBJ             -7
26   X1        C1              -1
27   X1        C2               5
28   X1        C3              -2
29   X2        OBJ             -2
30   X2        C1               2
31   X2        C2               1
32   X2        C3              -2
33 MARK0001  'MARKER'                 'INTEND'
34RHS
35   RHS       C1               4
36   RHS       C2              20
37   RHS       C3              -7
38BOUNDS
39 UP BOUND     X1               10
40 UP BOUND     X2               10
41ENDATA" > mip_sample.mps
42
43# Solve the MIP problem with custom parameters
44cuopt_cli --mip-absolute-gap 0.01 --time-limit 10 mip_sample.mps
45
46# Clean up
47rm -f mip_sample.mps

This should produce output similar to:

Output#
Running file mip_sample.mps
Solving a problem with 3 constraints 2 variables (2 integers) and 6 nonzeros
Objective offset 0.000000 scaling_factor 1.000000
After trivial presolve updated 3 constraints 2 variables
Running presolve!
After trivial presolve updated 3 constraints 2 variables
Solving LP root relaxation
Scaling matrix. Maximum column norm 1.225464e+00
Dual Simplex Phase 1
Dual feasible solution found.
Dual Simplex Phase 2
Iter     Objective   Primal Infeas  Perturb  Time
   1 -3.04000000e+01 7.57868205e+00 0.00e+00 0.00

Root relaxation solution found in 3 iterations and 0.00s
Root relaxation objective -3.01818182e+01

Strong branching on 2 fractional variables
| Explored | Unexplored | Objective   |    Bound    | Depth | Iter/Node |  Gap   |    Time
      0        1                +inf  -3.018182e+01      1   0.0e+00       -        0.00
B       3        1       -2.700000e+01  -2.980000e+01      2   6.7e-01     10.4%      0.00
B&B added a solution to population, solution queue size 0 with objective -27
B       4        0       -2.800000e+01  -2.980000e+01      2   7.5e-01      6.4%      0.00
B&B added a solution to population, solution queue size 1 with objective -28
Explored 4 nodes in 0.00s.
Absolute Gap 0.000000e+00 Objective -2.8000000000000004e+01 Lower Bound -2.8000000000000004e+01
Optimal solution found.
Consuming B&B solutions, solution queue size 2
Solution objective: -28.000000 , relative_mip_gap 0.000000 solution_bound -28.000000 presolve_time 0.227418 total_solve_time 0.000000 max constraint violation 0.000000 max int violation 0.000000 max var bounds violation 0.000000 nodes 4 simplex_iterations 3

Using Solver Parameters#

You can customize the solver behavior using various command line parameters. Here’s a comprehensive example showing different parameter options:

solver_parameters_example.sh

 1#!/bin/bash
 2# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 3# SPDX-License-Identifier: Apache-2.0
 4#
 5# Solver Parameters Example using cuopt_cli
 6#
 7# This example demonstrates how to customize solver behavior using various
 8# command line parameters with cuopt_cli.
 9#
10# Requirements:
11#   - cuopt_cli installed and available in PATH
12#
13
14# Create a sample MPS file for testing different parameters
15echo "* optimize
16*  cost = -0.2 * VAR1 + 0.1 * VAR2
17* subject to
18*  3 * VAR1 + 4 * VAR2 <= 5.4
19*  2.7 * VAR1 + 10.1 * VAR2 <= 4.9
20NAME          SAMPLE
21ROWS
22 N  COST
23 L  ROW1
24 L  ROW2
25COLUMNS
26 VAR1      COST                -0.2
27 VAR1      ROW1                3.0
28 VAR1      ROW2                2.7
29 VAR2      COST                0.1
30 VAR2      ROW1                4.0
31 VAR2      ROW2               10.1
32RHS
33 RHS1      ROW1                5.4
34 RHS1      ROW2                4.9
35ENDATA" > sample.mps
36
37echo "=== Example 1: Set absolute primal tolerance and PDLP solver mode ==="
38cuopt_cli --absolute-primal-tolerance 0.0001 --pdlp-solver-mode 1 sample.mps
39
40echo ""
41echo "=== Example 2: Set time limit and use specific solver method (PDLP only) ==="
42cuopt_cli --time-limit 5 --method 1 sample.mps
43
44echo ""
45echo "=== Example 3: Redirect output to log file and solution file ==="
46cuopt_cli --log-to-console false --log-file sample.log --solution-file sample.sol sample.mps
47echo "Log and solution files created: sample.log, sample.sol"
48
49# Clean up
50rm -f sample.mps sample.log sample.sol