bundles / scipy 1.17.1 / scipy / optimize / _milp / milp
function
scipy.optimize._milp:milp
source: /scipy/optimize/_milp.py :154
Signature
def milp ( c , * , integrality = None , bounds = None , constraints = None , options = None ) Summary
Mixed-integer linear programming
Extended Summary
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_iwhere is a vector of decision variables; , , , , and are vectors; is a matrix, and 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 @ xsuch 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.
Parameters
c: 1D dense array_likeThe coefficients of the linear objective function to be minimized.
cis converted to a double precision array before the problem is solved.integrality: 1D dense array_like, optionalIndicates the type of integrality constraint on each decision variable.
0Continuous variable; no integrality constraint.1Integer variable; decision variable must be an integer withinbounds.2Semi-continuous variable; decision variable must be withinboundsor take value0.3Semi-integer variable; decision variable must be an integer withinboundsor take value0.By default, all variables are continuous.
integralityis converted to an array of integers before the problem is solved.bounds: scipy.optimize.Bounds, optionalBounds on the decision variables. Lower and upper bounds are converted to double precision arrays before the problem is solved. The
keep_feasibleparameter of the Bounds object is ignored. If not specified, all decision variables are constrained to be non-negative.constraints: sequence of scipy.optimize.LinearConstraint, optionalLinear constraints of the optimization problem. Arguments may be one of the following:
A single LinearConstraint object
A single tuple that can be converted to a LinearConstraint object as
LinearConstraint(*constraints)A sequence composed entirely of objects of type 1. and 2.
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_feasibleparameter of LinearConstraint objects is ignored.options: dict, optionalA 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
Returns
res: OptimizeResultAn instance of scipy.optimize.OptimizeResult. The object is guaranteed to have the following attributes.
status
status
success
success
message
message
The following attributes will also be present, but the values may be
None, depending on the solution status.x
x
fun
fun
mip_node_count
mip_node_count
mip_dual_bound
mip_dual_bound
mip_gap
mip_gap
Notes
milp is a wrapper of the HiGHS linear optimization software [1]. The algorithm is deterministic, and it typically finds the global optimum of moderately challenging mixed-integer linear programs (when it exists).
Examples
Consider the problem at https://en.wikipedia.org/wiki/Integer_programming#Example, which is expressed as a maximization problem of two variables. Since `milp` requires that the problem be expressed as a minimization problem, the objective function coefficients on the decision variables are: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, dtype=float)✓
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: res.x✓
Aliases
-
scipy.optimize.milp