#python #pulp
#python #pulp
Вопрос:
Я делаю реализацию с использованием pulp на python в коде, который во время выполнения очень важен.
#Initialize model
model = LpProblem('eUCB_Model', sense=LpMaximize)
#Define decision variables
y = LpVariable.dicts('tenant', [(i) for i in range(size)], lowBound=None, upBound=None, cat='Binary')
#Define model
model = lpSum([y[i]*th_hat[t][i] for i in range(size)])
#Define Constraints
model = lpSum([y[i]*R[t][i] for i in range(size)]) <= C
#solving the model
model.solve()
моя проблема в том, что каждый раз, когда я вызываю решение модели с помощью model.solve()
метода, выводится много информации в терминале, например:
Welcome to the CBC MILP Solver
Version: 2.9.0
Build Date: Feb 12 2015
command line - /Users/henriquelima/opt/anaconda3/lib/python3.7/site-packages/pulp/apis/../solverdir/cbc/osx/64/cbc /var/folders/_6/r2j2fp7n5mxd5_1w2sbs8rvw0000gn/T/514d0624e4d645ae8582e6fa5203bc54-pulp.mps max ratio None allow None threads None presolve on strong None gomory on knapsack on probing on branch printingOptions all solution /var/folders/_6/r2j2fp7n5mxd5_1w2sbs8rvw0000gn/T/514d0624e4d645ae8582e6fa5203bc54-pulp.sol (default strategy 1)
At line 2 NAME MODEL
At line 3 ROWS
At line 6 COLUMNS
At line 19 RHS
At line 21 BOUNDS
At line 25 ENDATA
Problem MODEL has 1 rows, 3 columns and 3 elements
Coin0008I MODEL read with 0 errors
String of None is illegal for double parameter ratioGap value remains 0
String of None is illegal for double parameter allowableGap value remains 0
String of None is illegal for integer parameter threads value remains 0
String of None is illegal for integer parameter strongBranching value remains 5
Option for gomoryCuts changed from ifmove to on
Option for knapsackCuts changed from ifmove to on
Continuous objective value is 2.03584 - 0.00 seconds
Cgl0004I processed model has 0 rows, 0 columns (0 integer (0 of which binary)) and 0 elements
Cbc3007W No integer variables - nothing to do
Cuts at root node changed objective from -2.03584 to -1.79769e 308
Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)
Я хочу запустить этот метод без какого-либо типа информации, напечатанной в моем терминале, это может значительно сократить время выполнения программы. Вы знаете, как это сделать?
Спасибо всем.
Ответ №1:
Я не думаю, что отображение журнала является проблемой производительности. В любом случае, как показано в документации: https://coin-or.github.io/pulp/technical/solvers.html#pulp.apis.PULP_CBC_CMD
Вы можете просто передать msg=False
в качестве аргумента, выполнив:
model.solve(PULP_CBC_CMD(msg=False))
Комментарии:
1. Мне приходится запускать этот код несколько раз для очень длинных экземпляров, и это может повлиять на результаты. Ваш вклад был очень важен. большое вам спасибо =)