Building a Simulation for Coronavirus and Social Isolation using Repast Simphony Part 2/2

Nimish Verma
4 min readApr 14, 2020

--

This tutorial will cover the GUI, Initialization and Data sinks for the project. The official documentation by the Repast Team is attached in part 1 of this tutorial.

In Part 1, we define the agents and their behaviour. Now we will initialize our agents, build the context.

Let’s create a Builder file, right-click on the project (src) in the navigator>new>Class. Write SocialIsolationBuilder in file name, click on ‘Add’ in Interfaces and search ContextBuilder and select OK.

Click on Finish.

Replace ContextBuilder<T> with ContextBuilder<Object>.

Right-click on the workspace>Source>Override/Implement Methods..

Select the ContextBuilder checkbox, and click on OK.

Your file should know have the overridden build method.

Now we will assign space and grid to the context, the ID should be the project name, which has to match the project name in context.xml in Project_name.rs

Now, we have to also add the space, and grid in context.xml. Your context.xml should ultimately look like this

Now we will initialize agents in our builder, and add them to the context. The number of agents is parameterized so we will have to take the values from the parameters (discussed in part 1).

The code above, initialized agents and adds them to the context. Then it assigns the location of the agents in the grid.

Building the GUI

We run the model using the button above, if you see multiple options choose Project_name Model.

Let’s add Display. In Scenario Tree, right-click on Displays>Add Display.

Choose a name for your display, and move space and infection network on the right.

Now we select the agents we want to display. Choose all agents shown in the left side except SocialIsolationBuilder and transfer them to the right. The agents above are in front of the agents below in the space and are seen in that way.

Now we choose the styles/icons for the agents, I’ll leave it up to you.

After setting the display, we will add an aggregate data set. More information can be found on the PDF attached in part 1.

Choose Tick Count
Add Data Sources

We add data sources now, you can define custom functions but for now, we will use the count function of the agent to keep track of the count.

Click Ok, and finish.

Now we will add Charts > histogram chart.

Choose the counts you want to plot (as selected in Datasets and the color of the plot)

The last step is to add a Data sink into a file. We will collect the following data.

This creates file name as ModelOutput ___timestamp__ .txt

All done, save your scenario tree from the save button above.

Now for the last step, let’s add the parameters.

Click on Parameters tab, click on ‘+’ sign to add a parameter.

In Name- write variable name exactly as written in the code. Display name is as the name suggests, the name that is shown on the GUI. The type can be Integer, Float, Double, String etc.

And default value is what you want.

After adding our parameters the GUI should look like this,

All set. The simulation should work fine now, don't forget to save your parameters settings, and scenario tree :).

The symbols are for Initialize, Play/Pause, Step Forward, Stop, Reset

I have added video demos of the simulation I created, the code for which can be found on Github.

There are various settings in the simulation. With Social Isolation, without, with partial isolation and with few hospitals.

Hope you all liked it! :)

--

--

Nimish Verma
Nimish Verma

Written by Nimish Verma

MSc in CS. AI Researcher. Problem Solver

No responses yet