Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/include/cuopt/mathematical_optimization/cuopt_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ cuopt_int_t cuOptGetConstraintMatrixCSR(cuOptOptimizationProblem problem,
* @param[in] problem - The optimization problem.
*
* @param[out] constraint_matrix_column_offsets_ptr - A pointer to an array of type cuopt_int_t of
* size num_variables + 1 (see cuOptGetProblemIntAttribute) that on output will contain the column
* offsets of the constraint matrix.
* size num_variables + 1 that on output will contain the column offsets of the constraint
* matrix.
*
* @param[out] constraint_matrix_row_indices_ptr - A pointer to an array of type cuopt_int_t of size
* equal to the number of nonzeros (see cuOptGetNumNonZeros) that on output will contain the row
Expand Down
13 changes: 12 additions & 1 deletion docs/cuopt/source/cuopt-c/convex/convex-c-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ For problems with quadratic constraints, first create a problem, and then use
Support for quadratic constraints is currently in **beta**. ``cuOptAddQuadraticConstraint``
supports three types of quadratic constraints:
- **Convex quadratic constraints** of the form ``x^T Q x + d^T x <= alpha`` where ``H=(Q+Q^T)/2`` is a symmetric positive semidefinite matrix. `Q` need not be symmetric.
- **Second-order cone constraints** of the form ``sum_{i=1}^n x_i^2 <= x_0``, ``x_0 >= 0``
- **Second-order cone constraints** of the form ``sum_{i=1}^n x_i^2 <= x_0^2``, ``x_0 >= 0``
- **Rotated second-order cone constraints** of the form ``sum_{i=2}^n x_i^2 - 2 * x_0 * x_1 <= 0``, ``x_0 >= 0``, ``x_1 >= 0`` (supply ``Q[x_0, x_1] = -2`` in COO, or ``-x_0*x_1`` for the ``<= x_0*x_1`` cone form; see :doc:`/convex-features`)

Only ``CUOPT_LESS_THAN`` and ``CUOPT_GREATER_THAN`` sense is supported; equality constraints are not supported.
Expand Down Expand Up @@ -134,6 +134,7 @@ The following functions may be used to get information about an `cuOptimizationP
.. doxygenfunction:: cuOptGetNumNonZeros
.. doxygenfunction:: cuOptGetConstraintMatrix
.. doxygenfunction:: cuOptGetConstraintMatrixCSR
.. doxygenfunction:: cuOptGetConstraintMatrixCSC
.. doxygenfunction:: cuOptGetConstraintSense
.. doxygenfunction:: cuOptGetConstraintRightHandSide
.. doxygenfunction:: cuOptGetConstraintLowerBounds
Expand Down Expand Up @@ -300,6 +301,16 @@ These constants are used to configure `CUOPT_MULTIGPU_PDLP_PARTITIONER` via :c:f
.. doxygendefine:: CUOPT_MULTIGPU_PDLP_PARTITIONER_KAMINPAR
.. doxygendefine:: CUOPT_MULTIGPU_PDLP_PARTITIONER_ROUND_ROBIN

Presolve Constants
------------------
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

These constants are used to configure `CUOPT_PRESOLVE` via :c:func:`cuOptSetIntegerParameter`.

.. doxygendefine:: CUOPT_PRESOLVE_DEFAULT
.. doxygendefine:: CUOPT_PRESOLVE_OFF
.. doxygendefine:: CUOPT_PRESOLVE_PAPILO
.. doxygendefine:: CUOPT_PRESOLVE_PSLP

.. _barrier-iterative-refinement-constants:

Barrier Iterative Refinement Constants
Expand Down
26 changes: 13 additions & 13 deletions docs/cuopt/source/cuopt-c/convex/convex-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LP Example with Data

This example demonstrates how to use the LP solver in C. More details on the API can be found in :doc:`C API <convex-c-api>`.

The example code is available at ``examples/cuopt-c/lp/simple_lp_example.c`` (:download:`download <examples/simple_lp_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/simple_lp_example.c`` (:download:`download <examples/simple_lp_example.c>`):

.. literalinclude:: examples/simple_lp_example.c
:language: c
Expand All @@ -22,9 +22,9 @@ If you have built it locally, libcuopt.so will be in the build directory ``cpp/b
.. code-block:: bash

# Find the cuopt header file and assign to INCLUDE_PATH
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/linear_programming/*" -printf "%h\n" | sed 's/\/linear_programming//' 2>/dev/null)
# Find the libcuopt library and assign to LIBCUOPT_LIBRARY_PATH
LIBCUOPT_LIBRARY_PATH=$(find / -name "libcuopt.so" 2>/dev/null)
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/mathematical_optimization/*" -printf "%h\n" 2>/dev/null | head -1 | sed 's/\/cuopt\/mathematical_optimization$//')
# Find the libcuopt library directory and assign to LIBCUOPT_LIBRARY_PATH
LIBCUOPT_LIBRARY_PATH=$(dirname $(find / -name "libcuopt.so" 2>/dev/null | head -1))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved


Build and run the example
Expand Down Expand Up @@ -79,7 +79,7 @@ format is dispatched from the filename extension (case-insensitive):
their ``.gz`` / ``.bz2`` variants → MPS parser. Unknown extensions are
rejected. See :ref:`lp-file-example-c` for an LP counterpart.

The example code is available at ``examples/cuopt-c/lp/mps_file_example.c`` (:download:`download <examples/mps_file_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/mps_file_example.c`` (:download:`download <examples/mps_file_example.c>`):

.. literalinclude:: examples/mps_file_example.c
:language: c
Expand All @@ -93,9 +93,9 @@ If you have built it locally, libcuopt.so will be in the build directory ``cpp/b
.. code-block:: bash

# Find the cuopt header file and assign to INCLUDE_PATH
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/linear_programming/*" -printf "%h\n" | sed 's/\/linear_programming//' 2>/dev/null)
# Find the libcuopt library and assign to LIBCUOPT_LIBRARY_PATH
LIBCUOPT_LIBRARY_PATH=$(find / -name "libcuopt.so" 2>/dev/null)
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/mathematical_optimization/*" -printf "%h\n" 2>/dev/null | head -1 | sed 's/\/cuopt\/mathematical_optimization$//')
# Find the libcuopt library directory and assign to LIBCUOPT_LIBRARY_PATH
LIBCUOPT_LIBRARY_PATH=$(dirname $(find / -name "libcuopt.so" 2>/dev/null | head -1))

A sample MPS file (:download:`download sample.mps <https://raw.githubusercontent.com/BUGSENG/PPL/devel/demos/ppl_lpsol/examples/sample.mps>`):

Expand Down Expand Up @@ -157,7 +157,7 @@ rejected. See the ``read_lp`` declaration in
``cuopt/mathematical_optimization/io/parser.hpp`` for the supported subset of
the LP format.

The example code is available at ``examples/cuopt-c/lp/lp_file_example.c`` (:download:`download <examples/lp_file_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/lp_file_example.c`` (:download:`download <examples/lp_file_example.c>`):

.. literalinclude:: examples/lp_file_example.c
:language: c
Expand Down Expand Up @@ -187,7 +187,7 @@ Simple Quadratic Programming Example

This example demonstrates how to use the cuOpt C API for quadratic programming.

The example code is available at ``examples/cuopt-c/lp/simple_qp_example.c`` (:download:`download <examples/simple_qp_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/simple_qp_example.c`` (:download:`download <examples/simple_qp_example.c>`):

.. literalinclude:: examples/simple_qp_example.c
:language: c
Expand Down Expand Up @@ -227,7 +227,7 @@ Simple Second-Order Cone Programming Example

This example builds an SOCP directly with the C API: a linear problem is created with :c:func:`cuOptCreateProblem`, then a second-order cone constraint is added with :c:func:`cuOptAddQuadraticConstraint`. It minimizes ``x3`` subject to ``x1 + x2 >= 2`` and the cone ``||(x1, x2)||_2 <= x3``, written as the quadratic inequality ``x1^2 + x2^2 - x3^2 <= 0``. cuOpt detects the second-order cone structure and solves with the barrier method.

The example code is available at ``examples/cuopt-c/lp/simple_socp_example.c`` (:download:`download <examples/simple_socp_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/simple_socp_example.c`` (:download:`download <examples/simple_socp_example.c>`):

.. literalinclude:: examples/simple_socp_example.c
:language: c
Expand Down Expand Up @@ -273,7 +273,7 @@ cone ``x1^2 + x2^2 <= x3*x4`` is expressed as ``x1^2 + x2^2 - x3*x4 <= 0``. See
for other RSOC forms.
It minimizes ``x3 + x4`` subject to ``x1 + x2 >= 2`` and the rotated cone.

The example code is available at ``examples/cuopt-c/lp/rotated_socp_example.c`` (:download:`download <examples/rotated_socp_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/rotated_socp_example.c`` (:download:`download <examples/rotated_socp_example.c>`):

.. literalinclude:: examples/rotated_socp_example.c
:language: c
Expand Down Expand Up @@ -320,7 +320,7 @@ This example adds a general convex quadratic constraint with
``2*x^2 + 2*x*y + 2*y^2 <= 6``. Note that the quadratic matrix Q that encodes this
constraint need not be symmetric. Here the term ``2*x*y`` is supplied as a single entry ``Q[0,1] = 2``.

The example code is available at ``examples/cuopt-c/lp/general_quadratic_example.c`` (:download:`download <examples/general_quadratic_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/convex/examples/general_quadratic_example.c`` (:download:`download <examples/general_quadratic_example.c>`):

.. literalinclude:: examples/general_quadratic_example.c
:language: c
Expand Down
52 changes: 31 additions & 21 deletions docs/cuopt/source/cuopt-c/convex/examples/simple_qp_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ cuopt_int_t test_simple_qp()
// 0 is the coefficient of the linear term on y
cuopt_float_t linear_objective_coefficients[] = {0.0, 0.0};

// Quadratic objective matrix
// Quadratic objective matrix in COO format
// From the objective function: minimize x^2 + y^2
// 1 is the coefficient of the quadratic term on x^2
// 1 is the coefficient of the quadratic term on y^2
cuopt_float_t quadratic_objective_matrix_values[] = {1.0, 1.0};
cuopt_int_t quadratic_objective_matrix_row_offsets[] = {0, 1, 2};
cuopt_int_t quadratic_objective_matrix_column_indices[] = {0, 1};
cuopt_int_t quadratic_num_entries = 2;
cuopt_int_t quadratic_objective_row_indices[] = {0, 1};
cuopt_int_t quadratic_objective_column_indices[] = {0, 1};
cuopt_float_t quadratic_objective_values[] = {1.0, 1.0};

// Constraint bounds
// From the constraints:
Expand All @@ -115,28 +116,37 @@ cuopt_int_t test_simple_qp()

printf("Creating and solving simple QP problem...\n");

// Create the problem
status = cuOptCreateQuadraticProblem(num_constraints,
num_variables,
CUOPT_MINIMIZE,
0.0, // objective offset
linear_objective_coefficients,
quadratic_objective_matrix_row_offsets,
quadratic_objective_matrix_column_indices,
quadratic_objective_matrix_values,
row_offsets,
column_indices,
values,
constraint_sense,
constraint_rhs,
var_lower_bounds,
var_upper_bounds,
&problem);
// Create the problem with its linear data
status = cuOptCreateProblem(num_constraints,
num_variables,
CUOPT_MINIMIZE,
0.0, // objective offset
linear_objective_coefficients,
row_offsets,
column_indices,
values,
constraint_sense,
constraint_rhs,
var_lower_bounds,
var_upper_bounds,
variable_types,
&problem);
if (status != CUOPT_SUCCESS) {
printf("Error creating problem: %d\n", status);
goto DONE;
}

// Set the quadratic objective
status = cuOptSetQuadraticObjective(problem,
quadratic_num_entries,
quadratic_objective_row_indices,
quadratic_objective_column_indices,
quadratic_objective_values);
if (status != CUOPT_SUCCESS) {
printf("Error setting quadratic objective: %d\n", status);
goto DONE;
}

// Create solver settings
status = cuOptCreateSolverSettings(&settings);
if (status != CUOPT_SUCCESS) {
Expand Down
9 changes: 9 additions & 0 deletions docs/cuopt/source/cuopt-c/mip/mip-c-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ These constants are used to configure `CUOPT_MIP_DETERMINISM_MODE` via :c:func:`

.. doxygendefine:: CUOPT_MODE_OPPORTUNISTIC
.. doxygendefine:: CUOPT_MODE_DETERMINISTIC

MIP Scaling Constants
---------------------

These constants are used to configure `CUOPT_MIP_SCALING` via :c:func:`cuOptSetIntegerParameter`.

.. doxygendefine:: CUOPT_MIP_SCALING_OFF
.. doxygendefine:: CUOPT_MIP_SCALING_ON
.. doxygendefine:: CUOPT_MIP_SCALING_NO_OBJECTIVE
12 changes: 6 additions & 6 deletions docs/cuopt/source/cuopt-c/mip/mip-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Example with Data

This example demonstrates how to use the MIP solver in C. More details on the API can be found in :doc:`MIP C API <mip-c-api>`.

The example code is available at ``../lp-milp/examples/simple_milp_example.c`` (:download:`download <examples/simple_milp_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/mip/examples/simple_milp_example.c`` (:download:`download <examples/simple_milp_example.c>`):

.. literalinclude:: examples/simple_milp_example.c
:language: c
Expand All @@ -21,9 +21,9 @@ If you have built it locally, libcuopt.so will be in the build directory ``cpp/b
.. code-block:: bash

# Find the cuopt header file and assign to INCLUDE_PATH
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/linear_programming/*" -printf "%h\n" | sed 's/\/linear_programming//' 2>/dev/null)
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/mathematical_optimization/*" -printf "%h\n" 2>/dev/null | head -1 | sed 's/\/cuopt\/mathematical_optimization$//')
# Find the libcuopt library directory and assign to LIBCUOPT_LIBRARY_PATH
LIBCUOPT_LIBRARY_PATH=$(dirname $(find / -name "libcuopt.so" 2>/dev/null))
LIBCUOPT_LIBRARY_PATH=$(dirname $(find / -name "libcuopt.so" 2>/dev/null | head -1))


Build and run the example
Expand Down Expand Up @@ -80,7 +80,7 @@ Example with MPS File

This example demonstrates how to use the cuOpt solver in C to solve an MPS file.

The example code is available at ``examples/milp_mps_example.c`` (:download:`download <examples/milp_mps_example.c>`):
The example code is available at ``docs/cuopt/source/cuopt-c/mip/examples/milp_mps_example.c`` (:download:`download <examples/milp_mps_example.c>`):

.. literalinclude:: examples/milp_mps_example.c
:language: c
Expand All @@ -94,9 +94,9 @@ If you have built it locally, libcuopt.so will be in the build directory ``cpp/b
.. code-block:: bash

# Find the cuopt header file and assign to INCLUDE_PATH
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/linear_programming/*" -printf "%h\n" | sed 's/\/linear_programming//' 2>/dev/null)
INCLUDE_PATH=$(find / -name "cuopt_c.h" -path "*/mathematical_optimization/*" -printf "%h\n" 2>/dev/null | head -1 | sed 's/\/cuopt\/mathematical_optimization$//')
# Find the libcuopt library directory and assign to LIBCUOPT_LIBRARY_PATH
LIBCUOPT_LIBRARY_PATH=$(dirname $(find / -name "libcuopt.so" 2>/dev/null))
LIBCUOPT_LIBRARY_PATH=$(dirname $(find / -name "libcuopt.so" 2>/dev/null | head -1))

A sample MIP MPS file (:download:`download mip_sample.mps <https://raw.githubusercontent.com/coin-or/SYMPHONY/master/Datasets/sample.mps>`):

Expand Down
4 changes: 2 additions & 2 deletions docs/cuopt/source/cuopt-server/examples/milp-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ Aborting a Running Job In CLI

UUID that is returned by the solver while the solver is trying to find a solution so users can come back and check the status or query for results.

This aborts a job with UUID if it's in running state.
This aborts a job with UUID if it's queued or running.

.. code-block:: bash

# Please update ip and port if the server is running on a different IP address or port
export ip="localhost"
export port=5000
cuopt_sh -d -r -q <UUID> -i $ip -p $port
cuopt_sh -d <UUID> -i $ip -p $port
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,8 @@ def main():
ip="localhost", port=5000
)

# Delete the job if it is still queued or running
# Parameters:
# - job_uuid: The UUID of the job to abort
# - running=True: Abort if the job is currently running
# - queued=True: Abort if the job is in the queue
# - cached=False: Don't delete from cache (only abort active/queued jobs)
response = cuopt_service_client.delete(
job_uuid, running=True, queued=True, cached=False
)
# Abort the job if it is still queued or running
response = cuopt_service_client.delete(job_uuid)

print(f"Response: {response}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ echo "Aborting job with UUID: $UUID"

# Abort the job
# -d: Delete/abort
# -r: If running
# -q: If queued
cuopt_sh -d -r -q $UUID -i $ip -p $port
cuopt_sh -d $UUID -i $ip -p $port

echo "Job abort request sent"
echo ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Initial Solution

Previously run solutions or uploaded solutions can be used as the initial solution for new requests using previously run reqIds as follows:

.. note::
This example uploads a solution, which is only supported by the :ref:`legacy HTTP server <legacy-http-server>`. The HTTP proxy server returns 501 for uploaded solutions. See :ref:`legacy-http-differences`.

:download:`initial_solution_example.py <routing/examples/initial_solution_example.py>`

.. literalinclude:: routing/examples/initial_solution_example.py
Expand Down Expand Up @@ -255,6 +258,9 @@ Uploading a Solution

Users can also upload a solution which might have been saved for later runs.

.. note::
Uploaded solutions are only supported by the :ref:`legacy HTTP server <legacy-http-server>`. The HTTP proxy server returns 501. See :ref:`legacy-http-differences`.

.. code-block:: shell

# Please update ip and port if the server is running on a different IP address or port
Expand Down
Loading