使用 pyomo 最大化方程的三个约束

问题描述 投票:0回答:0

我试着解下一个方程

最大 Y = -787.09 + 34.22 * A + 707.37 * B + 5659.41 * C - 0.64 * A^{2} - 176.08 * B^{2} - 16520.51 * C^{2} - 1481.21 * B * C

受限于

一个* PA< PES_A

B * 铅 < PES_B

C * 电脑< PES_C

所以我使用 Pyomo 构建下一个代码

model=ConcreteModel()

model.A=Var(within=NonNegativeReals)

model.B=Var(within=NonNegativeReals)

model.C=Var(within=NonNegativeReals)

model.maximizeZ = Objective(expr=-787.09 + 34.22*model.A + 707.37*model.B + 5659.41*model.C - 0.64*(model.A**2) - 176.08*(model.B**2)  - 16520.51*(model.C**2)  - 1481.21*model.B*model.C, sense=maximize)

但是我在尝试在模型集中专门定义约束时遇到了一些麻烦,这就是我所做的功能

p_m=[PA,PB,PC]
pes_ma=[PES_A,PES_B,PES_C]

model.my_set = Set(initialize=[1 , 2, 3])

def my_rule(model, i):
      return model*p_ma[i-1] <= pre_ma[i-1]

model.Pes = Constraint(model.my_set, rule=my_rule)

但是我得到了下一个错误

WARNING: Implicitly replacing the Component attribute my_set (type=<class
    'pyomo.core.base.set.OrderedScalarSet'>) on block unknown with a new
    Component (type=<class 'pyomo.core.base.set.AbstractOrderedScalarSet'>).
    This is usually indicative of a modelling error. To avoid this warning,
    use block.del_component() and block.add_component().
WARNING: Implicitly replacing the Component attribute Presupuesto (type=<class
    'pyomo.core.base.constraint.IndexedConstraint'>) on block unknown with a
    new Component (type=<class
    'pyomo.core.base.constraint.IndexedConstraint'>). This is usually
    indicative of a modelling error. To avoid this warning, use
    block.del_component() and block.add_component().
ERROR: Rule failed when generating expression for Constraint Presupuesto with
    index 1: TypeError: unsupported operand type(s) for *: 'ConcreteModel' and
    'float'
ERROR: Constructing component 'Presupuesto' from data=None failed: TypeError:
    unsupported operand type(s) for *: 'ConcreteModel' and 'float'

有什么帮助吗?请

python optimization constraints pyomo maximize
© www.soinside.com 2019 - 2024. All rights reserved.