Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get integer solutions with scipy.optimize.linprog?

Tags:

python

scipy

When I solve the problem of Linear Programming, like in the following formula, I want the result of x all to be int type

Consider the following problem:

Minimize: f = -1*x[0] + 4*x[1]

Subject to:

-3*x[0] + 1*x[1] <= 6    
1*x[0] + 2*x[1] <= 4    
x[1] >= -3

where: -inf <= x[0] <= inf

next is the python coder

>>> c = [-1, 4]
>>> A = [[-3, 1], [1, 2]]
>>> b = [6, 4]
>>> x0_bounds = (None, None)
>>> x1_bounds = (-3, None)
>>> res = linprog(c, A_ub=A, b_ub=b, bounds=(x0_bounds, x1_bounds),
...               options={"disp": True})
>>> print(res)
Optimization terminated successfully.
Current function value: -11.428571
Iterations: 2
status: 0
success: True
fun: -11.428571428571429
x: array([-1.14285714,  2.57142857])
message: 'Optimization terminated successfully.'
nit: 2
like image 666
Yi Zhang Avatar asked Aug 23 '16 12:08

Yi Zhang


People also ask

How do you solve integer problems?

An integer programming (IP) problem is a linear programming (LP) problem in which the decision variables are further constrained to take integer values. Both the objective function and the constraints must be linear. The most commonly used method for solving an IP is the method of branch-and–bound.

What is integer programming in optimization techniques?

Integer programming expresses the optimization of a linear function subject to a set of linear constraints over integer variables. The statements presented in Linear programming: a production planning example are all linear programming models.


1 Answers

From the docs:

method : str, optional Type of solver. At this time only ‘simplex’ is supported.

Simplex cannot handle integrality constraints so you cannot solve integer programming problems with scipy.optimize.linprog yet. You can try other libraries like PuLP, Pyomo or CVXOPT.

like image 130
ayhan Avatar answered Sep 21 '22 13:09

ayhan