Example #1
0
        public bool NextIteration()
        {
            // Search ended.
            if (stack.Count == 0)
            {
                if (limitReached && results.Count == 0)
                {
                    limitReached = false;
                    currentMaxDepth++;
                    this.stack.Push(new SearchData(parent, 0, 0, graph.NextNodes(parent)));
                }
                else
                {
                    status = SearchStatus.Complete;
                    return(true);
                }
            }

            SearchData data = stack.Pop();

            uint next = data.NextNode();

            // We check if limit was reached.
            if (data.Depth + 1 >= currentMaxDepth)
            {
                // We discard such nodes.
                limitReached = true;
                return(false);
            }

            if (next == uint.MaxValue)
            {
                // No more nodes to process, go up.
                if (stack.Count == 0)
                {
                    return(false);
                }
                data = stack.Pop();
            }
            else
            {
                // We process next node.
                if (isGoal(next))
                {
                    // We create the result.
                    uint[] resultData = new uint[stack.Count + 2];
                    resultData[0] = parent;

                    // Copy the path.
                    SearchData[] d = stack.ToArray();
                    for (int i = 0; i < stack.Count; i++)
                    {
                        int wIndex = stack.Count - i - 1;
                        resultData[i + 1] = d[wIndex].SubNodes[d[wIndex].Index - 1];
                    }

                    // The last (goal) node.
                    resultData[stack.Count + 1] = next;

                    // We have found the goal, do not proceed.
                    SearchResult result = new SearchResult(resultData);
                    results.Add(result);
                    status = SearchStatus.RunningWithSolution;
                    return(false);
                }
                else
                {
                    // We add our node.
                    stack.Push(data);
                    data = new SearchData(next, 0, data.Depth + 1, graph.NextNodes(next));
                }
            }



            // We need to pus current node.
            stack.Push(data);
            return(false);
        }
Example #2
0
        public bool NextIteration()
        {
            // Search ended (early deformed graphs).
            if (stack.Count == 0)
            {
                status = SearchStatus.Complete;
                return(true);
            }

            SearchData data = stack.Pop();

            uint next = data.NextNode();

            if (next == uint.MaxValue)
            {
                // No more nodes to process, go up.
                if (stack.Count == 0)
                {
                    status = SearchStatus.Complete;
                    return(true);
                }
                data = stack.Pop();
            }
            else
            {
                // We process next node.
                if (isGoal(next))
                {
                    // We create the result.
                    uint[] resultData = new uint[stack.Count + 2];
                    resultData[0] = parent;

                    // Copy the path.
                    SearchData[] d = stack.ToArray();
                    for (int i = 0; i < stack.Count; i++)
                    {
                        int wIndex = stack.Count - i - 1;
                        resultData[i + 1] = d[wIndex].SubNodes[d[wIndex].Index - 1];
                    }

                    // The last (goal) node.
                    resultData[stack.Count + 1] = next;

                    // We have found the goal, do not proceed.
                    SearchResult result = new SearchResult(resultData);
                    results.Add(result);
                    status = SearchStatus.RunningWithSolution;
                    return(false);
                }
                else
                {
                    // We add our node.
                    stack.Push(data);
                    data = new SearchData(next, 0, graph.NextNodes(next));
                }
            }



            // We need to pus current node.
            stack.Push(data);
            return(false);
        }