|
From: Nick C. <ni...@sr...> - 2001-09-07 14:38:28
|
Thanks for the feedback. I've attached a new version with the shuffling in place. This does raise questions about how you want to handle the random seed, however. Nick On Thu, 2001-09-06 at 19:29, Laszlo Gulyas wrote: > Hi, > > First of all, I liked the SimpleModel class pretty much, so thanks for the > good work. > I'll give it some more thoughts during the coming days, though... > > At this point, the only thing which came up was the scrambling of the > agentList before each autoStep, in order to have the order in which the > agents are called randomized. I wonder whether this should also be automated. > I understand that you could do that in preStep(), but may be, having a flag > for that, > too would be even easier. > > Best, > > Gulya > > > At 02:42 PM 9/6/01 -0400, Nick Collier wrote: > >Hi, > > > >I've attached the first cut of a base model class that attempts to hide > >the scheduling mechanism. (For those of you tuning in late, this is for > >teaching purposes although its probably applicable to a lot of current > >models as well). Its based on the tutorial TemplateModel by Lars-Erik and > >Gulya. The idea here is that the user subclasses SimpleModel and > >implements or overrides a few methods while SimpleModel takes care of the > >scheduling. > > > >The important pieces here are: > > > >1. The run*(), and *step() methods. The idea here is to split up the > >behavoir executed each tick into pre (preStep()), post (postStep()), and > >executing (step()) phases. So in the case of a cooperation game, the user > >would override the step() method to have the agents play the game, and the > >preStep() and postStep() would do any necessary prepartion or destruction. > >What actually executes each tick is preStep(), step() and then postStep(). > > > >If autoStep is set to true, SimpleModel will execute the preStep(), > >autoStep() and then postStep(). autoStep() loops through the agent list > >calling step on each agent. For this to work the agents must implement the > >Stepable interface. > > > >2. The stopping time stuff. This was in the TemplateModel code so I > >assumed it was important and implemented it. The idea here is that the > >user can set the stopping time via a call to setStoppingTime in their > >model, and SimpleModel will schedule the model to stop when that tick has > >completed. > > > >So, is this enough? Do we need to include some random number > >initialization? Should SimpleModel be abstract and force people to > >implement buildModel()? Any other thoughts, comments, etc. are of course > >welcome. > > > >Nick > > > > > >Lars-Erik Cederman wrote: > >>Nick: This sounds like music to our ears! When do you think you might be > >>done with this new version? Gulya and I will be teaching RePast as of > >>October and we're obviously very keen to have a standardized hiding mechanism. > >>We'd be more than happy to contribute ideas and code so that we can get > >>this one up and running very soon. > >>I should mention that Gulya has now arrived in Cambridge. His email > >>address is gu...@la.... > >>Cheers, L-E > >> > >> > >>>Hi, > >>> > >>>I'm thinking for the next release of repast I'll add something along the > >>>lines of your tutorial model that hides the scheduler, and assumes a > >>>step method in the agents. I'd appreciate your thoughts on this. > >>> > >>>thanks, > >>> > >>>Nick > >>> > >>>-- > >>>Nick Collier > >>>Social Science Research Computing > >>>University of Chicago > >>>http://repast.sourceforge.net > >> > > > > > >-- > >Nick Collier > >Social Science Research Computing > >University of Chicago > >http://repast.sourceforge.net > > > > > > > >package uchicago.src.sim.engine; > > > >public interface Stepable { > > > > public void step(); > > > >} > >package uchicago.src.sim.engine; > > > >import java.util.ArrayList; > > > >public class SimpleModel extends SimModelImpl { > > > > protected Schedule schedule; > > protected ArrayList agentList; > > protected String name = "A RePast Model"; > > protected String[] params = {""}; > > private long stoppingTime = -1; > > private BasicAction stoppingAction; > > protected boolean autoStep = false; > > > > public void setStoppingTime(int time) { > > stoppingTime = time; > > if (stoppingAction != null) schedule.removeAction(stoppingAction); > > if (schedule != null) setStopAction(); > > } > > > > private void setStopAction() { > > System.out.println(stoppingTime); > > schedule.scheduleActionAt(stoppingTime, this,"stop", Schedule.LAST); > > } > > > > public void setup() { > > stoppingTime = -1; > > stoppingAction = null; > > schedule = new Schedule(); > > agentList = new ArrayList(); > > } > > > > public void begin() { > > buildModel(); > > buildSchedule(); > > } > > > > public String getName() { > > return name; > > } > > > > public Schedule getSchedule() { > > return schedule; > > } > > > > public String[] getInitParam() { > > return params; > > } > > > > public void buildModel() {} > > > > public void buildSchedule() { > > if (autoStep) schedule.scheduleActionBeginning(1, this, "runAutoStep"); > > else schedule.scheduleActionBeginning(1, this, "run"); > > setStopAction(); > > } > > > > public void runAutoStep() { > > preStep(); > > autoStep(); > > postStep(); > > } > > > > public void run() { > > preStep(); > > step(); > > postStep(); > > } > > > > private void autoStep() { > > int size = agentList.size(); > > for (int i = 0;i < size; i++) { > > Stepable agent = (Stepable)agentList.get(i); > > agent.step(); > > } > > } > > > > protected void preStep() {} > > protected void step() {} > > protected void postStep() {} > > > > public static void main(String[] args) { > > SimInit init = new SimInit(); > > SimpleModel model = new SimpleModel(); > > if (args.length > 0) init.loadModel(model, args[0], false); > > else init.loadModel(model, null, false); > > } > > > >} > > > > > > > > > > > > > > > > > > > > > > -- > Laszlo Gulyas, MSc > Government Department Weatherhead Center for International Affairs > Harvard University 602C Coolidge Hall > 1737 Cambridge street Cambridge, MA-02138 > > -- Nick Collier Social Science Research Computing University of Chicago http://repast.sourceforge.net |