简体   繁体   中英

Traversing a graph and meeting a certain criteria?

I want to find the path between two vertices of a graph grid (A x B size, with 1x1 cells) (a1, b1) and (a2, b2) but with additional criterion of avoiding some n forbidden nodes (x1, y1), (x2, y2) as far away as possible from any one node to reach the destination. This means for all potential paths, the closest distance to any forbidden node should be the largest. The node positions are integers but the distance away from the nodes can be float numbers.

I would think the shortest path algorithms like Dijkstra's probably wouldn't matter a lot since the shortest path could end up traversing one of the n forbidden nodes. But then how can I factor in the "furthest distance away" from the nodes factor? My thoughts:

  1. I could try to average positions of the forbidden nodes, but I have managed to come up with one counter example that this might end up traversing one of the nodes

  2. The alternative way is to simply compute all possible paths and find the one with the furthest distance from any one forbidden node. This might mean using some dynamic programming approach.

  3. We can also tabulate the min distance from any one forbidden nodes at every node in the graph, and choose the path that gives the greatest distance at each step.

  4. Other thoughts: might have to use disjoint sets and MSTs?

My potential solutions seem to incur very high time complexity and I thought this kind of problem should be quite common (people probably have thought of this before). Is there a standard practice or way to approach this kind of problems optimally?

Pick a distance D and remove from the graph all nodes within distance D of the forbidden nodes. Find out if the source and destination are still connected. Use binary chop to find the largest possible D still leaving the source and destination connected. The path from source to destination on this graph is the path you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM