Hi there,
I've had similar experiences with CPLEX when working with large models. While CPLEX does not have a direct equivalent to AMPL's "gentime," there are a few approaches you can take to diagnose and potentially reduce the model generation time:
Model Statistics:
-
- Use the
CPLEX
logging features to gain insights into the model's characteristics. Enabling detailed logging might help you see where the time is being spent.
IloCplex cplex(model);
cplex.setParam(IloCplex::Param::MIP::Tolerances::Integrality, 1e-9);
cplex.setParam(IloCplex::Param::MIP::Tolerances::MIPGap, 1e-4);
cplex.setParam(IloCplex::Param::ClockType, 1); // Use CPU time instead of wall clock time
cplex.setParam(IloCplex::Param::TimeLimit, 3600); // Set a time limit for debugging
Profiling Tools:
-
- Utilize C++ profiling tools to monitor where your application is spending most of its time. This can help you identify whether the delay is during model generation or another part of your application.
Model Size Reduction:
-
- Simplify your model if possible. Reducing the number of variables and constraints can significantly decrease the time required to generate the model.
Debugging Mode:
-
- Enable debugging mode in CPLEX to output more detailed information about the model generation process. This might not be as detailed as AMPL's "gentime," but it can still provide useful insights.
Warm Start:
-
- If applicable, use a warm start to provide CPLEX with a feasible solution or an initial guess. This can sometimes reduce the time needed to start the solution process.
Custom Logging:
-
- Implement custom logging in your C++ code to time different parts of your model generation process. For example:
auto start = std::chrono::high_resolution_clock::now();
// Code to generate model
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> duration = end - start;
std::cout << "Model generation time: " << duration.count() << " seconds" << std::endl;
By following these steps, you should be able to get a better understanding of where the time is being spent during the model generation phase in CPLEX. Although CPLEX doesn't have an exact equivalent to AMPL's "gentime," these methods can help you diagnose and improve performance.
------------------------------
thomas vick
------------------------------
Original Message:
Sent: Wed May 22, 2024 02:21 AM
From: Samuele Viaro
Subject: Time to generate the model
Hello,
I have a model in OPL, I call it and solve it from C++. I noticed that CPLEX hangs for a long time before starting to find the solution. I am guessing this is the time needed to generate the model.
In AMPL there is a function "gentime" that displays detailed time and memory statistics for generating all sets, parameters, variables, objectives, and constraints.
This was very helpful in locating the issue...
Is there an equivalent function in CPLEX?? I can't seem to find it...
Thank you
Sam
------------------------------
Samuele Viaro
------------------------------