Biology Portal

   


AgentSheets M&M Population Growth and Decay Model

Applet

Applet

Zip archive of the directory containing the applet version of the AgentSheets M&M Population model. To run the applet in your browser, uncompress the archive and open the "index.html" file.

applet.zip
Size: 226536 bytes


Model Source Files

Zip archive of the directory containing an AgentSheets project with all of the agent depictions for the M&M Population model, but without rules or worksheets.

model.zip
Size: 12014 bytes


Tutorial

An XML file describing how to build a growth and decay model

tutorial.xml
Size:

Agent-Based Modeling of Population Growth with AgentSheets

Introduction

A population (from a social and biological perspective) is defined as the collection of inter-breeding organisms of a particular species. A population shares a particular characteristic of interest most often that of living in a given geographic area. In the study of population dynamics or also known as population biology, special characteristics of a population are studied, such as age, size, growth, reproductive behavior, morality, sex structure and the growth of population. In a more rigid structure, population is strictly defined as the number of inhabitants (either the total number or the number of a particular race or class) in a given place (country or city etc.)

A simple statement of what happens to account for population growth could be:“In each generation a fraction of the individuals in the population reproduce.”This process can be modeled in the classroom using M&Ms. By putting M&Ms into a paper cup, and spilling them out onto a paper plate, we can identify the fraction that reproduce as the fraction that land with their “M” facing up. Generally, a population expands by moving and then reproducing. The goal of this activity is to construct an agent-based model using AgentSheets that reproduces M&M population growth as just described.

1 AgentSheets Models

AgentSheets is an educational cyber-learning tool that is used to create web-based interactive simulations and games. This tool is used to teach students how to program. AgentSheets represents the individuals in a system and provides a drag-and-drop interface for creating and editing the behaviors that govern agent behavior.

Note: The AgentSheets website contains many resources helpful to both beginners and advanced users, such as manuals, videos, tutorials, projects, and activities. It is highly recommended that one read the Getting Started manual before using all other resources. The Getting Started manual provides a detailed step-by-step instruction on how to build/start your first project.

Definition 1:(Agents) The AgentSheets official website states that agents are end-user programmable objects. Agents react to mouse clicks and keyboard input, move around, change their appearance, play MIDI music and videos, speak, read Web pages, send email, and compute formulae. Agents don’t operate alone. Dozens, hundreds or even thousands of agents interact with each other in a spreadsheet-like grid to create an AgentSheets simulation. In another words, An agent is an individual character with behaviors and attributes. You can think of an agent as a sims character or character playing his/her roles in a movie.

Defintion 2: (Behavior) A behavior describes what an agent does. Agent behaviors are expressed in Visual AgenTalk as IF-THEN statements/rules containing conditions and actions.

Definition 3 :(Behavior Editor) A combination of conditions and actions placed into rules determine the behavior of a certain agent. The grouping of these rules is called methods and methods are placed in behavior editors.

Definition 4: (Trigger) A method usually contains a list of rules and a trigger. The trigger defines when the rules contained in the method get checked. A perfect example of this trigger is the WHILE RUNNING trigger, which allows the method to check its rules once per each simulation cycle.

Definition 5:(Worksheet) A worksheet is the world that agents live and move in. In another words, a worksheet is like a canvas in which agents are placed and where they perform their behaviors.

Definition 6: (Depiction) A different image of the same agent.

Definition 7: (Behaviors) The rules/actions that an agent follows.

Definition 8: (Rules) The laws that the agents follow.

Definition 9: (Conditions) The limiting factors that control when or how often actions are exhausted.

Definition 10: (Actions) The verbs (what they do).

2 Building an AgentSheets Model

2.1 Opening a New Project
If you haven’t already, open the AgentSheets software. Once AgentSheets has been opened, we are going to create a new project. The AgentSheets tool bar first opens up and remains on the top of your screen meaning that the tool bar will be on top but the interface can still been seen. To create a new project, from the File menu, select New Project . When the save dialog box opens, click on the word Desktop in the left panel to save your model to the Desktop . AgentSheets will require a name (call it Population or something).

