1 / 18

Social Simulation Tutorial Session 2: The RePast Simphony Toolkit, an example model

Social Simulation Tutorial Session 2: The RePast Simphony Toolkit, an example model. International Symposium on Grid Computing Taipei, Taiwan, 7 th March 2010. The RePast Toolkit. Developed at Argonne National Labs Developed in Java on basis of Eclipse Framework

stephaniel
Download Presentation

Social Simulation Tutorial Session 2: The RePast Simphony Toolkit, an example model

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Social Simulation TutorialSession 2: The RePast Simphony Toolkit, an example model International Symposium on Grid ComputingTaipei, Taiwan, 7th March 2010

  2. The RePast 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

  3. RePast Development Environment

  4. RePast Runtime Environment

  5. Example Models • Schelling – classical model of segregation • Sugarscape – dynamic environments and resources • PredatorPrey – interactions between agents, resources • (Traffic model – Ascape model)

  6. RePast 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)

  7. The Tutorial Model • Agents: Person • Male • Female • Context: Demographics • Population • Male • Female

  8. Person • public abstract class Person { public static int SEX_MALE = 1;public static int SEX_FEMALE = 2;int sex = 0; Double bornAt = null; Person partner = null; Person() { bornAt = Helper.getTickCount(); } Person(Double bornAt) { this.bornAt = bornAt; } public Double getAge() { return (Helper.getTickCount() - bornAt) / 365; } public int getSex() { return sex; } public boolean isSingle() { return partner == null; } public void endRelationship() { partner = null; }

  9. Person (II) • public void step() { Context<Person> demographics = Helper.getMasterContext();Mortality m = (Mortality)Helper.getFromRegistry("Mortality");if(m.simulateMortality(this)) { if(partner != null) { partner.endRelationship(); } demographics.remove(this); }}

  10. Mortality • public class Mortality{ public double getAnnualLikelihood(Person p) { Double age = p.getAge(); if(p.getSex() == Person.SEX_MALE) {if(age < 1) return 0.4d; if(age < 15) return 0.1d; if(age < 30) return 0.1d; if(age < 60) return 0.05d; if(age < 99) return 0.4d; if(age < 110) return 0.9d; return 1.0d; } else { if(age < 1) return 0.4d; // and so on

  11. Mortality (II) • public double getDailyLikelihood(Person p) { return getAnnualLikelihood(p) / 365.0d;}public boolean simulateMortality(Person p) { return RandomHelper.nextDoubleFromTo(0d, 1d) < getDailyLikelihood(p);}

  12. Males • In addition to the behaviour Person defines, Male defines the findFemale behaviour • This is also where we define the Schedule for the behaviour, in this case, schedule at each tick • @ScheduledMethod(start = 1, interval = 1)public void step() { super.step(); if(isSingle() && getAge() > 14) { findFemale(); }}

  13. Males (II) • public void findFemale() { Context<Person> females = Helper.getContext("Females");Female f = null; boolean hasCourted = false; for(int tries = 100; tries > 0 && !hasCourted; tries--) { f = (Female)females.getRandomObject(); if(f.isSingle()) { if(f.getAge() > 18) { hasCourted = true; if(f.court(this)) { partner = f; } } else if(f.getAge() > 14 && this.getAge() < 18) { hasCourted = true; if(f.court(this)) { partner = f; } } } }

  14. Female • @ScheduledMethod(start = 1, interval = 1) public void step() { super.step(); if(!isPregnant() && !isSingle()) { Fertility f = (Fertility)Helper.getFromRegistry("Fertility"); if(f.simulateFertility((Male)partner, this)) { dueToGiveBirth = Helper.getTickCount() + 9d*30d; } } if(isPregnant()) { if(dueToGiveBirth.equals(Helper.getTickCount())) { givesBirth(); } }

  15. Female II • public void givesBirth() { if(RandomHelper.nextIntFromTo(0,1) == 0) {Context<Person> males = Helper.getContext("Males");males.add(new Male()); } else { Context<Person> females = Helper.getContext("Females");females.add(new Female()); }dueToGiveBirth = null;}public boolean court(Male m) { if(RandomHelper.nextIntFromTo(0, 1) == 1) { partner = m; return true; } return false; }

  16. PopulationContextBuilder • public void initGardenOfEden() { int numMales = Helper.getParameterAsInteger("numMales");int numFemales = Helper.getParameterAsInteger("numFemales");for (int i = 0; i < numFemales; i++) { Double bornAt = RandomHelper.nextDoubleFromTo(0, 60 * 356) * -1;females.add(new Female(bornAt)); } for (int i = 0; i < numMales; i++) { Double bornAt = RandomHelper.nextDoubleFromTo(0, 60 * 356) * -1;males.add(new Male(bornAt)); }}

  17. PopulationContextBuilder (II) • public void initFromFile() { String initFile = Helper.getParameterAsString("initFile"); CSVReader reader = new CSVReader(new FileReader(initFile),',','"',4); int age = 0; String[] row = null; while((row = reader.readNext()) != null) { if(row.length == 8) { createPeople(Integer.parseInt(row[4]) / 2, age, Person.SEX_MALE);createPeople(Integer.parseInt(row[4]) / 2, age, Person.SEX_FEMALE);age++; } } }

  18. Tutorial Model Summary • Three classes define agents and their behaviour • Person – Male, Female • PopulationContextBuilder 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 • RePast provides all the simulation logic and UI elements

More Related