Subject: quickest algorithm for calculating buffer area
From: Becu Nicolas (nicolas.becu@gmail.com)
Date: Thu Mar 04 2010 - 16:09:33 CET
Hello everyone,
On a model I have an extensive use of buffer areas (the cells that are
at a maximum distance X of another cell).
I need to use this so much that I'm trying to reduce as much as possible
the calculation time required for this method.
I manage to gain time since the first method I used but it's still quiet
long and I would like to ask you if you have quicker solution than the
one I'm using.
//some details on the model// the grid I'm using is 129*129 and the
buffers are 23 cells around the central cell.Most of the cells have to
calculate their buffer once or more during a simulation
At first I had try using ""allLayersTo: radius "" or
""recursiveNeighbourhood"" but I found out the calculation was quicker
when I use the x and y coordinates of the cells (in top of that using
the x and y cordinates to calculate the circle around a cell, allows me
to have a circular buffer instead of quadrilateral buffer when using
neighborhood calculation // I have squared shape cells)
This is the algorithm I'm currently using.
Any idea how this algorithm could be improve ?
bufferCellsAt: dist
|aa bb cc cells|
"I use at the Cell level a dictionary that stores the results of the
buffers that have already been calculated so that if I need to get the
same buffer a second time, it is not calculated it again and the result
is just fecth in the dictionary"
(self dicoBufferCells includesKey: dist) ifFalse:
["this is the algorithm for identifying the cells that
compose the buffer area"
cc := dist * dist.
cells := Set new.
self spaceModel cormasModel theCells do:[:c|
c ~= self ifTrue:[
aa := (c x - self x).
bb := (self y - c y).
((aa * aa ) + (bb * bb )) < cc ifTrue:[cells
add:c]]].
self dicoBufferCells at: dist put:cells ].
^self dicoBufferCells at: dist
Thanks,
Nicolas