private Route CalculateRoute(Waypoint start, Waypoint end) { IEnumerable<Connection> shortestPathResult; if (!(World.ShortestPathsDijkstra(e => e.Time.TotalSeconds, start)(end, out shortestPathResult))) throw new Exception("Cannot locate a path from " + start + " to " + end); var waypoints = shortestPathResult.ToList(); return new Route(waypoints); }
public Route Route(Waypoint start, Waypoint end) { if (!_routeCache.ContainsKey(start)) _routeCache[start] = new ConcurrentDictionary<Waypoint, Route>(); if (_routeCache[start].ContainsKey(end)) return _routeCache[start][end]; return (_routeCache[start][end] = CalculateRoute(start, end)); }