简体   繁体   English

是否可以在 Pyomo 的目标 function 内编写非线性分段 function?

[英]is it possible to write a nonlinear piecewise function inside the objective function in Pyomo?

I want to use Pyomo to solve a nonlinear optimization using Ipopt.我想使用 Pyomo 来解决使用 Ipopt 的非线性优化。 In this regard I devised a function as an objective function in my code which itself uses another function inside it.在这方面,我在我的代码中设计了一个 function 作为目标 function,它本身在其中使用了另一个 function。 the inner function is nonlinear and piecewise and is defined as follows.内部 function 是非线性和分段的,定义如下。

def U3(x,omega,U_alpha3):
       if x<=omega/U_alpha3:
              return omega*x-U_alpha3/2*x**2
       else:
              return 0.5*omega**2/U_alpha3

But this function leads to this error:但是这个 function 导致这个错误:

TypeError: '<=' not supported between instances of 'IndexedComponent_slice' and 'numpy.float64'

considering that my decision variable goes inside x (which is 'IndexedComponent_slice' type) and omega and U_alpha3 are fixed parameters(which are 'numpy.float64' type)考虑到我的决策变量在 x 内部(它是“IndexedComponent_slice”类型)并且 omega 和 U_alpha3 是固定参数(它们是“numpy.float64”类型)

Yes.是的。 The Pyomo NL-file interface to Ipopt supports this via the Expr_If expression class, given the standard caveats about the function you are defining being twice-continuously differentiable, etc. (which we do not verify for you). Ipopt 的 Pyomo NL 文件接口通过Expr_If表达式 class 支持这一点,考虑到关于 function 的标准警告,您定义的是两次连续可微分等(我们不会为您验证)。

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

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