private void SetStartingPoint()
        {
            Point startPoint = Graph.Points.First(); // We can set any point as starting point. I choosed first one.

            VisitedNodes.Add(startPoint);
            UnvisitedNodes.Remove(startPoint);
        }
Exemple #2
0
 public void AllowsEarlyExitWhileVisiting()
 {
     var ast = Parser.Parse("{ a, b { x }, c }", new ParseOptions
     {
         NoLocation = true,
     });
     var visitor = new VisitedNodes(node =>
     {
         if (node is Name && (node as Name).Value == "x")
         {
             throw new Visitor<INode>.BreakException();
         }
         return node;
     });
     visitor.VisitWithBreak(ast);
     visitor.Visited.ShouldBeEquivalentTo(ImmutableArray.Create(
         Tuple.Create(true, NodeType.Document, (object)null),
         Tuple.Create(true, NodeType.OperationDefinition, (object)null),
         Tuple.Create(true, NodeType.SelectionSet, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"a"),
         Tuple.Create(false, NodeType.Name, (object)"a"),
         Tuple.Create(false, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"b"),
         Tuple.Create(false, NodeType.Name, (object)"b"),
         Tuple.Create(true, NodeType.SelectionSet, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"x")
     ));
 }
        public bool FindTheShortestPathes(Node Start)
        {
            ShortestPathes[Start.Index].Weight = 0;

            for (int FirstIndex = 0; FirstIndex < InnerGraph.NumberOfNodes - 1; FirstIndex++)
            {
                Node CurrentNode = new Node {
                    Weight = Infinity
                };

                for (int SecondIndex = 0; SecondIndex < InnerGraph.NumberOfNodes; SecondIndex++)
                {
                    if (!VisitedNodes.Contains(ShortestPathes[SecondIndex]) && ShortestPathes[SecondIndex].Weight <= CurrentNode.Weight)
                    {
                        CurrentNode = ShortestPathes[SecondIndex];

                        Index = ShortestPathes[SecondIndex].Index;
                    }
                }

                VisitedNodes.Add(ShortestPathes[Index]);

                for (int SecondIndex = 0; SecondIndex < InnerGraph.NumberOfNodes; SecondIndex++)
                {
                    if (!VisitedNodes.Contains(ShortestPathes[SecondIndex]) && InnerGraph.SetOfNodes[Index][SecondIndex] != null && !ShortestPathes[Index].Weight.Equals(Infinity) && ShortestPathes[SecondIndex].Weight > ShortestPathes[Index].Weight + InnerGraph.FindEdge(InnerGraph.SetOfNodes[Index], InnerGraph.SetOfNodes[SecondIndex]).Weight)
                    {
                        ShortestPathes[SecondIndex].Weight = ShortestPathes[Index].Weight + InnerGraph.FindEdge(InnerGraph.SetOfNodes[Index], InnerGraph.SetOfNodes[SecondIndex]).Weight;
                    }
                }
            }

            return(InnerGraph.NegativeCycleChecker(ShortestPathes));
        }
        private void FindCircuitDfs(Node currentNode)
        {
            if (Done)
            {
                return;
            }

            if (currentNode == StartNode && VisitedEdges.Count > 0)
            {
                Done = true;
                return;
            }
            List <Edge> adjEdges = Graph.GetEdges(currentNode);

            adjEdges = adjEdges.Where(e => VisitedEdges.All(ve => ve != e) && VisitedNodes.All(vn => vn != e.OtherNode(currentNode))).ToList();
            foreach (Edge adjEdge in adjEdges)
            {
                VisitedEdges.Add(adjEdge);
                Node otherNode = adjEdge.OtherNode(currentNode);
                VisitedNodes.Add(otherNode);
                FindCircuitDfs(otherNode);
                if (Done)
                {
                    return;
                }
                VisitedNodes.Remove(otherNode);
                VisitedEdges.Remove(adjEdge);
            }
        }
        public bool BreadthFirstSearch(Node Start)
        {
            Queue.Enqueue(Start);

            VisitedNodes.Add(Start);

            for (; Queue.Count > 0;)
            {
                Start = Queue.Dequeue();

                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]));

                        Queue.Enqueue(InnerGraph.SetOfNodes[Index]);

                        VisitedNodes.Add(InnerGraph.SetOfNodes[Index]);
                    }
                }
            }

            return(VisitedNodes.Count.Equals(InnerGraph.NumberOfNodes));
        }
Exemple #6
0
        public void Move()
        {
            if (CompletedMoving)
            {
                return;
            }

            double prev   = 0;
            double random = new Random().NextDouble();

            foreach (var item in Choices.Where(z => !VisitedNodes.Contains(z.Item2)).OrderByDescending(z => z.Item1))
            {
                if (random > prev && random < item.Item1 + prev)
                {
                    var transition = item.Item2.Neighbours.GetValueOrDefault(CurrentNode);
                    LeavePheromone(transition);
                    VisitedNodes.Add(CurrentNode);

                    WayPassed  += transition.Value;
                    CurrentNode = item.Item2;   //.Neighbours.Where(z => z.Value == transition && z.Key != CurrentNode).First().Key;
                    RecalculateChoices();
                    return;
                }
                prev += item.Item1;
            }
            VisitedNodes.Add(CurrentNode);
            CompletedMoving = true;
        }
Exemple #7
0
        ///
        /// bfs var 2
        /// searching path to target node from some start node
        ///
        /// <param name="Start"> - first node
        /// <param name="Target"> - our scope
        /// <param name="Path"> - for our scope
        /// <returns></returns>
        public bool BreadthFirstSearch(Node Start, Node Target, Node[] Path)
        {
            Queue.Enqueue(Start);

            VisitedNodes.Add(Start);

            Path[Start.Index] = Start;

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

            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]) && InnerGraph.FindEdge(Start, InnerGraph.SetOfNodes[Index]).Weight > 0)
                    {
                        Path[Index] = Start;

                        Queue.Enqueue(InnerGraph.SetOfNodes[Index]);

                        VisitedNodes.Add(InnerGraph.SetOfNodes[Index]);
                    }
                }
            }

            return(VisitedNodes.Contains(Target));
        }
Exemple #8
0
        public void AllowsSkippingASubTree()
        {
            var ast = Parser.Parse("{ a, b { x }, c }", new ParseOptions
            {
                NoLocation = true,
            });
            var visitor = new VisitedNodes(node => (node is Field && (node as Field).Name.Value == "b") ? null : node);

            visitor.Visit(ast);
            visitor.Visited.ShouldBeEquivalentTo(ImmutableArray.Create(
                                                     Tuple.Create(true, NodeType.Document, (object)null),
                                                     Tuple.Create(true, NodeType.OperationDefinition, (object)null),
                                                     Tuple.Create(true, NodeType.SelectionSet, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"a"),
                                                     Tuple.Create(false, NodeType.Name, (object)"a"),
                                                     Tuple.Create(false, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"c"),
                                                     Tuple.Create(false, NodeType.Name, (object)"c"),
                                                     Tuple.Create(false, NodeType.Field, (object)null),
                                                     Tuple.Create(false, NodeType.SelectionSet, (object)null),
                                                     Tuple.Create(false, NodeType.OperationDefinition, (object)null),
                                                     Tuple.Create(false, NodeType.Document, (object)null)
                                                     ));
        }
