简体   繁体   English

无法在Python中设置linprog

[英]Trouble setting up linprog in Python

I am using the following code but I have not been able to set up the problem to run. 我正在使用以下代码,但无法设置要运行的问题。

import numpy as np
from scipy.optimize import linprog

c = np.asarray([-0.098782540360068297, -0.072316526358138802, 0.004, 0.004, 0.004, 0.004])
A_ub = np.asarray([[1.0, 0, 0, 0, 0, 0], [-1.0, 0, 0, 0, 0, 0], [0, -1.0, 0, 0, 0, 0], [0, 1.0, 0, 0, 0, 0], [1.0, 1.0, 0, 0, 0, 0]])
b_ub = np.asarray([3.0, 3.0, 3.0, 3.0, 20.0])
A_eq = np.asarray([[1.0, 0, -1, 1, -1, 1], [0, -1.0, -1, 1, -1, 1]])
b_eq = np.asarray([0,0])
res = linprog(c, A_ub, b_ub, A_eq, b_eq)
lb = np.zeros([6,1]) #lower bound for x array
ub = np.ones([6,1])*2 #upper bound for x array
res2 = linprog(c, A_ub, b_ub, bounds=(lb, ub))

I get error as: 我收到如下错误:

ValueError: Invalid input for linprog with method = 'simplex'.  Length of bounds is inconsistent with the length of c

The bounds parameter wants a list of pairs. bounds参数需要成对列表。 Use something like: 使用类似:

lb = np.zeros(6) #lower bound for x array
ub = np.ones(6)*2 #upper bound for x array
res2 = linprog(c, A_ub, b_ub, bounds=list(zip(lb, ub)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM