Hi,
nbKids is still 300 and does not change.
What you should write in the postprocess is
writeln("nbkids = ", ctKids.LB);
What confused you is that I used nbKids both a the constant 300 and as the variable name in the loop.
Let me make this better:
int nbKids=300;
{int} nbKidsOptions={nbKids+i*10 | i in -10..2};
int x2[i in 1..card(nbKidsOptions)]=item(nbKidsOptions,i-1);
int y2[i in 1..card(nbKidsOptions)];
float costBus40=500;
float costBus30=400;
dvar int+ nbBus40;
dvar int+ nbBus30;
minimize
costBus40*nbBus40 +nbBus30*costBus30;
subject to
{
ctKids:40*nbBus40+nbBus30*30>=0;
}
execute
{
writeln("nbBus40 = ",nbBus40);
writeln("nbBus30 = ",nbBus30);
writeln("nbkids = ", ctKids.LB);
}
main
{
thisOplModel.generate();
var k=1;
for(var nbKidsIter in thisOplModel.nbKidsOptions)
{
writeln("if we need to bring ",nbKidsIter," kids to the zoo");
thisOplModel.ctKids.LB=nbKidsIter;
cplex.solve();
thisOplModel.postProcess();
writeln("And the cost is ",cplex.getObjValue());
thisOplModel.y2[k]=cplex.getObjValue();
k++;
writeln();
}
}
------------------------------
[Alex] [Fleischer]
[EMEA CPLEX Optimization Technical Sales]
[IBM]
------------------------------
Original Message:
Sent: Wed July 07, 2021 12:48 PM
From: Siamak Mushakhian
Subject: Change a parameter and run the same model
Hi Alex,
Thanks for your reply.
I added a line to the execute section as below:
writeln("nbkids = ", nbKids);
When I run the model, in the script log I find two different values for the nbkids, Could you possibly explain to me why it that?

Best regards,
------------------------------
Siamak Mushakhian
------------------------------
Original Message:
Sent: Wed July 07, 2021 02:57 AM
From: ALEX FLEISCHER
Subject: Change a parameter and run the same model
Hi,
in Making optimization Simple
see
Simulation and what if analysis
int nbKids=300;{int} nbKidsOptions={nbKids+i*10 | i in -10..2};int x2[i in 1..card(nbKidsOptions)]=item(nbKidsOptions,i-1);int y2[i in 1..card(nbKidsOptions)];float costBus40=500;float costBus30=400; dvar int+ nbBus40;dvar int+ nbBus30; minimize costBus40*nbBus40 +nbBus30*costBus30; subject to{ ctKids:40*nbBus40+nbBus30*30>=nbKids;}execute{writeln("nbBus40 = ",nbBus40);writeln("nbBus30 = ",nbBus30);}main{thisOplModel.generate();var k=1;for(var nbKids in thisOplModel.nbKidsOptions){writeln("if we need to bring ",nbKids," kids to the zoo"); thisOplModel.ctKids.LB=nbKids;cplex.solve();thisOplModel.postProcess();writeln("And the cost is ",cplex.getObjValue());thisOplModel.y2[k]=cplex.getObjValue();k++;writeln();} }
------------------------------
[Alex] [Fleischer]
[EMEA CPLEX Optimization Technical Sales]
[IBM]