Social Simulation Tutorial Session 2 The Re Past

  • Slides: 18
Download presentation
Social Simulation Tutorial Session 2: The Re. Past Simphony Toolkit, an example model International

Social Simulation Tutorial Session 2: The Re. Past Simphony Toolkit, an example model International Symposium on Grid Computing Taipei, Taiwan, 7 th March 2010 SICSA student induction day, 2009 Slide 1

The Re. Past Toolkit • Developed at Argonne National Labs • Developed in Java

The Re. Past Toolkit • Developed at Argonne National Labs • Developed in Java on basis of Eclipse Framework • Open Source, under “New BSD” license • Development environment: Eclipse • Runtime environments – user interface • repast. sourceforge. net SICSA student induction day, 2009 Slide 2

Re. Past Development Environment SICSA student induction day, 2009 Slide 3

Re. Past Development Environment SICSA student induction day, 2009 Slide 3

Re. Past Runtime Environment SICSA student induction day, 2009 Slide 4

Re. Past Runtime Environment SICSA student induction day, 2009 Slide 4

Example Models • Schelling – classical model of segregation • Sugarscape – dynamic environments

Example Models • Schelling – classical model of segregation • Sugarscape – dynamic environments and resources • Predator. Prey – interactions between agents, resources • (Traffic model – Ascape model) SICSA student induction day, 2009 Slide 5

Re. Past Core Concepts • Agent – single socio-economic entity • Context – sets

Re. Past Core Concepts • Agent – single socio-economic entity • Context – sets of agents • – Subcontext – subset – Other ways to model different kinds of relationships Actions – either regular or in response to other actions/events – • Schedule – ordered set of actions (Projections – provide structure and relationships between agents) – Network, grid, space, geography (GIS) SICSA student induction day, 2009 Slide 6

The Tutorial Model • • Agents: Person – Male – Female Context: Demographics –

The Tutorial Model • • Agents: Person – Male – Female Context: Demographics – Population • Male • Female SICSA student induction day, 2009 Slide 7

