milp(c, *, integrality=None, bounds=None, constraints=None, options=None)
Solves problems of the following form:
\min_x \ & c^T x \\ \mbox{such that} \ & b_l \leq A x \leq b_u,\\ & l \leq x \leq u, \\ & x_i \in \mathbb{Z}, i \in X_i
where x is a vector of decision variables; c, b_l, b_u, l, and u are vectors; A is a matrix, and X_i is the set of indices of decision variables that must be integral. (In this context, a variable that can assume only integer values is said to be "integral"; it has an "integrality" constraint.)
Alternatively, that's:
minimize
c @ x
such that
b_l <= A @ x <= b_u
l <= x <= u
Specified elements of x must be integers
By default, l = 0
and u = np.inf
unless specified with bounds
.
milp is a wrapper of the HiGHS linear optimization software . The algorithm is deterministic, and it typically finds the global optimum of moderately challenging mixed-integer linear programs (when it exists).
The coefficients of the linear objective function to be minimized. c is converted to a double precision array before the problem is solved.
Indicates the type of integrality constraint on each decision variable.
Bounds on the decision variables. Lower and upper bounds are converted to double precision arrays before the problem is solved. The keep_feasible
parameter of the Bounds object is ignored. If not specified, all decision variables are constrained to be non-negative.
Linear constraints of the optimization problem. Arguments may be one of the following:
LinearConstraint(*constraints)
Before the problem is solved, all values are converted to double precision, and the matrices of constraint coefficients are converted to instances of scipy.sparse.csc_array. The keep_feasible
parameter of LinearConstraint objects is ignored.
A dictionary of solver options. The following keys are recognized.
disp
disp
node_limit
node_limit
presolve
presolve
time_limit
time_limit
mip_rel_gap
mip_rel_gap
An instance of scipy.optimize.OptimizeResult
. The object is guaranteed to have the following attributes.
Mixed-integer linear programming
import numpy as np
c = -np.array([0, 1])
A = np.array([[-1, 1], [3, 2], [2, 3]])
b_u = np.array([1, 12, 12])
b_l = np.full_like(b_u, -np.inf)
from scipy.optimize import LinearConstraint
constraints = LinearConstraint(A, b_l, b_u)
integrality = np.ones_like(c)
from scipy.optimize import milp
res = milp(c=c, constraints=constraints, integrality=integrality)
res.x
res = milp(c=c, constraints=constraints) # OR:
# from scipy.optimize import linprog; res = linprog(c, A, b_u)
res.x
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them