Build an Epidemic Model (part 5 of 8)

Tagged:

Previous: Infection (part 4 of 8)

Recovery

Go to the Everyone section of the Canvas. We want to create a Shared number variable controlled by a slider that determines the probability of recovery. So let's go to the Variables tab and grab a Shared number variable. Drag it out to the Everyone section and rename it Recovery.

Now go to the Setup and Run tab and get a Slider block to attach to the left hand side of the Recovery variable. Look at the Runtime window and you should see the slider appear. Now, whenever the slider is moved, the value of the Recovery variable is set accordingly.

Since the Recovery variable represents a percentage, you want the variable's value to be set between 0 and 100. To change the upper limit of the slider, click on the number on the bottom right end of the slider and change it to 100.

To use the variable in the model, let's go back to the Turtles section of the canvas. We're going to make a new Procedure that defines how Turtles recover. Go to the Procedures palette and get a Procedure block. Put it on the a Turtle's canvas. Rename the procedure Recover.

Get an If block (Logic tab) and attach it to the bottom of the Recover procedure. We want turtles to recover with a percentage chance determined by the slider. So get a <= block and attach it to the Test. Now put Random 100 in the left hand side of the <= block.

Go to the My Blocks palette, open the Everyone drawer and get the Recovery block, which reads the value of the slider. Attach this to the right side of the <= block.

For the Then part of the If block, put a Set Color Green block.

We want the turtle agents to run this procedure as a part of the Run block (forever loop). So navigate to the Run block in the Runtime section of the canvas. Go to the My Blocks palette and open the Turtles tab. Drag out the Recover block. This block "calls" the procedure, which means that it represents the stack of blocks that you made for the Recovery procedure above.

Now run your model. You should see different numbers of green and red agents as you change the value on the slider.

Next: Part 6 of 8 - Immunity Back To Top