Unified solver interface for LPs and MILPs (MILP_LP)
- class straindesign.solver_interface.MILP_LP(**kwargs)
Unified MILP and LP interface
This class is a wrapper for several solver interfaces to offer unique and consistent bindings for the construction and manipulation of MILPs and LPs in an vector-matrix-based manner and their solution.
- Accepts a (mixed integer) linear problem in the form:
minimize(c), subject to: A_ineq * x <= b_ineq, A_eq * x = b_eq, lb <= x <= ub, forall(i) type(x_i) = vtype(i) (continous, binary, integer), indicator constraints: x(j) = [0|1] -> a_indic * x [<=|=|>=] b_indic
Please ensure that the number of variables and (in)equalities is consistent
milp = MILP_LP(c, A_ineq, b_ineq, A_eq, b_eq, lb, ub, vtype, indic_constr)
A_ineq (sparse.csr_matrix) – (Default: None) A coefficient matrix of the static inequalities.
A_eq (sparse.csr_matrix) – (Default: None) A coefficient matrix of the static equalities.
vtype (str) – (Default: None) A character string that specifies the type of each variable: ‘c’ontinous, ‘b’inary or ‘i’nteger
indic_constr (IndicatorConstraints) – (Default: None) A set of indicator constraints stored in an object of IndicatorConstraints (see reference manual or docstring).
M (int) – (Default: None) A large value that is used in the translation of indicator constraints to bigM-constraints for solvers that do not natively support them. If no value is provided, 1000 is used.
solver (str) – (Default: taken from avail_solvers) Solver backend that should be used: ‘cplex’, ‘gurobi’, ‘glpk’ or ‘scip’
skip_checks (bool) – (Default: False) Upon MILP construction, the dimensions of all provided vectors and matrices are checked to verify their consistency. If skip_checks=True is set, these checks are skipped.
tlim (float) – Solution time limit in seconds.
A MILP/LP solver interface class.
- add_eq_constraints(A_eq, b_eq)
Add equality constraints to the model
Additional equality constraints have the form A_eq * x = b_eq. The number of columns in A_eq must match with the number of variables x in the problem.
- add_ineq_constraints(A_ineq, b_ineq)
Add inequality constraints to the model
Additional inequality constraints have the form A_ineq * x <= b_ineq. The number of columns in A_ineq must match with the number of variables x in the problem.
Set all coefficients in the objective vector to 0.
- populate(n) Tuple[List, float, float]
Generate a solution pool for MILPs
sols_x, optim, status = cplex.populate()
(Tuple[List of lists, float, float])
solution_vectors, optimal_value, optimization_status
- set_ineq_constraint(idx, a_ineq, b_ineq)
Replace a specific inequality constraint
Replace the constraint with the index idx with the constraint a_ineq*x ~ b_ineq
Set the objective function with a vector
Set the objective function with index-value pairs
e.g.: C=[[1, 1.0], [4,-0.2]]
Set the computation time limit (in seconds)
Set the upper bounds to a given vector
- slim_solve() float
Solve the MILP or LP, but return only the optimal value
optim = cplex.slim_solve()
Optimum value of the objective function.