如何禁用纸浆的计算日志

时间:2016-07-07 04:15:14

标签: python gurobi pulp

我和GUROBI一起在python中使用“纸浆”来解决一些优化问题。例如,GUROBI的计算日志是:

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)

我想禁用此输出,因为我将解决800k优化问题并在输出中写入这些日志会使我的代码太慢。是否有任何禁用这些日志的想法?

3 个答案:

答案 0 :(得分:1)

我刚刚发现我们如何做到这一点: 而不是默认的调用Gurobi的方式,即:

pulp.GUROBI().solve(prob)

我们需要写:

pulp.GUROBI(msg=0).solve(prob)

答案 1 :(得分:0)

m0_as的回答是正确的。只是想分享更多细节。在PuLP库中,每个求解器类都派生自相同的基类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

在构造函数中,这些是msg参数,它定义是否要将信息从求解器回显到stdout。这是class GUROBI

的实现

见第1774行

    @param msg: displays information from the solver to stdout

您可以非常轻松地在此源文件中轻松找到其他求解器特定参数。

答案 2 :(得分:0)

您需要显式声明一个求解器,因此请替换此行

p.solve()

与此

p.solve(PULP_CBC_CMD(msg=0))

或用您正在使用的任何求解器替换`PULP_CBC_CMD。