Solving Pyomo Models
Solving ConcreteModels
If you have a ConcreteModel, add these lines at the bottom of your Python script to solve it
>>> opt = pyo.SolverFactory('glpk')
>>> opt.solve(model)
Solving AbstractModels
If you have an AbstractModel, you must create a concrete instance of your model before solving it using the same lines as above:
>>> instance = model.create_instance()
>>> opt = pyo.SolverFactory('glpk')
>>> opt.solve(instance)
pyomo solve
Command
To solve a ConcreteModel contained in the file my_model.py
using the
pyomo
command and the solver GLPK, use the following line in a
terminal window:
pyomo solve my_model.py --solver='glpk'
To solve an AbstractModel contained in the file my_model.py
with data
in the file my_data.dat
using the pyomo
command and the solver GLPK,
use the following line in a terminal window:
pyomo solve my_model.py my_data.dat --solver='glpk'
Supported Solvers
Pyomo supports a wide variety of solvers. Pyomo has specialized
interfaces to some solvers (for example, BARON, CBC, CPLEX, and Gurobi).
It also has generic interfaces that support calling any solver that can
read AMPL “.nl
” and write “.sol
” files and the ability to
generate GAMS-format models and retrieve the results. You can get the
current list of supported solvers using the pyomo
command:
pyomo help --solvers