Skip to content

Commit c4659ce

Browse files
authored
Merge pull request #683 from NVIDIA/release/25.12
Forward-merge release/25.12 into main
2 parents 7ed353f + e3892d3 commit c4659ce

File tree

6 files changed

+784
-11
lines changed

6 files changed

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

docs/cuopt/source/cuopt-python/lp-milp/lp-milp-api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ LP and MILP API Reference
1616
:members:
1717
:undoc-members:
1818

19+
.. note::
20+
Quadratic Programming support (QuadraticExpression, QuadraticTerm) is currently **experimental** and may change in future releases.
21+
22+
.. autoclass:: cuopt.linear_programming.problem.QuadraticExpression
23+
:members:
24+
:undoc-members:
25+
1926
.. autoclass:: cuopt.linear_programming.problem.Constraint
2027
:members:
2128
:undoc-members:

docs/cuopt/source/cuopt-python/lp-milp/lp-milp-examples.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ The response is as follows:
2727
y = 0.0
2828
Objective value = 10.0
2929
30+
Simple Quadratic Programming Example
31+
------------------------------------
32+
33+
.. note::
34+
Quadratic Programming support is currently **experimental** and may change in future releases.
35+
36+
:download:`simple_qp_example.py <examples/simple_qp_example.py>`
37+
38+
.. literalinclude:: examples/simple_qp_example.py
39+
:language: python
40+
:linenos:
41+
42+
The response is as follows:
43+
44+
.. code-block:: text
45+
46+
Optimal solution found in 0.01 seconds
47+
x = 0.5
48+
y = 0.5
49+
Objective value = 0.5
50+
3051
Mixed Integer Linear Programming Example
3152
----------------------------------------
3253

docs/cuopt/source/lp-features.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ The LP solver can be accessed in the following ways:
2323

2424
Each option provide the same powerful linear optimization capabilities while offering flexibility in deployment and integration.
2525

26+
Quadratic Programming (QP)
27+
--------------------------
28+
29+
.. note::
30+
Quadratic Programming support is currently **experimental** and may change in future releases.
31+
32+
cuOpt supports Quadratic Programming problems with quadratic objectives of the form:
33+
34+
.. code-block:: text
35+
36+
minimize (or maximize) x'Qx + c'x
37+
subject to Ax {<=, =, >=} b
38+
lb <= x <= ub
39+
40+
where Q is a symmetric positive semi-definite matrix for minimization problems.
41+
42+
In the Python API, quadratic objectives can be constructed using the ``QuadraticExpression`` class or by multiplying variables directly:
43+
44+
.. code-block:: python
45+
46+
from cuopt.linear_programming.problem import Problem, MINIMIZE
47+
48+
prob = Problem("QP Example")
49+
x = prob.addVariable(lb=0, name="x")
50+
y = prob.addVariable(lb=0, name="y")
51+
52+
# Create quadratic objective: x^2 + 2*x*y + y^2
53+
quad_obj = x * x + 2 * (x * y) + y * y
54+
prob.setObjective(quad_obj, sense=MINIMIZE)
55+
2656
Variable Bounds
2757
---------------
2858

0 commit comments

Comments
 (0)