Convex Optimization API Reference#

class cuopt.linear_programming.problem.Problem(model_name='')#

A Problem defines a Linear Program or Mixed Integer Program Variable can be be created by calling addVariable() Constraints can be added by calling addConstraint() The objective can be set by calling setObjective() The problem data is formed when calling solve().

Parameters:
model_namestr, optional

Name of the model. Default is an empty string.

Attributes

Name

(str) Name of the model.

ObjSense

(sense) Objective sense (MINIMIZE or MAXIMIZE).

ObjConstant

(float) Constant term in the objective.

Status

(int) Status of the problem after solving.

SolveTime

(float) Time taken to solve the problem.

SolutionStats

(object) Solution statistics for LP or MIP problem.

ObjValue

(float) Objective value of the problem.

IsMIP

(bool) Indicates if the problem is a Mixed Integer Program.

NumVariables

(int) Number of Variables in the problem.

NumConstraints

(int) Number of constraints in the problem.

NumNZs

(int) Number of non-zeros in the problem.

Methods

addConstraint(constr[, name])

Adds a constraint to the problem defined by constraint object and name.

addVariable([lb, ub, obj, vtype, name])

Adds a variable to the problem defined by lower bound, upper bound, type and name.

getCSR()

Computes and returns the CSR representation of the constraint matrix.

getConstraint(identifier)

Get a Constraint by its index or name.

getConstraints()

Get a list of all the Constraints in a problem.

getIncumbentValues(solution, vars)

This is a utility function that can be used for extracting incumbent values of the given variables during a Solve using the incumbent callback.

getObjective()

Get the Objective expression of the problem.

getQCSR()

Computes and returns the CSR matrix representation of the quadratic objective.

getQuadraticConstraints()

Returns all quadratic (QCMATRIX) constraints in the problem.

getVariable(identifier)

Get a Variable by its index or name.

getVariables()

Get a list of all the variables in the problem.

getWarmstartData()

Note: Applicable to only LP.

read(file_path[, fixed_mps_format])

Initialize a problem from an MPS, QPS, or LP file.

readMPS(mps_file)

Initialize a problem from an MPS file.

relax()

Relax a MIP problem into an LP problem and return the relaxed model.

setObjective(expr[, sense])

Set the Objective of the problem with an expression that needs to be MINIMIZED or MAXIMIZED.

solve([settings])

Optimizes the LP or MIP problem with the added variables, constraints and objective.

update()

Update the problem.

updateConstraint(constr[, coeffs, rhs])

Updates a previously added constraint.

updateObjective([coeffs, constant, sense])

Updates the objective of the problem.

writeMPS(mps_file)

Write the problem into an MPS file.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=-2.0, ub=8.0, vtype=INTEGER)
>>> y = problem.addVariable(name="Var2")
>>> problem.addConstraint(2*x - 3*y <= 10, name="Constr1")
>>> expr = 3*x + y
>>> problem.addConstraint(expr + x == 20, name="Constr2")
>>> problem.setObjective(x + y, sense=MAXIMIZE)
>>> problem.solve()
property IsMIP#
property NumConstraints#
property NumNZs#
property NumVariables#
property Obj#
property ObjValue#
addConstraint(constr, name='')#

Adds a constraint to the problem defined by constraint object and name. A constraint is generated using LinearExpression or QuadraticExpression comparisons (<=, >=, or ==).

Parameters:
constrConstraint

Constructed using expression comparisons (see Examples).

namestring

Name of the constraint. Optional.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=-2.0, ub=8.0, vtype=INTEGER)
>>> y = problem.addVariable(name="Var2")
>>> problem.addConstraint(2*x - 3*y <= 10, name="Constr1")
>>> expr = 3*x + y
>>> problem.addConstraint(expr + x == 20, name="Constr2")
>>> problem.addConstraint(-x*x + y*y <= 0, name="soc")
addVariable(
lb=0.0,
ub=inf,
obj=0.0,
vtype=VType.CONTINUOUS,
name='',
)#

Adds a variable to the problem defined by lower bound, upper bound, type and name.

Parameters:
lbfloat

Lower bound of the variable. Defaults to 0.

ubfloat

Upper bound of the variable. Defaults to infinity.

vtypeenum VType

vtype.CONTINUOUS, vtype.INTEGER, or vtype.SEMI_CONTINUOUS. Defaults to CONTINUOUS.

namestring

Name of the variable. Optional.

Returns:
variableVariable

Variable object added to the problem.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=-2.0, ub=8.0, vtype=INTEGER,
        name="Var1")
getCSR()#

Computes and returns the CSR representation of the constraint matrix.

getConstraint(identifier)#

Get a Constraint by its index or name.

getConstraints()#

Get a list of all the Constraints in a problem.

getIncumbentValues(solution, vars)#

This is a utility function that can be used for extracting incumbent values of the given variables during a Solve using the incumbent callback. Please check docs for more details and examples of incumbent callbacks.

Parameters:
solutionList[float]

Array-like structure containing incumbent values.

varsList[Variable]

List of variables to extract corresponding incumbent values.

getObjective()#

Get the Objective expression of the problem.

getQCSR()#

Computes and returns the CSR matrix representation of the quadratic objective.

getQuadraticConstraints()#

Returns all quadratic (QCMATRIX) constraints in the problem.

getVariable(identifier)#

Get a Variable by its index or name.

getVariables()#

Get a list of all the variables in the problem.

getWarmstartData()#

Note: Applicable to only LP. Allows to retrieve the warm start data from the PDLP solver once the problem is solved. This data can be used to warmstart the next PDLP solve by setting it in cuopt.linear_programming.solver_settings.SolverSettings.set_pdlp_warm_start_data() # noqa

Examples

>>> problem = problem.Problem.readMPS("LP.mps")
>>> problem.solve()
>>> warmstart_data = problem.getWarmstartData()
>>> settings.set_pdlp_warm_start_data(warmstart_data)
>>> updated_problem = problem.Problem.readMPS("updated_LP.mps")
>>> updated_problem.solve(settings)
classmethod read(file_path, fixed_mps_format=False)#

Initialize a problem from an MPS, QPS, or LP file.

Dispatches on the file extension via the C++ read entry point (case-insensitive): .mps / .qps (and .gz / .bz2 variants) use the MPS/QPS reader; .lp (and compressed variants) use the LP reader.

Parameters:
file_pathstr

Path to an MPS, QPS, or LP file.

fixed_mps_formatbool

If the MPS/QPS reader should parse as fixed MPS format. Ignored for LP inputs. False by default.

Returns:
Problem

A problem populated from the file.

Examples

>>> problem = problem.Problem.read("model.mps")
>>> lp_problem = problem.Problem.read("model.lp")
classmethod readMPS(mps_file)#

Initialize a problem from an MPS file. # noqa

Always invokes the MPS/QPS reader directly (via the call_parse_mps Cython bridge), bypassing extension-based dispatch. Compressed .mps.gz / .mps.bz2 / .qps.gz / .qps.bz2 inputs are still supported via the reader’s path- based decompression.

Deprecated since version Use: read() instead.

Examples

>>> problem = problem.Problem.readMPS("model.mps")
relax()#

Relax a MIP problem into an LP problem and return the relaxed model. The relaxed model has all variable types set to CONTINUOUS.

Examples

>>> mip_problem = problem.Problem.readMPS("MIP.mps")
>>> lp_problem = problem.relax()
setObjective(expr, sense=sense.MINIMIZE)#

Set the Objective of the problem with an expression that needs to be MINIMIZED or MAXIMIZED.

Parameters:
exprLinearExpression or Variable or Constant

Objective expression that needs maximization or minimization.

senseenum sense

Sets whether the problem is a maximization or a minimization problem. Values passed can either be MINIMIZE or MAXIMIZE. Defaults to MINIMIZE.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=-2.0, ub=8.0, vtype=INTEGER)
>>> y = problem.addVariable(name="Var2")
>>> problem.addConstraint(2*x - 3*y <= 10, name="Constr1")
>>> expr = 3*x + y
>>> problem.addConstraint(expr + x == 20, name="Constr2")
>>> problem.setObjective(x + y, sense=MAXIMIZE)
solve(
settings=<cuopt.linear_programming.solver_settings.solver_settings.SolverSettings object>,
)#

