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

get_solutions() List[Dict[str, Any]][source]
nb_solutions() int[source]
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

remove(objects: Var | Constr | List[Var | Constr]) None[source]

removes variable(s) and/or constraint(s) from the model

Parameters:

objects (Union[mip.Var, mip.Constr, List[Union[mip.Var, mip.Constr]]]) – can be a Var, a Constr or a list of these objects

update() None[source]
discrete_optimization.generic_tools.mip.pymip_tools.release_token() None[source]

Module contents