pyepo.model.opt

Abstract optimization model

Classes

optModel

Abstract base class for predict-then-optimize models.

Module Contents

class pyepo.model.opt.optModel

Bases: abc.ABC

Abstract base class for predict-then-optimize models.

Subclasses wrap an optimization solver or algorithm with a unified _getModel / setObj / solve / num_cost interface that pyepo.func modules call during training. Concrete backends are provided for GurobiPy (optGrbModel), Pyomo (optOmoModel), COPT (optCoptModel), OR-Tools (optOrtModel / optOrtCpModel), and MPAX (optMpaxModel); subclass optModel directly to integrate any other solver or algorithm.

The default objective sense is minimization; set self.modelSense = EPO.MAXIMIZE in _getModel or __init__ for maximization problems (some backends, e.g. Gurobi and COPT, detect this automatically from the underlying solver model).

Variables:
  • _model (optimization model) – underlying solver model object

  • modelSense (ModelSense) – EPO.MINIMIZE (default) or EPO.MAXIMIZE

modelSense: pyepo.EPO.ModelSense
arcs: list = []
property num_cost: int

number of costs to be predicted

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

An abstract method to set the objective function

Parameters:

c – cost of objective function

abstractmethod solve() tuple[numpy.ndarray | torch.Tensor | list, float]

An abstract 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

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

A method to add a new constraint. Subclasses should override.

Parameters:
  • coefs – coefficients of the new constraint

  • rhs – right-hand side of new constraint

Returns:

new model with the added constraint

Return type:

optModel

abstractmethod relax() optModel

A method to relax the MIP model. Subclasses should override.