discrete_optimization.generic_tools.mip package
Submodules
discrete_optimization.generic_tools.mip.pymip_tools module
- class discrete_optimization.generic_tools.mip.pymip_tools.IncumbentStoreSolution(model: Model)[source]
Bases:
IncumbentUpdater
- update_incumbent(objective_value: float, best_bound: float, solution: List[Tuple[Var, float]]) List[Tuple[Var, float]] [source]
Method that is called when a new integer feasible solution is found
- Parameters:
objective_value (float) – cost of the new solution found
best_bound (float) – current lower bound for the optimal solution cost
solution (List[Tuple[mip.Var,float]]) – non-zero variables in the solution
- Return type:
List[Tuple[mip.Var, float]]
- class discrete_optimization.generic_tools.mip.pymip_tools.MyModelMilp(name: str = '', sense: str = 'MIN', solver_name: str = '', solver: Solver | None = None)[source]
Bases:
Model
- add_constr(lin_expr: LinExpr, name: str = '') Constr [source]
Creates a new constraint (row).
Adds a new constraint to the model, returning its reference.
- Parameters:
lin_expr (mip.LinExpr) – linear expression
name (str) – optional constraint name, used when saving model to lp or mps files
priority (mip.constants.ConstraintPriority) – optional constraint priority
Examples:
The following code adds the constraint \(x_1 + x_2 \leq 1\) (x1 and x2 should be created first using
add_var()
):m += x1 + x2 <= 1
Which is equivalent to:
m.add_constr( x1 + x2 <= 1 )
Summation expressions can be used also, to add the constraint \(\displaystyle \sum_{i=0}^{n-1} x_i = y\) and name this constraint
cons1
:m += xsum(x[i] for i in range(n)) == y, "cons1"
Which is equivalent to:
m.add_constr( xsum(x[i] for i in range(n)) == y, "cons1" )
- Return type:
mip.Constr