LP and MILP Examples#

This section contains examples of how to use the cuOpt linear programming and mixed integer linear programming Python API.

Note

The examples in this section are not exhaustive. They are provided to help you get started with the cuOpt linear programming and mixed integer linear programming Python API. For more examples, please refer to the cuopt-examples GitHub repository.

Simple Linear Programming Example#

simple_lp_example.py

 1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
 2# SPDX-License-Identifier: Apache-2.0
 3# AFFILIATES. All rights reserved.
 4# SPDX-License-Identifier: Apache-2.0
 5#
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17"""
18Simple Linear Programming Example
19
20This example demonstrates how to:
21- Create a linear programming problem
22- Add continuous variables
23- Add linear constraints
24- Set an objective function
25- Solve the problem and retrieve results
26
27Problem:
28    Maximize: x + y
29    Subject to:
30        x + y <= 10
31        x - y >= 0
32        x, y >= 0
33
34Expected Output:
35    Optimal solution found in 0.01 seconds
36    x = 10.0
37    y = 0.0
38    Objective value = 10.0
39"""
40
41from cuopt.linear_programming.problem import Problem, CONTINUOUS, MAXIMIZE
42from cuopt.linear_programming.solver_settings import SolverSettings
43
44
45def main():
46    """Run the simple LP example."""
47    # Create a new problem
48    problem = Problem("Simple LP")
49
50    # Add variables
51    x = problem.addVariable(lb=0, vtype=CONTINUOUS, name="x")
52    y = problem.addVariable(lb=0, vtype=CONTINUOUS, name="y")
53
54    # Add constraints
55    problem.addConstraint(x + y <= 10, name="c1")
56    problem.addConstraint(x - y >= 0, name="c2")
57
58    # Set objective function
59    problem.setObjective(x + y, sense=MAXIMIZE)
60
61    # Configure solver settings
62    settings = SolverSettings()
63    settings.set_parameter("time_limit", 60)
64
65    # Solve the problem
66    problem.solve(settings)
67
68    # Check solution status
69    if problem.Status.name == "Optimal":
70        print(f"Optimal solution found in {problem.SolveTime:.2f} seconds")
71        print(f"x = {x.getValue()}")
72        print(f"y = {y.getValue()}")
73        print(f"Objective value = {problem.ObjValue}")
74    else:
75        print(f"Problem status: {problem.Status.name}")
76
77
78if __name__ == "__main__":
79    main()

The response is as follows:

Optimal solution found in 0.01 seconds
x = 10.0
y = 0.0
Objective value = 10.0

Simple Quadratic Programming Example#

Note

The QP solver is currently in beta.

simple_qp_example.py

 1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
 2# SPDX-License-Identifier: Apache-2.0
 3
 4"""
 5Simple Quadratic Programming Example
 6====================================
 7
 8.. note::
 9   The QP solver is currently in beta.
10
11This example demonstrates how to formulate and solve a simple
12Quadratic Programming (QP) problem using the cuOpt Python API.
13
14Problem:
15    minimize    x^2 + y^2
16    subject to  x + y >= 1
17                x, y >= 0
18
19This is a convex QP that minimizes the squared distance from the origin
20while requiring the sum of x and y to be at least 1.
21"""
22
23from cuopt.linear_programming.problem import (
24    MINIMIZE,
25    Problem,
26)
27
28
29def main():
30    # Create a new optimization problem
31    prob = Problem("Simple QP")
32
33    # Add variables with non-negative bounds
34    x = prob.addVariable(lb=0, name="x")
35    y = prob.addVariable(lb=0, name="y")
36
37    # Add constraint: x + y >= 1
38    prob.addConstraint(x + y >= 1)
39
40    # Set quadratic objective: minimize x^2 + y^2
41    # Using Variable * Variable to create quadratic terms
42    quad_obj = x * x + y * y
43    prob.setObjective(quad_obj, sense=MINIMIZE)
44
45    # Solve the problem
46    prob.solve()
47
48    # Print results
49    print(f"Optimal solution found in {prob.SolveTime:.2f} seconds")
50    print(f"x = {x.Value}")
51    print(f"y = {y.Value}")
52    print(f"Objective value = {prob.ObjValue}")
53
54
55if __name__ == "__main__":
56    main()

The response is as follows:

Optimal solution found in 0.01 seconds
x = 0.5
y = 0.5
Objective value = 0.5

Mixed Integer Linear Programming Example#

simple_milp_example.py

 1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
 2# SPDX-License-Identifier: Apache-2.0
 3# AFFILIATES. All rights reserved.
 4# SPDX-License-Identifier: Apache-2.0
 5#
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17"""
18Mixed Integer Linear Programming Example
19
20This example demonstrates how to:
21- Create a mixed integer programming problem
22- Add integer variables with bounds
23- Add constraints with integer variables
24- Solve a MIP problem
25
26Problem:
27    Maximize: 5*x + 3*y
28    Subject to:
29        2*x + 4*y >= 230
30        3*x + 2*y <= 190
31        10 <= y <= 50
32        x, y are integers
33
34Expected Output:
35    Optimal solution found in 0.00 seconds
36    x = 36.0
37    y = 41.0
38    Objective value = 303.0
39"""
40
41from cuopt.linear_programming.problem import Problem, INTEGER, MAXIMIZE
42from cuopt.linear_programming.solver_settings import SolverSettings
43
44
45def main():
46    """Run the simple MIP example."""
47    # Create a new MIP problem
48    problem = Problem("Simple MIP")
49
50    # Add integer variables with bounds
51    x = problem.addVariable(vtype=INTEGER, name="V_x")
52    y = problem.addVariable(lb=10, ub=50, vtype=INTEGER, name="V_y")
53
54    # Add constraints
55    problem.addConstraint(2 * x + 4 * y >= 230, name="C1")
56    problem.addConstraint(3 * x + 2 * y <= 190, name="C2")
57
58    # Set objective function
59    problem.setObjective(5 * x + 3 * y, sense=MAXIMIZE)
60
61    # Configure solver settings
62    settings = SolverSettings()
63    settings.set_parameter("time_limit", 60)
64
65    # Solve the problem
66    problem.solve(settings)
67
68    # Check solution status and results
69    if problem.Status.name == "Optimal":
70        print(f"Optimal solution found in {problem.SolveTime:.2f} seconds")
71        print(f"x = {x.getValue()}")
72        print(f"y = {y.getValue()}")
73        print(f"Objective value = {problem.ObjValue}")
74    else:
75        print(f"Problem status: {problem.Status.name}")
76
77
78if __name__ == "__main__":
79    main()

The response is as follows:

Optimal solution found in 0.00 seconds
x = 36.0
y = 40.99999999999999
Objective value = 303.0

Advanced Example: Production Planning#

