May 2006


Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Wed, 3 May 2006 01:23:58 -0400
text/plain (70 lines)
Sean, Liviu,

Thanks for the response.  Let me try to rephrase the question.

How do I access the neighbors grid created by createGrids() procedure from 
within the code?  I understand how start() recreates the 
grid because it calls createGrids().  My original code (copied below) was 
similar to what you had except I'm trying to call it from within

I created a procedure within the code (mine is called for this project in CSS610) to capture the current agent 
population by using the colors on the grid.  I've copied the code below.  
I call this procedure from the so I can post some 
population statistics onto the JFree window.

What I get back is a grid with no data -- it seems I get an empty, 
uninitialized version of neighbors or I'm not calling the grid correctly. 
I already tried to move this code to the code and 
modifying IntGrid2D line with ((rumDil).state).neighbors with the same 


    protected double[] getProportion()
     int countTerrorist = 0;
     int countNeutral = 0;
     int countFriendly = 0;
     int population;
     double[] proportion = {0.0, 0.0, 0.0};
     IntGrid2D grid2d = neighbors;
     int[][] c = grid2d.field;
     for (int x = 0; x < gridWidth; x++)
      for (int y = 0; y < gridHeight; y++)
       c[x][y] = neighbors.get(x,y);
       if (c[x][y] == RED) countTerrorist++;
       else if (c[x][y] == GREY) countNeutral++;
       else if (c[x][y] == BLUE) countFriendly++;
     population = countTerrorist + countNeutral + countFriendly;
     proportion[0] = countTerrorist/population;
     proportion[1] = countNeutral/population;
     proportion[2] = countFriendly/population;
     return proportion;

On May 2, 2006, at 1:08 AM, Moses wrote:

> New question: I've got to access the grid created in Schelling after 
> createGrids().  I tried to access it through neighbors but got an 
> empty grid in the new function I created to access the grid.  How 
> would I access the grid created by createGrids()?

Moses, your question is not posed well enough to answer.

createGrids() is called when the object is constructed, and then is called 
again at start().  Whenever the method is called, the grid is rebuilt from 

If you're trying to access the grid from an agent, you could probably do 
it with something like:

 IntGrid2D grid2d= ((Schelling)state).neighbors;
 int[][] theGridProper = grid.field;