AgentSheets will then pop up with a Define Agent Size box and will require you to specify a size (in pixels) for the agents in your model (16x16 is usually a good size, 32 is often too big).

Once OK has been clicked in the Define Agent Size Window, the Gallery window opens up.

2.2 Creating a New Agent
After the Gallery window pops up, create a New Agent (the button is at the bottom left of the Gallery window). An agent as discussed earlier is an individual character with behaviors and attributes. You can think of an agent as a Sims character or even a character playing his/her role in a movie Click the button called New Agent and a new window will open asking for the name of the agent. Call it “Background”.

Once you have named the agent “Background” and clicked OK, the Gallery will have created an agent. It should have a picture of the gentleman that created AgentSheets, and the name “Background” next to it.

2.3 Editing an Agent
Now we must change the appearance of the agent “Background”. Select the agent (a light blue border should appear around it upon selection) and then click Edit Depiction (lower right). A window called Depiction:Background should pop-up. Select the color black from the palette at the top and click on the shaded rectangle beneath the “erase” and “pencil” icon. This will allow you to drag your cursor from the top left to the bottom right so you can form a square almost covering the entire white area. Make sure to leave a white “frame” around it like the figure below. Click Done when finished.

2.4 Creating a New Worksheet
A Worksheet is the world that agents live and move in. In other words, a Worksheet is like a canvas in which agents are placed and perform their behaviors. Go to File and select New Worksheet .

Once a Worksheet has been brought up, click the shaded rectangle on the left side of the Worksheet window and drag your mouse from the top left corner of the worksheet to the bottom right corner. You should now have a grid-like worksheet.

Save the Worksheet, making sure to save it in the same place as your project so it can be easily located.

2.5 Creating the M&M Agent
Create another new agent called “MnM” (the “&” symbol is not allowed). This is done the same way as before. Once “MnM” appears in the Gallery, select Edit Depiction to make “MnM” actually look like one. First draw the M&M with “m” face-down. This can be done by first making another background for your M&M to lie on. Next, select a color for your M&M and using the shaded Circle tool, make the shape of the M&M on top of the black area. Click Done.

To make the M&M face-up, do not create another agent. Instead, select the MnM agent and click New Depiction (below New Agent ). Type in “MnMup” for its name and click OK. Now there should be two items under the MnM agent tab. To put an “m” on “MnMup”, select it in the “MnM” tab and click Edit Depiction . Choose white from the color palette and use the Pencil tool on the left toolbar to draw an “m”. Click Done.

Add five "MnM" (3 regular and 2 up) agents anywhere on to the worksheet using the Pencil tool and Save the worksheet. Running the model (pressing the play button) technically does work because no instructions have been given. It's doing what it is supposed to do, which is nothing.

2.6 Adding Behaviors to Agents

Add behaviors to the M&M's by clicking Edit Behavior with the M&M agents selected.
Behaviors: are the rules/actions that an agent follows
Methods: a group of rules that perform an overall task (methods in this program are flip and count)
Rules: laws you follow
Conditions: limiting factors that control when or how often actions are exhausted
Actions: verbs (what they do).

What do we want the M&M’s to do? On each step, all M&M’s should move and flip (randomly choose which side is up). In addition, m-up M&M’s should reproduce and make another M&M.

2.6a: For the first rule:

Click on the “MnM” agent tab and then select Edit Behavior . Double clicking in the If and Then boxes should open a Conditions window and an Actions window . From Conditions drag the “See” command (the first command) into If . This command means “If I see that I (signified by the dot) am a face down M&M”. The Then box must be filled to complete the statement. Drag “Move random on” and “Make” (the third and ninth commands) from Actions into Then . Click on the icon next to “Move random on” and change the icon to the black background. Click on the icon next to “Move” and change it to the dot. Change the “method_0”in the text box to “Flip”. These two commands form the statement “Then move randomly to an empty space and make myself flip”. AgentSheets has no idea what “Flip” is. “Flip” is a method that the user creates. Making “Flip” will be discussed later in the tutorial. Drag errors to the Trashcan to get rid of them.

