Project Description
This is a .NET library that calculates the best route that connects two nodes in a network. It can be used to calculate a road route between two geographic locations in a road network. It can also be used in other physical or conceptual networks, such as a computer network. The problem is also known as single-pair shortest path problem.

Example
Consider the network displayed in the following picture. Please read the notes in the legend, as well as the special cases underneath.
NetRouting is capable of finding routes between any of these nodes. You can ask for all the possible routes as well as the shortest one.
See the code bellow to see how.
Network.png

// Define the network
var rp = new MemoryRouteProvider();
rp.Add("A", "B");
rp.Add("C", "H");
rp.Add("D", "E");
rp.Add("I", "F");
rp.Add("F", "G");
rp.Add("G", "I");

// B-C this is two way road
rp.Add("B", "C", twoWay: true);
rp.Add("C", "D", twoWay: true);

// There are two routes from B to I. We assign tags to them to differentiate them
rp.Add("B", "I", length: 5, tag: "alt1");
rp.Add("B", "I", length: 1, tag: "alt2");

// Route with length equal to 6
rp.Add("I", "E", length: 6);

// Route that begins and ends to the same spot
rp.Add("G", "G");

// Use the network
var allPaths     = rp.GetPaths("A", "E");         // get all paths from A to E
var shortestPath = rp.GetShortestPath("A", "E");  // get shortest path from A to E

// Assert the results
Assert.AreEqual(3, allPaths.ToList().Count);
Assert.AreEqual("A.B.C.D.E", shortestPath.ToNodeString("."));
Assert.AreEqual(4, shortestPath.Length);

Last edited Mar 2, 2012 at 1:56 PM by papadi, version 15