Pyomo installation: see http://www.pyomo.org/installation
pip install pyomo
In [ ]:
from pyomo.environ import *
In [ ]:
model = ConcreteModel(name="Getting started")
model.x1 = Var(initialize=1.5)
model.x2 = Var(initialize=1.5)
def rosenbrock(model):
return (1.0 - model.x1)**2 + 100.0 * (model.x2 - model.x1**2)**2
model.obj = Objective(rule=rosenbrock, sense=minimize)
model.pprint()
# @tail:
print()
print("-" * 60)
print()
opt = SolverFactory('ipopt')
results = opt.solve(model)
model.display()
print()
print("Optimal solution: ", value(model.x1), value(model.x2))
print("Gain of the optimal solution: ", value(model.obj))
# @:tail