0

I have the following code:

loop (d,
 rnd(d)=uniformInt(1,nd)
 );

I am going to use the integer numbers rnd(d) as an index of another set s(i). But for example when rnd(d)=34.000 however, it is integer, but s(34.000) has no valid index since, 34.000 is not 34 !! and GAMS shows a error message.

Morteza
  • 85
  • 1
  • 6

2 Answers2

0

Is i an ordered set? If yes, you could use something like this:

loop(d,
  s(i)$(ord(i)=rnd(d)) = ...;
)
Lutz
  • 2,197
  • 1
  • 10
  • 12
0

I don't know if @Lutz solution worked out for you. In case it did not, you can try the following: First, it is not necessary to loop over the set d, just a simple:

rnd(d) = uniformInt(1,nd);

will suffice. Next line can go like:

loop(d,
     s(i)$(i.val = ord(d)) = . . .;
     );

If you still have issues, then using @Lutz suggestion just append '*1.000' to 'ord(i)' and/or 'rnd(d)', whichever is giving you issues.

EJay
  • 159
  • 4