public Stack <Edge <POI> > GetShortestPath(POI Source, POI Target) { QuickGraph.Algorithms.ShortestPath.DijkstraShortestPathAlgorithm <POI, Edge <POI> > algo = new QuickGraph.Algorithms.ShortestPath.DijkstraShortestPathAlgorithm <POI, Edge <POI> >(POIsGraph, (Edge <POI> arg) => arg.Distance); // creating the observer & attach it var vis = new VertexPredecessorRecorderObserver <POI, Edge <POI> >(); vis.Attach(algo); // compute and record shortest paths algo.Compute(Target); // vis can create all the shortest path in the graph IEnumerable <Edge <POI> > path = null; vis.TryGetPath(Source, out path); Stack <Edge <POI> > pathStack = new Stack <Edge <POI> >(); if (path == null) { return(null); } foreach (Edge <POI> e in path) { pathStack.Push(e); } return(pathStack); }
public bool FindPOI(string DeviceId, POI Source, POI Target) { Stack <Edge <POI> > path = GetShortestPath(Source, Target); if (path == null) { return(false); } //You may want to do it manually? then check if the key does not exist using ContainsKey, then call TryAdd //and if it does exist, then do ActiveDevicesTable[deviceId] = your new NavigationDetails object var nav = new NavigationDetails { CurrentPOI = Source, DestinationPOI = Target, PathToDestination = path }; ActiveDevicesTable.AddOrUpdate(DeviceId, nav, (k, v) => nav); ActiveDevicesTable.TryAdd(DeviceId, new NavigationDetails { CurrentPOI = Source, }); return(true); }