Getting agents inRadius without iterating through all the agents of the context

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting agents inRadius without iterating through all the agents of the context

Bruno
Hello,

Does getObjectsAt(x,y) from class Grid iterate through all the gridCells of the grid  or does it return the objects contained in gridCell(x,y) directly?  

Here is my problem:
In my model, I have a grid filled up with non-mobile agents (all the gridCell have one and only one agent, and the latter never change position during a the entire simulation).
At some point, each agent has to check the states of its neighboring agents within an certain circular area around itself, the size of the area is defined by a given “radius”.
To do so, I create a list of agents (for each agent) – called “neighborList” - that contains all the other agents that are within the distance “radius”  (I calculate the Euclidian distance between each pair of agents). The problem is that I have to iterate through all the other agents every time I make a “neighborList” (I do stop the process when the neighborList.size() gets to a certain threshold value though). This takes too much time.

I wonder if using getObjectsAt(x,y) from the class Grid would be a better option (I would just have to iterate through the set of coordinates around my agent of focus and no more). However, I do not know how the method proceeds: does it iterate through all the gridCells (in this case this option does not seem better) or not???

Thank you,

Best

Bruno
Reply | Threaded
Open this post in threaded view
|

Re: Getting agents inRadius without iterating through all the agents of the context

srcnick
getObjectsAt(x,y) doesn’t iterate through the grid. You can think of the Grid as a kind of Map indexed by the coordinates. So, neighborhood type operations of the kind you want to do should be much faster.

Nick


> On May 25, 2016, at 6:19 PM, Bruno <[hidden email]> wrote:
>
> Hello,
>
> Does getObjectsAt(x,y) from class Grid iterate through all the gridCells of
> the grid  or does it return the objects contained in gridCell(x,y) directly?  
>
> Here is my problem:
> In my model, I have a grid filled up with non-mobile agents (all the
> gridCell have one and only one agent, and the latter never change position
> during a the entire simulation).
> At some point, each agent has to check the states of its neighboring agents
> within an certain circular area around itself, the size of the area is
> defined by a given “radius”.
> To do so, I create a list of agents (for each agent) – called “neighborList”
> - that contains all the other agents that are within the distance “radius”
> (I calculate the Euclidian distance between each pair of agents). The
> problem is that I have to iterate through all the other agents every time I
> make a “neighborList” (I do stop the process when the neighborList.size()
> gets to a certain threshold value though). This takes too much time.
>
> I wonder if using getObjectsAt(x,y) from the class Grid would be a better
> option (I would just have to iterate through the set of coordinates around
> my agent of focus and no more). However, I do not know how the method
> proceeds: does it iterate through all the gridCells (in this case this
> option does not seem better) or not???
>
> Thank you,
>
> Best
>
> Bruno
>
>
>
>
> --
> View this message in context: http://repast.10935.n7.nabble.com/Getting-agents-inRadius-without-iterating-through-all-the-agents-of-the-context-tp11544.html
> Sent from the repast-interest mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Mobile security can be enabling, not merely restricting. Employees who
> bring their own devices (BYOD) to work are irked by the imposition of MDM
> restrictions. Mobile Device Manager Plus allows you to control only the
> apps on BYO-devices by containerizing them, leaving personal data untouched!
> https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
> _______________________________________________
> Repast-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/repast-interest


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest