Original Message:
Sent: Wed February 15, 2023 05:51 PM
From: Grégoire Turzo
Subject: Best way to run severall optimizations with a loop for
Hi Alex,
Thank you for your answer, it worked !
However, I would like to improve the time resolution by running severall years at the same time. I read your thread (https://community.ibm.com/community/user/ai-datascience/discussion/how-to-call-many-models-in-parallel-thanks-to-ilooplexec) but I didn't manage to adapt it to my code because you don't use a main, just an "Execute" at the end of your model. Besides, I would like to choose the number of simulations I launch at the same time (for example, 5 simulations at the same time for a span of 10 years and when one is over a new one starts) because my laptop is not so powerful and launching 10 years at the same time would be inefficient.
Here is my code:
main {
var source = new IloOplModelSource("MyModel.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
for(var k=2023;k<=2033;k++)
{
var opl = new IloOplModel(def,cplex);
var dataParam= new IloOplDataElements();
dataParam.prmAnneeResolution=k;
opl.addDataSource(dataParam);
writeln("Année de résolution : " + dataParam.prmAnneeResolution);
var data = new IloOplDataSource("Source1.dat");
var data2 = new IloOplDataSource("Source2.dat");
var data3 = new IloOplDataSource("Source3.dat");
opl.addDataSource(data);
opl.addDataSource(data2);
opl.addDataSource(data3);
opl.generate();
if (cplex.solve()) {
opl.postProcess();
writeln("OBJ = " + cplex.getObjValue());
} else {
writeln("No solution");
}
opl.end();
}
}
I tried to add the command "IloOplExec()" in different ways but I didn't manage to get results.
Thanks in advance for your help
Best regards
------------------------------
Grégoire Turzo
Original Message:
Sent: Tue February 14, 2023 07:10 AM
From: ALEX FLEISCHER
Subject: Best way to run severall optimizations with a loop for
Hi,
in https://github.com/AlexFleischerParis/howtowithoplchange/blob/master/changevalue.mod
you have a basic example that could help you.
main { var source = new IloOplModelSource("subvalue.mod"); var cplex = new IloCplex(); var def = new IloOplModelDefinition(source); for(var k=1;k<=10;k++) { var opl = new IloOplModel(def,cplex); var data2= new IloOplDataElements(); data2.maxOfx=k; opl.addDataSource(data2); opl.generate(); if (cplex.solve()) { opl.postProcess(); writeln("OBJ = " + cplex.getObjValue()); } else { writeln("No solution"); } opl.end(); } }
with subvalue.mod
float maxOfx = ...; dvar float x; maximize x; subject to { x<=maxOfx; } execute { writeln("x= ",x); }
------------------------------
[Alex] [Fleischer]
[Data and AI Technical Sales]
[IBM]
Original Message:
Sent: Mon February 13, 2023 06:06 PM
From: Grégoire Turzo
Subject: Best way to run severall optimizations with a loop for
Hi everyone,
I have a Cplex model that calls data from a database and publish in it when the optimization is over. There is also a .dat file that contains parameters and one of these parameters is the year. All the optimization runs for the data corresponding to that year. My goal is now to create a ilog script (or Python script if it's possible) so that the optimization will run year after year for a time window I choose (10 years for exemple) without the need to change the .dat file manually and to launch a new optimization.
What would be the best way to do that ?
Thank you,
Best regards
------------------------------
Grégoire Turzo
------------------------------