Sometimes the solver stops with a termination condition that is not known to pyomo, where the termination condition returned by pyomo is 'other' or 'unknown'. In such cases it is useful to use tee=True to look at the actual solver output and find out what the problem is. My question is that whether it is possible to have pyomo does not repress the solver output but store it in a python variable instead of printing it in the output, e.g., something like this:
pymoSolver = SolverFactory('gurobi')
optSoln = pyomoSolver.solve(myOptModel, tee = True) # and somehow store the solver output into a variable
If str(optSoln.solver.termination_condition).lower() in ['other', 'unknown']:
# Print out the actual solver output stored in a variable
print 'The actual solver output is as follows: ',variable_storing_solver_output
else:
# Do other stuff and does not show the solver output
The reason is that I normally don't like to see the actual solver output, unless the termination condition is 'other' or 'unknown'. Thanks!