Displaying Agent data in Agent-based modeling using Insight Maker.

This Post takes into account that the reader familiar with my previous posts about Agent-based modeling using Insight Maker. The intent of this post is to help others to display Total Agents, Certain agent type, and specific agent data in Insight Maker. I found this task not trivial, so I thought sharing how to do it will be beneficial to others.

Insight Maker enables you to have variables and stock primitive inside an agent to collect and use agent data. But, if you want to display this data on a graph, you won’t be able to see stocks and variables hosted inside an agent folder.

Let’s create a stock and call it A and a Variable that calls B. Select them and put them in a folder. Name the folder as “Z”. Add a flow to “a” that adds 1. Connect “a” to “b” and set B to be Log(“a”). If you’ll run this model you’ll see “a” and “b” values. If not you can go to the configuration of simulation results and add those primitives from the Data field.

Values when using a folder

Now, Let’s change the folder to be an Agent and try to run the model. We’ll get an error message that flows can’t cross agent boundaries. To fix that let’s create a dummy stock and connect the flow. Now the model will run, but no data will be displayed. The Data field in the configuration window of simulation results won’t have any primitive to select.

Values when using folder as Agent

The solution is to create Variables outside of the agents and to use them to display the data. For visibility, I’m using a naming convention for those variables. “Agent Name”.”Variable Name”. Next, we need to link an Agent population that our agent defines as its “Agent Base” to the variables. Name the new Agent population “Zs”. I created 3 variables. Z.a, Z.b and “Z.a of second Agent” (we will use the last one just to show the data of specific agent). Link the Agent population (Zs) to the three new variables. Without linking Agent Population, we won’t be able to reference agent fields. An attempt to link directly a and b to the variables won’t work. You won’t see those primitives in the reference section (formula form).

We will use Z.a to view the sum of the values during the run. I couldn’t find any way how to use the historical data function “PastValues” to sum the data. The only way that I found working is using FindAll and then the Value functions of agent:
Add this code to the Value/equation of Z.a. and the relevant one to Z.b:

Getting the value of a, but just for the second agent required a different approach. This time we need to use The agents’ Index function to return the second agent. The value of “Z.a of second Agent” is:

Run the model. If you won’t see any data, open the data field in the configuration window of Simulation results and add the last three primitives we added. Now you should see the data:

Final results

You can use those instructions to add several agent types and use a variable to connect them and display the overall value of the model.

Leave a Reply

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

%d bloggers like this: