public void OnVisitSyntaxNode(T syntaxNode)
 {
     VisitedNodes.Add(syntaxNode);
     if (_callback is object)
     {
         _callback(syntaxNode);
     }
 }
Beispiel #2
0
 public void Init(int startNodeId)
 {
     StartNodeId = startNodeId;
     Distance    = 0;
     VisitedNodes.Add(Graph.Points.Where(x => x.Id == startNodeId).First());
     UnvisitedNodes = Graph.Points.Where(x => x.Id != startNodeId).ToList();
     Path.Clear();
 }
Beispiel #3
0
 public void visitNode(uint u)
 {
     if (CurrentNode != null)
     {
         VisitedNodes.Add(CurrentNode);
     }
     CurrentNode = Convert.ToInt32(u);
     NotifyStateChanged();
 }
Beispiel #4
0
        private void ProcessPath(string path)
        {
            var inputs = path.ToCharArray();

            foreach (var next in inputs.Select(input => new Direction(input)).Select(dir => Point + dir.Translation).Where(next => Graph.Map.ContainsKey(next)))
            {
                Node  = Graph.GetNodeFrom(next);
                Point = next;
                VisitedNodes.Add(Node);
            }
        }
Beispiel #5
0
        public bool A_StarAlgorithm(Node Start, Node Target)
        {
            Node CurrentNode = Start;

            ActualNodes.Add(CurrentNode);

            for (; ActualNodes.Count > 0;)
            {
                CurrentNode = ActualNodes[0];

                if (CurrentNode.Equals(Target))
                {
                    VisitedNodes.Add(Target);

                    for (int Index = 0; Index < VisitedNodes.Count - 1; Index++)
                    {
                        ShortesPath.Add(InnerGraph.FindEdge(VisitedNodes[Index], VisitedNodes[Index + 1]));
                    }

                    return(true);
                }

                ActualNodes.Remove(CurrentNode);

                ClosedNodes.Add(CurrentNode);

                foreach (Node Incomer in CurrentNode.Incomers.Where(Node => Node != null && Node.Index != Node.Incomers.Length - 1))
                {
                    if (!ClosedNodes.Contains(Incomer))
                    {
                        if (!ActualNodes.Contains(Incomer))
                        {
                            Incomer[Incomer.Index] = CurrentNode;

                            Incomer.HeuristicCost = HeruisticPath(Incomer, Target);

                            Incomer.PastWayCost = InnerGraph.FindEdge(CurrentNode, Incomer).Weight;

                            Incomer.TotalPathCost = Incomer.PastWayCost + Incomer.HeuristicCost;

                            ActualNodes.Add(Incomer);

                            ActualNodes = ActualNodes.OrderBy(Node => Node.TotalPathCost).ToList <Node>();
                        }
                    }
                }

                VisitedNodes.Add(CurrentNode);
            }

            return(true);
        }
        public bool FindTheShortesPath(Node Start, Node Target)
        {
            Node CurrentNode = Start;

            OpenList.Add(CurrentNode);

            for (; OpenList.Count > 0;)
            {
                CurrentNode = OpenList[0];

                if (CurrentNode.Equals(Target))
                {
                    VisitedNodes.Add(Target);

                    for (int Index = 0; Index < VisitedNodes.Count - 1; Index++)
                    {
                        ShortesPath.Add(InnerGraph.FindEdge(VisitedNodes[Index], VisitedNodes[Index + 1]));
                    }

                    return(true);
                }

                OpenList.Remove(CurrentNode);

                ClosedList.Add(CurrentNode);

                foreach (Node Inheritor in CurrentNode.Inheritors.Where(Node => Node != null && Node.Index != Node.Inheritors.Length - 1))
                {
                    if (!ClosedList.Contains(Inheritor))
                    {
                        if (!OpenList.Contains(Inheritor))
                        {
                            Inheritor[Inheritor.Index] = CurrentNode;

                            Inheritor.HeuristicPathWeight = CalculateHeuristic(Inheritor, Target);

                            Inheritor.GainedPathWeight = InnerGraph.FindEdge(CurrentNode, Inheritor).Weight;

                            Inheritor.TotalPathWeight = Inheritor.GainedPathWeight + Inheritor.HeuristicPathWeight;

                            OpenList.Add(Inheritor);

                            OpenList = OpenList.OrderBy(Node => Node.TotalPathWeight).ToList <Node>();
                        }
                    }
                }

                VisitedNodes.Add(CurrentNode);
            }

            return(true);
        }
Beispiel #7
0
        public void Init(int startNodeId)
        {
            StartNodeId = startNodeId;
            Distance    = 0;
            List <Point> visitedPoints = Graph.Points.Where(x => x.Id == startNodeId).ToList();

            if (visitedPoints.Count > 0)
            {
                VisitedNodes.Add(visitedPoints.First());
            }
            UnvisitedNodes = Graph.Points.Where(x => x.Id != startNodeId).ToList();
            Path.Clear();
        }
Beispiel #8
0
        private bool DoSearch()
        {
            AssignCurrentVertex();

            if (VisitedNodes.Contains(Current))
            {
                return(MoveNext());
            }

            VisitedNodes.Add(Current);

            PushNeighborsToStack();

            return(true);
        }
        public bool DepthFirstSearch(Node Start)
        {
            VisitedNodes.Add(Start);

            for (int Index = 0; Index < InnerGraph.NumberOfNodes; Index++)
            {
                if (InnerGraph.SetOfNodes[Start.Index][Index] != null && !VisitedNodes.Contains(InnerGraph.SetOfNodes[Index]))
                {
                    ResultOfSearching.Add(InnerGraph.FindEdge(Start, InnerGraph.SetOfNodes[Index]));

                    DepthFirstSearch(InnerGraph.SetOfNodes[Index]);
                }
            }

            return(VisitedNodes.Count.Equals(InnerGraph.NumberOfNodes));
        }
Beispiel #10
0
        /// bool  BreadthFirstSearch(Node Start) starting from StartNode
        /// adding that Node in queue, afterthat starting cycle for all Graph
        /// </summary>
        /// <param name="Start"></param> - first Node
        /// <returns></returns>
        public bool BreadthFirstSearch(Node Start)
        {
            Queue.Enqueue(Start);

            VisitedNodes.Add(Start);

            for (; Queue.Count > 0;)
            {
                Start = Queue.Dequeue();
                for (int Index = 0; Index < InnerGraph.QuantityOfNodes; Index++)
                {
                    if (InnerGraph.SetOfNodes[Start.Index][Index] != null && !VisitedNodes.Contains(InnerGraph.SetOfNodes[Index]))
                    {
                        ResultOfSearching.Add(InnerGraph.FindEdge(Start, InnerGraph.SetOfNodes[Index]));
                        Queue.Enqueue(InnerGraph.SetOfNodes[Index]);
                        VisitedNodes.Add(InnerGraph.SetOfNodes[Index]);
                    }
                }
            }
            return(VisitedNodes.Count.Equals(InnerGraph.QuantityOfNodes));
        }
Beispiel #11
0
        public Edge Move()
        {
            Point endPoint;
            var   startPoint = CurrentNode();

            if (UnvisitedNodes.Count == 0)
            {
                endPoint = VisitedNodes[0]; // if ant visited every node, just go back to start
            }
            else
            {
                endPoint = ChooseNextPoint();
                VisitedNodes.Add(endPoint);
                UnvisitedNodes.RemoveAt(UnvisitedNodes.FindIndex(x => x.Id == endPoint.Id));
            }

            var edge = Graph.GetEdge(startPoint.Id, endPoint.Id);

            Path.Add(edge);
            Distance += edge.Length;
            return(edge);
        }
        public bool FindMinimumSpanningTree()
        {
            VisitedNodes.Add(InnerGraph.SetOfNodes[0]);

            for (; VisitedNodes.Count < InnerGraph.NumberOfNodes;)
            {
                Node Start = new Node();

                Node End = new Node();

                Edge CurrentEdge = new Edge {
                    Weight = Infinity
                };

                for (int Index = 0; Index < InnerGraph.NumberOfNodes; Index++)
                {
                    if (VisitedNodes.Contains(InnerGraph.SetOfNodes[Index]))
                    {
                        foreach (Node Inheritor in InnerGraph.SetOfNodes[Index].Inheritors.Where(Node => Node != null && !VisitedNodes.Contains(Node)))
                        {
                            if (CurrentEdge.Weight > InnerGraph.FindEdge(InnerGraph.SetOfNodes[Index], Inheritor).Weight)
                            {
                                CurrentEdge = InnerGraph.FindEdge(InnerGraph.SetOfNodes[Index], Inheritor);

                                Start = CurrentEdge[0];

                                End = CurrentEdge[1];
                            }
                        }
                    }
                }

                VisitedNodes.Add(End);

                MinimumSpanningTree.Add(InnerGraph.FindEdge(Start, End));
            }

            return(VisitedNodes.Count.Equals(InnerGraph.NumberOfNodes));
        }
        public bool DepthFirstSearch(Node Start, Node Target)
        {
            VisitedNodes.Add(Start);

            if (VisitedNodes.Contains(Target))
            {
                return(true);
            }

            for (int Index = 0; Index < InnerGraph.NumberOfNodes; Index++)
            {
                if (InnerGraph.SetOfNodes[Start.Index][Index] != null && !VisitedNodes.Contains(InnerGraph.SetOfNodes[Index]))
                {
                    ResultOfSearching.Add(InnerGraph.FindEdge(Start, InnerGraph.SetOfNodes[Index]));

                    if (DepthFirstSearch(InnerGraph.SetOfNodes[Index], Target))
                    {
                        return(true);
                    }
                }
            }

            return(VisitedNodes.Contains(Target));
        }
        public bool DepthFirstSearch(Node Start, Node Target, Node[] FoundPath)
        {
            VisitedNodes.Add(Start);

            if (VisitedNodes.Contains(Target))
            {
                return(true);
            }

            for (int Index = 0; Index < InnerGraph.NumberOfNodes; Index++)
            {
                if (InnerGraph.SetOfNodes[Start.Index][Index] != null && !VisitedNodes.Contains(InnerGraph.SetOfNodes[Index]) && InnerGraph.FindEdge(Start, InnerGraph.SetOfNodes[Index]).Weight > 0)
                {
                    FoundPath[Index] = Start;

                    if (DepthFirstSearch(InnerGraph.SetOfNodes[Index], Target, FoundPath))
                    {
                        return(true);
                    }
                }
            }

            return(VisitedNodes.Contains(Target));
        }
 public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
 {
     VisitedNodes.Add(syntaxNode);
 }