How Randomly select an element from a 2-dimensional set in AMPL?

28 views
Skip to first unread message

Diego Fernandes Pantuza

unread,
Nov 13, 2017, 5:45:38 AM11/13/17
to AMPL Modeling Language
Good morning, I'm implementing a Grasp Heuristic, and I need to randomly select an element from a 2-dimensional set, there is any command in AMPL to make this selection?

Code: 
set RCL dimen 2 default {}; #set of items that have hik within the defined range


#function to determine the RCL set
for {i in I, k in K}{
if (h[i,k]>=h_inf and h[i,k]<=h_sup) then {
let RCL:= RCL union {(i,k)};
}
}

Example:

set RCL: (1,1), (2,1), (3,1), (3,3), (4,1)

I need to randomly select one of these elements.

Thanks.

Robert Fourer

unread,
Nov 14, 2017, 1:14:11 PM11/14/17
to am...@googlegroups.com
The attached example shows one possibility for selecting a random member from the set-of-pairs RCL. The first line "set RCL = ..." would be replaced by your code for computing the members of RCL. At the end the random pair is given in the values of the two params RCL1 and RCL2, which you can use in expressions including subscripts of indexed params and vars.

Bob Fourer
4...@ampl.com

=======
RCL1.run
Reply all
Reply to author
Forward
0 new messages