TIAN YUAN
TIAN YUAN

Reputation: 31

the differece of logfile when calling cplex from IDE and python

Recently, I'm doing a research about MISOCP. At first, I tried to build a model in python and solve it by calling CPLEX. But I got a problem about the objective CPLEX solved and I was told to check the tolerance of the answer in the logfile by my professor. At the same time, my professor sent me an example of his logfile(created by IDE), but when I opened my logfile created by python, I found there's a big difference about the information. Then I will add the part of the difference and really wish somebody could give me some suggestions to fix my problem or told me the reason why there's a difference and if I can fix it.(the difference just happened at the last part so I just copy the last part) a sample file created by professor(IDE):

Real time             =   18.64 sec. (12682.02 ticks)
Parallel b&c, 24 threads:
  Real time             = 12251.58 sec. (2317064.29 ticks)
  Sync time (average)   =  197.11 sec.
  Wait time (average)   =    0.30 sec.
                          ------------
Total (root+branch&cut) = 12270.22 sec. (2329746.31 ticks)

Solution pool: 50 solutions saved.

MIP - Integer optimal, tolerance (1e-08/1e-06):  Objective =  2.3086668423e+01
Current MIP best bound =  2.3086667423e+01 (gap = 9.99915e-07, 0.00%)
Solution time = 12270.22 sec.  Iterations = 98522464  Nodes = 8530098 (2567)
Deterministic time = 2329746.32 ticks  (189.87 ticks/sec)

and a sample file of mine:

Real time             =    0.53 sec. (470.96 ticks)
Parallel b&c, 8 threads:
  Real time             =    3.69 sec. (3396.36 ticks)
  Sync time (average)   =    0.77 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    4.22 sec. (3867.32 ticks)
Solution status = 101:
MIP_optimal

we can see that compared to the file of my professor, I lost some information like

Solution pool: 50 solutions saved.

    MIP - Integer optimal, tolerance (1e-08/1e-06):  Objective =  2.3086668423e+01
    Current MIP best bound =  2.3086667423e+01 (gap = 9.99915e-07, 0.00%)
    Solution time = 12270.22 sec.  Iterations = 98522464  Nodes = 8530098 (2567)
    Deterministic time = 2329746.32 ticks  (189.87 ticks/sec)

. I don't know why this happened and really hope somebody can help me. Thanks so much.

Upvotes: 2

Views: 189

Answers (1)

rkersh
rkersh

Reputation: 4465

The extra information you've identified is not coming from the IDE, but rather from the CPLEX interactive. This extra summary information is not included in the output when using the programmatic APIs (e.g., Python, Java, C++, etc.).

However, you can print out this information yourself, using the Python API and code like the following:

c = cplex.Cplex()
# <- Your model building logic here.
start = c.get_time()
c.solve()

time = c.get_time() - start
epgap = c.parameters.mip.tolerances.mipgap.get()
epagap = c.parameters.mip.tolerances.absmipgap.get()

print("Solution pool: {0} solutions saved.".format(
    c.solution.pool.get_num()))

print("MIP - {0} ({1}/{2}): Objective = {3:19.10e}".format(
    c.solution.get_status_string(),
    epgap,
    epagap,
    c.solution.get_objective_value()))

left = c.solution.progress.get_num_nodes_remaining()
if left > 0:
    print("Solution time = {:.2} sec.  Iterations = {}  Nodes = {} ({})".format(
        time,
        c.solution.progress.get_num_iterations(),
        c.solution.progress.get_num_nodes_processed(),
        left))
else:
    print("Solution time = {:.2} sec.  Iterations = {}  Nodes = {}".format(
        time,
        c.solution.progress.get_num_iterations(),
        c.solution.progress.get_num_nodes_processed()))
print("Deterministic time = {:.2} ({:.2} ticks/sec)".format(
    c.get_dettime(), c.get_dettime()/time))

NOTE: The code snippet above makes a number of assumptions and is not intended to be generic for all problem types (e.g., an LP). It is merely an example of what can be done.

Upvotes: 1

Related Questions