简体   繁体   English

如何在pyomo的目标函数中使用最小值和最大值

[英]How to use min & max in objective function in pyomo

I am very new to Pyomo, working on a use case where my objective function coefficient is dynamic & needs a min-max function.我对 Pyomo 很陌生,正在研究一个用例,其中我的目标函数系数是动态的并且需要一个最小-最大函数。

Objective function = Max( sum (P * UC) - sum ( P - min(P)) * UC where P is variable needs to be optimized and UC is function which is derived value based on some calculation.目标函数 = Max( sum (P * UC) - sum ( P - min(P)) * UC 其中 P 是变量需要优化,UC 是基于某些计算得出的值的函数。

I have few doubts我几乎没有怀疑

  1. how to use min or max function in objective function, I have tried np.min or calling function but it gives error since function has if else condition如何在目标函数中使用 min 或 max 函数,我尝试过 np.min 或调用函数但它给出错误,因为函数具有 if else 条件
  2. Since coefficient is dynamic ie derived from some function on the basis of calculation should we go ahead with AbstractModel or ConcreteModel由于系数是动态的,即在计算的基础上从某个函数导出,我们应该继续使用 AbstractModel 还是 ConcreteModel

I have tried multiple things but none seems to be working.我尝试了多种方法,但似乎没有任何效果。 If someone can help me with dummy code that will be great.如果有人可以帮助我编写虚拟代码,那就太好了。

Thanks in Advance.提前致谢。

Min could be implemented by defining a new variable min_P , which needs to be smaller than any of the P , expressed by constraints: Min 可以通过定义一个新变量min_P来实现,该变量需要小于任何P ,由约束表示:

min_P <= P[i] for all i min_P <= P[i]对于所有 i

This will make sure, that min_P is not larger than the smallest of the P .这将确保min_P不大于P的最小值。 Then you can just use min_P in your objective function.然后你可以在你的目标函数中使用min_P I assume you know how to define constraints like this.我假设您知道如何定义这样的约束。 This might result in an unbound variable problem, depending on how exactly you are optimizing, but this should put you on the right track.这可能会导致未绑定变量问题,具体取决于您优化的准确程度,但这应该使您走上正确的轨道。

The max case is analogous, if you define another value for the expression sum (P * UC) - sum ( P - min(P)) .最大情况类似,如果您为表达式sum (P * UC) - sum ( P - min(P))定义另一个值。

It is not clear whether UC is a parameter or a variable itself (calculated in another constraint).目前尚不清楚UC是参数还是变量本身(在另一个约束中计算)。 In the latter case, the whole problem will be highly nonlinear and should be reconsidered.在后一种情况下,整个问题将是高度非线性的,应该重新考虑。

I do not understand your AbstractModel vs ConcreteModel question.我不明白您的 AbstractModel 与 ConcreteModel 问题。 If you have the data available, use a ConcreteModel.如果您有可用的数据,请使用 ConcreteModel。 Apart from that, see here .除此之外,请参见此处

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

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