python - 我如何知道满足纸浆目标值的所有变量的所有组合?
问题描述
我想知道满足纸浆解决方案的所有变量组合。
所以,我做了一个样本问题,它有许多目标值的变量组合。
我添加了一个与解决方案平行的约束。
以下是我的代码。
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)
我想知道其他组合。
但纸浆只显示一种解决方案。
怎么可能认识别人?
解决方案
推荐阅读
- java - Cucumber Java 如何更新 DataTable 中的元素
- mongodb - 使用测试容器和 docker 的集成测试问题“原因:java.lang.NullPointerException:未指定 containerId”
- excel - 在 Power Pivot DAX 中获取全年工作日
- javascript - 使用外部 json 数据在画布 js 中渲染图形
- ubuntu - 在 ubuntu 上构建 ffmpeg:构建 nasm 失败
- jenkins-pipeline - 神器配置
- c# - 获取与 LINQ to XML 中的模式匹配的属性值的 C# Lambda 方法语法
- vue.js - 使用 v-for 检索被点击元素的数据属性值
- javascript - Actions on Google - 未找到应用请求许可的意图
- python - 如何将列拆分为具有相同列名并在 Python 中具有相同值的两个?