How to define an Integral as an objective function in pyomo?
<p>I want to be able to define an integral in <code>pyomo</code> as part of an objective function. </p>

<p>I cannot figure out what kind of expression is needed for the integral.<br>
Here's my best guess:</p>

<pre><code>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)
</code></pre>

<p>The error is: <code>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.</code></p>

<p>But, I don't understand why the expression inside of the integral is a problem, since these variables seem to be totally indexable by the index <code>model.t</code>:</p>

<pre><code># but, this is totally fine:  
print model.dydt[0]
print model.dydt[1]
</code></pre>

<p>Am I misunderstanding something about this?  </p>

<p>Here are some resources that I consulted thus far: </p>

<p><a href="https://groups.google.com/forum/#!topic/pyomo-forum/6RhEXEMDTPc" rel="nofollow">https://groups.google.com/forum/#!topic/pyomo-forum/6RhEXEMDTPc</a>
<a href="https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_parameters" rel="nofollow">https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_parameters</a>
<a href="https://projects.coin-or.org/Coopr/browser/pyomo/trunk/examples/dae/Heat_Conduction.py?rev=9315" rel="nofollow">https://projects.coin-or.org/Coopr/browser/pyomo/trunk/examples/dae/Heat_Conduction.py?rev=9315</a></p>

<p>I'm open to suggestions/links about other resources about <code>pyomo</code>.</p>

<p>This looks like a bug. You should open up a ticket here: <a href="https://github.com/Pyomo/pyomo/issues" rel="nofollow">https://github.com/Pyomo/pyomo/issues</a></p>

python pyomo