0

I'd like to include in my output the version of CP Optimizer (e.g. 12.9) used when solving. I'm working with problems solved under multiple versions of the software, so it'd be helpful to see which version was used while looking at the solution. I can't just check the about menu because I write the results to external files and review them a long time afterward.

Is there a way to programmatically retrieve the version number in OPL?

I'm using OPL inside the provided Oplide. I found the CP.Version property for the .NET interface (https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.9.0/ilog.odms.cpo.help/refdotnetcpoptimizer/html/P_ILOG_CP_CP_Version.htm), but I can't figure out an equivalent in OPL code.

Jordan Ticktin
  • 435
  • 4
  • 8

1 Answers1

2

It seems the IloCP scripting class does not export the version number. However, I can see two other ways to get the version:

Option 1: From an execute or main block you can instantiate the IloCP Java class and use the getVersion() function of that class:

execute {
   var cpo = IloOplCallJava("ilog.cp.IloCP", "<init>", "()Lilog/cp/IloCP");
   writeln(cpo.getVersion());
   cpo.end();
}

Option 2: The IloCplex scripting class does provide a getVersion() function. So in a main block you can do

main {
   writeln(cplex.getVersion());
   // or
   var cpx = new IloCplex();
   writeln(cpx.getVersion());
   cpx.end();
}

The version number of CP Optimizer and CPLEX are the same.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22
  • The IloCP Java option (Option 1) worked, thanks! The IloCplex option (Option 2) did not; I state `using CP;` at the beginning of the file, and instantiating Cplex after that caused an error. It did work once I removed the `using CP;`, but just using the Java version is cleaner. – Jordan Ticktin May 06 '19 at 00:33
  • The one problem with the Java approach is that the `oplrun` command line interface doesn't support executing Java, so it crashes when this code is included. Any ideas of a third option? – Jordan Ticktin May 23 '19 at 20:28
  • Are you on Windows? On non-Windows try using `oprunjava` instead of `oplrun`. – Daniel Junglas May 24 '19 at 03:01
  • I’m using both macOS and Windows, and both have `oplrunjava`. However, according to the documentation it runs much more slowly than `oplrun`, and I’m performing benchmarking tests so I need to be using the faster solver. – Jordan Ticktin May 24 '19 at 18:01
  • Would it be an option to run `oplrun` twice? First run `oprun -version` to get the version, then perform a call with all the right argument. About `oplrunjava`: what exactly are you benchmarking here? The time it takes to setup tihngs in OPL or the time to actually solve the model? As soon as the model is extracted to the engine and optimization starts, everything happens in the engine, which is the exact same for `oplrun` and `oplrunjava`. So if you only measure solution time then either of the two should be fine. Moreover, did you actually observe a timing difference between the two? – Daniel Junglas May 25 '19 at 04:42
  • I can't edit my previous comment, but I was wrong about Windows having `oplrunjava`. I'm running the majority of my tests on a Windows machine so the point is somewhat moot. I think the easiest method will be just manually tracking the version. Thanks for the help! – Jordan Ticktin May 25 '19 at 17:50