Skip to main content
3 of 3
edited tags
TheSimpliFire
  • 5.5k
  • 5
  • 23
  • 56

Why does the getTime() function from cplex concert returns wrong value?

I am running a MILP formulation (implemented in C++) with the Cplex Concert Technology 12.10, and I am trying to get the total elapsed time. So till the moment, I have tried three approaches: Be cplex my IloCplex object.

  1. Using the clock() function from the time.h C++ library:
    cplex.setParam(IloCplex::Param::TimeLimit, time_limit);
    time_t start = clock();
    cplex.solve();
    double total_time = (double) (clock() - start) / (double) CLOCKS_PER_SEC;
  1. Using the Cplex Concert function getTime():
    cplex.setParam(IloCplex::Param::TimeLimit, time_limit);
    cplex.solve();
    double total_time = cplex.getTime();
  1. Using the Cplex Concert parameter ClockType:
    cplex.setParam(IloCplex::Param::TimeLimit, time_limit);
    cplex.setParam(IloCplex::Param::ClockType, 2);
    cplex.solve();
    double total_time = cplex.getTime();

My code does not make use of any callbacks (informational callback neither), and does not set any value to the Cplex Concert parameter Threads, i.e., the piece of code cplex.setParam(IloCplex::Param::Threads, n); is not executed. Since such piece of code is not executed, then (according to the Cplex Concert official documentation) my code is using all available threads:

When this parameter is at its default setting 0 (zero), and your application includes no callbacks or only an informational callback, CPLEX can use all available threads.

The problem that I am facing is that in all these three approaches the total_time presents a wrong value. For example, if I set the variable time_limit to 120, i.e., set the optimization time limit to 120 seconds, then the variable total_time presents a value much bigger than the expected one, such as 892.322.

So, I'd like to know if anyone already faced this problem before.