if-statement - with set-indexed parameter in if condition

Dear Anonymous Colleague,

Ordinarily a set reference indicates an implicit iteration over the set
elements.

The IF statement does not know how to handle this. GAMS does not know
which element of the set i you want to perform the IF test on.
So it is asking you to “control the set” i.

Not knowing what you are trying to do in the IF block, I can suggest two
general approaches:

1.) If you do mean to perform the IF test and do some operations for all
values of i, then you can either use a LOOP over i, or (better) the $
condition in your subsequent operations.

E.g. suppose your objective is to flip the sign of x(i) if it meets your
criterion crit:


set i /1 * 3/ ;

parameter Ton(i)
/1 5
2 7
3 9/;

parameter x(i);
x(i) = ord(i);

scalar crit;
crit=1;

variable ON(i);
ON.fx(i)=5;

DISPLAY x;
LOOP(i,
if( ON.l(i)$(x(i)=crit) >= Ton(i),
x(i) = (-1)*x(i);
);
);
DISPLAY x;


Or, using the $ operator


set i /1 * 3/ ;

parameter Ton(i)
/1 5
2 7
3 9/;

parameter x(i);
x(i) = ord(i);

scalar crit;
crit=1;

variable ON(i);
ON.fx(i)=5;

DISPLAY x;
x(i) ( ON.l(i)(x(i)=crit) >= Ton(i)) = (-1)*x(i);
DISPLAY x;


2.) If you do mean to perform the IF test and do some operations for a
particular value of i, e.g. i=2, specify that value explicitly in the
LOOP or $ condition, thereby “controlling” the index i:


LOOP(i$SAMEAS(i,“2”),
if( ON.l(i)$(x(i)=crit) >= Ton(i),
x(i) = (-1)*x(i);
);
);


Or


x(i) (( ON.l(i)(x(i)=crit) >= Ton(i))$SAMEAS(i,“2”)) = (-1)*x(i);




Best wishes,
Paul

-----Original Message-----
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On
Behalf Of tobster
Sent: Wednesday, August 05, 2009 8:22 AM
To: gamsworld
Subject: if-statement


Dear community,
by trying to run the following source-code…:



set i /1 * 3/ ;

parameter Ton(i)
/1 5
2 7
3 9/;

parameter x(i);
x(i) = ord(i);

scalar crit;
crit=1;

variable ON(i);
ON.fx(i)=5;

if( ON.l(i)$(x(i)=crit) >= Ton(i), );



…I always get the Error 149 (Uncontrolled set entered as constant):
18 if( ON.l(i)$(x(i)=crit) >= Ton(i), );
**** $149 $149 $149.

Does anybody know what I can do?!

Thanks in advance!!




–~–~---------~–~----~------------~-------~–~----~
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
-~----------~----~----~----~------~----~------~–~—

\

Dear Paul,
thank you very much - your suggestions have exactly been what I was
looking for…
…and it work’s!!

Thanks to all for participtaing in the discussion.

Best wishes,
Tobias

–~–~---------~–~----~------------~-------~–~----~
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
-~----------~----~----~----~------~----~------~–~—

\