Optimizes the LP or MIP problem with the added variables, constraints and objective.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=-2.0, ub=8.0, vtype=INTEGER)
>>> y = problem.addVariable(name="Var2")
>>> problem.addConstraint(2*x - 3*y <= 10, name="Constr1")
>>> expr = 3*x + y
>>> problem.addConstraint(expr + x == 20, name="Constr2")
>>> problem.setObjective(x + y, sense=MAXIMIZE)
>>> problem.solve()
update()#

Update the problem. This is mandatory if attributes of existing Variables, Constraints or Objective has been modified.

updateConstraint(constr, coeffs=[], rhs=None)#

Updates a previously added constraint. Values that can be updated are constraint coefficients and RHS.

Parameters:
constrConstraint

Constraint to be updated.

coeffsList[Tuple[Variable, coefficient]]

List of Tuples containing variable and corresponding coefficient. Optional.

rhsint|float

New RHS value for the constraint.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=0.0, vtype=INTEGER)
>>> y = problem.addVariable(lb=0.0, vtype=INTEGER)
>>> c1 = problem.addConstraint(2 * x + y <= 7, name="c1")
>>> c2 = problem.addConstraint(x + y <= 5, name="c2")
>>> problem.updateConstraint(c1, coeffs=[(x, 1)], rhs=10)
updateObjective(coeffs=[], constant=None, sense=None)#

Updates the objective of the problem. Values that can be updated are objective coefficients, constant and sense.

Parameters:
coeffsList[Tuple[Variable, coefficient]]

List of Tuples containing variable and corresponding coefficient. Optional.

constantint|float

New Objective constant for the problem. Optional.

senseenum sense

Sets the objective sense to either maximize or minimize. Optional.

Examples

>>> problem = problem.Problem("MIP_model")
>>> x = problem.addVariable(lb=0.0, vtype=INTEGER)
>>> y = problem.addVariable(lb=0.0, vtype=INTEGER)
>>> problem.setObjective(4*x + y + 4, MAXIMIZE)
>>> problem.updateObjective(coeffs=[(x1, 1.0), (x2, 3.0)], constant=5,
        sense=MINIMIZE)
writeMPS(mps_file)#

Write the problem into an MPS file. # noqa Examples ——– >>> problem.writeMPS(“model.mps”)

class cuopt.linear_programming.problem.Variable(lb=0.0, ub=inf, obj=0.0, vtype=VType.CONTINUOUS, vname='')#

cuOpt variable object initialized with details of the variable such as lower bound, upper bound, type and name. Variables are always associated with a problem and can be created using Problem.addVariable().

Parameters:
lbfloat

Lower bound of the variable. Defaults to 0.

ubfloat

Upper bound of the variable. Defaults to infinity.

vtypeenum

CONTINUOUS or INTEGER. Defaults to CONTINUOUS.

objfloat

Coefficient of the Variable in the objective.

namestr

Name of the variable. Optional.

Attributes

VariableName

(str) Name of the Variable.

VariableType

(CONTINUOUS, INTEGER, or SEMI_CONTINUOUS) Variable type.

LB

(float) Lower Bound of the Variable.

UB

(float) Upper Bound of the Variable.

Obj

(float) Coefficient of the variable in the Objective function.

Value

(float) Value of the variable after solving.

ReducedCost

(float) Reduced Cost after solving an LP problem.

MIPStart

(float) Initial value (warm-start hint) for the variable. Defaults to NaN (unset). Only used for a MIP problem.

Methods

getIndex()

Get the index position of the variable in the problem.

getLowerBound()

Returns the lower bound of the variable.

getMIPStart()

Returns the MIP start (initial primal solution hint) value of the variable.

getObjectiveCoefficient()

Returns the objective coefficient of the variable.

getUpperBound()

Returns the upper bound of the variable.

getValue()

Returns the Value of the variable computed in current solution.

getVariableName()

Returns the name of the variable.

getVariableType()

Returns the type of the variable.

setLowerBound(val)

Sets the lower bound of the variable.

setMIPStart(val)

