oliversm
oliversm

Reputation: 1967

Pyomo - Set maximum number of function evaluations using baron solver

I would like to set the maximal number of function evaluations when using Pyomo (with the BARON solver). My code is:

from __future__ import division
from pyomo.environ import *
opt = SolverFactory('baron')
m = ConcreteModel()
m.x1 = Var(bounds=(-10.0, 10.0))
m.x2 = Var(bounds=(-10.0, 10.0))
m.o = Objective(expr=(2.0 * m.x2 + m.x1 - 7.0) ** 2.0 + (2.0 * m.x1 + m.x2 - 5.0) ** 2.0)
results = opt.solve(m) # maxEvaluations=5
print results

where the expr corresponds to Booth' function. I would like to set the maximal number of function evaluations as the terminating criteria. How can I achieve this?

If it is also possible to get a more verbose output of results, ideally listing the running best result with the number of function evaluations, then that would be a bonus.

Upvotes: 0

Views: 651

Answers (1)

jsiirola
jsiirola

Reputation: 2634

You can send options to solvers as a dictionary using the options keyword argument for the solve method. Options are passed through to the solver verbatim. You will need to look at the individual solver documentation to see what options it supports (for BARON, see here). For example:

solver = SolverFactory('baron')
solver.solve(model, options={'MaxIter': 5})

If you want to watch the solver process in realtime, you can tell Pyomo to not suppress the solver stdout/stderr output using the tee option:

solver.solve(model, options={'MaxIter': 5}, tee=True)

As almost all solvers are launched as separate subprocesses, there is (currently) no way for Pyomo to get intrusive information (like the current incumbent variable values) during the solver execution.

Upvotes: 1

Related Questions