Exemple #9
0
        public void AllowsEarlyExitWhileVisiting()
        {
            var ast = Parser.Parse("{ a, b { x }, c }", new ParseOptions
            {
                NoLocation = true,
            });
            var visitor = new VisitedNodes(node =>
            {
                if (node is Name && (node as Name).Value == "x")
                {
                    throw new Visitor <INode> .BreakException();
                }
                return(node);
            });

            visitor.VisitWithBreak(ast);
            visitor.Visited.ShouldBeEquivalentTo(ImmutableArray.Create(
                                                     Tuple.Create(true, NodeType.Document, (object)null),
                                                     Tuple.Create(true, NodeType.OperationDefinition, (object)null),
                                                     Tuple.Create(true, NodeType.SelectionSet, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"a"),
                                                     Tuple.Create(false, NodeType.Name, (object)"a"),
                                                     Tuple.Create(false, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"b"),
                                                     Tuple.Create(false, NodeType.Name, (object)"b"),
                                                     Tuple.Create(true, NodeType.SelectionSet, (object)null),
                                                     Tuple.Create(true, NodeType.Field, (object)null),
                                                     Tuple.Create(true, NodeType.Name, (object)"x")
                                                     ));
        }
        public double Run()
        {
            Point toPoint, fromPoint;

            SetStartingPoint();

            for (int i = 0; i < Graph.Dimensions; i++)
            {
                fromPoint = GetCurrentNode();

                if (UnvisitedNodes.Count > 0)   // if we have nodes to visit;
                {
                    toPoint = ChooseNextPoint(fromPoint);
                    VisitedNodes.Add(toPoint);
                    UnvisitedNodes.Remove(toPoint);
                }
                else
                {
                    toPoint = VisitedNodes[0]; // if visited every node, just go back to start
                }

                Edge edge = Graph.GetEdge(fromPoint.Id, toPoint.Id);
                Path.Add(edge);
                TourDistance += edge.Length;
            }

            return(Math.Round(TourDistance));
        }
Exemple #11
0
        public bool DijkstraSWSAlgorithm(Node Start)
        {
            ShortestPath[Start.Index].Weight = 0;

            for (int FirstIndex = 0; FirstIndex < InnerGraph.QuantityOfNodes - 1; FirstIndex++)
            {
                Node CurrentNode = new Node {
                    Weight = double.PositiveInfinity
                };
                for (int SecondIndex = 0; SecondIndex < InnerGraph.QuantityOfNodes; SecondIndex++)
                {
                    if (!VisitedNodes.Contains(ShortestPath[SecondIndex]) && ShortestPath[SecondIndex].Weight <= CurrentNode.Weight)
                    {
                        CurrentNode = ShortestPath[SecondIndex];
                        Index       = ShortestPath[SecondIndex].Index;
                    }
                }
                VisitedNodes.Add(ShortestPath[Index]);
                for (int SecondIndex = 0; SecondIndex < InnerGraph.QuantityOfNodes; SecondIndex++)
                {
                    if (!VisitedNodes.Contains(ShortestPath[SecondIndex]) && InnerGraph.SetOfNodes[Index][SecondIndex] != null &&
                        !ShortestPath[Index].Weight.Equals(double.PositiveInfinity) &&
                        ShortestPath[SecondIndex].Weight >
                        ShortestPath[Index].Weight + InnerGraph.FindEdge(InnerGraph.SetOfNodes[Index], InnerGraph.SetOfNodes[SecondIndex]).Weight)

                    {
                        ShortestPath[SecondIndex].Weight = ShortestPath[Index].Weight + InnerGraph.FindEdge(InnerGraph.SetOfNodes[Index], InnerGraph.SetOfNodes[SecondIndex]).Weight;
                    }
                }
            }

            return(InnerGraph.NegativeCycleChecker(ShortestPath));
        }
Exemple #12
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();
 }
 public void OnVisitSyntaxNode(T syntaxNode)
 {
     VisitedNodes.Add(syntaxNode);
     if (_callback is object)
     {
         _callback(syntaxNode);
     }
 }
Exemple #14
0
 public void visitNode(uint u)
 {
     if (CurrentNode != null)
     {
         VisitedNodes.Add(CurrentNode);
     }
     CurrentNode = Convert.ToInt32(u);
     NotifyStateChanged();
 }
