public static RouteInfo GetPathInfo(List <Node> paths) { //get the number of stops on each path var route = new StringBuilder(); int totalDistance = 0; int counter = 0; var initialNode = new Node(); foreach (Node stopOver in paths) { // set route map route.AppendFormat("{0} ", stopOver.Name); //get distance between each other if (counter < paths.Count) { if (counter > 0) //check if first item { //compare Edge endPoint = initialNode.Edges.FirstOrDefault(e => e.NodeDestination.Name == stopOver.Name); if (endPoint == null) { return(null); } //get distance totalDistance += endPoint.Distance; } //replace initial node; will be used to compare with the next node initialNode = stopOver; counter++; } } var result = new RouteInfo { Path = route.ToString(), NumberOfStops = paths.Count, TotalDistance = totalDistance }; return(result); }
public static GraphResult GetAllPathInfo(Node from, Node to) { var result = new GraphResult() { Start = from, End = to }; var allPaths = FindAllPaths(from, to).ToList(); var pathInfo = new RouteInfo(); foreach (var path in allPaths) { pathInfo = GetPathInfo(path); result.PossibleRoutes.Add(pathInfo); } return(result); }