纸浆解算犯规得到最佳的结果,而这是可以的。难道是不明确的问题,或者是有在图书馆或约束的问题?
通常这是给最适合大多数的制约可能性,但它不是为这个特定的情况下。
from pulp import *
prob = LpProblem("minimization", LpMinimize)
#introducing vars
a=LpVariable("a", 0, None)
b=LpVariable("b", 0, None)
c=LpVariable("c", 0, None)
d=LpVariable("d", 0, None)
e=LpVariable("e", 0, None)
#introducing main obj and constraints
#basically addition of all vars should be minimized to 1.
prob+=a+b+c+d+e>=1,"main objective"
prob+=a<=0.3,"a const"
prob+=b<=0.3,"b const"
prob+=c<=0.3,"c const"
prob+=d<=0.3,"d const" #can change to 0
prob+=e==0.1,"e const"
"""
for this const.
the res is:
a=0.3
b=0.3
c=0.3
d=0.3
e=0.1
a+b+c+d+e=1.3
if you change prob+=d<=0.3 to prob+=d<=0
then:
a=0.3
b=0.3
c=0.3
d=0.0
e=0.1
a+b+c+d+e=1
"""
#solves the problem
status = prob.solve()
#checks if optimal or infeasible
print("status:",LpStatus[prob.status])
#shows all the vars
for variable in prob.variables():
print("{} = {}".format(variable.name, variable.varValue))
这个常量。
该水库是:
一个= 0.3
B = 0.3
C = 0.3
d = 0.3
E = 0.1
A + B + C + d + E = 1.3
它应该是1,因为它是LpMinimize。
如果更改的概率+ = d <= 0.3〜概率+ = d <= 0
然后:
一个= 0.3
B = 0.3
C = 0.3
d = 0.0
E = 0.1
A + B + C + d + E = 1
这是一种约束,而不是一个目标:
prob+=a+b+c+d+e>=1,"main objective"
从本质上讲,你没有一个客观的,因此求解器只是寻找一个可行的解决方案。
尝试
prob+=a+b+c+d+e,"main objective"
prob+=a+b+c+d+e>=1,"constraint"
现在,你都尽量减少a+b+c+d+e
以及具有在此约束。
结论:我认为纸浆是正确的在这里。