Conditional placement and program execution speed

Top  Previous  Next

As discussed above $ conditionals can be employed to cause calculations to not be done potentially causing faster executing code.  For example the statement (conditional.gms)

 

X=sum(I,a(i)) $qq;

Eq5(i)$qq..   sum(j,ijvar(I,j))=g= -a(i);

 

will generally be faster than

 

X=sum(I$qq,a(i));

Eq6(i)..   sum(j,ijvar(I,j)) $qq =g= -a(i) $qq;

 

because some work is avoided.  In general, conditionals are important tools to speed up execution.  The Speeding up GAMS chapter elaborates.