production_planning_example.py

 1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
 2# SPDX-License-Identifier: Apache-2.0
 3# AFFILIATES. All rights reserved.
 4# SPDX-License-Identifier: Apache-2.0
 5#
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17"""
18Production Planning Example
19
20This example demonstrates a real-world application of MIP:
21- Production planning with resource constraints
22- Multiple constraint types (machine time, labor, materials)
23- Profit maximization
24
25Problem:
26    A factory produces two products (A and B)
27    - Product A: $50 profit per unit
28    - Product B: $30 profit per unit
29
30    Resources:
31    - Machine time: 2 hrs/unit A, 1 hr/unit B, max 100 hrs
32    - Labor: 1 hr/unit A, 3 hrs/unit B, max 120 hrs
33    - Material: 4 units/unit A, 2 units/unit B, max 200 units
34
35    Constraints:
36    - Minimum 10 units of Product A
37    - Minimum 15 units of Product B
38
39Expected Output:
40    === Production Planning Solution ===
41    Status: Optimal
42    Solve time: 0.09 seconds
43    Product A production: 36.0 units
44    Product B production: 28.0 units
45    Total profit: $2640.00
46"""
47
48from cuopt.linear_programming.problem import Problem, INTEGER, MAXIMIZE
49from cuopt.linear_programming.solver_settings import SolverSettings
50
51
52def main():
53    """Run the production planning example."""
54    # Production planning problem
55    problem = Problem("Production Planning")
56
57    # Decision variables: production quantities
58    # x1 = units of product A
59    # x2 = units of product B
60    x1 = problem.addVariable(lb=10, vtype=INTEGER, name="Product_A")
61    x2 = problem.addVariable(lb=15, vtype=INTEGER, name="Product_B")
62
63    # Resource constraints
64    # Machine time: 2 hours per unit of A, 1 hour per unit of B, max 100 hours
65    problem.addConstraint(2 * x1 + x2 <= 100, name="Machine_Time")
66
67    # Labor: 1 hour per unit of A, 3 hours per unit of B, max 120 hours
68    problem.addConstraint(x1 + 3 * x2 <= 120, name="Labor_Hours")
69
70    # Material: 4 units per unit of A, 2 units per unit of B, max 200 units
71    problem.addConstraint(4 * x1 + 2 * x2 <= 200, name="Material")
72
73    # Objective: maximize profit
74    # Profit: $50 per unit of A, $30 per unit of B
75    problem.setObjective(50 * x1 + 30 * x2, sense=MAXIMIZE)
76
77    # Solve with time limit
78    settings = SolverSettings()
79    settings.set_parameter("time_limit", 30)
80    problem.solve(settings)
81
82    # Display results
83    if problem.Status.name == "Optimal":
84        print("=== Production Planning Solution ===")
85        print(f"Status: {problem.Status.name}")
86        print(f"Solve time: {problem.SolveTime:.2f} seconds")
87        print(f"Product A production: {x1.getValue()} units")
88        print(f"Product B production: {x2.getValue()} units")
89        print(f"Total profit: ${problem.ObjValue:.2f}")
90
91    else:
92        print(f"Problem not solved optimally. Status: {problem.Status.name}")
93
94
95if __name__ == "__main__":
96    main()

The response is as follows:

=== Production Planning Solution ===

Status: Optimal
Solve time: 0.09 seconds
Product A production: 36.0 units
Product B production: 28.000000000000004 units
Total profit: $2640.00

Working with Expressions and Constraints#

expressions_constraints_example.py

 1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
 2# SPDX-License-Identifier: Apache-2.0
 3# AFFILIATES. All rights reserved.
 4# SPDX-License-Identifier: Apache-2.0
 5#
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17"""
18Working with Expressions and Constraints Example
19
20This example demonstrates:
21- Creating complex linear expressions
22- Using expressions in constraints
23- Different constraint types (<=, >=, ==)
24- Building constraints from multiple variables
25
26Problem:
27    Maximize: x + 2*y + 3*z
28    Subject to:
29        2*x + 3*y - z <= 100  (Complex_Constraint_1)
30        x + y + z >= 20        (Complex_Constraint_2)
31        x + y == 50            (Equality_Constraint)
32        x <= 30                (Upper_Bound_X)
33        y >= 10                (Lower_Bound_Y)
34        z <= 100               (Upper_Bound_Z)
35
36Expected Output:
37    === Expression Example Results ===
38    x = 0.0
39    y = 50.0
40    z = 100.0
41    Objective value = 400.0
42"""
43
44from cuopt.linear_programming.problem import Problem, MAXIMIZE
45from cuopt.linear_programming.solver_settings import SolverSettings
46
47
48def main():
49    """Run the expressions and constraints example."""
50    problem = Problem("Expression Example")
51
52    # Create variables
53    x = problem.addVariable(lb=0, name="x")
54    y = problem.addVariable(lb=0, name="y")
55    z = problem.addVariable(lb=0, name="z")
56
57    # Create complex expressions
58    expr1 = 2 * x + 3 * y - z
59    expr2 = x + y + z
60
61    # Add constraints using expressions
62    problem.addConstraint(expr1 <= 100, name="Complex_Constraint_1")
63    problem.addConstraint(expr2 >= 20, name="Complex_Constraint_2")
64
65    # Add constraint with different senses
66    problem.addConstraint(x + y == 50, name="Equality_Constraint")
67    problem.addConstraint(1 * x <= 30, name="Upper_Bound_X")
68    problem.addConstraint(1 * y >= 10, name="Lower_Bound_Y")
69    problem.addConstraint(1 * z <= 100, name="Upper_Bound_Z")
70
71    # Set objective
72    problem.setObjective(x + 2 * y + 3 * z, sense=MAXIMIZE)
73
74    settings = SolverSettings()
75    settings.set_parameter("time_limit", 20)
76
77    problem.solve(settings)
78
79    if problem.Status.name == "Optimal":
80        print("=== Expression Example Results ===")
81        print(f"x = {x.getValue()}")
82        print(f"y = {y.getValue()}")
83        print(f"z = {z.getValue()}")
84        print(f"Objective value = {problem.ObjValue}")
85    else:
86        print(f"Problem status: {problem.Status.name}")
87
88
89if __name__ == "__main__":
90    main()

The response is as follows:

=== Expression Example Results ===
x = 0.0
y = 50.0
z = 99.99999999999999
Objective value = 399.99999999999994

Working with Incumbent Solutions#

Incumbent solutions are intermediate feasible solutions found during the MIP solving process. They represent the best integer-feasible solution discovered so far and can be accessed through callback functions.

Note

Incumbent solutions are only available for Mixed Integer Programming (MIP) problems, not for pure Linear Programming (LP) problems.

incumbent_solutions_example.py

  1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
  2# SPDX-License-Identifier: Apache-2.0
  3# AFFILIATES. All rights reserved.
  4# SPDX-License-Identifier: Apache-2.0
  5#
  6# Licensed under the Apache License, Version 2.0 (the "License");
  7# you may not use this file except in compliance with the License.
  8# You may obtain a copy of the License at
  9#
 10# http://www.apache.org/licenses/LICENSE-2.0
 11#
 12# Unless required by applicable law or agreed to in writing, software
 13# distributed under the License is distributed on an "AS IS" BASIS,
 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15# See the License for the specific language governing permissions and
 16# limitations under the License.
 17"""
 18Working with Incumbent Solutions Example
 19
 20This example demonstrates:
 21- Using callbacks to receive intermediate solutions during MIP solving
 22- Tracking solution progress as the solver improves the solution
 23- Accessing incumbent (best so far) solutions before final optimum
 24- Custom callback class implementation
 25
 26Incumbent solutions are intermediate feasible solutions found during the MIP
 27solving process. They represent the best integer-feasible solution discovered
 28so far.
 29
 30Note:
 31    Incumbent solutions are only available for Mixed Integer Programming (MIP)
 32    problems, not for pure Linear Programming (LP) problems.
 33
 34Problem:
 35    Maximize: 5*x + 3*y
 36    Subject to:
 37        2*x + 4*y >= 230
 38        3*x + 2*y <= 190
 39        x, y are integers
 40
 41Expected Output:
 42    Incumbent 1: [ 0. 58.], cost: 174.00
 43    Incumbent 2: [36. 41.], cost: 303.00
 44
 45    === Final Results ===
 46    Problem status: Optimal
 47    Solve time: 0.16 seconds
 48    Final solution: x=36.0, y=41.0
 49    Final objective value: 303.00
 50"""
 51
 52from cuopt.linear_programming.problem import Problem, INTEGER, MAXIMIZE
 53from cuopt.linear_programming.solver_settings import SolverSettings
 54from cuopt.linear_programming.solver.solver_parameters import CUOPT_TIME_LIMIT
 55from cuopt.linear_programming.internals import GetSolutionCallback
 56
 57
 58# Create a callback class to receive incumbent solutions
 59class IncumbentCallback(GetSolutionCallback):
 60    """Callback to receive and track incumbent solutions during solving."""
 61
 62    def __init__(self):
 63        super().__init__()
 64        self.solutions = []
 65        self.n_callbacks = 0
 66
 67    def get_solution(self, solution, solution_cost):
 68        """
 69        Called whenever the solver finds a new incumbent solution.
 70
 71        Parameters
 72        ----------
 73        solution : array-like
 74            The variable values of the incumbent solution
 75        solution_cost : array-like
 76            The objective value of the incumbent solution
 77        """
 78        self.n_callbacks += 1
 79
 80        # Store the incumbent solution
 81        incumbent = {
 82            "solution": solution.copy_to_host(),
 83            "cost": solution_cost.copy_to_host()[0],
 84            "iteration": self.n_callbacks,
 85        }
 86        self.solutions.append(incumbent)
 87
 88        print(
 89            f"Incumbent {self.n_callbacks}: {incumbent['solution']}, "
 90            f"cost: {incumbent['cost']:.2f}"
 91        )
 92
 93
 94def main():
 95    """Run the incumbent solutions example."""
 96    # Create a more complex MIP problem that will generate multiple incumbents
 97    problem = Problem("Incumbent Example")
 98
 99    # Add integer variables
