Example #1
0
 private static double getShortestDistance(GraphNodeEx destination)
 {
     if (distance.ContainsKey(destination))
     {
         return(distance[destination]);
     }
     else
     {
         return(99999);
     }
 }
Example #2
0
 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);
         }
     }
 }
Example #3
0
 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);
         }
     }
 }
Example #4
0
        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);
        }
Example #5
0
        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;
        }
Example #6
0
        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);
        }
Example #7
0
 private static double getShortestDistance(GraphNodeEx destination)
 {
     if (distance.ContainsKey(destination))
     {
         return distance[destination];
     }
     else
     {
         return 99999;
     }
 }