本文介绍了纸浆:lpDot()有什么作用,如何使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

PulpVar = [x1,x2]

Constants = [5,6]

然后将点积做为:

model += lpDot(PulpVar, Constants)

据我所知,这应该生成一个等式为 x1 * 5 + x2 * 6

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

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

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

推荐答案

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

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))

输出:

17 <class 'pulp.pulp.LpAffineExpression'>

如果您对方程式 x1 * 5 + x2 * 6 进行量化,则应使用 LpVariable ,如下所示:

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))

输出:

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

这篇关于纸浆:lpDot()有什么作用,如何使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 17:52