pyepo.model.opt¶
Abstract optimization model
Classes¶
Abstract base class for predict-then-optimize models. |
Module Contents¶
- class pyepo.model.opt.optModel¶
Bases:
abc.ABCAbstract base class for predict-then-optimize models.
Subclasses wrap an optimization solver or algorithm with a unified
_getModel/setObj/solve/num_costinterface thatpyepo.funcmodules call during training. Concrete backends are provided for GurobiPy (optGrbModel), Pyomo (optOmoModel), COPT (optCoptModel), OR-Tools (optOrtModel/optOrtCpModel), and MPAX (optMpaxModel); subclassoptModeldirectly to integrate any other solver or algorithm.The default objective sense is minimization; set
self.modelSense = EPO.MAXIMIZEin_getModelor__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¶
- 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:
- 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: