180 likes | 419 Views
RePast Tutorial I. Today’s agenda. The RePast toolkits and its features The Iterated Prisoner‘s Dilemma How to build a model (1) SimpleIPD. What is RePast?. Re cursive P orous A gent S imulation T oolkit http://repast.sourceforge.net
E N D
Today’s agenda • The RePast toolkits and its features • The Iterated Prisoner‘s Dilemma • How to build a model (1) • SimpleIPD
What is RePast? • Recursive Porous Agent Simulation Toolkithttp://repast.sourceforge.net • Repast is an open-source software framework for creating agent-based simulations using Java • Initially developed by the Social Science Research Computing at the University of Chicago • Will be further developed by the RePast Organization for Architecture and Development (ROAD) and Argonne National Laboratory
Why RePast? • Alternatives: Swarm, Ascape, NetLogo... • “RePast is at the moment the most suitable simulation framework for the applied modeling of social interventions based on theories and data” (2004):http://jasss.soc.surrey.ac.uk/7/1/6.html • Modeled on Swarm but easier to use and better documented • Important criteria: • abstraction, ease of use and user-friendliness • flexibility and extensibility • performance and scalability • support for modeling, simulation & experimentation • Interoperability (GIS, statistical packages, …)
What does RePast offer? • Skeletons of agents and their environment • Graphical user interface • Scheduling of simulations • Parameters management • Behavior display • Charting • Data collection • Batch and parallel runs • Utilities and sample models
Tutorial Sequence December 7SimpleIPD: strategy space December 14EvolIPD: RWR December 21GraphIPD: charts and GUI GridIPD: 2DK January 11ExperIPD: batch runs and parameter sweeps
Iterated Prisoner’s Dilemma • Cohen, Riolo, and Axelrod. 1999. “The Emergence of Social Organization in the Prisoner's Dilemma” (SFI Working Paper 99-01-002) http://www.santafe.edu/research/publications/wpabstract/199901002 • In The Evolution of Cooperation, Robert Axelrod (1984) created a computer tournament of IPD • cooperation sometimes emerges • Tit For Tat a particularly effective strategy
Prisoner’s Dilemma Game Column: C D C 3,3 0,5 Row: D 5,0 1,1
One-Step Memory Strategies Strategy = (i, p, q) i = prob. of cooperating at t = 0 p = prob. of cooperating if opponent cooperated q = prob. of cooperating if opponent defected C p Memory: C D q C D D t t-1
D D D D D D TFT meets ALLD Cumulated Payoff p=1; q=0 0 + 1 + 1 + 1 = 3 Row (TFT) i=1 C D C Column (ALLD) D i=0 1 5 + 1 + 1 + = 8 p=0; q=0 0 1 2 3 4 t
How to build a model (1) • Extending the SimpleModel class with our own model class: import uchicago.src.sim.engine.SimpleModel; publicclass MyModel extendsSimpleModel { ... }
Setting up the simulation import uchicago.src.sim.engine.SimpleModel; publicclass MyModel extends SimpleModel { public static final int TFT = 1; public static final int ALLD = 3; privateinta1Strategy = TFT; privateinta2Strategy = ALLD; ... publicvoid setup() { super.setup(); a1Strategy = TFT; a2Strategy = ALLD; } publicvoid buildModel() { super.buildModel(); Agenta1 = newAgent(a1Strategy); Agenta2 = newAgent(a2Strategy); agentList.add(a1); agentList.add(a2); } } SimInit.loadModel() Called when the simulation is first started and when setup button pressed Executed every time the simulation is run
Running the simulation import uchicago.src.sim.engine.SimpleModel; public class MyModel extends SimpleModel { ... publicvoid setup() {...} publicvoid buildModel() {...} public void preStep() {...} public void step() {super.step();for (Iterator it = agentList.iterator(); it.hasNext();) { Agentagent = (Agent) iterator.next(); agent.play(); } } public void postStep() {...} } Executed at every time step
Model parameters import uchicago.src.sim.engine.SimpleModel; public class MyModel extends SimpleModel { public static final int TFT = 1; public static final int ALLD = 3; privateinta1Strategy = TFT; privateinta2Strategy = ALLD; public MyModel() { params = new String[] {“A1Strategy”}; name = “Example Model”; } ... public void setA1Strategy(int strategy) { this.a1Strategy = strategy; } public int getA1Strategy() { returna1Strategy; } } Introspection
SimpleModel methods • setStoppingTime(long time)set the time at which the current simulation run will stop • setRngSeed(long seed)set the seed for the random number generator (default: 1) • getNextIntFromTo(int from, int to)returns the next random double between from and to (exclusive) • getNextDoubleFromTo(double from,double to)returns the next random double between from and to (exclusive) • atPause()will be executed whenever your simulation is paused • atEnd()will be executed whenever your simulation ends
SimpleModel fields • boolean isGuitrue if the simulation is running in GUI mode, false if running in batch mode • long startAtthe time step at which to start executing the preStep(), step(), postStep() actions (default: 1) • Schedule schedulecan be used to add your own actions to the schedule ... • For the full list, consult the RePast API:http://repast.sourceforge.net/docs/api/