Python 如何禁用纸浆的计算日志

Python 如何禁用纸浆的计算日志,python,gurobi,pulp,Python,Gurobi,Pulp,我正在使用python中的“纸浆”和GUROBI来解决一些优化问题。例如,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

我正在使用python中的“纸浆”和GUROBI来解决一些优化问题。例如,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优化问题,在输出中写入这些日志会使我的代码太慢。有没有禁用这些日志的想法?

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

pulp.GUROBI().solve(prob)
我们需要写:

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

m0_as的答案是正确的。我只是想分享更多的细节。在纸浆库中,每个解算器类都派生自同一基类LPSOVER

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参数,用于定义是否要将信息从解算器回显到标准输出。这是执行

见第1774行

    @param msg: displays information from the solver to stdout

您可以很容易地在此源文件中找到其他特定于解算器的参数。

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

p.solve()
用这个

p.solve(PULP_CBC_CMD(msg=0))
或者用您正在使用的任何解算器替换“palp\u CBC\u CMD”