problem in using ord

Problems with syntax of GAMS
Post Reply
Sajjad.gh
User
User
Posts: 2
Joined: 7 months ago

problem in using ord

Post by Sajjad.gh »

i tried to save i th term of a parameter in a scalar but gams says Uncontrolled set entered as constant. can anybody help me?
here is my code
sets i /1*3/
j/1*3/;

scalar counter /1/
a /0/
b /0/;

parameters
dinf(i) /1*3 0/ ;

a= dinf(i)$(ord(i) = counter);
display a
User avatar
dirkse
Moderator
Moderator
Posts: 215
Joined: 7 years ago
Location: Fairfax, VA

Re: problem in using ord

Post by dirkse »

Sajjad,

In the example below are a couple ways to do what you ask.

Code: Select all

set i / 1*3 /;
singleton set s(i);
scalar
  counter / 1 /
  a / NA /
  b / NA /
  ;
parameter dinf(i);
dinf(i) = ord(i);

a = sum{i$[ord(i) = counter], dinf(i)};

* singleton sets can have at most one member, so
* we can do things with them we cannot do with multi-element sets.
s(i)$[ord(i) = counter] = yes;
b = dinf(s);
display a, b;
Post Reply