GhettiG
GhettiG

Reputation: 91

AnyLogic - adding agents in the network

I'm new to AnyLogic and I have a problem that I'm not able to solve...

I "Main", section "Space and network" I put "Layout type" and "Network type" as "Random" and I checked the box "Apply on startup"...at the beginning I have my nice social network

enter image description here

Yet agents born and die...the problem is that when I add agents main.add_individuals() the newly created agents do not have connections! So I when all the intial agents are dead I find my self with agents but with no network!

enter image description here

How can I do? When I add a new agent I want it to connects with others :S

Thanks!!!


I tried the following
enter image description here
but it didn't work...I always end up with a population without network

enter image description here

Upvotes: 0

Views: 700

Answers (1)

one way is to do it manually during agent creation (the "On startup" parameter) with the connections.connectTo(Agent). This code will connect the agent to about half of the agent in your agent list. You could also use normal() instead of 0.5 to get a more realistic number of connections.

for(Agent ag : yourListOfAgents){
     if(random() < 0.5){
         connections.connectTo(ag);
     }
}

Upvotes: 1

Related Questions