Referencing elements in a set

8 views
Skip to first unread message

Ruben P.

unread,
Dec 10, 2010, 4:04:05 PM12/10/10
to AMPL Modeling Language
Here is an interesting situation,

Say you have the following syntax:

# in the model file

set T;
set B{T};

# in the data file

set T:= 1 2 3;

set B[1]:=a b;
set B[2]:= c d e;
set B[3]:= f g;

Then how do you refer to the first element of B[1] ( 'a' ) ? I tried
using B[1][1] and B[1,1] but they did not work. Is there a way one can
refer to any of the elements of B[j]?

Thanks,

Ruben

Paul

unread,
Dec 10, 2010, 10:49:23 PM12/10/10
to AMPL Modeling Language
If you want to access set members by index, then you must declare the
set ordered. If you change the declaration of B to

set B(T) ordered;

then you can use member(i,B[j]) to get the i-th element of B[j].

/Paul
Reply all
Reply to author
Forward
0 new messages