我正在尝试PuLP中的使模型定义自动化]。现在,我有以下模型:
import pulp as pl " Cost parameters" p1 = 200 # Cost per unit 1 p2 = 300 # Cost per unit 2 " VARIABLES" k0101 = pl.LpVariable("k0101", 0, 1, pl.LpInteger) k0102 = pl.LpVariable("k0102", 0, 1, pl.LpInteger) k0201 = pl.LpVariable("k0201", 0, 1, pl.LpInteger) k0202 = pl.LpVariable("k0202", 0, 1, pl.LpInteger) ###### DEMAND x010101 = pl.LpVariable("x010101", lowBound = 0) x010102 = pl.LpVariable("x010102", lowBound = 0) x010103 = pl.LpVariable("x010103", lowBound = 0) x010104 = pl.LpVariable("x010104", lowBound = 0) x010201 = pl.LpVariable("x010201", lowBound = 0) x010202 = pl.LpVariable("x010202", lowBound = 0) x010203 = pl.LpVariable("x010203", lowBound = 0) x010204 = pl.LpVariable("x010204", lowBound = 0) x020101 = pl.LpVariable("x020101", lowBound = 0) x020102 = pl.LpVariable("x020102", lowBound = 0) x020103 = pl.LpVariable("x020103", lowBound = 0) x020104 = pl.LpVariable("x020104", lowBound = 0) x020201 = pl.LpVariable("x020201", lowBound = 0) x020202 = pl.LpVariable("x020202", lowBound = 0) x020203 = pl.LpVariable("x020203", lowBound = 0) x020204 = pl.LpVariable("x020204", lowBound = 0) # Problem z = pl.LpProblem("optimizator", pl.LpMinimize) "OBJECTIVE FUNCTION" z += ((p1) * (x010101 + x010102 + x010103 + x010104) + (p1) * (x010201 + x010202 + x010203 + x010204) + (p2) * (x020101 + x020102 + x020103 + x020104) + (p2) * (x020201 + x020202 + x020203 + x020204) + (p1) * (x010101 + x010102 + x010103 + x010104) + (p1) * (x010201 + x010202 + x010203 + x010204) + (p2) * (x020101 + x020102 + x020103 + x020104) + (p2) * (x020201 + x020202 + x020203 + x020204)) " CONSTRAINTS " z += x010101 + x020101 >= 15 * k0101 " SOLUTION " print(z) estado = z.solve() print(pl.LpStatus[estado]) "TOTAL COST:" print(pl.value(z.objective))
我想简化此变量定义,以便能够在更简单的描述中定义更多变量。
现在有人可以将我的变量和参数定义为字典,并在目标函数和约束中考虑这一点吗?
我正在尝试自动在PuLP中定义模型。现在,我有以下模型:将纸浆作为pl导入“成本参数” p1 = 200#每单位成本1 p2 = 300#每单位成本2“ ...
这将有助于进一步解释问题。现在编写的目标函数具有重复的术语,很难从概念上理解您要最小化的内容。