From: Joseph S. <js...@dm...> - 2013-04-12 10:04:54
|
Michelle - my understanding of how Eric's code works is that each grid cell contains a CA agent, but that their initial state is seeded, with a few being given state 1 to represent being alive. This is rather different to the grid being seeded with agents - you could implement a CA this way, but it would be more difficult and, perhaps, rather contrary to the original CA concept. If you randomly place the CA's and that placement is quite sparse, it is likely that the MooreQuery will return no neighbours and therefore that the state of the simulation will never change. Could that be the issue? J Richard Snape PhD Student ---------------- CASCADE (Complex Adaptive Systems, Cognitive Agents and Distributed Energy) project : a Complexity Science-Based Investigation into the Smart Grid Concept see, http://www.iesd.dmu.ac.uk/~cascade --------------- Queens Building, The Gateway, Leicester LE1 9BH Email: js...@dm... Mobile +44(0)7980 585778 ============================= Message: 2 Date: Fri, 12 Apr 2013 20:16:55 +1200 From: Michelle <ma...@pa...> Subject: Re: [Repast-interest] trying to create Game of Life in RePast Java To: 'Sebastian Rasch' <voi...@gm...>, "'Tatara, Eric R.'" <ta...@an...>, rep...@li... Message-ID: <000301ce3756$186d1440$49473cc0$@paradise.net.nz> Content-Type: text/plain; charset=iso-8859-1 Hi Sebastian, I'm still a bit too novice to understand annotation vs. global, but I assume it's a global step method as the entire grid seems to be queried simultaneously rather than walking through the state of each cell using a loop. Using the basic CA class as per internet and Eric's code: package JavaGameOfLife4; import java.util.Iterator; import repast.simphony.context.Context; import repast.simphony.engine.schedule.ScheduleParameters; import repast.simphony.engine.schedule.ScheduledMethod; import repast.simphony.query.space.grid.MooreQuery; import repast.simphony.random.RandomHelper; import repast.simphony.space.grid.Grid; import repast.simphony.util.ContextUtils; import repast.simphony.valueLayer.GridValueLayer; public class CA { public int state; public int oldState; /** * Maintain the history of the state for one time interval */ @ScheduledMethod(start=1, interval=1, priority=ScheduleParameters.FIRST_PRIORITY) public void setOldState(){ oldState = state; } @ScheduledMethod(start=1) public void initState(){ setState(RandomHelper.nextIntFromTo(0, 1)); setOldState(); } @ScheduledMethod(start=1, interval=1) public void step(){ Context<CA> context = ContextUtils.getContext(this); Grid<CA> grid = (Grid)context.getProjection("Grid"); <snip> |