简体   繁体   中英

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

I am trying to generate an equation via lpDot() , Such as

PulpVar = [x1,x2]

Constants = [5,6]

then doing dot product as:

model += lpDot(PulpVar, Constants)

Form what I understand this should generate an equation as x1*5+x2*6

but I am getting lpAffineExpression as output and the lp file so generated is empty

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

So, if you use with constants, lpDot() will return dot product, that is a <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))

Output:

17 <class 'pulp.pulp.LpAffineExpression'>

If you quant the equation x1*5+x2*6 you should use LpVariable like this:

import pulp


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

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

Output:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM