2016-09-30 14 views
0

次のコードを使用していますが、問題を実行するための設定ができませんでした。Pythonでlinprogを設定する際に問題が発生する

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)) 

ように私はエラーを取得する:boundsパラメータは、ペアのリストを望んでいる

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

答えて

1

。次のようなものを使用してください:

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))) 
関連する問題