I’m using JuMP to solve a large number of instancies with CPLEX and I would like to use the information output by CPLEX such as the number of Flow cuts applied or time spent during branch & bound. Is there any elegant way to get these informations in variables?
As of now, my solution is to redirect my stdout to a file so that CPLEX prints everything there and do a grep (+ cast to Float) on the resulting file. It’s a quick and dirty solution but I didn’t find anything else either in the CPLEX documentation or in the JuMP one.
JuMP is a great way to interact with solvers, such as CPLEX. Loosely speaking, JuMP will “convert” CPLEX’s C API calls into JuMP calls, which can be solver independent (the same function for many solvers) or solver dependent (each solver will have particular functions).
I am not aware of the functionality you are asking for, however, if you find some info about how to do that in CPLEX’s manual we can help you with a (hopefully) nice way to that with JuMP + Julia.
Root node processing (before b&c):
Real time = 1.77 sec. (2896.93 ticks)
Sequential b&c:
Real time = 1.67 sec. (3203.84 ticks)
------------
Total (root+branch&cut) = 3.44 sec. (6100.77 ticks)
I would like to access this information.
There’s no function directly in the CPLEX API for C that does this as far as I’m aware, so it’s probably not just me missing a JuMP function or a missing bridge.
It’s probably local variables that are destroyed when CPLEX is done running. As these are not Julia variables in the first place, I have little hope that it’s possible to retrieve these information in a neat way but I might be wrong.
In the C API you can retrieve the number of applied cuts with CPXgetnumcuts( CPXCENVptr env, CPXCLPptr lp, int cuttype, int * num_p ). However, it is not well documented in JuMP.jl and CPLEX.jl how to obtain the pointers to “env” and “lp”. You can try to find some function which is supported by JuMP and CPLEX here (e.g., CPXgetmiprelgap should be supported) and look up how it is done in the source code of the packages.
If you come up with an solution please share it.
To reach the env and lp pointers, the simplest is to use direct mode, then make your way through the various layers until you reach the CPLEX objects (technically, pointers to the CPLEX objects)
In most cases, you should be able to query the information you want from cplex_model directly, since most (if not all) C api functions are wrapped in Julia.
Finally, to query the number of cuts, call CPXgetnumcuts (as wrapped in CPLEX.jl) as @mike_k pointed out.
The strategy is similar if you want to access a different attribute.