Solved

Loop, empty all sets except 1


Userlevel 1
Hi,

How can I empty all sets except 1?
I only want to empty self declared sets.

I tried it with a for loop.
However I have some trouble comparing the name of the set with a string.

Kind regards, Wiet
icon

Best answer by Chris Kuip 27 May 2019, 14:06

Thanks for the clarification.



Indeed, you'll need to create an additional subset. Assuming that self_declared_sets is declared as:



code:
set self_declared_sets {
subsetOf: AllIdentifiers;
index: i_sds ;
}




You can create a subset thereof as follows



code:
set operated_upon_sets {
SubsetOf: self_Declared_sets ;
}




And then fill it along the following lines:



code:
operated_upon_sets := { i_sds | not ( formatString("%e", i_sds) = "setNameToBeExcluded" ) }
View original

3 replies

Userlevel 3
Hello Wiet,

The empty statement has the functionality you want when the identifier to be emptied is a subset of AllIdentifiers, see the example below:

Suppose you want to empty the sets s_A, s_B ;

To do this, you first create a subset of AllIdentifiers as follows:

code:
s_setsToBeEmptied {
subsetOf: AllIdentifiers ;
}


Subsequently in your model execute:

code:
s_SetsToBeEmptied := data { s_A, s_B } ;
Empty s_SetsToBeEmptied ;


The empty statement will now empty the sets s_A and s_B.

When you want to empty the sets in a section or model, you can construct the subset of AllIdentifiers as follows:

code:
s_SetsToBeEmptied := modelName * allSets ;


Here modelName is the name of your model and in code it is a set that contains all identifiers declared below that set. You can use the name of any section in the model tree as an alternative. Allsets is a predeclared subset of AllIdentifiers, and contains the names of all declared sets. The * operator acts as intersection.


With kind regards,

Chris.
Userlevel 1
Thanks, but this doesn't exactly answer my question.
I want to loop over and perform and action on all sets in the set self_declared_sets where...

code:
self_declared_sets:= modelName * allSets ;


And then I want to skip a set if the name of that set matches a string, e.g. "self_declared_sets" or "myBuildings".

In your answer the sets on which an action needs to be performed are specified. I need to specify the sets on which no action needs to be performed.

Maybe I need to create a subset first in which some elements of the original set are excluded.
Userlevel 3
Thanks for the clarification.

Indeed, you'll need to create an additional subset. Assuming that self_declared_sets is declared as:

code:
set self_declared_sets {
subsetOf: AllIdentifiers;
index: i_sds ;
}


You can create a subset thereof as follows

code:
set operated_upon_sets {
SubsetOf: self_Declared_sets ;
}


And then fill it along the following lines:

code:
operated_upon_sets := { i_sds | not ( formatString("%e", i_sds) = "setNameToBeExcluded" ) }

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator