【发布时间】:2018-11-03 04:13:27
【问题描述】:
我使用下面的代码已经有一段时间了,除了现在,它总是能够找到最大/最小值。
我得到一个角点:x=168,y=192,objective=3288
但是有一个角点是真正的最大值:x=0,y=304,objective=3344
我做错了什么导致这段代码无法找到真正最大化目标的 x,y?
from pulp import LpVariable, LpProblem, LpMaximize, LpStatus, value, LpMinimize
# declare your variables
x = LpVariable("y1", 0, None)
y = LpVariable("y2", 0, None)
# defines the problem
prob = LpProblem("problem", LpMaximize)
# defines the constraints
prob += 1/2*x+3/4*y == 228
prob += 1/2*x+1/4*y == 132
# defines the objective function to maximize
prob += 7*x+11*y
# solve the problem
status = prob.solve()
LpStatus[status]
# print the results
print('x={0},y={1}.'.format(round(value(x)),round(value(y))))
print("The objective is ${}.".format(round(value(prob.objective))))
【问题讨论】:
-
我认为您可能希望每个约束的左侧小于或等于相应的右侧。如果是这样,那么您报告的角点确实是最佳的。如果你在约束中强制等式,你有两个变量和两个方程,并且可行空间是只有一个点,对应的线性方程组的解。
标签: python math linear-programming maxima pulp