100    x = problem.addVariable(vtype=INTEGER)
101    y = problem.addVariable(vtype=INTEGER)
102
103    # Add constraints to create a problem that will generate multiple
104    # incumbents
105    problem.addConstraint(2 * x + 4 * y >= 230)
106    problem.addConstraint(3 * x + 2 * y <= 190)
107
108    # Set objective to maximize
109    problem.setObjective(5 * x + 3 * y, sense=MAXIMIZE)
110
111    # Configure solver settings with callback
112    settings = SolverSettings()
113    # Set the incumbent callback
114    incumbent_callback = IncumbentCallback()
115    settings.set_mip_callback(incumbent_callback)
116    # Allow enough time to find multiple incumbents
117    settings.set_parameter(CUOPT_TIME_LIMIT, 30)
118
119    # Solve the problem
120    problem.solve(settings)
121
122    # Display final results
123    print("\n=== Final Results ===")
124    print(f"Problem status: {problem.Status.name}")
125    print(f"Solve time: {problem.SolveTime:.2f} seconds")
126    print(f"Final solution: x={x.getValue()}, y={y.getValue()}")
127    print(f"Final objective value: {problem.ObjValue:.2f}")
128
129    # Display all incumbents found
130    print(
131        f"\nTotal incumbent solutions found: "
132        f"{len(incumbent_callback.solutions)}"
133    )
134
135
136if __name__ == "__main__":
137    main()

The response is as follows:

Optimal solution found.
Incumbent 1: [ 0. 58.], cost: 174.00
Incumbent 2: [36. 41.], cost: 303.00
Generated fast solution in 0.158467 seconds with objective 303.000000
Consuming B&B solutions, solution queue size 2
Solution objective: 303.000000 , relative_mip_gap 0.000000 solution_bound 303.000000 presolve_time 0.043211 total_solve_time 0.160270 max constraint violation 0.000000 max int violation 0.000000 max var bounds violation 0.000000 nodes 4 simplex_iterations 3

=== Final Results ===
Problem status: Optimal
Solve time: 0.16 seconds
Final solution: x=36.0, y=40.99999999999999
Final objective value: 303.00

Working with PDLP Warmstart Data#

Warmstart data allows to restart PDLP with a previous solution context. This should be used when you solve a new problem which is similar to the previous one.

Note

Warmstart data is only available for Linear Programming (LP) problems, not for Mixed Integer Linear Programming (MILP) problems.

