Cartesian Product of unknown number of sets?

40 views
Skip to first unread message

SD

unread,
Aug 23, 2005, 12:01:55 PM8/23/05
to AMPL Modeling Language
Hi,
Can someone point me to how to do the following:

I have a set A, and a set of sets B[a] for each a in A.

i.e.

set A;
set B{A};

I want to define set C, such that it will be the cartesian (cross)
product of all sets B[a].

i.e. if say,
set A = {a1, a2}
and
B[a1] = {b_a1_1, b_a1_2}
and B[a2] = {b_a2_1, b_a2_2}

then, I want C = {(b_a1_1, b_a2_1), (b_a1_1, b_a2_2), (b_a1_2, b_a2_1),
(b_a1_2, b_a2_2)}

Thanks, S

Robert Fourer

unread,
Aug 24, 2005, 10:44:20 AM8/24/05
to SD, AMPL Modeling Language

There is no direct way to do this in AMPL. The "arity" or dimension of an
AMPL set must be fixed in the model. It cannot be a function of the data,
as it would be if it were the Cartesian product of sets B[a] for all a in A,
where the number of members of A is only known from the data.

Sometimes there are ways to work around this limitation, but they depend
upon particular features of the model being formulated.

Bob Fourer
4...@ampl.com
Reply all
Reply to author
Forward
0 new messages