纸浆:lpDot() 做什么,如何使用它

Pulp : What does lpDot() does, How to use it

我正在尝试通过 lpDot() 生成方程式,例如

PulpVar = [x1,x2]

Constants = [5,6]

然后做点积:

model += lpDot(PulpVar, Constants)

根据我的理解,这应该生成一个等式 x1*5+x2*6

但我得到 lpAffineExpression 作为输出,这样生成的 lp 文件是空的

lpDot() – given two lists of the form [a1, a2, …, an] and [ x1, x2, …, xn] will construct a linear epression to be used as a constraint or variable ref

因此,如果您使用常量,lpDot() 将 return 点积,即 <class 'pulp.pulp.LpAffineExpression'>:

import pulp

x1 = [1]
x2 = [2]

X = [x1,x2]
Constants = [5, 6]

model = pulp.lpDot(X, Constants)
print(model, type(model))

输出:

17 <class 'pulp.pulp.LpAffineExpression'>

如果您量化方程式 x1*5+x2*6,您应该像这样使用 LpVariable

import pulp


PulpVar1 = pulp.LpVariable('x1')
PulpVar2 = pulp.LpVariable('x2')
Constants = [13, 2]

model = pulp.lpDot([PulpVar1, PulpVar2], Constants)
print(model, type(model))

输出:

5*x1 + 6*x2 <class 'pulp.pulp.LpAffineExpression'>