Difference: SetsInAMPL (10 vs. 11)

Revision 112008-04-06 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Ready to Review - done - Lauren-->

Sets in AMPL

Line: 20 to 20
 Return to top

Declaring a Set

Changed:
<
<
Sets are declared using the set keyword followed by a label, possibly some attributes and either a set literal or set expression. The most common attribute is set by the within keyword. This specifies that the set will only contain elements from the following set definition:
set ARCS within NODES cross NODES; # Elements of ARCS must have both elements in NODES 
If you need a multi-dimensional set, but don't have the 1-dimensional sets to construct it yet you can use the dimen keyword:
set ROUTES dimen 2; 
There are some other set attributes, but we will not use them.
>
>
Sets are declared using the set keyword followed by a label, possibly some attributes and either a set literal or set expression. The most common attribute is set by the within keyword. This specifies that the set will only contain elements from the following set definition:
set ARCS within NODES cross NODES;
# Elements of ARCS must have both elements in NODES

If you need a multi-dimensional set, but don't have the 1-dimensional sets to construct it yet you can use the dimen keyword:

set ROUTES dimen 2;
There are some other set attributes, but we will not use them here.
  Set literals can be defined as a list of elements:
Changed:
<
<
{'HOST', 'DEVICE', 'SWITCH', 'HUB', 'LINK', 'SUPERLINK'} 
or a sequence of numbers:
param start; param end > start; param step;  set NUMBERS := start .. end by step; 
If the by step is missing, the step is assumed to be 1
set NUMBERS := 1..5; # NUMBERS = {1, 2, 3, 4, 5} 
Note Automatic set generation can only be done in the model environment, in the data environment you must define the set explicitly:
set NUMBERS := 1 2 3 4 5; # NUMBERS = {1, 2, 3, 4 5} 
>
>
{'HOST', 'DEVICE', 'SWITCH', 'HUB', 'LINK', 'SUPERLINK'}
or a sequence of numbers:
param start;
param end > start;
param step;
set NUMBERS := start .. end by step;
If the by step is missing, the step is assumed to be 1:
set NUMBERS := 1..5; # NUMBERS = {1, 2, 3, 4, 5}
Note Automatic set generation can only be done in the model environment, in the data environment you must define the set explicitly:
set NUMBERS := 1 2 3 4 5; # NUMBERS = {1, 2, 3, 4 5}
  Return to top
Line: 145 to 171
 
# The set of time-staged arcs

Changed:
<
<
set TIME_ARCS within TIME_NODES cross TIME_NODES := { (m, t) in TIME_NODES, (n, u) in TIME_NODES : ( ( (m, n) in ARCS) and (t = u) ) or # The arcs used for transportation ( (m = n) and (ord(t, MONTHS) + 1 = ord(u, MONTHS)) )}; # The arcs used for storage
>
>
set TIME_ARCS within TIME_NODES cross TIME_NODES := { (m, t) in TIME_NODES, (n, u) in TIME_NODES : ( ( (m, n) in ARCS) and (t = u) ) or # The transportation arcs ( (m = n) and (ord(t, MONTHS) + 1 = ord(u, MONTHS)) )}; # The storage arcs
 

There are many concepts within this one statement, let's look at them one at a time.

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback