0
votes

I have a large number of Agents defined in my model. They represent areas that have been defined as GISRegion map objects and are linked to the map objects by the “start in node” selector. Within a Java function within my AnyLogic Main agent, I am reading the list of agent names and their parameters from a csv text file. In previous models I have used this sort of config file to generate populations of agents. But, in this case, the agents are pre-defined and the names in the config file are used to link the parameters to the agent. I have found several Agent functions that will get agents based on proximity to locations or other agents. But, I have not found any way to get an agent by name. Is there a function that returns the Agent by name so I can set its starting parameter values? I was hoping for something like this:

String agentName = “AnAgentName”;
Agent theAgent = get_Main().getAgent(agentName);

where “AnAgentName” is the name of one of the existing agents.

2
share some more details. Agent structure, screenshot, the function... not clear yet what you mean. cheers - Benjamin
I’ve added more detail to the question. - Thom DeCarlo

2 Answers

1
votes

It´s easy if you add the agents to a collection (LinkedHashMap) at the same time they are created. For example, if your Agents are of the type Person, create a collection (Palette Agent) with these parameters:

Name: myCollection
Collection class: LinkedHashMap
Key elements class: String
Value elements class: Person

Now, when you create a new agent for the people´s population, add the respective agent to the collection. For example:

Person p;

p = add_people();

p.set_name("Ant-Man");
p.set_size(1.8);

if (!myCollection.containsKey(p.name))
    myCollection.put(p.name, p);

traceln("Ant-Man is " + myCollection.get("AntMan").size + " tall");
0
votes

Agents that are part of a population do not have names, they can only be accessed by their index in the population (main.myPopuluation.get(x)).

However, if your agents have a parameter p_Name, you can loop across the population to find the one with a specific name: findFirst(main.myPopulation, p->p.p_Name.equals"SomeName") , assuming that the name is unique to each agent.

Hope this is what you need (not entirely clear still ;-) ).