多点之间的最短路径 [英] Shortest route between multiple points

查看:186
本文介绍了多点之间的最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

<一个href="http://www.$c$cproject.com/Articles/22647/Dijkstra-Shortest-Route-Calculation-Object-Oriente">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.

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

这篇关于多点之间的最短路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