我试图将几个lpSum表达式连接到一个长表达式,这将是我的目标函数。然而,我以优雅的方式合并这些表达式的尝试导致了不希望的结果。
我想要这样的东西:
a = pulp.lpSum(...)
b = pulp.lpSum(...)
c = pulp.lpSum(...)
prob += a + b - c
对我的代码更具体:
alloc_prob = pulp.LpProblem("Supplier Allocation Problem", pulp.LpMinimize)
TPC_func = pulp.lpSum(X[s][p]*procCosts[s][p] for s in supplier for p in
project), "Total Procurement Costs"
TTC_func = pulp.lpSum(X[s][p]*transCosts[s][p] for s in supplier for p in
project), "Total Transportation Costs (incl. taxes/duties)"
TD_func = pulp.lpSum(X_SEP[c][1]*discountFactor['Bonus / ton [€/t]'][c] for
c in company), "Total Discounts"`
# Objective function: TPC + TTC - TD -> min
alloc_prob += TPC_func + TTC_func - TD_func
我已经尝试过不同的嵌套方法,例如:
prob += [pulp.lpSum(X[s][p]*procCosts[s][p] + X[s][p]*transCosts[s][p] for s
in supplier for p in project) - pulp.lpSum(X_SEP[c][1]*discountFactor['Bonus
/ ton [€/t]'][c] for c in company)]
输出做它应该做的。然而,这既不是一个很好的代码,也不能分配给目标函数。有没有聪明的实施方式?
杨__羊羊
相关分类