Page 1 of 1

problem in using ord

Posted: Tue Oct 10, 2023 3:02 pm
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

Re: problem in using ord

Posted: Wed Oct 11, 2023 2:41 pm
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;