Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cplex Python how to avoid printing the output

after setting the objective function and constraints, i use

prob.solve()
print prob.solution.get_objective_value()

actually, I just want to print the objective value, however, it displays a lot of information of cplex,

Tried aggregator 1 time.
LP Presolve eliminated 5 rows and 1 columns.
All rows and columns eliminated.
Presolve time = -0.00 sec. (0.00 ticks)
0.5

I just want to display the last line 0.5, how to avoid printing other information by Cplex? Thank you in advance.

like image 636
ilovecp3 Avatar asked Dec 04 '13 02:12

ilovecp3


2 Answers

cplex specifies 3 output streams: log, error, warning and results. You can disable the output with the commands. set_xxx_stream(None). In your example,

prob.set_log_stream(None)
prob.set_error_stream(None)
prob.set_warning_stream(None)
prob.set_results_stream(None)

will disable all output. You can also specify an output file, instead of None. There are also several parameters that you can set to control the verbosity of the cplex output, but this is the best way to prevent cplex from printing anything.

like image 73
David Nehme Avatar answered Nov 05 '22 20:11

David Nehme


You can adjust the verbosity level using the mip.display parameter:

# where c is a Cplex object
c.parameters.mip.display.set(0)

See here for more info.

like image 3
Tyler MacDonell Avatar answered Nov 05 '22 19:11

Tyler MacDonell