Andy,
I’m just back in the office after a week’s vacation, and surprised to
see no answer to this question. I would have guessed that GAMS is
doing short-circuit evaluation of boolean AND and OR operators, but I
thought I’d write a little model to check it out. The test (included
below) shows we do not do short-circuit evals. Run with “profile=1”
on the command line to get timing outputs.
-Steve
set I / i1 * i120 /;
set T 'trips through the loop ’ / t1 * t30 /;
alias (I,J,K);
parameter A(I,J,K);
a(I,J,K) = 1;
scalars continue, hits;
hits = 0;
loop {T$[sum{(I,J,K), a(I,J,K)} >= ord(T) * power(card(I),3)],
hits = hits + 1;
};
display hits;
continue = 1;
hits = 0;
loop {T$[continue and (sum{(I,J,K), a(I,J,K)} >= ord(T) * power(card(I),3))],
continue = 0;
hits = hits + 1;
};
display continue, hits;
continue = 1;
hits = 0;
loop {T$continue,
if {[sum{(I,J,K), a(I,J,K)} >= ord(T) * power(card(I),3)],
continue = 0;
hits = hits + 1;
};
};
display continue, hits;
On Mon, Apr 2, 2012 at 9:17 PM, AC wrote:
Hi
If I have a loop with a $conditional on it, and that $conditional
contains more than one item to be evaluated, does GAMS stop evaluating
the items as soon as it discovers the condition as a whole can never
be true?
For example:
loop (x,y,z)$((CONTINUE = 1) AND ()) do
:
do stuff
:
if () then
CONTINUE = 0;
endif;
endloop;
My question is that once CONTINUE = 0 then the entire loop conditional
can never be true. Does the GAMS code ignore evaluating the slow
complicated test for the given xyz tuple?
Or do I need to write the code something like:
loop (x,y,z) do
if (CONTINUE = 1) then
if ()) then
:
do stuff
:
if () then
CONTINUE = 0;
endif;
endif;
endif;
endloop;
Thanks in advance.
AndyC
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
– Steven Dirkse, Ph.D. GAMS Development Corp., Washington DC Voice: (202)342-0180 Fax: (202)342-0181 sdirkse@gams.com http://www.gams.com