【发布时间】:2017-02-15 22:33:58
【问题描述】:
我希望能够将pyomo 中的积分定义为目标函数的一部分。
我不知道积分需要什么样的表达式。
这是我的最佳猜测:
model = ConcreteModel()
model.t = ContinuousSet(bounds = (0,1))
model.y = Var(model.t)
model.dydt = DerivativeVar(model.y, wrt=(model.t))
def myintegral(model,i):
return model.dydt[i]
model.n = Integral(model.t, wrt=model.t, rule=myintegral) # this line is the trouble
def myobjective(model):
return model.n
model.obj = Objective(rule=myobjective)
错误是:TypeError: A callable type that is not a Pyomo expression can not be used to initialize an Expression object. Use 'rule' to initalize with function types.
但是,我不明白为什么积分内部的表达式有问题,因为这些变量似乎完全可以通过索引model.t 进行索引:
# but, this is totally fine:
print model.dydt[0]
print model.dydt[1]
我对此有什么误解吗?
以下是我迄今为止咨询过的一些资源:
https://groups.google.com/forum/#!topic/pyomo-forum/6RhEXEMDTPc https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_parameters https://projects.coin-or.org/Coopr/browser/pyomo/trunk/examples/dae/Heat_Conduction.py?rev=9315
我愿意接受有关pyomo 的其他资源的建议/链接。
【问题讨论】: