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);
So, I want to find out which points to go past first, in order to get the shortest route, from startPoint to endPoint.
Can anyone help me?
Update: It has to go past each of the points in the pointsToGoPast list. The cost is even for each route.
You can do this by Dijkstra’s Algorithm.
Sample project with code here
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
Locationto store aPointand theConnectionto calculate the weight (distance) in the constructor.Wikipedia has a very nice article on the algorithm