小编Yi *_*ang的帖子

如何使用scipy.optimize.linprog获取整数解?

当我解决线性规划问题时,如下面的公式,我希望x all的结果是int类型

请考虑以下问题:

最小化: f = -1*x[0] + 4*x[1]

受制于:

-3*x[0] + 1*x[1] <= 6    
1*x[0] + 2*x[1] <= 4    
x[1] >= -3
Run Code Online (Sandbox Code Playgroud)

哪里: -inf <= x[0] <= inf

接下来是python编码器

>>> 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 …
Run Code Online (Sandbox Code Playgroud)

python scipy

7
推荐指数
2
解决办法
4611
查看次数

标签 统计

python ×1

scipy ×1