Set depending on value of another set

6 views
Skip to first unread message

earlyb...@gmail.com

unread,
Jun 20, 2017, 9:48:54 AM6/20/17
to AMPL Modeling Language
Hi,

I need to declare two sets: A and B.

Set A is the following: 

set A := 0..t;   #where t is a given parameter

What I am struggling with is the declaration of Set B. The range of set B depends on a value x in set A.

Intuitionally I would write:

set B := 0..x in A

This obviously doesn´t work. I am very thankful for any helpful advice.

Best,
DS

Robert Fourer

unread,
Jun 21, 2017, 9:18:00 AM6/21/17
to am...@googlegroups.com
Given a param t, you can index any AMPL object or operator over this indexing expression:

{x in 0..t, j in 0..x}

Also you can define A to be 0..t. But you cannot define B to be 0..x, because 0..x is a different set for each value of x. You could define an indexed collection of sets B[x] to equal 0..x, by defining

set A = 0..t;
set B {x in 0..t} = 0..x;

and then you could write the indexing expression as

{x in A, j in B[x]}

but arguably this just makes the model more complicated and harder to read.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages