0

Is there a way to get from pyomo a list of the objective values at every X iterations, especially when using cbc?

The usual way of running the solver only returns the final solver results.

results = SolverFactory('cbc').solve(model)
results.write()
print(model.obj()) # final objective value
gameveloster
  • 901
  • 1
  • 6
  • 18

1 Answers1

1

You can add the tee=True option to your call to solve to print the solver log to the screen. Most solvers will print out the value of the objective function at every iteration.

SolverFactory('cbc').solve(model, tee=True)

Pyomo doesn't automatically load/record solver information at intermediate iterations but you could always write a simple parser to read the solver log file into Python and extract the values you want. An example of doing this for Ipopt can be found here: https://github.com/Pyomo/pyomo/blob/main/pyomo/contrib/parmest/utils/ipopt_solver_wrapper.py

Bethany Nicholson
  • 2,723
  • 1
  • 11
  • 18