Sets the MIP start (initial primal solution hint) value for the variable.

setObjectiveCoefficient(val)

Sets the objective cofficient of the variable.

setUpperBound(val)

Sets the upper bound of the variable.

setVariableName(val)

Sets the name of the variable.

setVariableType(val)

Sets the variable type of the variable.

getIndex()#

Get the index position of the variable in the problem.

getLowerBound()#

Returns the lower bound of the variable.

getMIPStart()#

Returns the MIP start (initial primal solution hint) value of the variable. Defaults to NaN when unset.

getObjectiveCoefficient()#

Returns the objective coefficient of the variable.

getUpperBound()#

Returns the upper bound of the variable.

getValue()#

Returns the Value of the variable computed in current solution. Defaults to 0

getVariableName()#

Returns the name of the variable.

getVariableType()#

Returns the type of the variable.

setLowerBound(val)#

Sets the lower bound of the variable.

setMIPStart(val)#

Sets the MIP start (initial primal solution hint) value for the variable. Use float("nan") to unset.

setObjectiveCoefficient(val)#

Sets the objective cofficient of the variable.

setUpperBound(val)#

Sets the upper bound of the variable.

setVariableName(val)#

Sets the name of the variable.

setVariableType(val)#

Sets the variable type of the variable. Variable types can be CONTINUOUS, INTEGER, or SEMI_CONTINUOUS.

class cuopt.linear_programming.problem.LinearExpression(vars, coefficients, constant)#

LinearExpressions contain a set of variables, the coefficients for the variables, and a constant. LinearExpressions can be used to create constraints and the objective in the Problem. LinearExpressions can be added and subtracted with other LinearExpressions and Variables and can also be multiplied and divided by scalars. LinearExpressions can be compared with scalars, Variables, and other LinearExpressions to create Constraints.

Parameters:
varsList

List of Variables in the linear expression.

coefficientsList

List of coefficients corresponding to the variables.

constantfloat

Constant of the linear expression.

Methods

getCoefficient(i)

Gets the coefficient of the variable at ith index of the linear expression.

getCoefficients()

Returns all the coefficients in the linear expression.

getConstant()

Returns the constant in the linear expression.

getValue()

Returns the value of the expression computed with the current solution.

getVariable(i)

Gets Variable at ith index in the linear expression.

getVariables()

Returns all the variables in the linear expression.

zipVarCoefficients

getCoefficient(i)#

Gets the coefficient of the variable at ith index of the linear expression.

getCoefficients()#

Returns all the coefficients in the linear expression.

getConstant()#

Returns the constant in the linear expression.

getValue()#

Returns the value of the expression computed with the current solution.

getVariable(i)#

Gets Variable at ith index in the linear expression.

getVariables()#

Returns all the variables in the linear expression.

zipVarCoefficients()#
class cuopt.linear_programming.problem.QuadraticExpression(
qmatrix=None,
qvars=[],
qvars1=[],
qvars2=[],
qcoefficients=[],
vars=[],
coefficients=[],
constant=0.0,
)#

QuadraticExpressions contain quadratic terms, linear terms, and a constant. Use them for quadratic objectives (Problem.setObjective) or quadratic constraints via <= or >= comparisons passed to Problem.addConstraint() (equality is not supported). QuadraticExpressions can be added and subtracted with other QuadraticExpressions, LinearExpressions, and Variables, and can also be multiplied and divided by scalars.

Parameters:
qmatrixList[List[float]] or 2D numpy array.

Matrix containing quadratic coefficient matrix terms. Should be a square matrix with shape as (num_vars, num_vars).

qvarsList[Variable]

List of variables denoting the rows and cols in qmatrix. It is a mandatory field when providing qmatrix. qvars should be in the order of variables added to the problem and can be obtained using problem.getVariables(). The length of qvars should be equal to length of row/col in qmatrix.

qvars1List[Variable]

List of first variables for quadratic terms. This should be used if adding quadratic terms in triplet (i, j, x) format where i is the row variable, j is the column variable and x is the corresponding coefficient. qvars1 contains all i variables representing the row.

qvars2List[Variable]

