.
, . . O (r * (s + r)), r - , s - .
, , ( ) . , , , , , . , , .
, " ". . , : , . , , . , , .
:
unknown = list of random points
frontier = new queue()
add all source cells to frontier
while (!unknown.isEmpty() && !frontier.isEmpty())
{
point = frontier.dequeue()
for each unknown_point
{
if (dist(point, unknown_point) < distance)
{
remove unknown_point from unknown list,
and add to frontier queue
}
}
}
if (!unknown.IsEmpty())
{
}
, O (r * (s + r)), r - s - . , , .
, " unknown_point " O (r), unknown . unknown :
point = frontier.dequeue()
unknown_count = unknown.count()
while (unknown_count > 0)
{
unknown_point = unknown.dequeue()
--unknown_count
if (dist(point, unknown_point) < distance)
{
// within range, add to frontier
frontier.enqueue(unknown_point)
}
else
{
// not reachable. Put it back in the unknown.
unqnown.enqueue(unknown_point)
}
}
, "", . , , : , . , . - :
0 1 2 3 4 5
-------------------------------------------------------
| .. | | . . | | | |
A | . . | | . . | . | | . . |
| . | | . | . . | | . |
-------------------------------------------------------
| | . .| | . . . | |. |
B | | . | . | . . | | |
| | . | | . | | .|
-------------------------------------------------------
| . . | | . | | | . |
C | . | | . | | | . |
| | | . | | | . |
-------------------------------------------------------
| . | | . . | . | . . | . . |
D | | | . | . | . | . . . |
| . | | . | | . | . |
-------------------------------------------------------
| |. . | . . | | | |
E | | . | . | | | |
| | . | . . | | | |
-------------------------------------------------------
| | . | | . . | . . | . . |
F | | . | | . . | . . | . . |
| | . . | | . | . | . |
-------------------------------------------------------
dist, dist .
, B3 dist . , , F5. , A3 B3, . , B3 โโB3. , : . , dist.
.
, , - . , . . Bin A0 (, ). .
, :
frontier = new queue()
add source points to frontier
while (!allBinsAreEmpty() && !frontier.IsEmpty())
{
point = frontier.dequeue()
sourceBin = determine bin that point is in
adjacentBins = getAdjacentBins(sourceBin.x, sourceBin.y)
for each adjacent bin
{
for each binPoint in bin
{
if distance(point, binPoint) <= dist
{
frontier.enqueue(binPoint)
bin.Remove(binPoint)
}
}
if (bin is empty)
remove bin
}
}
if (!allBinsAreEmpty())
{
}
:
getAdjacentBins(binx, biny)
{
adjacentBins[] = [bins[binx, biny]]
if (bins[binx-1, biny-1] != null) adjacentBins += bin[binx-1, biny-1]
if (bins[binx-1, biny] != null) adjacentBins += bin[binx-1, biny]
if (bins[binx-1, biny+1] != null) adjacentBins += bin[binx-1, biny+1]
if (bins[binx, biny+1] != null) adjacentBins += bin[binx, biny+1]
....
return adjacentBins
}