pyepo.model.opt¶
Abstract optimization model
Classes¶
Module Contents¶
- class pyepo.model.opt.ModelSpec(model_type: type[optModel], config: dict, args: tuple = ())¶
Serializable recipe for building a fresh optimization model.
- 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¶
- classmethod from_config(config: dict, args: tuple = ()) Self¶
Build a model from a configuration produced by
get_config.
- rebuild() Self¶
Build a structurally equivalent model with clean runtime state.
- 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:
- property c_pred_index: numpy.ndarray | None¶
Variable positions the predicted cost lands on, or
Nonewhen every variable is predicted (the default).
- 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: