首页 > 解决方案 > 我如何知道满足纸浆目标值的所有变量的所有组合?

问题描述

我想知道满足纸浆解决方案的所有变量组合。

所以,我做了一个样本问题,它有许多目标值的变量组合。

我添加了一个与解决方案平行的约束。

以下是我的代码。

prob = LpProblem(name="small-problem", sense=LpMaximize)
x = LpVariable(name="x", lowBound=0, cat ="Integer")
y = LpVariable(name="y", lowBound=0, cat = "Integer")
prob += (x >= 0, "x_constraint") 
prob += (y >= 0, "y_constraint")
prob += (x + 2*y <= 10, "for multi objective value")
prob += x + 2*y 
status = prob.solve() 
print(f"status: {prob.status}, {LpStatus[prob.status]}")
print(f"objective: {prob.objective.value()}")
for var in prob.variables(): 
    print(f"{var.name}: {var.value()}")
for name, constraint in prob.constraints.items():
    print(f"{name}: {constraint.value()}")

以下是结果....

status: 1, Optimal
objective: 10.0
x: 10.0
y: 0.0
x_constraint: 10.0
y_constraint: 0.0
for_multi_objective_value: 0.0

但是,这个问题对于目标 10.0 有更多的变量组合。

(x,y) : (10,0) (8,1) (6,2) (4,3) (2,4) (0,5)

我想知道其他组合。

但纸浆只显示一种解决方案。

怎么可能认识别人?

标签: pythonpulp

解决方案


推荐阅读