Reducing loop execution time in GAMS model

Hello,

I hope you are doing well.

I am working on a Mixed-Integer Programming (MIP) model. To evaluate the computational complexity of the model, I perform multiple runs using a loop, where each iteration generates a new set of random parameters:

loop(run,

*----- Generate data -----

d(p,i,t) = UniformInt(650,750);

loop(p,

    cc = **UniformInt**(1, **card**(u));

    l(p) = **sum**(uu$(**ord**(uu)=cc), val(uu));

);

hm(p,s,t)$(**ord**(s)<=**ord**(t)) = 0.01 + (**ord**(t)-**ord**(s))\*l(p);

h(p,s,i,t)$(**ord**(s)<=**ord**(t)) = 0.02 + (**ord**(t)-**ord**(s))\*l(p);

sc(p,t) = 25\***UniformInt**(6,10);

st(p) = **UniformInt**(6,10);

cb(p)=**UniformInt**(2,5);

C(p) = **UniformInt**(150,200);

Vbox(p) = **UniformInt**(250,300);

Vvehicle = **ceil**(1.5\***sum**((p,i,t),(d(p,i,t)/C(p))\*Vbox(p))/**card**(k));

cap(t) = (**sum**((p,i),(d(p,i,t)\*pt(p))) + **sum**(p,st(p)))/0.6;

Cmax = **ceil**(**sum**((p,i,t), d(p,i,t)) / **card**(t));

RCmax(i) = **ceil**(**sum**((p,t), d(p,i,t)) / **card**(t));

*----- Solve -----*

solve PBPP using mip minimizing OF;

display d,l,hm,h,sc,pc,tc,C, Vbox,Vvehicle, cap,Cmax,RCmax,cap;

*----- Store results -----*

Obj(run)  = OF.l;

Time(run) = PBPP.resusd;

)

the solve time is quite high. The solver profile shows that a significant portion of the computational time is spent in the loop structure itself: :

— Profile Summary (97 records processed)
33.985 0.004GB 154 Loop
30.046 0.004GB 177 Solver PBPP
9.219 0.004GB 190 Execute
3.903 0.004GB 177 Solver PBPP
0.016 0.004GB 177 Solve Read PBPP
0.016 0.004GB 177 Solve Fini PBPP (849)

Could you please advise on how to reduce the loop execution time of this model? Note that I am working with small instances.

Thank you in advance

You are using the right tools but your conclusions are slightly wrong. The profile you get it is GAMS profile, not the solver profile. Solve is a part of it. When you see loop in this profile, it doesn’t mean that loop structure is taking long. It means your profile option is set only to the granularity of loop.

Increment option profile it by 1 to go one level deeper. Profile =1 might show that loop is taking some time. Profile =2 will show you which statement in the loop takes more time. If you still see some loop, increment it further.

finally, you likely want solve times which you can get by extracting the relevant model attribute after solve.