Exemple #15
0
 private void CreateMoreAgents()
 {
     foreach (var connectedNode in CurrentNode.Connections)
     {
         if (!VisitedNodes.Contains(connectedNode))
         {
             CreateAgent(connectedNode);
         }
     }
 }
Exemple #16
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);
            }
        }
Exemple #17
0
 public void clear()
 {
     StartNode   = -1;
     EndNode     = -1;
     path        = new int[] { };
     mouseDown   = false;
     CurrentNode = -1;
     BlockedNodes.Clear();
     VisitedNodes.Clear();
     NotifyStateChanged();
 }
 void MarkNodeAsVisisted(Node node)
 {
     if (!VisitedNodes.Contains(node))
     {
         VisitedNodes.Enqueue(node);
     }
     if (UnvisitedNodes.Contains(node))
     {
         UnvisitedNodes.Remove(node);
     }
 }
Exemple #19
0
        private void PushNeighborsToStack()
        {
            IEnumerable <T> neighborList = _graph[Current];

            foreach (T neighbor in neighborList)
            {
                if (!VisitedNodes.Contains(neighbor))
                {
                    _pendingSearches.Push(new SearchData(neighbor, _currentSearchData.Level + 1));
                }
            }
        }
        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);
        }
Exemple #21
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);
        }
Exemple #22
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();
        }
Exemple #23
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));
        }
Exemple #25
0
            protected override bool Skip(Node node)
            {
                if (base.Skip(node))
                {
                    return(true);
                }

                var dependencyNode = _dependenciesGraph.AllNodes[node.Id];

                foreach (var parent in dependencyNode.Parents)
                {
                    if (!VisitedNodes.Contains(parent.Id))
                    {
                        return(true);
                    }
                }
                return(false);
            }
Exemple #26
0
        internal static Queue <DungeonNode> GetWeightedNearestMinimapVisitedRoute()
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();
            Vector3 myPosition = ZetaDia.Me.Position;

            Queue <DungeonNode>        route         = new Queue <DungeonNode>();
            List <WeightedDungeonNode> weightedNodes = new List <WeightedDungeonNode>();

            // We want to give a high weight to nodes which have Explored nodes near it
            // A maximum weight will be given to an unexplored node with 4 directly connected explored (facing) nodes, and 4 corner-connected nodes
            // This is theoretically possible if we are standing IN this maximum-weighted unexplored node
            // Typically a node will have 1 or more directly connected nodes and 0 or more corner-connected nodes

            foreach (var unWeightedNode in UnVisitedNodes)
            {
                var weightedNode = new WeightedDungeonNode(unWeightedNode.WorldTopLeft, unWeightedNode.WorldBottomRight)
                {
                    Weight = 0
                };

                // Number of visited nodes connected to this unvisited node will give higher weight
                int numNodesConnected = VisitedNodes.Count(node => node.GridCenter.DistanceSqr(weightedNode.GridCenter) <= (MaxCornerDistance * MaxCornerDistance));
                weightedNode.Weight = numNodesConnected / MaxConnectedNodes;
                weightedNodes.Add(weightedNode);
            }

            foreach (var node in weightedNodes.OrderByDescending(n => (1 / n.NavigableCenter.Distance(myPosition)) * n.Weight))
            {
                if (SetNodesExploredAutomatically && ZetaDia.Minimap.IsExplored(node.NavigableCenter, ZetaDia.CurrentWorldDynamicId))
                {
                    continue;
                }

                route.Enqueue(node);
            }

            Logger.Log("Generated new Weighted Nearest Minimap Visited Route with {0} nodes in {1}ms", route.Count, timer.ElapsedMilliseconds);
            return(route);
        }
Exemple #27
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, 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 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));
        }
