Originally posted by: DavidGravot
I don't think this is possible through OplScript
I suggest you keep your opl model and runs it into your favorite language, go to folder ...\IBM\ILOG\CPLEX_Studio129\opl\examples\opl_interfaces to browse examples such as Mulprod.java
package mulprod;
import ilog.concert.*;
import ilog.cplex.*;
import ilog.opl.*;
public class Mulprod
{
static final String DATADIR = ".";
static public void main(String[] args) throws Exception
{
int status = 127;
try {
IloOplFactory.setDebugMode(true);
IloOplFactory oplF = new IloOplFactory();
IloOplErrorHandler errHandler = oplF.createOplErrorHandler();
IloOplModelSource modelSource = oplF.createOplModelSource(DATADIR
+ "/mulprod.mod");
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,settings);
IloCplex cplex = oplF.createCplex();
cplex.setOut(null);
IloOplModel opl = oplF.createOplModel(def, cplex);
IloOplDataSource dataSource = oplF.createOplDataSource(DATADIR
+ "/mulprod.dat");
opl.addDataSource(dataSource);
opl.generate();
if (cplex.solve())
{
System.out.println("OBJECTIVE: " + opl.getCplex().getObjValue());
opl.postProcess();
opl.printSolution(System.out);
}
else
{
System.out.println("No solution!");
}
oplF.end();
status = 0;
} catch (IloOplException ex) {
System.err.println("### OPL exception: " + ex.getMessage());
ex.printStackTrace();
status = 2;
} catch (IloException ex) {
System.err.println("### CONCERT exception: " + ex.getMessage());
ex.printStackTrace();
status = 3;
} catch (Exception ex) {
System.err.println("### UNEXPECTED UNKNOWN ERROR ...");
ex.printStackTrace();
status = 4;
}
System.exit(status);
}
}
Then, instead of calling cplex.solve() , you may create your callback there and pass it as an argument
The callback will have to monitor your mathematical variables, that can be extracted from the IloOplModel through API such as
IloNumVarMap cuts = masterOpl.getElement("Cut").asNumVarMap();
as shown in the Cutstock_change.java sample
Basically, each data / variable of your .mod file can be queried by its name, then cast in the ad-hoc type (you may check getType on an element to figure out accurately what type it is, depending on how is build your collection : arrays, sets, tuple set …)
Once you get familiar with these APIs, it is relatively simple to mix both of best worlds : OPL to build an easy-to-write-read model , and your favorite language (C++ / .NET / JAVA / SCALA …) to access advanced features of CPLEX / CPO that are not part of the OPL script
David
#DecisionOptimization#OPLusingCPLEXOptimizer