A Shortest Path Algorithm With Minimum Number Of Nodes Traversed

我是研究僧i 提交于 2019-11-30 17:04:33

Let me demonstrate that adding a constant value to all edges can change which route is "shortest" (least total weight of edges).

Here's the original graph (a triangle):

A-------B
 \  5  /
2 \   / 2
   \ /
    C

Shortest path from A to B is via C. Now add constant 2 to all edges. The shortest path becomes instead the single step from A directly to B (owing to "penalty" we've introduced for using additional edges).

Note that the number of edges used is (excluding the node you start from) the same as the number of nodes visited.

The way you can do that is adapt the weights of the edges to always be 1, so that you traverse 5 nodes, and you've gone a distance of "5". The algorithm would be the same at that point, optimizing for number of nodes traversed rather than distance traveled.

If you want some sort of hybrid, you need to determine how much importance to give to traversing a node and the distance. The weight used in calculations should look something like:

weight = node_importance * 1 + (1 - node_importance) * distance

Where node_importance would be a percentage which gauges how much distance is a factor and how much minimum node traversal is important. Though you may have to normalize the distances to be an average of 1.

I'm going to go out on a limb here, but have you tried the A* algorithm? I may have understood your question wrong, but it seems like A* would be a good starting point for what you want to do.

Check out: http://en.wikipedia.org/wiki/A*_search_algorithm

Some pseudo code there to help you out too :)

Praveen

If i understood the question correctly then its best analogy would be that used to find the best network path.

In network communication a path may not only be selected because it is shortest but has many hop counts(node), thus may lead to distortion, interference and noise due to node connection.

So the best path calculation contains the minimizing the function of variables as in your case Distance and Hop Count(nodes).

You have to derive a functional equation that could relate the distance and node counts with quality.

so something as suppose
1 hop count change = 5 unit distance (which means the impact is same for 5unit distace or 1 node change)

so to minimize the loss you can use it in the linear equation.
minimize(distance + hopcount);
where hopcount can be expressed as distance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!