Originally posted by: lyxthe
Hello all,
I develop a code in java to solve several MILP problems. When I execute it, I have a too much time spend issue in my code.
I have to do something like this :
for (MyObjectA a : getMyObjectsA()) {
iloNumExpr2 = model.linearNumExpr();
for (MyObjectB b : getMyObjectsB(a)) {
ilog.concert.IloNumExpr iloNumExpr3 = model.linearNumExpr();
for (MyObjectsB b2 : getMyObjectBExc(a, b)) {
iloNumExpr3 = model.sum(iloNumExpr3, model.prod(t.get(a).get(b).get(b2),getCost(b, b2)));
}
iloNumExpr2 = model.sum(iloNumExpr2, iloNumExpr3);
}
iloNumExpr1 = model.sum(iloNumExpr1,iloNumExpr2);
}
but in this scenario, the bigger the iloNumExpr1 becomes, the more the time spent to execute the model.sum(). It begins by 5ms but quickly reach 250ms for only one call. If I have 3000 elements in getMyObjectsA() it gets arround 10 minutes to acchieve the loop, which can be quite too much as I have a lot of them in my code.
The thing is that it is quite easy to solve this particular issue like this :
int count=0;
int thresholdForLimitGrowthOfCplexSum=250;
for (MyObjectA a : getMyObjectsA()) {
iloNumExpr2 = model.linearNumExpr();
for (MyObjectB b : getMyObjectsB(a)) {
ilog.concert.IloNumExpr iloNumExpr3 = model.linearNumExpr();
for (MyObjectsB b2 : getMyObjectBExc(a, b)) {
iloNumExpr3 = model.sum(iloNumExpr3, model.prod(t.get(a).get(b).get(b2),getCost(b, b2)));
}
iloNumExpr2 = model.sum(iloNumExpr2, iloNumExpr3);
}
iloNumExpr2prime = model.sum(iloNumExpr2prime,iloNumExpr2);
if((count<thresholdForLimitGrowthOfCplexSum)&&(getMyObjectsA().indexOf(a)<getMyObjectsA().size()-1)){
count++;
}else{
iloNumExpr1 = model.sum(iloNumExpr1,iloNumExpr2prime);
iloNumExpr2prime=model.linearNumExpr();
count=0;
}
}
In this solution, the increase of iloNumExpr1 is done by steps by using an extra variable : iloNumExpr2prime whom I limit the growth with a threshold.
My question is the following, isn't there a way or a parameter to do such things automatically rather than doing it for every loop ?
Or maybe I'm not doing it the right way ... ?
Thanks for your attention.
Lyxthe
#CPLEXOptimizers#DecisionOptimization