Search code examples
pythonpyomo

How to change Pyomo solver interface


Using Pyomo, instead of creating a file that is to be sent to the solver, I want to start using the Python interface of solvers that are compatible (i.e. CPLEX or GUROBI). What is the default solver interface when not specified, and how can someone specify the wanted solver interface within this code?:

opt = SolverFactory('gurobi')
results = opt.solve(model, options= solverOptions)

Solution

  • You can either create the direct solver explicitly:

    from pyomo.environ import SolverFactory
    solver = SolverFactory('gurobi_direct')
    

    or with using the "python" IO option to the Gurobi "metasolver":

    solver = SolverFactory('gurobi', solver_io='python')