Exemple #31
0
        public void GreedySearch(string destinationName)
        {
            /// Şuan bulunduğumuz nodu ağacın kök noduna eşitle (başlangıç noktası)
            Node currentNode = Root;
            /// Hedef noktasına giden yolu tutacak stack
            var destinationPath = new Stack <Node>();
            /// Bütün gezilen yolları tutacak stack
            var fullPath = new Stack <Node>();

            for (;;)
            {
                /// Şuanki bulunduğumuz nodu yola ekle
                destinationPath.Push(currentNode);
                parent_return :;
                /// Şuanki bulunduğumuz nodu gezilen nodlar stackına ekle
                fullPath.Push(currentNode);
                currentNode.Visited = true;

                Trace.WriteLine("node : {0}", currentNode.Name);

                /// Hedef noda varıldı mı?
                if (currentNode.Name.CompareTo(destinationName) == 0)
                {
                    Trace.WriteLine("Destination found");

                    break;
                }
                /// Şuan bulunduğumuz nodun alt nodları arasından seçilen nod
                Node selectedNode = null;
                /// Bütün alt nodlar için
                foreach (Node n in currentNode.Nodes)
                {
                    /// Eğer alt nodun altında kalan nodlar gezildiyse
                    if (n.VisitedAllNodes)
                    {
                        continue;
                    }
                    /// Seçilen nod boşsa, şuankine eşitle
                    if (selectedNode == null)
                    {
                        selectedNode = n;
                    }
                    else
                    {
                        /// Değilse, heuristic değerlerini karşılaştır ve küçük olanı seç
                        if (selectedNode.HeruisticValue > n.HeruisticValue)
                        {
                            selectedNode = n;
                        }
                    }
                }
                /// Eğer herhangi bir nod seçilmediyse
                if (selectedNode == null)
                {
                    /// Şuanki bulunduğumuz nodun bütün nodlarını gezildi olarak işaretle
                    currentNode.VisitedAllNodes = true;
                    /// Bir üst noda dön
                    currentNode = currentNode.Parent;
                    destinationPath.Pop();
                    goto parent_return;
                }
                else
                {
                    currentNode = selectedNode;
                    continue;
                }
            } /// (break) döngünün bitişi

            /// Sonucu değişkenlere aktar
            ///
            while (fullPath.Count > 0)
            {
                VisitedNodes += "," + fullPath.Pop().Name;
            }

            char[] chars = VisitedNodes.ToCharArray();
            Array.Reverse(chars);
            VisitedNodes = new string(chars);


            int totalpathcost = 0;

            while (destinationPath.Count > 0)
            {
                var point = destinationPath.Pop();
                Path          += "," + point.Name;
                totalpathcost += point.PathCost;
            }

            TotalPathCost = totalpathcost;

            Trace.WriteLine("{0}", totalpathcost.ToString());

            char[] charss = Path.ToCharArray();
            Array.Reverse(charss);
            Path = new string(charss);
        }
Exemple #32
0
 public void AllowsSkippingASubTree()
 {
     var ast = Parser.Parse("{ a, b { x }, c }", new ParseOptions
     {
         NoLocation = true,
     });
     var visitor = new VisitedNodes(node => (node is Field && (node as Field).Name.Value == "b") ? null : node);
     visitor.Visit(ast);
     visitor.Visited.ShouldBeEquivalentTo(ImmutableArray.Create(
         Tuple.Create(true, NodeType.Document, (object)null),
         Tuple.Create(true, NodeType.OperationDefinition, (object)null),
         Tuple.Create(true, NodeType.SelectionSet, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"a"),
         Tuple.Create(false, NodeType.Name, (object)"a"),
         Tuple.Create(false, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Field, (object)null),
         Tuple.Create(true, NodeType.Name, (object)"c"),
         Tuple.Create(false, NodeType.Name, (object)"c"),
         Tuple.Create(false, NodeType.Field, (object)null),
         Tuple.Create(false, NodeType.SelectionSet, (object)null),
         Tuple.Create(false, NodeType.OperationDefinition, (object)null),
         Tuple.Create(false, NodeType.Document, (object)null)
     ));
 }