AIMA.Core.Search.Framework.SearchUtils.actionsFromNodes C# (CSharp) Method

actionsFromNodes() public static method

public static actionsFromNodes ( List nodeList ) : List
nodeList List
return List
        public static List<Action> actionsFromNodes(List<Node> nodeList)
        {
            List<Action> actions = new List<Action>();
            if (nodeList.Count == 1)
            {
                // I'm at the root node, this indicates I started at the
                // Goal node, therefore just return a NoOp
                actions.Add(NoOpAction.NO_OP);
            }
            else
            {
                // ignore the root node this has no action
                // hence index starts from 1 not zero
                for (int i = 1; i < nodeList.Count; i++)
                {
                    Node node = nodeList[i];
                    actions.Add(node.getAction());
                }
            }
            return actions;
        }

Usage Example

Example #1
0
        /**
         *
         * @param problem
         * @param frontier
         * @return if goal found, the list of actions to the Goal. If already at the
         *         goal you will receive a List with a single NoOp Action in it. If
         *         fail to find the Goal, an empty list will be returned to indicate
         *         that the search failed.
         */
        public virtual List <Action> search(Problem problem, Queue <Node> frontier)
        {
            this.frontier = frontier;

            clearInstrumentation();
            // initialize the frontier using the initial state of the problem
            Node root = new Node(problem.getInitialState());

            if (isCheckGoalBeforeAddingToFrontier())
            {
                if (SearchUtils.isGoalState(problem, root))
                {
                    return(SearchUtils.actionsFromNodes(root.getPathFromRoot()));
                }
            }
            frontier.Enqueue(root);
            setQueueSize(frontier.Count);
            while (!(frontier.Count == 0))
            {
                // choose a leaf node and remove it from the frontier
                Node nodeToExpand = popNodeFromFrontier();
                setQueueSize(frontier.Count);
                // Only need to check the nodeToExpand if have not already
                // checked before adding to the frontier
                if (!isCheckGoalBeforeAddingToFrontier())
                {
                    // if the node contains a goal state then return the
                    // corresponding solution
                    if (SearchUtils.isGoalState(problem, nodeToExpand))
                    {
                        setPathCost(nodeToExpand.getPathCost());
                        return(SearchUtils.actionsFromNodes(nodeToExpand
                                                            .getPathFromRoot()));
                    }
                }
                // expand the chosen node, adding the resulting nodes to the
                // frontier
                foreach (Node fn in getResultingNodesToAddToFrontier(nodeToExpand,
                                                                     problem))
                {
                    if (isCheckGoalBeforeAddingToFrontier())
                    {
                        if (SearchUtils.isGoalState(problem, fn))
                        {
                            setPathCost(fn.getPathCost());
                            return(SearchUtils.actionsFromNodes(fn
                                                                .getPathFromRoot()));
                        }
                    }
                    frontier.Enqueue(fn);
                }
                setQueueSize(frontier.Count);
            }
            // if the frontier is empty then return failure
            return(failure());
        }
All Usage Examples Of AIMA.Core.Search.Framework.SearchUtils::actionsFromNodes