约束:
5x1 + 6x2> = 95
18x1-9x2> = 189
x1 + x2 <= 45
x1,x2> = 0
最大化:
z = 15x1 + 15x2
代码:
import numpy as np
import scipy as sp
c = [-15,-15]
A = [[-5,-6], [-18,9],[1,1]]
b = [-95,-189,45]
x0_bounds = (0,None)
x1_bounds = (0,None)
from scipy.optimize import linprog
# Solve the problem by Simplex method in Optimization
res = linprog(c, A_ub=A, b_ub=b, bounds=(x0_bounds, x1_bounds), method='simplex', options={"disp": True})
print(res)
这将返回:
x1 = 22,x2 = 23时最多出现675个
但是答案是max = 675出现在(x1,x2)=(22,23)&(45,0)
因此它不会返回x1和x2的第二个值