7

I am using "pulp" in python together with GUROBI to solve some optimization problems. For example, the calculations log for GUROBI is:

Optimize a model with 12 rows, 25 columns and 39 nonzeros
Coefficient statistics:
  Matrix range    [1e+00, 1e+00]
  Objective range [1e+00, 1e+00]
  Bounds range    [1e+00, 1e+00]
  RHS range       [1e+00, 1e+00]
Found heuristic solution: objective 12
Presolve removed 3 rows and 12 columns
Presolve time: 0.00s
Presolved: 9 rows, 13 columns, 27 nonzeros
Variable types: 0 continuous, 13 integer (13 binary)

Root relaxation: objective 7.000000e+00, 11 iterations, 0.00 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

*    0     0               0       7.0000000    7.00000  0.00%     -    0s

Explored 0 nodes (11 simplex iterations) in 0.00 seconds
Thread count was 4 (of 4 available processors)

Optimal solution found (tolerance 1.00e-04)
Best objective 7.000000000000e+00, best bound 7.000000000000e+00, gap 0.0%
('Gurobi status=', 2)

I want to disable this output because I am going to solve 800k optimization problems and writing these logs in the output make my code too slow. Any idea for disabling these logs?

m0_as
  • 451
  • 1
  • 5
  • 13

3 Answers3

9

You need to explicitly declare a solver so replace this line

p.solve()

with this

p.solve(PULP_CBC_CMD(msg=0))

or replace `PULP_CBC_CMD with whatever solver you are using.

David Buck
  • 3,752
  • 35
  • 31
  • 35
user9123297
  • 99
  • 1
  • 2
5

I just found how we can do that: instead of default way of calling Gurobi which is:

pulp.GUROBI().solve(prob)

we need to write:

pulp.GUROBI(msg=0).solve(prob)
m0_as
  • 451
  • 1
  • 5
  • 13
3

m0_as's answer is correct. Just want to share some more details. In PuLP library each solver class derives from the same base class LpSolver.

class LpSolver:
    """A generic LP Solver"""

    def __init__(self, mip = True, msg = True, options = [], *args, **kwargs):
        self.mip = mip
        self.msg = msg
        self.options = options

In the constructor these is msg parameter which defines if you want to echo information from solver to stdout. This is implementation of class GUROBI

See line 1774 it says

    @param msg: displays information from the solver to stdout

You can easily found other solver specific parameters in this source file very easily.

fmars
  • 139
  • 1
  • 4