Hi,
to understand what went wrong you can export .lp
In my example https://github.com/AlexFleischerParis/zooopl/blob/master/zooincremental.mod
I added the export
cplex.exportModel("test.lp");
int nbKids=300;
float costBus40=500;
float costBus30=400;
dvar int+ nbBus40;
dvar int+ nbBus30;
dvar int+ emptyVar;
minimize
costBus40*nbBus40 +nbBus30*costBus30;
subject to
{
ctKids:40*nbBus40+nbBus30*30>=nbKids;
ctEmpty:0<=0;
}
execute DISPLAY_After_SOLVE
{
writeln("The minimum cost is ",costBus40*nbBus40 +nbBus30*costBus30);
writeln("We will use ",nbBus40," 40 seats buses and ",nbBus30," 30 seats buses ");
writeln();
}
main
{
thisOplModel.generate();
writeln("Basic model");
cplex.solve();
thisOplModel.postProcess();
writeln("Let us add a row : saying that nbBus40 and nbBus30 should be equal");
thisOplModel.ctEmpty.setCoef(thisOplModel.nbBus40,1);
thisOplModel.ctEmpty.setCoef(thisOplModel.nbBus30,-1);
thisOplModel.ctEmpty.setBounds(0,0);
cplex.solve();
thisOplModel.postProcess();
writeln("Let us add a column : saying that nbBus50 could also be used and their cost is 700");
cplex.setObjCoef(thisOplModel.emptyVar,700);
thisOplModel.ctKids.setCoef(thisOplModel.emptyVar,50);
cplex.exportModel("test.lp");
cplex.solve();
writeln("The minimum cost is ",
thisOplModel.costBus40*thisOplModel.nbBus40.solutionValue +thisOplModel.nbBus30.solutionValue*thisOplModel.costBus30
+700*thisOplModel.emptyVar.solutionValue);
writeln("We will use ",thisOplModel.nbBus40.solutionValue," 40 seats buses ",thisOplModel.nbBus30.solutionValue,
" 30 seats buses and "+thisOplModel.emptyVar.solutionValue," 50 seats buses");
}
and then in test.lp I get
Minimize
obj1: 500 nbBus40#0 + 400 nbBus30#1 + 700 _emptyVar#2
Subject To
ctKids: 40 nbBus40#0 + 30 nbBus30#1 + 50 _emptyVar#2 >= 300
ctEmpty: nbBus40#0 - nbBus30#1 = 0
Bounds
nbBus40#0 >= 0
nbBus30#1 >= 0
_emptyVar#2 >= 0
Generals
nbBus40#0 nbBus30#1 _emptyVar#2
End
------------------------------
[Alex] [Fleischer]
[Data and AI Technical Sales]
[IBM]
------------------------------
Original Message:
Sent: Wed April 17, 2024 01:44 PM
From: Dheeban Kumar Srinivasan Sampathi
Subject: Setting bounds in OPL
Hello Community,
I'm encountering an issue in my OPL main script where I need to set certain variables to zero before solving the problem. Specifically, I'm trying to set the upper bound (UB) for job 2 to zero. However, even after solving the problem, I still observe a solution for job 2. Could someone assist me with this? Your help would be greatly appreciated.
Thank you.
Here is my constraint where I need the UB to zero:
forall(j in Jobs)
LambdaCons:
sum(s in Good_Schedule: s.Job==j) lambda[s] == Z[j];
var masterDef = thisOplModel.modelDefinition;var masterCplex = cplex;var masterData = thisOplModel.dataElements;var masterOpl = new IloOplModel(masterDef, masterCplex);masterOpl.addDataSource(masterData); masterOpl.generate();writeln("Upper bound before set ", masterOpl.LambdaCons[2].UB);masterOpl.LambdaCons[2].UB = 0;if (masterCplex.solve()) { curr = masterCplex.getObjValue();}
------------------------------
Dheeban Kumar Srinivasan Sampathi
------------------------------