何时使用 sum v.s。 lpSum 使用纸浆?

When to use sum v.s. lpSum using pulp?

案例研究“A Set Partitioning Problem”中pulp文档中的“sum”用于表示约束条件,例如:

#A guest must seated at one and only one table
for guest in guests:
    seating_model += sum([x[table] for table in possible_tables
                                if guest in table]) == 1, "Must_seat_%s"%guest

而“lpSum”似乎另有用途。例如,考虑案例研究中的以下约束 A Transportation Problem

for b in Bars:
    prob += lpSum([vars[w][b] for w in Warehouses])>=demand[b], "Sum_of_Products_into_Bar%s"%b

第一个例子为什么用“sum”?以及何时使用“总和”v.s。 “lpSum”?

每次在求和表达式中至少有一个 pulp 变量时,您应该使用 lpSum。使用 sum 并没有错,只是效率更低。我们可能应该更改文档以使它们保持一致。随意打开一个问题,或者更好的是,做一个 PR 以便我们可以更正 Set Partitioning Problem 示例。