Remove Elements from a Set
The empty statement in AIMMS is used to clear the contents of a set or reset values of identifiers within a subset of predefined sets.
Its behavior depends on the type of set being emptied:
The set is not a subset of
AllIdentifiers: the empty statement will remove all elements from the given set.The set is a subset of
AllIdentifiers: the empty statement will empty all the identifiers that are in the given subset.
Example: Clearing a Regular Set vs. a Subset of AllVariables
Let’s assume the following two identifiers:
Set NormalSet;
Set ActiveVariables {
SubsetOf: AllVariables;
}
As you can see, it holds that ActiveVariables \(\subseteq\) AllVariables \(\subseteq\) AllIdentifiers because the predefined
set AllVariables is defined in AIMMS to be a subset of AllVariablesConstraints, which in turn is a subset of AllIdentifiers.
You can verify this by opening the attribute window of these predefined sets.
This means that the empty statement behaves differently for NormalSet and ActiveVariables, as explained below:
1!This will remove all elements from the set NormalSet
2empty NormalSet ;
3
4!This will clear the values of all variables in the subset ActiveVariables
5!After the empty statement, the set itself will still contain elements!
6empty ActiveVariables ;
7
8!This will actually remove all elements from the set ActiveVariables
9ActiveVariables := {} ;
Key Takeaways
The
emptystatement removes elements from general sets but only clears values for subsets of predefined sets.To fully remove elements from a subset of
AllIdentifiers, assign an empty set{}to it explicitly.Use
emptycarefully when dealing with predefined sets to avoid unintended behavior.