2.6b:Making the Second Rule:

Now create these same commands for “MnMup”. This can be easily done by selecting the entire first rule and clicking Duplicate (bottom). There should now be two first rules. To make the first rule apply to m-up M&M’s, change the “MnM” icon in If of the second rule to an “MnMup” icon. Since “MnMup” is the M&M mature enough to reproduce in our experiment, we must add the “New” command (fifth under Actions ) to Then of the second rule. Change the upwards facing arrow in “New” to a dot. This places the newly made M&M on top of the old one. This is alright because the old M&M moves randomly to another Background square each time.

2.6c: Making the Third Rule:

Duplicate the second rule and change the M&M icon next to “New” of the third rule to an m-up M&M.The second rule tells “MnMup” to always create an m-down M&M when it reproduces. However, this is not realistic because there is a 50% chance the M&M will land m-up or m-down each step. To fix this, add the “% chance” command (ninth command under Conditions ) to If of the second rule. The default chance, 50%, is the correct probability.

Here is what the three rules should look like in the “MnM” Behavior window when finished:

2.7: Making the Flip method

For the “Flip” method click New Method (next to New Rule ) and change the name of the method in the tab to “Flip”. The spelling and capitalization of the “Flip”s must be exactly alike for the computer to recognize them. Under the “Flip” method there will be two rules. The first should read: if there’s a 50% chance, then I change myself to an m-down M&M. The second should read: then change myself to an m-up M&M. Click OK when you’re finished. The “Flip” method should look like the figure below.

You may need to help students with non-working models. A student may ask: “what is the purpose of the “%chance” and Flip method?” Basically we are introducing randomness into the model and we are saying that 50% of the time the M&M will land with the “m” up and the rest of time it will land with the “m” down. This is what we did with the M&M model.

2.8: Adding a Counter agent

The purpose of a Counteragent is to count the number of M&M’s on the Worksheet and stop your model once the population gets to big. If the population becomes too large, your computer memory will not be able to handle it and your AgentSheets may freeze for a few moments. Go to the Gallery and add a new agent named “Counter”. Using the Pencil tool make sure you add a “Counter” agent to your worksheet and Save it afterwards.

Now we must tell the Counter agent what to do. Select “Counter” in the Gallery and click Edit Behavior . Create a rule. Drag the “is” command (the eleventh command under Conditions ) to If . Change “value” to “@MnM_count”, the “=” to “>”, and the “0” to “1000”. Drag “Stop simulation” (one of the last commands under Actions ) into Then . This tells “Counter” to stop the simulation when the M&M population reaches greater than 1000 M&M’s.

Create a second rule. Leave If blank because we want this rule to apply to all M&M’s. Drag the “Set” and “Broadcast” commands into Then . Change “value” next to “Set” to “@MnM_count” and the “value[left] + 1” to “0”. This sets the initial M&M count to 0. Choose “MnM” from the drop-down menu next to “Broadcast” and change “method_13” to “count”. “Count” will be the name of the method that tells “MnM” how to count itself. The “Broadcast” command tells the “MnM” agent to “count”. Click OK when you’re finished.

The next step is to tell the “MnM” agent how to “count”. Select “MnM” from the Gallery and click Edit Behavior . Create a New Method . Change the name of it to “count”. Drag the “Set” command to Then . Change “value” to “@MnM_count” and “value[left] + 1” to “@MnM_count+1”. Click OK . This method tells every M&M to add 1 to the M&Mpopulation count each step in the simulation. Here is what the methods should look like:

3 Counting and Plotting Your Data

To see the value of the counter, select Simulation Properties from the Tools menu. Move the window to the side of the worksheet so it is visible when the Worksheet window is on top. Now when you step the model forward or run it, you can see the counter variable tracking the number of M&M’s on the Worksheet. After the simulation is run, pressing Reset will return the Worksheet to its original format.

To plot the simulation, click Plot in the Simulation Properties window. Click the checkbox in the Plot Simulation Properties window. Name the plot window “Population” and click OK. The next time the simulation is run, the plot should appear. Multiple simulation runs can be recorded on the same plot.

bytes