简体   繁体   English

Pyomo中的多索引约束或目标

[英]Multi indexed constraints or objectives in Pyomo

I have a fairly basic MILP that I'm trying to solve, but while my code runs ok I do not actually get any values. 我正在尝试解决一个相当基本的MILP,但是当我的代码运行正常时,我实际上没有任何值。 I think this is because of my objective function (since changing it to something trivial does produce an answer): 我认为这是由于我的目标函数(因为将其更改为琐碎的事情确实会产生答案):

def OPEX (m):
    return sum (m.Q_ng[u,t]*m.ng_price[t] + m.E_imp[t]*m.el_price_imp[t] - m.E_exp[t]*m.el_price_exp[t] for u in m.U for t in m.P)
m.obj = Objective(rule=OPEX)

I need to minimise the sum over u and t , is this how you would go about it? 我需要最小化ut的总和,这是你要怎么做?

My problem ended up being how I wrote my constraints. 我的问题最终是我如何编写约束。 According to the book by William E. Hart, Carl Laird, Jean-Paul Watson and David L. Woodruff: Pyomo - Optimization Modeling in Python , you can write functions with _rule appended to them and then when you define your constraint just name it the same without using rule, eg 根据William E. Hart,Carl Laird,Jean-Paul Watson和David L.Woodruff的书:Pyomo-Python中的优化建模 ,您可以编写带有_rule函数,然后在定义约束时将其命名为不使用规则,例如

def BOIL_off_rule (m,t):
    return (0,m.f["BOIL",t]*Boiler_max,Boiler_max*y["BOIL",t])
m.BOIL_off = Constraint(m.P)

However this doesn't seem to work (possibly because in the book they use coopr which includes other libraries / modules and not just Pyomo) 但是,这似乎不起作用(可能是因为在书中他们使用了coopr,其中包括其他库/模块而不仅仅是Pyomo)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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