Reputation: 149
Using Python and Pulp, I want to print out the optimization time Cplex needs.
I use
prob.solve(CPLEX_CMD(msg=1))
so I already receive messages from Cplex, but I don't know where to find the total solution time.
Here's what I get from Cplex:
Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 12.8.0.0
with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
Copyright IBM Corp. 1988, 2017. All Rights Reserved.
Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.
CPLEX> Problem '/tmp/591faecbb00f459f8a6148ec85927a46-pulp.lp' read.
Read time = 0.00 sec. (0.08 ticks)
CPLEX> Tried aggregator 2 times.
MIP Presolve eliminated 8 rows and 7 columns.
MIP Presolve modified 175 coefficients.
Aggregator did 6 substitutions.
Reduced MIP has 679 rows, 361 columns, and 4140 nonzeros.
Reduced MIP has 288 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (3.00 ticks)
Probing fixed 6 vars, tightened 0 bounds.
Probing time = 0.00 sec. (3.58 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 0 rows and 6 columns.
Reduced MIP has 679 rows, 355 columns, and 4080 nonzeros.
Reduced MIP has 282 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (2.11 ticks)
Probing time = 0.00 sec. (2.76 ticks)
Clique table members: 2393.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 12 threads.
Root relaxation solution time = 0.00 sec. (2.20 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
0 0 -412.3658 29 -412.3658 107
0 0 -418.2065 28 Cuts: 41 140
0 0 -418.6510 28 Cuts: 27 157
0 0 -418.7747 28 Cuts: 9 163
* 0+ 0 -506.6606 -418.7747 17.35%
0 2 -418.7747 28 -506.6606 -478.2859 163 5.60%
Elapsed time = 0.17 sec. (115.98 ticks, tree = 0.01 MB, solutions = 1)
Implied bound cuts applied: 27
Flow cuts applied: 9
Mixed integer rounding cuts applied: 10
Zero-half cuts applied: 2
Lift and project cuts applied: 7
Gomory fractional cuts applied: 6
Root node processing (before b&c):
Real time = 0.16 sec. (115.64 ticks)
Parallel b&c, 12 threads:
Real time = 0.08 sec. (45.29 ticks)
Sync time (average) = 0.03 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.23 sec. (160.94 ticks)
Solution pool: 1 solution saved.
MIP - Integer optimal solution: Objective = -5.0666058400e+02
Solution time = 0.24 sec. Iterations = 7802 Nodes = 554
Deterministic time = 160.94 ticks (683.22 ticks/sec)
CPLEX> MILP problem relaxed to LP with fixed integer variables using
incumbent solution.
CPLEX> Tried aggregator 1 time.
LP Presolve eliminated 410 rows and 295 columns.
Aggregator did 10 substitutions.
Reduced LP has 273 rows, 69 columns, and 546 nonzeros.
Presolve time = 0.00 sec. (0.57 ticks)
Initializing dual steep norms . . .
Iteration log . . .
Iteration: 1 Dual objective = -467.571080
Dual simplex - Optimal: Objective = -5.0666058400e+02
Solution time = 0.00 sec. Iterations = 6 (0)
Deterministic time = 1.11 ticks (1105.50 ticks/sec)
CPLEX> Solution written to file '/tmp/591faecbb00f459f8a6148ec85927a46-pulp.sol'.
CPLEX> Status: Optimal
Where can I find/ how can I get the total time Cplex needs to solve my optimization problem?
Upvotes: 1
Views: 1474
Reputation: 4465
From the log it looks like you are solving twice. Once to solve an MILP and then you change the problem to a "fixed MILP" and solve again. I'm not sure if you are doing this specifically, or if PuLP is doing it for you. Either way, the solution times from each, respectively, can be seen with the following lines from the log:
Solution time = 0.24 sec. Iterations = 7802 Nodes = 554
and
Solution time = 0.00 sec. Iterations = 6 (0)
So, to get the total time overall, you'll need to add them up, like so:
0.24 sec. + 0.00 sec. = 0.24 sec.
Alternatively, you can get the time before and after you call the solve
method in your Python code. This will include the extra overhead of calling through Python and PuLP. For example, using time.perf_counter, you could do something like this:
import time
...
start = time.perf_counter()
prob.solve(CPLEX_CMD(msg=1))
total = time.perf_counter() - start
print("Total time:", total)
Upvotes: 1