简体   繁体   中英

Is there a bug with using timelimit within pulp in python using CPLEX?

I am currently writing my thesis, where I want to implement an algorithm to converges towards a good solution using a large OR model.

I can include the model, if you will need it to answer my question or better yet understand my question.

When I run the model with a certain timelimit (60 seconds in this case), the model ignores it and solve to optimality. See the code, where I solve the model prob :

path_to_cplex = r'C:\Program Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64\cplex.exe'
solver = pulp.CPLEX_CMD(path=path_to_cplex,timelimit=timelimitnumber)

print('The timelimit on the solver is: '+str(solver.timelimit))
print('Start Solving')

prob.solve(solver)
status =  pulp.LpStatus[prob.status]
ObjectiveValue = prob.objective.value()
solutiontime = prob.solutionTime

print('The solution time was: '+str(solutiontime))

The output for solving this model is:

The timelimit on the solver is: 60
Start Solving
The solution time was: 225.6275095000001

Am I doing anything wrong here? I hope you can help.

UPDATE:

CPLEX log:

Log started (V12.10.0.0) Fri Nov  6 14:46:47 2020


Problem 'Plant_Allocation_Problem-pulp.lp' read.
Read time = 3.30 sec. (185.85 ticks)
New value for time limit in seconds: 60
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de2ae
CPXPARAM_TimeLimit                               60
Found incumbent of value 6.8557690e+08 after 0.42 sec. (345.18 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 75703 rows and 75650 columns.
MIP Presolve modified 2500 coefficients.
Reduced MIP has 77062 rows, 3655050 columns, and 7312500 nonzeros.
Reduced MIP has 50 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 3.44 sec. (2580.68 ticks)
Tried aggregator 1 time.
Detecting symmetries...
Elapsed time for symmetry detection = 6.13 sec. (10026.07 ticks)
Elapsed time for symmetry detection = 11.86 sec. (20030.20 ticks)
Elapsed time for symmetry detection = 17.83 sec. (30034.36 ticks)
Elapsed time for symmetry detection = 23.98 sec. (40038.62 ticks)
Elapsed time for symmetry detection = 29.72 sec. (50042.91 ticks)
Elapsed time for symmetry detection = 35.19 sec. (60047.07 ticks)
Elapsed time for symmetry detection = 40.64 sec. (70051.21 ticks)
Elapsed time for symmetry detection = 46.19 sec. (80055.38 ticks)
Presolve time = 54.67 sec. (89646.54 ticks)

Root node processing (before b&c):
  Real time             =   60.16 sec. (93475.49 ticks)
Parallel b&c, 12 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =   60.16 sec. (93475.49 ticks)

Solution pool: 1 solution saved.

MIP - Time limit exceeded, integer feasible:  Objective =  6.8557690211e+08
Current MIP best bound =  0.0000000000e+00 (gap = 6.85577e+08, 100.00%)
Solution time =   60.17 sec.  Iterations = 0  Nodes = 0
Deterministic time = 93486.16 ticks  (1553.65 ticks/sec)

MILP problem relaxed to LP with fixed integer variables using
incumbent solution.
Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de2ae
CPXPARAM_TimeLimit                               60
Parallel mode: deterministic, using up to 12 threads for concurrent optimization:
 * Starting dual Simplex on 1 thread...
 * Starting Barrier on 9 threads...
 * Starting primal Simplex on 1 thread...
 * Starting Sifting on 1 thread...
Tried aggregator 1 time.
LP Presolve eliminated 152765 rows and 3730700 columns.
All rows and columns eliminated.
Presolve time = 2.09 sec. (1210.10 ticks)

Dual simplex solved model.


Dual simplex - Optimal:  Objective =  2.1151566247e+08
Solution time =    4.14 sec.  Iterations = 0 (0)
Deterministic time = 1929.76 ticks  (466.01 ticks/sec)


Solution written to file 'Plant_Allocation_Problem-pulp.sol'.

I think the issue is the prob.solutionTime attribute, which you assume (correctly or incorrectly) to be in seconds. I'm not sure what units it has.

The code shows the current logic used in pulp, you'd have to check the time library of python for more information.

try:
    from time import process_time as clock
except ImportError:
    from time import clock

# (...)
self.solutionTime = -clock()
status = solver.actualSolve(self, **kwargs)
self.solutionTime += clock()
#(...)

If you want to keep the log file, you can do the following:

solver = pulp.CPLEX_CMD(path=path_to_cplex,timelimit=timelimitnumber, logPath='PATH_TO_LOG.log')

More information on possible arguments for CPLEX_CMD at: https://coin-or.github.io/pulp/technical/solvers.html#pulp.apis.CPLEX_CMD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM