Moving agents in agent-based modeling (ABM) using InsightMaker.

This post is all about how to move agents in agent-based modeling created using It’s the 4th post on Agent-Based Modeling (ABM) and it takes in an account that you already watch the first three and you have an understanding and experience of ABM and Insight Maker. For your convenience, you can find the links to the 1st, 2nd and 3rd posts.

Create a new model. On the empty canvas create two states, one called Red with a red border. The other called Green, with a green border. Inbetween create an action called Move. Select the 3 new primitives and create a folder around them. Name the folder Person and set it behavior property to Agent.

Create a new “Agent Population” and name it MyCompany. Set the Agent Base property to “Person”. Leave all other properties with default values. If you’ll run the model, you should get the following result:

Image 1 – basic settings

Create a new variable “% of Reds”. Set it value to 0.5. Turn “Show Value Slider” to Yes and Max to 1, Min to 0, and Slider Step to 0.1. Link this variable to Red. In the Red state “Start Active” property uses the linked variable to define RandBoolean function: RandBoolean([% of Reds]). Create a link between Red and Green and set Green’s “Start Active” property to “![Red]. If you’ll run the model, you’ll see half red, half green agents moving in one direction.

Image 2 – Setting states and running with 50% red & 50% green

If you don’t see the slider. Collapse and expand the property window. You can play with the slider bar to create different % of reds and green.

The agents are moving because of the default value in the “Action” property. We will implement repel functionality between the reds and the greens. The first move is to link MyCompany, Green state, and Red state to the Move action primitive.

We will implement simple rules. Greens will move away from reds that are in 25 radios from them, reds will move away from greens that are in 25 radios from them. Simple.

Code wise all we need to do is to find out if the current agent is green or red. Based on that, we want to find all the opposite agents around it. To do that, we will use FindNearby to get all agents around a given agent and FindSate to find the agents with an opposite state. Based on the vector we’ll get, we will use MoveFoward with a negative value. The negative value will move the agent away from the opposite one. This is the code:

If [Green] = true then
Reds <- [MyCompany].FindNearby(self,25).FindState([Red])
for CurRed in Reds
self.MoveTowards(CurRed, -2)
end loop
else if [Red] = true then
Greens <- [MyCompany].FindNearby(self,25).FindState([Green])
for CurGreen in Greens
self.MoveTowards(CurGreen, -2)
end loop
end if

Running the model will create the following results:

Image 3 – running with code

If you want to attract an agent to an agent, use positive value and switch “Self” and the other entity (CurGreen or CurRed in this example.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
%d bloggers like this: