0
votes

I'm new to AnyLogic and I am trying to create a custom network...but i don't get to succeed in this task :(

Agents have a parameter "AgeClass", that is an int from 0 to 14, according to their age.

Then I have a variable "network" that contains the mean number of links between age class.

What I want is every agent to create link with other agent according to the matrix.

I don't get how I can say to an agent "connect to another agent with AgeClass = 3"

I thought something like this (to put in the "on startup block" or in an event inside the agent type):

int i = AgeClass \\ this is the AgeClass of the agent who is executing the code for( int j=0; j<network[i].length; j++ ) { \\ in this way I go through all the age classes for ( int k=0; k<poisson(network[i] [j]); k++) { \\ for every j I get the mean # of link connectTo(????); } }

Instead of ???? i want to say "connect to another agent with AgeClass = j" ...is there a way thorugh?

Thanks for the support!!!

1

1 Answers

1
votes

Please use the function "filter()" to select all agents from the population with AgeClass = j. Then, you can get random of them to connect to the agent executing the code. The expression ???? may look like:

randomFrom(filter(main.people, p -> p.AgeClass == j))

Here is the description of the function "filter()": http://help.anylogic.com/topic/com.xj.anylogic.help/html/agentbased/Subset.html