Пример #1
0
        public static Node <State> TreeSearchWithQueue <State> (IProblem <State> problem, IFringe <Node <State> > fringe, bool enableAStarMethod = false)
        {
            if (enableAStarMethod)
            {
                fringe.GetCost = (Node <State> node) => { return(problem.EstimatedCostToGoal(node.state) + problem.GetCurrentCost(node.state, node.node.state, node.CurrentCost)); };
            }
            else
            {
                fringe.GetCost = (Node <State> node) => { return(problem.EstimatedCostToGoal(node.state)); };
            }

            fringe.Add(new Node <State>(problem.InitialState, null));

            int a = 1;

            while (!fringe.IsEmpty)
            {
                Node <State> node = fringe.Pop();

                if (problem.IsGoal(node.state))
                {
                    return(node);
                }

                foreach (State state in problem.Expand(node.state))
                {
                    if (!node.OnPathToRoot(state, problem.StateCompare))
                    {
                        fringe.Add(new Node <State>(state, node, problem.GetCurrentCost(state, node.state, node.CurrentCost)));
                        if (rownyRzad(a))
                        {
                            problem.Print(state);
                        }
                        a++;
                    }
                }
            }
            return(null);
        }