Hi,
I am very new to Pyomo, but seem to have gotten it running with the glpk solver. I am trying to integrate pyomo into some already-built Python models to optimize some inputs. I have a steady-state heat exchanger model that is basically trying to minimize the temperature difference between two fluids while satisfying a simple constraint. I am trying to use pyomo to adjust the mass flows of the fluids to do this, and I got something that runs, but it is saying the constraint function is constant, and therefore is not optimizing. Here are the outputs I get:
WARNING: Constant objective detected, replacing with a placeholder to prevent solver failure.
# ==========================================================
# = Solver Results =
# ==========================================================
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
Lower bound: 418.919688579
Upper bound: 418.919688579
Number of objectives: 1
Number of constraints: 2
Number of variables: 5
Number of nonzeros: 5
Sense: maximize
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
Termination condition: optimal
Statistics:
Branch and bound:
Number of bounded subproblems: 1
Number of created subproblems: 1
Error rc: 0
Time: 0.00999999046326
# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
number of solutions displayed: 0
Displaying Solution
------------------------------------------------------------
x : Size=4, Index=t
Key : Lower : Value : Upper : Fixed : Stale : Domain
1 : 1 : 1.0 : 24 : False : False : NonNegativeIntegers
2 : 1 : 1.0 : 24 : False : False : NonNegativeIntegers
3 : 1 : 1.0 : 24 : False : False : NonNegativeIntegers
4 : 1 : 1.0 : 24 : False : False : NonNegativeIntegers
My guess is that it is how I set up the objective function. What i am doing is taking a pyomo variable, inserting its value into another python variable, doing a much of math with that, then returning a value. Here is some of the key code:
import pyomo.environ as po
model = po.ConcreteModel()
model.t = po.RangeSet(1, len(self.mode_list))
model.x = po.Var(model.t, initialize=1, bounds=(1, 24), domain=po.NonNegativeIntegers)
def objective_function(model):
for i in model.t:
mode_list[i-1].run_time = model.x[i].value
...bunch of math to get objective as a Python float...
return objective
mode_list is a list of objects containing the attribute run_time, which does bunch of math to determine mass flows and the heat transfer dynamics.
So do I have to completely alter all of my code to use pyomo parameters and sets and all that? Is there an easy way to patch this up? Thanks for any advice.
Miles