pyepo.model.ort.ortcpmodel

Abstract optimization model based on Google OR-Tools CP-SAT

Classes

optOrtCpModel

Abstract base class for OR-Tools CP-SAT (constraint programming) models.

Module Contents

class pyepo.model.ort.ortcpmodel.optOrtCpModel

Bases: pyepo.model.opt.optModel

Abstract base class for OR-Tools CP-SAT (constraint programming) models.

Subclasses implement _getModel to build a cp_model.CpModel and return (model, variables). CP-SAT is an integer-only solver, so float cost vectors are scaled internally (multiplied by _OBJ_SCALE and cast to int) before being passed to the solver; the objective value returned by solve is rescaled back to the original units.

As with the other non-Gurobi/non-COPT backends, modelSense is not auto-detected – set self.modelSense = EPO.MAXIMIZE in _getModel for maximization (default is minimization). CP-SAT does not support LP relaxation, so relax() raises RuntimeError.

Variables:

_model (cp_model.CpModel) – underlying OR-Tools CP-SAT model

setObj(c: numpy.ndarray | torch.Tensor | list) None

A method to set the objective function

Parameters:

c – cost of objective function

solve() tuple[numpy.ndarray, float]

A method to solve the model

Returns:

optimal solution (list) and objective value (float)

Return type:

tuple

copy() Self

A method to copy the model

Returns:

new copied model

Return type:

optModel

addConstr(coefs: numpy.ndarray | torch.Tensor | list, rhs: float) Self

A method to add a new constraint

Parameters:
  • coefs – coefficients of new constraint

  • rhs – right-hand side of new constraint

Returns:

new model with the added constraint

Return type:

optModel

relax() optOrtCpModel

CP-SAT does not support LP relaxation.