Pyomo installation: see http://www.pyomo.org/installation
pip install pyomo
See also these excellent tutorials that details how to install Pyomo and several solvers (GLPK, COIN-OR CBC, COIN-OR Ipopt, ...):
In [ ]:
from pyomo.environ import *
In [ ]:
model = ConcreteModel(name="Getting started")
model.x = Var(bounds=(-10, 10))
model.obj = Objective(expr=model.x)
model.const_1 = Constraint(expr=model.x >= 5)
# @tail:
opt = SolverFactory('glpk') # "glpk" or "cbc"
res = opt.solve(model) # solves and updates instance
model.display()
print()
print("Optimal solution: ", value(model.x))
print("Cost of the optimal solution: ", value(model.obj))
# @:tail
Optimal total cost is: 350.0
x_1 = 50.
x_2 = 50.
In [ ]:
model = ConcreteModel(name="Getting started")
model.x1 = Var(within=NonNegativeReals)
model.x2 = Var(within=NonNegativeReals)
model.obj = Objective(expr=4. * model.x1 + 3. * model.x2, sense=maximize)
model.ineq_const_1 = Constraint(expr=model.x1 + model.x2 <= 100)
model.ineq_const_2 = Constraint(expr=2. * model.x1 + model.x2 <= 150)
model.ineq_const_3 = Constraint(expr=3. * model.x1 + 4. * model.x2 <= 360)
# @tail:
opt = SolverFactory('glpk') # "glpk" or "cbc"
results = opt.solve(model) # solves and updates instance
model.display()
print()
print("Optimal solution: ({}, {})".format(value(model.x1), value(model.x2)))
print("Gain of the optimal solution: ", value(model.obj))
# @:tail