private static double getShortestDistance(GraphNodeEx destination) { if (distance.ContainsKey(destination)) { return(distance[destination]); } else { return(99999); } }
private static void findMinimunGraphNode(GraphNodeEx Entry) { foreach (KeyValuePair <GraphNodeEx, double> mapper in Entry.Nodes) { if (getShortestDistance(mapper.Key) > getShortestDistance(Entry) + mapper.Value) { distance.Add(mapper.Key, distance[Entry] + mapper.Value); UnSettledNodes.Add(mapper.Key); Paths.Add(mapper.Key, Entry); } } }
private static void findMinimunGraphNode(GraphNodeEx Entry) { foreach (KeyValuePair<GraphNodeEx, double> mapper in Entry.Nodes) { if (getShortestDistance(mapper.Key) > getShortestDistance(Entry) + mapper.Value) { distance.Add(mapper.Key, distance[Entry] + mapper.Value); UnSettledNodes.Add(mapper.Key); Paths.Add(mapper.Key, Entry); } } }
private static GraphNodeEx getDirectionNode(HashSet <GraphNodeEx> UnSettledNodes) { GraphNodeEx DirectionNode = null; foreach (GraphNodeEx node in UnSettledNodes) { if (DirectionNode == null) { DirectionNode = node; } else { if (getShortestDistance(node) < getShortestDistance(DirectionNode)) { DirectionNode = node; } } } return(DirectionNode); }
public static Dictionary<GraphNodeEx, GraphNodeEx> getShortestPath(GraphNodeEx head) { //Initialize distance = new Dictionary<GraphNodeEx, double>(); SettledNodes = new HashSet<GraphNodeEx>(); UnSettledNodes = new HashSet<GraphNodeEx>(); Paths = new Dictionary<GraphNodeEx, GraphNodeEx>(); //Execute GraphNodeEx CurrentNode = null; UnSettledNodes.Add(head); distance.Add(head, 0); while (UnSettledNodes.Count != 0) { CurrentNode = getDirectionNode(UnSettledNodes); UnSettledNodes.Remove(CurrentNode); SettledNodes.Add(CurrentNode); findMinimunGraphNode(CurrentNode); } return Paths; }
public static Dictionary <GraphNodeEx, GraphNodeEx> getShortestPath(GraphNodeEx head) { //Initialize distance = new Dictionary <GraphNodeEx, double>(); SettledNodes = new HashSet <GraphNodeEx>(); UnSettledNodes = new HashSet <GraphNodeEx>(); Paths = new Dictionary <GraphNodeEx, GraphNodeEx>(); //Execute GraphNodeEx CurrentNode = null; UnSettledNodes.Add(head); distance.Add(head, 0); while (UnSettledNodes.Count != 0) { CurrentNode = getDirectionNode(UnSettledNodes); UnSettledNodes.Remove(CurrentNode); SettledNodes.Add(CurrentNode); findMinimunGraphNode(CurrentNode); } return(Paths); }
private static double getShortestDistance(GraphNodeEx destination) { if (distance.ContainsKey(destination)) { return distance[destination]; } else { return 99999; } }