Search code examples
simulationanylogic

AnyLogic: cast OptionList into AgentType with List


At model startup I manually instantiate each instance of my resource with parameters. Parameters are name, capacities, required number of employees and ResourceType. The ResourceType of each Resource is taken from an OptionList.

At the end of the simulation I want to retrieve data for each resource for a data extract. Since I don't want to query all resources manually and individually, I want to iterate through the different resources.

Should look like:

for (ResourceType rt : Resources) { // export in excel }

But for that I would have to create a list with all resources filled with ResourceType (OptionList). Is there a way to cast an OptionList to an AgentType within a List? The end product should be something like: Resources.listOfAllResources filled with the enums.


Solution

  • You need to loop through your OptionList entries and find all resources of that type:

    for (int i=0; i<myOptionList.values().length; i++) {
        myOptionList currentEntry = myOptionList.values()[i];
        findAll(myResourcesInAList, r->r.getType().equals(currentEntry));
    }