Is this NP multiple source multiple source algorithm difficult?

I have a map of the city (2D) and random points throughout the city. Some of these random points are places where tourists could be discarded. Of those that fall out, I need to color all the other points that tourists cannot reach within the length of X (say, miles) from the previously visited point. Thus, the descent points can be riveted if they are close enough through each jump at a distance of X. Again, all the random sources and destinations, so there is no established direction chart.

But I feel it could be NP-Hard. Is it correct?

I donโ€™t need only the shortest path, so I feel that it excludes Dijkstra and some of the graphical options that I can use.

Searches for brute force BFS with various pruning were unsuccessful. Generating all potential neighbors is simply too complicated for a certain number of random points. I was considering Floyd-Warshall or some option, and the flag points are not as sensitive to my sources as this happens, but since the points have no connections with each other, it will also require a considerable amount of time and memory to calculate all possible neighbors for each relevant node.

Am I complicating complexity too much? Perhaps inverting the problem can help - switching from all random nodes to the source nodes as โ€œdestinationsโ€?

+4
2

.

, . . 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())
{
    // there are still points in the unknown,
    // which means that not all points are reachable.
}

, 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())
{
    // there are unreachable points
}

:

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
}
+1

R * R, R - , .

, " R ", 3 * 3 , .

BFS , , , .

(, , NP-.)

+2

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


All Articles