Example #1
0
        public void Traversal()
        {
            foreach (var dijnode in AllDijNode)
            {
                foreach (var arc in dijnode.Node.Arcs)
                {
                    DijNode tempDijnode = visited.Find(a => a.Node == arc.Child);

                    if (tempDijnode != null)
                    {
                        continue;
                    }

                    DijNode tempParent = AllDijNode.Find(a => a.Node == arc.Parent);
                    DijNode tempChild  = AllDijNode.Find(a => a.Node == arc.Child);

                    if (dijnode.Cost + arc.Weigth < tempChild.Cost)
                    {
                        tempChild.Cost = arc.Weigth + tempParent.Cost;
                    }
                }
            }


            visited.Add(dijnode);
        }
Example #2
0
        public dijkstra(Node startNode, Node Target, Graph graph)
        {
            visited    = new List <DijNode>();
            AllDijNode = new List <DijNode>();
            foreach (var Node in graph.AllNodes)
            {
                if (Node.Name == startNode.Name)
                {
                    startdijNode = new DijNode(Node, 0);
                    AllDijNode.Add(startdijNode);
                    continue;
                }

                dijnode = new DijNode(Node, int.MaxValue);
                AllDijNode.Add(dijnode);
            }
            Traversal();
        }