Types of Set
A set is a collection of unique elements. In AIMMS, a set is finite. When you declare a set in AIMMS, it is one of the following:
Root Set
Calendar
Subset
Relation
Root Set
A collection of explicit names is called a root set.
For instance, the set s_Weathertypes = { Rainy, Cloudy, Sunny }
is a root set.
Set s_WeatherTypes {
Index: i_WeatherType;
Parameter: ep_WeatherType;
Definition: data { Rainy, Cloudy, Sunny };
}
The elements of this set are Rainy
, Cloudy
, and Sunny
.
Note that the elements of a root set do not need to be specified in the model, they can be read in when the model is running; for instance from a database.
Calendar
A collection of dates is called a calendar. A calendar is also a root set.
For instance the calendar cal_ThisWeek
is declared as:
Calendar cal_ThisWeek {
Index: i_dayThisWeek;
Parameter: ep_dayThisWeek;
Unit: day;
BeginDate: "2025-02-17";
EndDate: "2025-02-23";
TimeslotFormat: "%c%y-%m-%d";
}
With this declaration, the calendar cal_ThisWeek
contains the elements 2025-02-17
, 2025-02-18
, 2025-02-19
, 2025-02-20
, 2025-02-21
, 2025-02-22
, and 2025-02-23
.
Note that the BeginDate
, EndDate
, and TimeslotFormat
need not be explicit strings, but string parameters can be used as well.
Subset
A collection of elements, which are also elements of a root set (or calendar), is called a subset.
For instance, the set s_DryWeatherTypes
is a subset of s_WeatherTypes
and declared as follows:
Set s_DryWeatherTypes {
SubsetOf: s_WeatherTypes;
Index: i_DryWeatherType;
Parameter: ep_DryWeatherType;
Definition: data { Cloudy, Sunny };
}
A subset is not a root set. But like root sets, the data for a subset need not be specified in the model, but can be read in at runtime.
Relation
A collection of tuples, in which each component is an element of another set, is called a relation.
Observations can be modeled as a relation, for instance as follows:
Set s_ThisWeeksWeather {
SubsetOf: (cal_ThisWeek,s_WeatherTypes);
Definition: {
data
{ ( 2025-02-17, Cloudy ), ( 2025-02-18, Sunny ),
( 2025-02-19, Cloudy ), ( 2025-02-20, Sunny ),
( 2025-02-21, Rainy ), ( 2025-02-22, Rainy ),
( 2025-02-23, Rainy ) }
}
}
In this example, ( 2025-02-17, Cloudy )
is a tuple.
Also 2025-02-17
is a component in a tuple, and it is an element of the set cal_ThisWeek
.
Simple Sets vs. Relations
A root set, a calendar and a subset are all simple sets. A relation is not a simple set. For a simple set, you can declare: zero, one, or more indices; and zero, one, or more element parameters.
Compound Sets
A set that is both a relation and a simple set, is called a compound set.
Important
Compound sets are no longer supported, see Overview: Deprecation of Compound Sets.