最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Linprog error - A_ub must have exactly two dimensions - Stack Overflow

programmeradmin3浏览0评论

I tried to make calculations with linprog, but keeping to get this error; however, A_ub and c are the same size.

A_eq = np.array([[1,0,0,0,0,1], [0,1,0,-1.05,1,0], [-0.4,-0.3,1,0,-1.05,1]])
b_eq = np.array([200,100,0])
A_ub = [0,0,0,-1,-1,-1]
b_ub = -300
c = np.array([1.2, 1.3, 1.3, 0, 0, 1.05])
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=[0, None])

ValueError: Invalid input for linprog: A_ub must have exactly two dimensions, and the number of columns in A_ub must be equal to the size of c

I tried to make calculations with linprog, but keeping to get this error; however, A_ub and c are the same size.

A_eq = np.array([[1,0,0,0,0,1], [0,1,0,-1.05,1,0], [-0.4,-0.3,1,0,-1.05,1]])
b_eq = np.array([200,100,0])
A_ub = [0,0,0,-1,-1,-1]
b_ub = -300
c = np.array([1.2, 1.3, 1.3, 0, 0, 1.05])
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=[0, None])

ValueError: Invalid input for linprog: A_ub must have exactly two dimensions, and the number of columns in A_ub must be equal to the size of c

Share Improve this question asked Mar 11 at 9:31 Azil559Azil559 212 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

Your current A_ub doesn't have two dimensions.

If you want it to be one row, 6 columns then define it as A_ub = [[0,0,0,-1,-1,-1]]

Complete program:

import numpy as np
from scipy.optimize import linprog

A_eq = np.array([[1,0,0,0,0,1], [0,1,0,-1.05,1,0], [-0.4,-0.3,1,0,-1.05,1]])
b_eq = np.array([200,100,0])
A_ub = [[0,0,0,-1,-1,-1]]
b_ub = -300
c = np.array([1.2, 1.3, 1.3, 0, 0, 1.05])
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=[0, None])
print( res )
发布评论

评论列表(0)

  1. 暂无评论