List of second variables for quadratic terms. This should be used if adding quadratic terms in triplet (i, j, x) format where i is the row variable, j is the column variable and x is the corresponding coefficient. qvars2 contains all j variables representing the column.

qcoefficientsList[float]

List of coefficients for the quadratic terms. This should be used if adding quadratic terms in triplet (i, j, x) format where i is the row variable, j is the column variable and x is the corresponding coefficient. qcoefficients contains all x values representing coefficients for (i,j)

varsList[Variable]

List of Variables for linear terms.

coefficientsList[float]

List of coefficients for linear terms.

constantfloat

Constant of the quadratic expression.

Methods

getCoefficient(i)

Gets the coefficient of the quadratic term at ith index.

getCoefficients()

Returns all the coefficients of the quadratic term.

getLinearExpression()

Returns the Linear Expression associated with the Quadratic Expression.

getValue()

Returns the value of the expression computed with the current solution.

getVariable1(i)

Gets first Variable at ith index in the quadratic term.

getVariable2(i)

Gets second Variable at ith index in the quadratic term.

getVariables()

Returns all the quadractic variables in the expression as list of tuples containing Variable 1 and Variable 2 for each term.

Examples

>>> x = problem.addVariable()
>>> y = problem.addVariable()
>>> # Create objective x^2 + 2*x*y + 3*x + 4 using matrix
>>> quad_matrix = QuadraticExpression(
...     qmatrix=[[1.0, 2.0], [0.0, 0.0]],
...     qvars=[x, y]
... )
>>> quad_obj_using_matrix = quad_matrix + 3*x + 4
>>> # Create objective x^2 + 2*x*y + 3*x + 4 using expression
>>> quad_obj_using_expr = x*x + 2*x*y + 3*x + 4
__ge__(other)#

Return self>=value.

__le__(other)#

Return self<=value.

__neg__()#
getCoefficient(i)#

Gets the coefficient of the quadratic term at ith index.

getCoefficients()#

Returns all the coefficients of the quadratic term.

getLinearExpression()#

Returns the Linear Expression associated with the Quadratic Expression.

getValue()#

Returns the value of the expression computed with the current solution.

getVariable1(i)#

Gets first Variable at ith index in the quadratic term.

getVariable2(i)#

Gets second Variable at ith index in the quadratic term.

getVariables()#

Returns all the quadractic variables in the expression as list of tuples containing Variable 1 and Variable 2 for each term.

class cuopt.linear_programming.problem.Constraint(expr, sense, rhs, name='')#

cuOpt constraint object containing a linear or quadratic (QCMATRIX) expression, the sense of the constraint, and the right-hand side. Constraints are associated with a problem and can be created using Problem.addConstraint().

Parameters:
exprLinearExpression or QuadraticExpression

Expression corresponding to the constraint.

senseenum

Sense of the constraint. Either LE for <=, GE for >= or EQ for == .

rhsfloat

Constraint right-hand side value.

namestr, Optional

Name of the constraint. Optional.

Attributes

ConstraintName

(str) Name of the constraint.

Sense

(LE, GE or EQ) Row sense. LE for <=, GE for >= or EQ for == .

RHS

(float) Constraint right-hand side value (linear rows).

is_quadratic

(bool) True when the row is exported as a QCMATRIX quadratic constraint.

Slack

(float) Computed LHS - RHS with current solution.

DualValue

(float) Constraint dual value in the current solution.

Methods

getCoefficient(var)

Returns the coefficient of a variable in the constraint.

getConstraintName()

Returns the name of the constraint.

getRHS()

Returns the right-hand side value of the constraint.

getSense()

Returns the sense of the constraint.

getCoefficient(var)#

Returns the coefficient of a variable in the constraint.

getConstraintName()#

Returns the name of the constraint.

getRHS()#

Returns the right-hand side value of the constraint.

getSense()#

Returns the sense of the constraint. Constraint sense can be LE(<=), GE(>=) or EQ(==).

class cuopt.linear_programming.solver_settings.SolverSettings#

Attributes

mip_callbacks

mip_callbacks: list

pdlp_warm_start_data

pdlp_warm_start_data: object

settings_dict

settings_dict: dict

Methods

dump_parameters_to_file(self, path[, ...])

Apply settings_dict / warm start to C++, then dump parameters to path.

get_mip_callbacks(self)

Return callback class object

get_parameter(self, name)

Get the value of a parameter used by cuOpt's LP/MIP solvers.

get_pdlp_warm_start_data(self)

Returns the warm start data.

load_parameters_from_file(self, path)

Load parameters from a cuOpt config file.

set_c_solver_settings(self)

Replay Python-side state into the C++ solver_settings_t object.

set_mip_callback(self, callback, user_data)

Note: Only supported for MILP

set_optimality_tolerance(self, eps_optimal)

NOTE: Not supported for MILP, absolute is fixed to 1e-4,

set_parameter(self, name, value)

Set the value of a parameter used by cuOpt's LP/MIP solvers.

set_pdlp_warm_start_data(self, ...)

Set the pdlp warm start data.

dump_parameters_to_file(
self,
path,
hyperparameters_only=True,
)#

Apply settings_dict / warm start to C++, then dump parameters to path.

Calls set_c_solver_settings() then the C++ solver_settings_t::dump_parameters_to_file.

Parameters:
pathstr

Output path (e.g. file path or /dev/stdout).

hyperparameters_onlybool, optional

Forwarded to C++; when True, dump hyperparameter subset only.

Returns:
bool

True if the C++ layer reports success.

get_mip_callbacks(self)#

Return callback class object

get_parameter(self, name)#

Get the value of a parameter used by cuOpt’s LP/MIP solvers.

Parameters:
namestr

The name of the parameter to get.

Returns:
valuefloat, int, bool, or str

The value of the parameter.

Notes

For a list of availabe parameters, their descriptions, default values, and acceptable ranges, see the cuOpt documentation parameter.rst.

get_pdlp_warm_start_data(self)#

Returns the warm start data. See set_pdlp_warm_start_data for more details.

Returns:
pdlp_warm_start_data:
load_parameters_from_file(self, path)#

Load parameters from a cuOpt config file.

Loads into the current C++ object, then refreshes settings_dict from C++ for each registered parameter name. That keeps get_parameter() aligned with what set_c_solver_settings() will replay on the next solve (see reset-replay invariant on set_c_solver_settings()).

Parameters:
pathstr

Path to a parameter file with name = value lines (see C++ solver_settings_t::load_parameters_from_file).

mip_callbacks#

mip_callbacks: list

pdlp_warm_start_data#

pdlp_warm_start_data: object

set_c_solver_settings(self)#

Replay Python-side state into the C++ solver_settings_t object.

set_mip_callback(self, callback, user_data)#

Note: Only supported for MILP

Set the callback to receive incumbent solution.

Parameters:
callbackclass for function callback

Callback class that inherits from GetSolutionCallback or SetSolutionCallback.

user_dataobject

User context passed to the callback.

Notes

Registering a SetSolutionCallback disables presolve.

Examples

>>> # Callback for incumbent solution
>>> class CustomGetSolutionCallback(GetSolutionCallback):
>>>     def __init__(self, user_data):
>>>         super().__init__()
>>>         self.n_callbacks = 0
>>>         self.solutions = []
>>>         self.user_data = user_data
>>>
>>>     def get_solution(
>>>         self, solution, solution_cost, solution_bound, user_data
>>>     ):
>>>         assert user_data is self.user_data
>>>         self.n_callbacks += 1
>>>         assert len(solution) > 0
>>>         assert len(solution_cost) == 1
>>>         assert len(solution_bound) == 1
>>>
>>>         self.solutions.append(
>>>             {
>>>                 "solution": solution.tolist(),
>>>                 "cost": float(solution_cost[0]),
>>>                 "bound": float(solution_bound[0]),
>>>             }
>>>         )
>>>
>>> class CustomSetSolutionCallback(SetSolutionCallback):
>>>     def __init__(self, get_callback, user_data):
>>>         super().__init__()
>>>         self.n_callbacks = 0
>>>         self.get_callback = get_callback
>>>         self.user_data = user_data
>>>
>>>     def set_solution(
>>>         self, solution, solution_cost, solution_bound, user_data
>>>     ):
>>>         assert user_data is self.user_data
>>>         self.n_callbacks += 1
>>>         assert len(solution_bound) == 1
>>>         if self.get_callback.solutions:
>>>             solution[:] =
>>>             self.get_callback.solutions[-1]["solution"]
>>>             solution_cost[0] = float(
>>>                 self.get_callback.solutions[-1]["cost"]
>>>             )
>>>
>>> user_data = {"source": "example"}
>>> get_callback = CustomGetSolutionCallback(user_data)
>>> set_callback = CustomSetSolutionCallback(get_callback, user_data)
>>> settings.set_mip_callback(get_callback, user_data)
>>> settings.set_mip_callback(set_callback, user_data)
set_optimality_tolerance(self, eps_optimal)#

