0

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'.
  • try adding the `msg=True` argument for the solver. You can then see the CPLEX log and check what's going on and if the parameters is passed correctly. – pchtsp Nov 06 '20 at 11:18
  • Hi, This might be a dumb question. But where does should this message be? I have looked at in my folder, where a CPLEX.log is, but it delete itself, when the solver is done. I was fast and look inside the file, where I saw the following in the log: – Jakob Kaufmann Jespersen Nov 06 '20 at 13:00
  • And in this log, I can see the following line (the max characters does not allow me to post the entire log): `CPXPARAM_TimeLimit 60` So it must be something else? – Jakob Kaufmann Jespersen Nov 06 '20 at 13:06
  • Which version of CPLEX are you using? Also, could you add the log printed from the solver to your question? – abc Nov 06 '20 at 13:50
  • I have added the CPLEX log to my quesion now. According to the log - maybe CPLEX V.12.10.0.0? I just downloaded CPLEX a month ago, so I should be somewhat updated. – Jakob Kaufmann Jespersen Nov 06 '20 at 14:05

1 Answers1

0

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

pchtsp
  • 794
  • 1
  • 6
  • 15
  • Hi @pchtsp, I have added the CPLEX log for my model to my question here in stackoverflow. it still returns after ~210 seconds. I have also timed it on my phone to verify it. According to the CPLEX log, the solution time should be 4.14 sec + 60.17 sec right? But pulp does not return the solution before ~210 sec. What am I missing here? According to all measurements, all attributes must be in seconds, right? – Jakob Kaufmann Jespersen Nov 06 '20 at 13:57
  • You need to profile your code to check where it's spending time. The 60s of CPLEX only consider the solving part itself... Maybe pulp is taking time somewhere else. – pchtsp Nov 06 '20 at 17:24
  • I think I know, where its spending time. I have timed it between, when it start solving and ends solving. This takes around 210 seconds. Within these seconds the CPLEX log happens. This means, that there is ~150 seconds for the solver to do something, that I do not know anything about. No log, nothing. And it returns the solution offered by CPLEX after ~60 seconds. So I think my problem lies within figuring out, what the solver do for the remaining 150 seconds. But for me it is a black box. Can one get some kind of log of what happens inside the pulp solver? – Jakob Kaufmann Jespersen Nov 07 '20 at 09:29
  • You can try profiling the code, as I said: https://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script this will tell you which function takes time. – pchtsp Nov 07 '20 at 23:39
  • Ah, sorry. Did not know, what you meant by profiling your code. I will definitely try that. Thanks for the help. – Jakob Kaufmann Jespersen Nov 08 '20 at 09:40