Sender: |
|
Subject: |
|
From: |
|
Date: |
Wed, 3 May 2006 01:23:58 -0400 |
Comments: |
|
Reply-To: |
|
Parts/Attachments: |
|
|
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 Schelling.java 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
Schelling.java.
I created a procedure within the Schelling.java code (mine is called
rumDil.java 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 SchellingWithUI.java 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 SchellingWithUI.java code and
modifying IntGrid2D line with ((rumDil).state).neighbors with the same
effect.
Moses
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
scratch.
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;
Sean
|
|
|