'LpAffineExpression'对象在纸浆Lp问题中没有属性'solve'-优化

问题描述

$Object = [Ordered]@{
    'Null' = $Null
    'EmptyString' = ''
    'EmptyArray' = @()
    'SingleItem' =,''
    'EmptyHashtable' = @{}
}
ConvertTo-Expression $Object

我尝试在纸浆中进行线性编程。但是我有'LpAffineExpression'对象没有属性'solve'错误

我该如何解决?谢谢。

解决方法

我建议先研究以下示例:https://www.coin-or.org/PuLP/CaseStudies/a_blending_problem.html。它具有涵盖您的示例的所有要素。

因此工作模型如下所示:

import pulp as p
import numpy as np
 
a1=np.array([1000,2000,3000,7000,8000,13000,223000,32000,35000,369000,38000,3885000])

x=p.LpVariable('x',lowBound=5000,cat='Continuous')
y=p.LpVariable('y',lowBound=8000,cat='Continuous')

Lp_prob = p.LpProblem("This_Example_Works",p.LpMaximize)
Lp_prob += (((y-x)*1.3+x)*0.014428)+((a1-y)*1.5*0.014428)
Lp_prob.solve()
print("Status:",p.LpStatus[Lp_prob.status])

请注意,PuLP将其解释为:

MAXIMIZE
-0.0043284000000000005*x + -0.24094759999999996*y + 99899.472
VARIABLES
5000 <= x Continuous
8000 <= y Continuous

非常奇怪的构造a1-y在这里解释为sum(a1-y)=sum(a1)-n*y,其中n=a1.size。我建议不要在PuLP模型中以这种方式使用NumPy数组。