pdlp_warmstart_example.py

  1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION &
  2# SPDX-License-Identifier: Apache-2.0
  3# AFFILIATES. All rights reserved.
  4# SPDX-License-Identifier: Apache-2.0
  5#
  6# Licensed under the Apache License, Version 2.0 (the "License");
  7# you may not use this file except in compliance with the License.
  8# You may obtain a copy of the License at
  9#
 10# http://www.apache.org/licenses/LICENSE-2.0
 11#
 12# Unless required by applicable law or agreed to in writing, software
 13# distributed under the License is distributed on an "AS IS" BASIS,
 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15# See the License for the specific language governing permissions and
 16# limitations under the License.
 17"""
 18Working with PDLP Warmstart Data Example
 19
 20This example demonstrates:
 21- Using PDLP (Primal-Dual hybrid gradient for LP) solver method
 22- Extracting warmstart data from a solved problem
 23- Reusing warmstart data to solve a similar problem faster
 24- Comparing solve times with and without warmstart
 25
 26Warmstart data allows restarting PDLP with a previous solution context.
 27This should be used when you solve a new problem which is similar to the
 28previous one.
 29
 30Note:
 31    Warmstart data is only available for Linear Programming (LP) problems,
 32    not for Mixed Integer Linear Programming (MILP) problems.
 33
 34Problem 1:
 35    Maximize: 2*x + y
 36    Subject to:
 37        4*x + 10*y <= 130
 38        8*x - 3*y >= 40
 39        x, y >= 0
 40
 41Problem 2 (similar):
 42    Maximize: 2*x + y
 43    Subject to:
 44        4*x + 10*y <= 100
 45        8*x - 3*y >= 50
 46        x, y >= 0
 47
 48Expected Output:
 49    Optimal solution found in 0.01 seconds
 50    x = 25.0
 51    y = 0.0
 52    Objective value = 50.0
 53"""
 54
 55from cuopt.linear_programming.problem import Problem, CONTINUOUS, MAXIMIZE
 56from cuopt.linear_programming.solver.solver_parameters import CUOPT_METHOD
 57from cuopt.linear_programming.solver_settings import (
 58    SolverSettings,
 59    SolverMethod,
 60)
 61
 62
 63def main():
 64    """Run the PDLP warmstart example."""
 65    print("=== Solving Problem 1 ===")
 66
 67    # Create a new problem
 68    problem = Problem("Simple LP")
 69
 70    # Add variables
 71    x = problem.addVariable(lb=0, vtype=CONTINUOUS, name="x")
 72    y = problem.addVariable(lb=0, vtype=CONTINUOUS, name="y")
 73
 74    # Add constraints
 75    problem.addConstraint(4 * x + 10 * y <= 130, name="c1")
 76    problem.addConstraint(8 * x - 3 * y >= 40, name="c2")
 77
 78    # Set objective function
 79    problem.setObjective(2 * x + y, sense=MAXIMIZE)
 80
 81    # Configure solver settings
 82    settings = SolverSettings()
 83    settings.set_parameter(CUOPT_METHOD, SolverMethod.PDLP)
 84
 85    # Solve the problem
 86    problem.solve(settings)
 87
 88    print(f"Problem 1 solved in {problem.SolveTime:.4f} seconds")
 89    print(f"x = {x.getValue()}, y = {y.getValue()}")
 90    print(f"Objective value = {problem.ObjValue}")
 91
 92    # Get the warmstart data
 93    warmstart_data = problem.get_pdlp_warm_start_data()
 94    print(
 95        f"\nWarmstart data extracted (primal solution size: "
 96        f"{len(warmstart_data.current_primal_solution)})"
 97    )
 98
 99    print("\n=== Solving Problem 2 with Warmstart ===")
100
101    # Create a new problem
102    new_problem = Problem("Warmstart LP")
103
104    # Add variables
105    x = new_problem.addVariable(lb=0, vtype=CONTINUOUS, name="x")
106    y = new_problem.addVariable(lb=0, vtype=CONTINUOUS, name="y")
107
108    # Add constraints (slightly different from problem 1)
109    new_problem.addConstraint(4 * x + 10 * y <= 100, name="c1")
110    new_problem.addConstraint(8 * x - 3 * y >= 50, name="c2")
111
112    # Set objective function
113    new_problem.setObjective(2 * x + y, sense=MAXIMIZE)
114
115    # Configure solver settings with warmstart data
116    settings.set_pdlp_warm_start_data(warmstart_data)
117
118    # Solve the problem
119    new_problem.solve(settings)
120
121    # Check solution status
122    if new_problem.Status.name == "Optimal":
123        print(f"Optimal solution found in {new_problem.SolveTime:.2f} seconds")
124        print(f"x = {x.getValue()}")
125        print(f"y = {y.getValue()}")
126        print(f"Objective value = {new_problem.ObjValue}")
127    else:
128        print(f"Problem status: {new_problem.Status.name}")
129
130
131if __name__ == "__main__":
132    main()

The response is as follows:

Optimal solution found in 0.01 seconds
x = 25.000000000639382
y = 0.0
Objective value = 50.000000001278764