In my previous post (https://galaxiez.com/2019/12/30/creating-agent-base-models-abm-in-insightmaker-part-1/), I covered in detail how to use InsightMaker.com to create Agent-Based models and running them as simulation. This post is taking into account that you read, exercise and understood the previous post. In this post, I’ll show how to deal with more than 2 states by implementing simple rules of personality preferences. The next post will expand this model by using actions in agent-based models.
There are three personalities depicted as states. Head, Will, and Hart. I base the logic on the mastering leadership model (https://www.amazon.com/Mastering-Leadership-Breakthrough-Performance-Extraordinary/dp/1119147190), but not necessarily depict the logic defined in the model. The logic is a little more complicated than the first model we created in the previous post:
- Hart will become Head if the current agent has at least 6 Head neighbors.
- Hart will Become Will if the current agent has at least 4 Will neighbors.
- Head will become Hart if the current agent has at least 4 Hart neighbors.
- Head will become Will if the current agent has at least 6 Will neighbors.
- Will will become Head if the current agent has at least 3 Head neighbors.
- Will will become Hart if the current agent has at least 6 Hart neighbors.
There are 3 main challenges in this model:
- How to create dependencies between 3 different states?
- How to create a random initial state for 3 state primitives?
- How to keep the number of neighbors of different states?
Let’s address each challenge:
How to create dependencies between 3 different states?
The approach that I used will work for 3 dependent states. If you have more than 3 dependent states, my recommendation is to shy away from transition lines and to use the Action primitive. The solution that I came with was to connect each one of the states with the two other states they can transit to. The solution looks like that: (Image 1)
How to create a random initial state for 3 state primitives?
In the previous example, we used one of the random functions to define one state and we allocate all the rest to be the other state. In this model, we need to take a different approach. This is how I approached it. I create a variable and named it “Rand Agent Personality”. The value attribute of this variable as very simple logic. It generates a random number between 1 and 4 and round it down to its nearest integer: Floor(Rand(1,4)).
I placed this variable in the center between the 3 values and linked it to each one of the States: (Image 2)
Then I follow this logic in each “Start Active” attribute of each state primitive. If the random number is 1, it’s a Will agent, If the number is 2, It’s a Head agent, and if the number is 3 It’s a Hart agent. This is an example of the Head “Start Active” attribute: IfThenElse([Rand Agent personality] = 2,1,0). Make sure that the relevant logic is defined for each state. If you’ll run the model, you should see a random distribution. (Image 3)
How to keep the number of neighbors of different states?
In the previous example, we could keep track of one state to implement our logic. In this model, we have to maintain the number of surrounding agents per each state. The solution that I implemented was three variables, each one is holding the number of surrounding agents of one state. I created 3 variables and named them “# of XXX neighbors” I placed each one beside the relevant state. The next step is to connect each state to the relevant variable and associates with each one of the variables. The model looks like that: (Image 4)
Each value property of those three variables has the same code we used in the previous post, just adjusted to the Variable. For example, the variable “# of Head Neighbors” Value property is: [Associates].FindNearest(Self, 8).FindState([Head]).Count().
Apply the same logic to the “# of Will Neighbors” and “# of Hart Neighbors” variables.
Apply logic to transitions
Following the logic above, every “# of XXX neighbors” should be linked to two relevant transitions lines impacting the Head, Will, or Hart states. The model looks like that: (Image 5)
Now when we have all the links, we can follow the logic above per link (the same as we did it in the previous post). This is an example of the Head to Hart transition “Value” property:
if PastValues([Head]).Length() > 1 then
if [# of Hart Neighbors] > 2 then
I’m using PastValues and Length to make sure that the transition is applied after the first allocation of a default value. For some reason, without this logic, the model can act strangely in certain random allocations.
Implement the same relevant logic to each transition line following the logic above.
Run and enjoy
Run the model and follow how randomness becomes clusters of personalities and eventually how the yellow (head) personality disappears from the model. (Image 6)
Agent-based models and their simulation are helpful to see how behavior changes over time and how certain changes will impact the existing state of a group. I hope that the last two examples helped you to realize the potential in agent-based models.