cuopt-numerical-optimization-api-c

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

cuOpt Numerical Optimization — C API

cuOpt数值优化——C API

Solve LP, MILP, and QP problems via the cuOpt C API. The same library, headers, build pattern, and core calls (
cuOptCreate*Problem
,
cuOptSolve
,
cuOptGetObjectiveValue
) apply across all three; QP extends the API with quadratic-objective creation calls.
Confirm problem type and formulation (variables, objective, constraints, variable types) before coding.
This skill is C only.
通过cuOpt C API求解LP、MILP和QP问题。三者使用相同的库、头文件、构建模式以及核心调用(
cuOptCreate*Problem
cuOptSolve
cuOptGetObjectiveValue
);QP通过新增二次目标创建调用扩展了API。
编码前请确认问题类型和公式(变量、目标函数、约束条件、变量类型)。
本技能仅支持C语言

Quick Reference: C API

快速参考:C API

c
#include <cuopt/linear_programming/cuopt_c.h>

// CSR format for constraints
cuopt_int_t row_offsets[] = {0, 2, 4};
cuopt_int_t col_indices[] = {0, 1, 0, 1};
cuopt_float_t values[] = {2.0, 3.0, 4.0, 2.0};
char var_types[] = {CUOPT_CONTINUOUS, CUOPT_INTEGER};

cuOptCreateRangedProblem(
    num_constraints, num_variables, CUOPT_MINIMIZE,
    0.0, objective_coefficients,
    row_offsets, col_indices, values,
    constraint_lower, constraint_upper,
    var_lower, var_upper, var_types,
    &problem
);
cuOptSolve(problem, settings, &solution);
cuOptGetObjectiveValue(solution, &obj_value);
c
#include <cuopt/linear_programming/cuopt_c.h>

// CSR格式的约束条件
cuopt_int_t row_offsets[] = {0, 2, 4};
cuopt_int_t col_indices[] = {0, 1, 0, 1};
cuopt_float_t values[] = {2.0, 3.0, 4.0, 2.0};
char var_types[] = {CUOPT_CONTINUOUS, CUOPT_INTEGER};

cuOptCreateRangedProblem(
    num_constraints, num_variables, CUOPT_MINIMIZE,
    0.0, objective_coefficients,
    row_offsets, col_indices, values,
    constraint_lower, constraint_upper,
    var_lower, var_upper, var_types,
    &problem
);
cuOptSolve(problem, settings, &solution);
cuOptGetObjectiveValue(solution, &obj_value);

QP via C API (beta)

通过C API使用QP(测试版)

QP uses the same library, include/lib paths, and build pattern as LP/MILP — only the problem-creation call differs (it accepts a quadratic objective). See the cuOpt C headers (
cpp/include/cuopt/linear_programming/
) for the QP-specific creation/solve calls and the repo docs at
docs/cuopt/source/cuopt-c/lp-qp-milp/
for end-to-end QP examples.
QP rules:
  • MINIMIZE only (
    CUOPT_MINIMIZE
    ). To maximize
    f(x)
    , negate objective coefficients and Q entries.
  • Continuous variables only — set
    CUOPT_CONTINUOUS
    for every variable; integer QP is not supported.
  • Q should be PSD for a convex problem.
QP使用与LP/MILP相同的库、头文件/库路径以及构建模式——仅问题创建调用不同(它支持传入二次目标函数)。请查看cuOpt C头文件(
cpp/include/cuopt/linear_programming/
)获取QP专属的创建/求解调用,以及仓库文档
docs/cuopt/source/cuopt-c/lp-qp-milp/
获取完整的QP示例。
QP规则:
  • 仅支持最小化
    CUOPT_MINIMIZE
    )。若要最大化
    f(x)
    ,请对目标系数和Q矩阵元素取负值。
  • 仅支持连续变量——所有变量都需设置为
    CUOPT_CONTINUOUS
    ;不支持整数QP。
  • 凸问题要求Q矩阵为半正定矩阵(PSD)

Debugging (MPS / C)

调试(MPS / C)

MPS parsing: Required sections in order: NAME, ROWS, COLUMNS, RHS, (optional) BOUNDS, ENDATA. Integer markers:
'MARKER'
,
'INTORG'
,
'INTEND'
.
OOM or slow: Check problem size (variables, constraints); use sparse matrix; set time limit and gap tolerance.
MPS解析: 按顺序需要以下部分:NAME、ROWS、COLUMNS、RHS、(可选)BOUNDS、ENDATA。整数标记:
'MARKER'
'INTORG'
'INTEND'
内存不足(OOM)或运行缓慢: 检查问题规模(变量、约束条件数量);使用稀疏矩阵;设置时间限制和间隙容差。

Examples

示例

  • examples.md — LP/MILP with build instructions
  • assets/README.md — Build commands for all reference code below
  • lp_basic — Simple LP: create problem, solve, get solution
  • lp_duals — Dual values and reduced costs
  • lp_warmstart — PDLP warmstart (see README)
  • milp_basic — Simple MILP with integer variable
  • milp_production_planning — Production planning with resource constraints
  • mps_solver — Solve from MPS file via
    cuOptReadProblem
For CLI (MPS files), use
cuopt_cli
and product docs.
  • examples.md — LP/MILP示例及构建说明
  • assets/README.md — 以下所有参考代码的构建命令
  • lp_basic — 简单LP示例:创建问题、求解、获取结果
  • lp_duals — 对偶值与约减成本
  • lp_warmstart — PDLP热启动(详见README)
  • milp_basic — 含整数变量的简单MILP示例
  • milp_production_planning — 带资源约束的生产规划示例
  • mps_solver — 通过
    cuOptReadProblem
    求解MPS文件中的问题
如需处理CLI(MPS文件),请使用
cuopt_cli
及产品文档。

Escalate

进阶支持

For contribution or build-from-source, use product or repo documentation.
如需贡献代码或从源码构建,请参考产品或仓库文档。