Select an element randomly from a multidimensional set
Posted: Mon Feb 11, 2019 7:41 am
Hello,
I have a problem for which I don't find a simple solution.
I have a multidimensional set s(i,j,k).
I would like to select randomly an element from this set.
I was thinking about using randomNum = uniformint(1,card(s)) to select a random number between 1 and the number of elements in s.
Then, I wanted to apply:
sRand(i,j,k) $ (ord(s(i,j,k)) = randomNum) = yes;
to make sRand the subset that contains the single random element from s.
The problem is that GAMS does not allow to use "ord" on multidimensional set.
It looks strange to me because we can think of a "naturel" order of multimensional set such as this one:
1.1.1
1.1.2
1.2.1
1.2.2
2.1.1
2.1.2
etc...
In this case, we would have ord(1.2.1) = 3.
Anyway, because I cannot use "ord" on this multidimensional set, I have no idea how to pick up randomly an element from this set.
Does anyone know a simple trick to do this?
Thank you
I have a problem for which I don't find a simple solution.
I have a multidimensional set s(i,j,k).
I would like to select randomly an element from this set.
I was thinking about using randomNum = uniformint(1,card(s)) to select a random number between 1 and the number of elements in s.
Then, I wanted to apply:
sRand(i,j,k) $ (ord(s(i,j,k)) = randomNum) = yes;
to make sRand the subset that contains the single random element from s.
The problem is that GAMS does not allow to use "ord" on multidimensional set.
It looks strange to me because we can think of a "naturel" order of multimensional set such as this one:
1.1.1
1.1.2
1.2.1
1.2.2
2.1.1
2.1.2
etc...
In this case, we would have ord(1.2.1) = 3.
Anyway, because I cannot use "ord" on this multidimensional set, I have no idea how to pick up randomly an element from this set.
Does anyone know a simple trick to do this?
Thank you