NOTE: Not supported for MILP, absolute is fixed to 1e-4,

Set both absolute and relative tolerance on the primal feasibility, dual feasibility, and gap. Changing this value has a significant impact on accuracy and runtime.

Optimality is computed as follows:

dual_feasibility < absolute_dual_tolerance + relative_dual_tolerance
  • norm_objective_coefficient (l2_norm(c))

primal_feasibility < absolute_primal_tolerance
  • relative_primal_tolerance * norm_constraint_bounds (l2_norm(b))

duality_gap < absolute_gap_tolerance + relative_gap_tolerance
  • (abs(primal_objective) + abs(dual_objective))

If all three conditions hold, optimality is reached.

Parameters:
eps_optimalfloat64

Tolerance to optimality

Notes

Default value is 1e-4. To set each absolute and relative tolerance, use the provided setters.

set_parameter(self, name, value)#

Set the value of a parameter used by cuOpt’s LP/MIP solvers.

Parameters:
namestr

The name of the parameter to set.

valuestr

The value the parameter should take.

For a list of availabe parameters, their descriptions, default values,
and acceptable ranges, see the cuOpt documentation `parameter.rst`.
set_pdlp_warm_start_data(self, pdlp_warm_start_data)#

Set the pdlp warm start data. This 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.

Parameters:
pdlp_warm_start_dataPDLPWarmStartData

PDLP warm start data obtained from a previous solve. Refer cuopt.linear_programming.problem.Problem.getWarmstartData() # noqa

Notes

For now, the problem must have the same number of variables and constraints as the one found in the previous solution.

Only supported solver modes are Stable2 and Fast1.

Examples

>>> settings.set_pdlp_warm_start_data(pdlp_warm_start_data)
settings_dict#

settings_dict: dict

class cuopt.linear_programming.problem.CType(*values)#

The sense of a constraint is either LE, GE or EQ. Constraint Sense Types can be directly used as a constant. LE is CType.LE GE is CType.GE EQ is CType.EQ

LE = 'L'#
GE = 'G'#
EQ = 'E'#
class cuopt.linear_programming.problem.sense(*values)#

The sense of a model is either MINIMIZE or MAXIMIZE. Model objective sense can be directly used as a constant. MINIMIZE is sense.MINIMIZE MAXIMIZE is sense.MAXIMIZE

MAXIMIZE = -1#
MINIMIZE = 1#
cuopt.linear_programming.io.Read(
file_path: str,
fixed_mps_format: bool = False,
) DataModel#

Read an optimization problem from a file, dispatching on extension.

Dispatches to the MPS/QPS or LP reader based on the filename suffix (case-insensitive), matching the C++ read entry point:

  • .mps, .mps.gz, .mps.bz2, .qps, .qps.gz, .qps.bz2 → MPS/QPS reader

  • .lp, .lp.gz, .lp.bz2 → LP reader

Parameters:
file_pathstr

Path to an MPS, QPS, or LP file (optionally .gz / .bz2 compressed).

fixed_mps_formatbool

If the MPS/QPS reader should parse as fixed MPS format. Ignored for LP inputs. False by default.

Returns:
data_modelDataModel

A fully formed LP/MILP/QP problem.

Raises:
InputValidationError, InputRuntimeError, OutOfMemoryError

Parser errors from the underlying C++ readers (via catch_io_exception).

RuntimeError

If the file extension is not one of the supported suffixes (raised by the C++ read dispatch).