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
37 changes: 37 additions & 0 deletions cpp/include/cuopt/mathematical_optimization/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,41 @@
#define CUOPT_BARRIER_ITERATIVE_REFINEMENT_OFF 0
#define CUOPT_BARRIER_ITERATIVE_REFINEMENT_ON 1

/* @brief Scalar problem attribute selectors
* Passed as cuopt_int_t; the valid set depends on the accessor's value type. */
#define CUOPT_ATTR_NUM_VARIABLES 0
#define CUOPT_ATTR_NUM_CONSTRAINTS 1
#define CUOPT_ATTR_NUM_NONZEROS 2
#define CUOPT_ATTR_NUM_INTEGERS 3
#define CUOPT_ATTR_OBJECTIVE_SENSE 4
#define CUOPT_ATTR_OBJECTIVE_OFFSET 5
#define CUOPT_ATTR_OBJECTIVE_SCALING_FACTOR 6
#define CUOPT_ATTR_PROBLEM_CATEGORY 7
#define CUOPT_ATTR_IS_MIP 8
#define CUOPT_ATTR_HAS_QUADRATIC_OBJECTIVE 9
#define CUOPT_ATTR_HAS_QUADRATIC_CONSTRAINTS 10
/* NOTE: HAS_QUADRATIC_OBJECTIVE / HAS_QUADRATIC_CONSTRAINTS report presence only. The quadratic
* objective matrix (Q) and quadratic constraint data are not currently retrievable through any
* getter */

/* @brief Numeric/char array problem attribute selectors
* (see cuOptGetProblem{Float,Char}ArrayAttribute; sized by num_variables / num_constraints).
* The constraint matrix is retrieved via cuOptGetConstraintMatrix / cuOptGetConstraintMatrixCSC,
* not through these selectors. Passed as cuopt_int_t. Numbered in a separate range from the scalar
* selectors so a selector from the wrong family fails validation (there is no compile-time type).
*/
#define CUOPT_ARRAY_ATTR_OBJECTIVE_COEFFICIENTS 100
#define CUOPT_ARRAY_ATTR_VARIABLE_LOWER_BOUNDS 101
#define CUOPT_ARRAY_ATTR_VARIABLE_UPPER_BOUNDS 102
#define CUOPT_ARRAY_ATTR_CONSTRAINT_LOWER_BOUNDS 103
#define CUOPT_ARRAY_ATTR_CONSTRAINT_UPPER_BOUNDS 104
#define CUOPT_ARRAY_ATTR_CONSTRAINT_RHS 105
#define CUOPT_ARRAY_ATTR_CONSTRAINT_SENSE 106
#define CUOPT_ARRAY_ATTR_VARIABLE_TYPES 107

/* @brief String-array problem attribute selectors (see cuOptGetProblemStringArrayAttribute).
* Passed as cuopt_int_t; numbered in a separate range from the scalar and array selectors. */
#define CUOPT_STRING_ARRAY_VARIABLE_NAMES 200
#define CUOPT_STRING_ARRAY_ROW_NAMES 201

