Shweta Nayan
Shweta Nayan

Reputation: 1

How to fetch index of agent from list of agent in ANYLOGIC

As i am using getConnections() that will Returns a collection of agents(i.e,list not single agent) connected to any agent. I want to connect the agents (those which are present in the collection returned by getConnections()) to another agent. Problem is connectTo() function is only used for connecting to particuar agent, not list of agent.

Instead of connectTo(), which function can be used or any other way?

Upvotes: 0

Views: 641

Answers (1)

Benjamin
Benjamin

Reputation: 12793

You need to loop across all agents retrieved from getConnections(). A simple solution assuming you want to connect myInitialAgent to all agents currently connected to myOtherAgent:

for (Agent currentAgent : myOtherAgent.getConnections()) {
    myInitialAgent.connectTo(currentAgent);
}

You could also do it using Lambda expressions but I prefer readability ;-)

Upvotes: 1

Related Questions