land cover and search

View: New views
2 Messages — Rating Filter:   Alert me  

land cover and search

by jung :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Message
Hi All,
I have written this code for an agent to check the landcover within a certain search radius (see below).The landcover is a grid valuelayer and is accessed using the method:

public int getCoverAt(double x, double y) {

return (int)getValueLayer("CoverType").get(x,y);

}

The code seems to be working just right - but my problem is that is slows down the model immensely. Does anyone have any suggestion as to how I can do this differently? I do not have landcover as a separate class, just as a value layer.

Thanks,

Lene

 

public int searchAreaForCover(double vision, int myCoverType){

int myCover=0;

int xLook, yLook;

Context context = ContextUtils.getContext(this);

Grid<Object> grid = (Grid) context.getProjection("Simple Grid");

ContinuousSpace<Object> space = (ContinuousSpace) context.getProjection("Continuous Space");

NdPoint point = space.getLocation(this); // Get the agent's point coordinate from the space

x = point.getX(); // The x coordinate on the 2D continuous space

y = point.getY(); // The y coordinate on the 2D continuous space

yLook = (int) y;

for (xLook = (int) (x - vision); xLook <= x + vision; xLook++) {

    for (yLook = (int) (y - vision); yLook <= y + vision; yLook++) {

        if (this.getCover(xLook, yLook) == myCoverType) {

            myCover = myCover + 1;

}

}

}

return myCover;

}

______________________________________
 
Lene Jung Kjær, PhD. Candidate
Cooperative Wildlife Research Laboratory
Southern Illinois University
Life Science II, Room 269B
Carbondale, Il 62901
Phone office: 618-453-5495
Fax office: 618-453-6944
Phone home: 618-303-6136
Email: jung@...
______________________________________
 

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest

Re: land cover and search

by Nick Collier-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm. It shouldn't slow things down much. What's the actual ValueLayer used (Grid or Continuous)? Are you sure its the call to the layer rather than the looping?

Nick

On Oct 27, 2009, at 10:49 AM, Lene Jung Kjaer wrote:

Hi All,
I have written this code for an agent to check the landcover within a certain search radius (see below).The landcover is a grid valuelayer and is accessed using the method:

public int getCoverAt(double x, double y) {

return (int)getValueLayer("CoverType").get(x,y);

}

The code seems to be working just right - but my problem is that is slows down the model immensely. Does anyone have any suggestion as to how I can do this differently? I do not have landcover as a separate class, just as a value layer.

Thanks,

Lene

 

public int searchAreaForCover(double vision, int myCoverType){

int myCover=0;

int xLook, yLook;


Context context = ContextUtils.getContext(this);

Grid<Object> grid = (Grid) context.getProjection("Simple Grid");

ContinuousSpace<Object> space = (ContinuousSpace) context.getProjection("Continuous Space");


NdPoint point = space.getLocation(this); // Get the agent's point coordinate from the space


x = point.getX(); // The x coordinate on the 2D continuous space

y = point.getY(); // The y coordinate on the 2D continuous space




yLook = (int) y;


for (xLook = (int) (x - vision); xLook <= x + vision; xLook++) {




    for (yLook = (int) (y - vision); yLook <= y + vision; yLook++) {


        if (this.getCover(xLook, yLook) == myCoverType) {

            myCover = myCover + 1;

}


}

}




return myCover;

}

______________________________________
 
Lene Jung Kjær, PhD. Candidate
Cooperative Wildlife Research Laboratory
Southern Illinois University
Life Science II, Room 269B
Carbondale, Il 62901
Phone office: 618-453-5495
Fax office: 618-453-6944
Phone home: 618-303-6136
Email: jung@...
______________________________________
 
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Repast-interest mailing list
Repast-interest@...
https://lists.sourceforge.net/lists/listinfo/repast-interest