Simulation with AnyLogic/Agent-Based Modeling/Step 11. Making people contacts distance-based

''' Step 11. Making People Contacts Distance-Based '''

Now people are located randomly in 650x300 miles square area. Let people only contact if they are not more than 25 miles away.

Set up the environment properties


 * 1) Open the Main class diagram by double-clicking the Main item in the Project view.
 * 2) Select the environment object.
 * 3) Open the Advanced tab of the environments Properties' view.
 * 4) Change the Network type to Distance based and modify the Connection range: 25. [[File:Step 11. Making people contacts distance-based1.png]]

Modify the agent's statechart

People will now contact only with their neighbors.
 * 1) Open the Person class diagram by double-clicking the Person item in the Project view.
 * 2) Click on the internal transition of the Adopter state.
 * 3) Modify the transition's Action. Substitute the existing string for the following:

Now we will modify our animation a little bit to visualize the network of contacts.

Draw a line to depict people contacts

Choose the Line element from the Presentation page of the Palette view. Then click in the graphical editor at the point (0,0) to place the start point of the line and finally click aside where you want to draw the end point. , (you can use code completion assist when typing). Here we specify the number of contact lines for the agent. We need to draw a line for each connection of this agent. For that, we call the getConnectionsNumber function, returning the number of agents currently connected to this one in our network. In the dX field, type:
 * 1) Open the Person class diagram.
 * 2) Draw a line like shown in the figure below. [[File:Step 11. Making people contacts distance-based3.png]]
 * 1) Open the Dynamic tab of the lines Properties' view and modify some dynamic properties of the line.
 * 2) In the Replication field, type:
 * 1) Define line's location on the animation:

In the dY field, type:

Here we place the end point of each line to the point with the coordinates of the corresponding connected agent. Connected agents are alternately accessed using the getConnectedAgent(index) function. Now those people who contact with each other will be shown on our presentation connected with lines.

We have finished creating the animation. Run the model and watch the dynamics on the network.