多点之间的最短路径多点、最短、路径

由网友(七等年)分享简介:我需要找到多发性两点之间的最短路径。比方说,我有以下四点:I need to find the shortest route between multipe points. Let's say that I have these four points:var startPoint = new Point(1, 1...

我需要找到多发性两点之间的最短路径。比方说,我有以下四点:

I need to find the shortest route between multipe points. Let's say that I have these four points:

var startPoint = new Point(1, 1);
var pointsToGoPast = new List<Point> { new Point(3,1); new Point(2,4); };
var endPoint = new Point(10, 10);

所以,我想找出它指向晃过首先,为了获得最短的路线,从的startPoint到终点。

So, I want to find out which points to go past first, in order to get the shortest route, from startPoint to endPoint.

谁能帮我?

更新:它走过去每次在pointsToGoPast列表中的点。成本还要为每个路由

Update: It has to go past each of the points in the pointsToGoPast list. The cost is even for each route.

推荐答案

您可以通过Dijkstra算法做到这一点。

You can do this by Dijkstra's Algorithm.

Sample项目code这里

这是需要改变的唯一一件事就是在项目中的权重,起重量不基于两点之间的距离。 (所以你需要修改位置来存储连接计算在构造函数中的权重(距离)。

The only thing that needs to change is the weights in the project, since the weight is based off of distance between the two points. (So you need to modify the Location to store a Point and the Connection to calculate the weight (distance) in the constructor.

维基百科对算法一个非常不错的文章

阅读全文

相关推荐

最新文章