Hi,
I often got the question : how can we call an external program from OPL ?
( In order to launch some visualization, reporting, or any other program)
Up to CPLEX 12.7.1 my answer was :
Use an external java call. See IloOplCallJava
But some people do not use java but C# or simply need to call a program and that's it.
In CPLEX 12.8, we have IloOplExec
And this is very useful.
Let me share a small example:
I use Windows but this works for all platforms.
In C: you have volsay.mod
dvar float+ Gas;
dvar float+ Chloride;
maximize
40 * Gas + 50 * Chloride;
subject to {
ctMaxTotal:
Gas + Chloride <= 50;
ctMaxTotal2:
3 * Gas + 4 * Chloride <= 180;
ctMaxChloride:
Chloride <= 40;
}
tuple SolutionT{
float Gas;
float Chloride;
};
{SolutionT} Solution = {<Gas,Chloride>};
execute{
var o=new IloOplOutputFile("output.txt");
o.writeln(Solution);
o.close();
}
and then you may call example.mod
execute
{
// call notepad
IloOplExec("c:\\Windows\\System32\\notepad.exe");
// call OPL
IloOplExec("C:\\ILOG\\CPLEX_Studio128\\opl\\bin\\x64_win64\\oplrun.exe c:/volsay.mod",true);
// display the result by importing output.txt
writeln("result");
var f=new IloOplInputFile("c:/output.txt");
while (!f.eof) {
s=f.readline();
writeln(s);
}
f.close();
}
which will open notepad and then give
result
{<20 30>}
regards
Alex Fleischer
PS:
Many how to with OPL at https://www.linkedin.com/pulse/how-opl-alex-fleischer/
Many examples from a very good book : https://www.linkedin.com/pulse/model-building-oplcplex-alex-fleischer/
Making optimization simple : https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/
#DecisionOptimization#OPLusingCPLEXOptimizer