77
Building a Hierarchical Metapopulation Model Nathaniel Osgood MIT 15.879 April 13, 2012

Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Building a Hierarchical Metapopulation Model

Nathaniel Osgood

MIT 15.879

April 13, 2012

Page 2: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Capturing Multi-Level Hierarchies: A Frequent Modeling Need

• We frequently have hierarchies of environments and actors

– Region/Municipalities/Neighborhoods/Individuals

– Region/Municipalities/Schools/Children

• As is widely recognized in multi-level modeling (e.g. HLM), these hierarchies frequently exert successive levels of influence

• Frequently these hierarchies are also associated with their own structural and dynamic complexities

Page 3: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

One Example of Structural and Dynamic Complexities

• Municipalities may be arranged in transportation networks (road, rail, air connections)

• People may exhibit primarily contact patterns within a given municipalities

• People may move between municipalities

Page 4: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

AnyLogic Flexibility

• While certain AnyLogic elements are most commonly associated with part of the project hierarchy, we can use them in many places, e.g.

– Statecharts can be placed within “Main”

– Populations of other agents can be placed within “Agents”

• Partly because of this flexibility, we can create structural hierarchies in AnyLogic that parallel the hierarchies in the world

Page 5: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Hands on Model Use Ahead

Load Previously Built Model: MinimalistNetworkABMModel

Suggest Saving as “HierarchicalCityPopulationModel”

Page 6: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

One Example

• Main contains a population of Cities

– Arranged in one type of network

• City contains a population of Persons

– Arranged in another type of network

Page 7: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Initial State

Page 8: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Copy “Person” Class (Right Click on “Person” in “Project” Window and Choose “Copy”)

Page 9: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click Right on Project Name & Choose “Paste”

Page 10: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Result

Page 11: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Rename “Person1” as “City”

Page 12: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Open “Main”

Page 13: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click on “population”

Page 14: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Delete “population” (Right click & Choose

“Delete”, or Use “Edit” menu)

Page 15: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click (once) on “City” and Drag into “Main” Canvas & Drop

Page 16: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Result

Page 17: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click on “city” in Main Canvas, set name to “cities”, use “environment”&set replication to 10

Page 18: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

In “Advanced” tab in “Properties” window for “environment”, make sure that “Network Type” is

“Distance Based”, and “Connection Range” is “250”

Page 19: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Double-click on “City” in “Project” Window

Page 20: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Adding a Municipal Population Click (once) on “Person” and Drag into “City” Canvas & Drop

Page 21: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click on “person” in “City” canvas, set name to “cityPopulation”&set replication to “uniform(10, 200)”.

Result:

Page 22: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add an Environment & Rename it “City Environment”

Page 23: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

In “Advanced” properties of “Properties” window for “cityEnvironment”, set “Network Type” to “Scale free”

and the “Width” and “Height” both to 75

Page 24: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click on “cityPopulation”, and set the “Environment” field to “cityEnvironment”. Result:

Page 25: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Run the Model

Page 26: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Change the Relative Size for Cities & People Double-Click on “City”

Expand “Project” Window Hierarchy on left under “City” to get to “oval”(Under “presentation”

Page 27: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Drag to Enlarge

Page 28: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Recenter on Origin

Page 29: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Model

Page 30: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Now Move the Origin for Placing People to Upper Left of City

Page 31: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Centered View

Page 32: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a Function the “Person” canvas. Name it “moveToRandomCity”. Set the “General” tab

properties as follows

Page 33: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set “Code” Tab for “moveToRandomCity” as follows

Page 34: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a Function to “Person” canvas, named “moveBetweenSpecifiedCities”. Set “General” tab properties as

follows

Page 35: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Code for New Function

Page 36: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add an Event to the “Person” canvas. Name it “desiringIntercityMove”

Page 37: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Run the Model. People Should Now be Moving Around between the Cities

Page 38: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Extension 1: Adding Name Labels to Cities

Page 39: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add “Name” Parameter to City

Page 40: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Establishing a Text Field (Label) for Cities

Page 41: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set Dynamic “Name” Text Field Property

Page 42: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Establishing Collection (Array) of City Names

Page 43: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Setting the “Name” Parameters of Successive Cities Upon Creation

Page 44: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Running

Page 45: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Extension 2: Extending the Model with Infection Spread

(Note that this does not build on Extension 1)

Page 46: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Hands on Model Use Ahead

Load Previously Built Model: “HierarchicalCityPopulationModel”

Suggest Saving as “HierarchicalCityPopulationModelWithInfectionSpread”

Page 47: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Model Upon Opening

Page 48: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

In “Person”, add a Statechart Entry Point

Page 49: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a “Susceptible” State

Page 50: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add an “Infective” State

Page 51: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a “Recovered” State

Page 52: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Neaten Up (as Aesthetics Require)

Page 53: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a “Recovery” Flow Rate is 0.1 (implying mean residence time of 10)

Page 54: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add “InfectionIncidence” transition

Page 55: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

In “Agent” Properties for “Person”, Route the message to the “infectionStatechart”

Page 56: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add an “exposureTransition” to Spread Infection (This sends an “Infection” message every time unit)

Page 57: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a Variable called “color” This is of type “Color”, and should have initial value “Black”

Page 58: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set Color for “Infective” State to Green

Page 59: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set Color for “Infective” State to Red

Page 60: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set Color for “Recovered” State to Gray

Page 61: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set the Formula for Person’s Oval “Fill Color” Property to be “color”

Page 62: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Run the Model The Infection Spreads locally, and a bit between Cities

Page 63: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around
Page 64: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Add a “meanRecoveryTime” parameter to “Person”

Page 65: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set the “Recovery” Rate to the Reciprocal of “meanRecoveryTime”

Note that need to Request up 2 levels

Note that “meanRecoveryTime” lives in

“Main”. To get a reference to “Main”, we

first have to get a reference to our

enclosing city, and from the city request

a reference to “Main”

Page 66: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Note that Experiments now have a “meanRecoveryTime” parameter

Page 67: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Request Creation of a New Experiment

Page 68: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Call the new Experiment “RecoveryTime100”

Page 69: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

For this Experiment, Assume a “meanRecoveryTime” of 100

Page 70: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Click on the original Experiment (“Simulation”) Rename it to “RecoveryTime10”

Page 71: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Create a 3rd Experiment, called “Baseline”

Page 72: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set “Baseline” to Assume a “meanRecoveryTime” of 200

Page 73: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Run the Baseline Experiment

Page 74: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Output from the Baseline Experiment

Page 75: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Set the “Stop Time” for the Final Experiment to “500” (in the “Model Time” tab for the Properties of the experiment”)

Page 76: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Do the same for the “RecoveryTime10” Experiment

Page 77: Building a Hierarchical Metapopulation Model€¦ · Add an Event to the “Person” canvas. Name it “desiringIntercityMove” Run the Model. People Should Now be Moving Around

Do the same for the “RecoveryTime100” Experiment