Person • public abstract class Person { public static int SEX_MALE = 1; public

Person • public abstract class Person { public static int SEX_MALE = 1; public static int SEX_FEMALE = 2; int sex = 0; Double born. At = null; Person partner = null; Person() { born. At = Helper. get. Tick. Count(); } Person(Double born. At) { this. born. At = born. At; } public Double get. Age() { return (Helper. get. Tick. Count() - born. At) / 365; } public int get. Sex() { return sex; } public boolean is. Single() { return partner == null; } public void end. Relationship() { partner = null; } SICSA student induction day, 2009 Slide 8

Person (II) • public void step() { Context<Person> demographics = Helper. get. Master. Context();

Person (II) • public void step() { Context<Person> demographics = Helper. get. Master. Context(); Mortality m = (Mortality)Helper. get. From. Registry("Mortality"); if(m. simulate. Mortality(this)) { if(partner != null) { partner. end. Relationship(); } demographics. remove(this); } } SICSA student induction day, 2009 Slide 9

Mortality • public class Mortality{ public double get. Annual. Likelihood(Person p) { Double age

Mortality • public class Mortality{ public double get. Annual. Likelihood(Person p) { Double age = p. get. Age(); if(p. get. Sex() == Person. SEX_MALE) { if(age < 1) return 0. 4 d; if(age < 15) return 0. 1 d; if(age < 30) return 0. 1 d; if(age < 60) return 0. 05 d; if(age < 99) return 0. 4 d; if(age < 110) return 0. 9 d; return 1. 0 d; } else { if(age < 1) return 0. 4 d; // and so on SICSA student induction day, 2009 Slide 10

Mortality (II) • public double get. Daily. Likelihood(Person p) { return get. Annual. Likelihood(p)

Mortality (II) • public double get. Daily. Likelihood(Person p) { return get. Annual. Likelihood(p) / 365. 0 d; } public boolean simulate. Mortality(Person p) { return Random. Helper. next. Double. From. To(0 d, 1 d) < get. Daily. Likelihood(p); } SICSA student induction day, 2009 Slide 11

Males • In addition to the behaviour Person defines, Male defines the find. Female

Males • In addition to the behaviour Person defines, Male defines the find. Female behaviour • This is also where we define the Schedule for the behaviour, in this case, schedule at each tick • @Scheduled. Method(start = 1, interval = 1) public void step() { super. step(); if(is. Single() && get. Age() > 14) { find. Female(); } } SICSA student induction day, 2009 Slide 12

Males (II) • public void find. Female() { Context<Person> females = Helper. get. Context("Females");

Males (II) • public void find. Female() { Context<Person> females = Helper. get. Context("Females"); Female f = null; boolean has. Courted = false; for(int tries = 100; tries > 0 && !has. Courted; tries--) { f = (Female)females. get. Random. Object(); if(f. is. Single()) { if(f. get. Age() > 18) { has. Courted = true; if(f. court(this)) { partner = f; } } else if(f. get. Age() > 14 && this. get. Age() < 18) { has. Courted = true; if(f. court(this)) { partner = f; } } SICSA student induction day, 2009 Slide 13

Female • @Scheduled. Method(start = 1, interval = 1) public void step() { super.

Female • @Scheduled. Method(start = 1, interval = 1) public void step() { super. step(); if(!is. Pregnant() && !is. Single()) { Fertility f = (Fertility)Helper. get. From. Registry("Fertility"); if(f. simulate. Fertility((Male)partner, this)) { due. To. Give. Birth = Helper. get. Tick. Count() + 9 d*30 d; } } if(is. Pregnant()) { if(due. To. Give. Birth. equals(Helper. get. Tick. Count())) { gives. Birth(); } } SICSA student induction day, 2009 Slide 14

Female II • public void gives. Birth() { if(Random. Helper. next. Int. From. To(0,

Female II • public void gives. Birth() { if(Random. Helper. next. Int. From. To(0, 1) == 0) { Context<Person> males = Helper. get. Context("Males"); males. add(new Male()); } else { Context<Person> females = Helper. get. Context("Females"); females. add(new Female()); } due. To. Give. Birth = null; } public boolean court(Male m) { if(Random. Helper. next. Int. From. To(0, 1) == 1) { partner = m; return true; } return false; } SICSA student induction day, 2009 Slide 15

Population. Context. Builder • public void init. Garden. Of. Eden() { int num. Males

Population. Context. Builder • public void init. Garden. Of. Eden() { int num. Males = Helper. get. Parameter. As. Integer("num. Males"); int num. Females = Helper. get. Parameter. As. Integer("num. Females"); for (int i = 0; i < num. Females; i++) { Double born. At = Random. Helper. next. Double. From. To(0, 60 * 356) * 1; females. add(new Female(born. At)); } for (int i = 0; i < num. Males; i++) { Double born. At = Random. Helper. next. Double. From. To(0, 60 * 356) * 1; males. add(new Male(born. At)); } } SICSA student induction day, 2009 Slide 16

Population. Context. Builder (II) • public void init. From. File() { String init. File

Population. Context. Builder (II) • public void init. From. File() { String init. File = Helper. get. Parameter. As. String("init. File"); CSVReader reader = new CSVReader(new File. Reader(init. File), ', ', '"', 4); int age = 0; String[] row = null; while((row = reader. read. Next()) != null) { if(row. length == 8) { create. People(Integer. parse. Int(row[4]) / 2, age, Person. SEX_MALE); create. People(Integer. parse. Int(row[4]) / 2, age, Person. SEX_FEMALE); age++; } } } SICSA student induction day, 2009 Slide 17

Tutorial Model Summary • Three classes define agents and their behaviour – Person –

Tutorial Model Summary • Three classes define agents and their behaviour – Person – Male, Female • Population. Context. Builder creates an initial population, either ‘Garden of Eden’ or from a file • The classes shown provide the core simulation model • Some more code exists to support additional functionality such as printing out stats in a batch run • Re. Past provides all the simulation logic and UI elements SICSA student induction day, 2009 Slide 18