Effective algorithm for agents sharing energy only with neighboring agents?

Soooo, I have a bunch of turtle agents who need to "share" / "receive" energy with each other. The idea is simple, inside a group of turtles you take medium energy and move a small amount from those who have more than average than those who have less than average.

It is completely trivial if you take the full group of turtles, but because the turtles are grouped by location, the only way to fully calculate everything that happens is to check who is next to the turtle. Then you ask all the turtles around them to add / subtract from their energies. It would be much better to do a linear time calculation somehow, but I can't think of any good way to do this. One of the possibilities that I considered was to pre-calculate the entire distance matrix in advance, in order to find nearby turtles, you do not need to call for “turtles along the radius X”.

I am looking for other implementation shortcuts that can shorten processing time, or alternative ideas for sharing algorithms. Thanks!

+4
source share
2 answers

I know what you wanted to avoid in-radius, but it is actually quite effective for small radii. So, without knowing anymore, I think this would be the easiest way to get the effect you want:

ask turtles [
  set energy mean [ energy ] of turtles in-radius d
]

, d , , , , . , . , . , : , , . , , , .

, , , :

foreach groups [
  let new-energy mean [ energy ] of ?
  ask ? [ set energy new-energy ]
]

, , ( : a b , b c , a c ). , , .

, , , , :

ask patches [
  set mean-energy mean [ energy ] of turtles-here
]
diffuse mean-energy .5
ask turtles [
  set energy mean-energy
]

. , , .

+1

( ) Quadtrees (http://en.wikipedia.org/wiki/Quadtree).

, , , , - . .

, ( n ^ 2)

0

Source: https://habr.com/ru/post/1527049/


All Articles