Пример #1
0
 private static double getShortestDistance(GraphNodeEx destination)
 {
     if (distance.ContainsKey(destination))
     {
         return(distance[destination]);
     }
     else
     {
         return(99999);
     }
 }
Пример #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);
         }
     }
 }
Пример #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);
         }
     }
 }
Пример #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);
        }
Пример #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;
        }
Пример #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);
        }
Пример #7
0
 private static double getShortestDistance(GraphNodeEx destination)
 {
     if (distance.ContainsKey(destination))
     {
         return distance[destination];
     }
     else
     {
         return 99999;
     }
 }