From: Novice007 <zha...@12...> - 2009-01-22 07:28:09
|
Hi, I used Repast Simphony to simulate fire spread by CA. Following is my code: public class FireAgent extends SimpleAgent { @Override public int isFire() { return 1; } @Override @ScheduledMethod(start = 2, interval = 1, priority = 2) public void step() { int x,y; Context context = ContextUtils.getContext(this);//Get Context Grid <SimpleAgent> grid = (Grid<SimpleAgent>)context.getProjection("Woodland Grid");//Get Grid GridPoint point = grid.getLocation(this); //Get current location x=point.getX(); y=point.getY(); int iCount=4,xDst,yDst; VNQuery <SimpleAgent> query=new VNQuery(grid,this); Iterator <SimpleAgent> iter=query.query().iterator(); SimpleAgent neighborAgent = null; boolean bFire=false; boolean bTree=false; boolean bFighter=false; while (iter.hasNext()) { neighborAgent = iter.next(); point = grid.getLocation(neighborAgent); x=point.getX(); y=point.getY(); for (SimpleAgent agent : grid.getObjectsAt(x, y)) { if (agent instanceof FireAgent) { bFire = true; break; } if (agent instanceof TreeAgent) { bTree = true; } } if(bFire) continue; if(bTree){ FireAgent fire = new FireAgent(); context.add(fire); grid.moveTo(fire, x, y); } } } As I ran the model, I found the fire spreading is not following "the Von Neumann neighborhood ". There are some pictures I've got. The model is initializing as the following(at tick 1) http://www.nabble.com/file/p21599109/fire0.png At tick2 :(This step looks correct) http://www.nabble.com/file/p21599109/fire1.png At tick3 : (The fire is only spread toward right, why?) http://www.nabble.com/file/p21599109/fire2.png At tick4: (The fire is still spread toward right) http://www.nabble.com/file/p21599109/fire3.png …… At tick15: (After 15 steps, the fire stop spreading, I got the following result) http://www.nabble.com/file/p21599109/fire15.png Any feedback would be highly appreciated. -- View this message in context: http://www.nabble.com/Simulating-Fire-Spread-in-Repast-Simphony-tp21599109p21599109.html Sent from the repast-developer mailing list archive at Nabble.com. |