public IEnumerable <TNode> Search(TNode initialNode) { SearchInit(); var closedNodes = new HashSet <TState>(); var fringeStack = new Stack <TNode>(); fringeStack.Push(initialNode); while (fringeStack.Any()) { var currentNode = fringeStack.Pop(); if (Mode == SearchMode.GraphSearch) { if (closedNodes.Contains(currentNode.State)) { continue; } else { closedNodes.Add(currentNode.State); } } UpdateMaxDepth(currentNode); if (currentNode.IsGoalState()) { yield return(currentNode); } else { if (ExpandNodeDepthTest(currentNode)) { ExpandedNodesStat++; foreach (var successorNode in Expander.ExpandNode(currentNode)) { fringeStack.Push(successorNode); } } } } }
public IEnumerable <Node <State> > Search(Node <State> initialNode) { var closedNodes = new HashSet <State>(); var fringesQueue = new Queue <IEnumerable <Node <State> > >(); fringesQueue.Enqueue(new[] { initialNode }); while (fringesQueue.Any()) { var currentFringe = fringesQueue.Dequeue(); foreach (var currentNode in currentFringe) { if (Mode == SearchMode.GraphSearch) { if (closedNodes.Contains(currentNode.State)) { continue; } else { closedNodes.Add(currentNode.State); } } MaxDepthStat = Math.Max(MaxDepthStat, currentNode.Depth); if (currentNode.IsGoalState()) { yield return(currentNode); } else { fringesQueue.Enqueue(Expander.ExpandNode(currentNode)); ExpandedNodesStat++; } } } }
public IEnumerable <AStarNode <State> > Search(AStarNode <State> initialNode) { var closedNodes = new HashSet <State>(); var fringesPriorityQueue = new Heap <AStarNode <State> >(new[] { initialNode }); while (fringesPriorityQueue.Any()) { var currentNode = fringesPriorityQueue.ExtractMin(); if (Mode == SearchMode.GraphSearch) { if (closedNodes.Contains(currentNode.State)) { continue; } else { closedNodes.Add(currentNode.State); } } MaxDepthStat = Math.Max(MaxDepthStat, currentNode.Depth); if (currentNode.IsGoalState()) { yield return(currentNode); } else { foreach (var node in Expander.ExpandNode(currentNode)) { fringesPriorityQueue.Add(node); ExpandedNodesStat++; } } } }