logo

First Steps in Agent-Based Simulation: Representing with Scatter Plots 📂Dynamics

First Steps in Agent-Based Simulation: Representing with Scatter Plots

Simulation

Code Review

Step 1. Load Packages, Set Initial Parameters

code1

The code above loads packages and sets the initial number of agents, along with movement rules that allow them to wander around each turn. The amount of movement is defined by the following $2$-dimensional normal distribution.

eq1

Step 2. Agent Creation

Talking big, calling it agent creation, but in fact, it’s nothing much. Drawing samples equal to the number of agents from a 2-dimensional normal distribution makes those coordinates represent the agents themselves.

code2 The coordinates above represent the positions of agents. Each row points to one agent, with the first column being the x coordinate and the second column the y coordinate. For now, it’s sufficient without the agents needing any behavior rules.


Step 3. Drawing a Scatter Plot

code3 By inserting the option seriestype = :scatter in the plot() function, it plots the agents’ positions as dots like above. And as entered in the first line, a file named "agent_tutorial.png" would have been created at the given path.

agent_tutorial.png

The actual appearance of "agent_tutorial.png" is as shown above. This demonstrates creating agents and visualizing them with a scatter plot.

Complete Code

Below is the Julia code used in this post.

code4