#endif // CUOPT_CONSTANTS_H
88 changes: 87 additions & 1 deletion cpp/include/cuopt/mathematical_optimization/cuopt_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ cuopt_int_t cuOptGetObjectiveCoefficients(cuOptOptimizationProblem problem,
*/
cuopt_int_t cuOptGetNumNonZeros(cuOptOptimizationProblem problem, cuopt_int_t* num_non_zeros_ptr);

/** @brief Get the constraint matrix of an optimization problem in compressed sparse row format.
/** @brief Get the linear constraint matrix of an optimization problem in compressed sparse row
* format. This is the matrix of the linear constraints only; quadratic constraint terms (if any)
* are not included.
*
* @param[in] problem - The optimization problem.
*
Expand All @@ -586,6 +588,31 @@ cuopt_int_t cuOptGetConstraintMatrix(cuOptOptimizationProblem problem,
cuopt_int_t* constraint_matrix_column_indices_ptr,
cuopt_float_t* constraint_matrix_coefficients_ptr);

/** @brief Get the linear constraint matrix of an optimization problem in compressed sparse column
* format. This is the matrix of the linear constraints only; quadratic constraint terms (if any)
* are not included.
*
* @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 cuOptGetNumVariables) 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
* indices of the non-zero entries of the constraint matrix.
*
* @param[out] constraint_matrix_coefficients_ptr - A pointer to an array of type cuopt_float_t of
* size equal to the number of nonzeros that on output will contain the coefficients of the
* non-zero entries of the constraint matrix.
*
* @return A status code indicating success or failure.
*/
cuopt_int_t cuOptGetConstraintMatrixCSC(cuOptOptimizationProblem problem,
cuopt_int_t* constraint_matrix_column_offsets_ptr,
cuopt_int_t* constraint_matrix_row_indices_ptr,
cuopt_float_t* constraint_matrix_coefficients_ptr);

/** @brief Get the constraint sense of an optimization problem.
*
* @param[in] problem - The optimization problem.
Expand Down Expand Up @@ -1055,6 +1082,65 @@ cuopt_int_t cuOptGetDualObjectiveValue(cuOptSolution solution,
*/
cuopt_int_t cuOptGetReducedCosts(cuOptSolution solution, cuopt_float_t* reduced_cost_ptr);

/* -------------------------------------------------------------------------- */
/* Generic problem attributes */
/* -------------------------------------------------------------------------- */

/*
* Attribute selectors are the CUOPT_ATTR_*, CUOPT_ARRAY_ATTR_*, and
* CUOPT_STRING_ARRAY_* integer constants defined in constants.h, passed as cuopt_int_t.
*
* These accessors use copy-out semantics: the caller allocates the output buffer and cuOpt copies
* values into it. Array attributes are sized by the problem dimensions: variable-indexed arrays
* have num_variables entries and constraint-indexed arrays have num_constraints entries (see
* cuOptGetNumVariables / cuOptGetNumConstraints). The sole exception to copy-out is the
* string-array getter, which fills a caller-provided array of pointers with borrowed pointers into
* cuOpt-owned string storage; those pointers are valid until the problem is modified or destroyed
* and must not be freed.
*
* The constraint matrix is retrieved via cuOptGetConstraintMatrix (CSR) /
* cuOptGetConstraintMatrixCSC.
*
* TODO: quadratic data is not yet retrievable. CUOPT_ATTR_HAS_QUADRATIC_OBJECTIVE and
* CUOPT_ATTR_HAS_QUADRATIC_CONSTRAINTS report presence only; there is no getter for the
* quadratic objective matrix (Q) or the quadratic constraint rows.
*/

/** @brief Get a scalar integer problem attribute (a CUOPT_ATTR_* with an integer value). */
cuopt_int_t cuOptGetProblemIntAttribute(cuOptOptimizationProblem problem,
cuopt_int_t attribute,
cuopt_int_t* value_out);

/** @brief Get a scalar floating-point problem attribute (objective offset / scaling factor). */
cuopt_int_t cuOptGetProblemFloatAttribute(cuOptOptimizationProblem problem,
cuopt_int_t attribute,
cuopt_float_t* value_out);

/** @brief Copy a floating-point array attribute into out. count must equal num_variables for
* variable-indexed attributes or num_constraints for constraint-indexed attributes (see
* cuOptGetNumVariables / cuOptGetNumConstraints). */
cuopt_int_t cuOptGetProblemFloatArrayAttribute(cuOptOptimizationProblem problem,
cuopt_int_t attribute,
cuopt_float_t* out,
cuopt_int_t count);

/** @brief Copy a char array attribute (constraint sense or variable types) into out. count must
* equal num_constraints (constraint sense) or num_variables (variable types) (see
* cuOptGetNumConstraints / cuOptGetNumVariables). */
cuopt_int_t cuOptGetProblemCharArrayAttribute(cuOptOptimizationProblem problem,
cuopt_int_t attribute,
char* out,
cuopt_int_t count);

/** @brief Fill a caller-provided array of `count` pointers with borrowed pointers to cuOpt-owned
* strings (CUOPT_STRING_ARRAY_VARIABLE_NAMES or _ROW_NAMES). count must equal
* num_variables or num_constraints respectively. The returned pointers are valid until the problem
* is modified or destroyed; do not free them. */
cuopt_int_t cuOptGetProblemStringArrayAttribute(cuOptOptimizationProblem problem,
cuopt_int_t attribute,
const char** strings_out,
cuopt_int_t count);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions cpp/src/pdlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(LP_CORE_FILES
set(LP_ADAPTER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/utilities/cython_solve.cu
${CMAKE_CURRENT_SOURCE_DIR}/cuopt_c.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cuopt_c_attributes.cpp
)

# Choose which files to include based on build mode
Expand Down
Loading
Loading