示例#1
0
 /**
  * Clears the set of explored states and calls the search implementation of
  * <code>QueSearch</code>
  */
 public override List<Action> search(Problem problem, Queue<Node> frontier)
 {
     // Initialize the explored set to be empty
     explored.Clear();
     frontierStates.Clear();
     return base.search(problem, frontier);
 }
示例#2
0
 /**
  * Clears the set of explored states and calls the search implementation of
  * <code>QueSearch</code>
  */
 public override List<Action> search(Problem problem, Queue<Node> frontier)
 {
     // initialize the explored set to be empty
     explored.Clear();
     // expandedNodes = new List<Node>();
     return base.search(problem, frontier);
 }
        public BidirectionalEightPuzzleProblem(EightPuzzleBoard initialState)
            : base(initialState, EightPuzzleFunctionFactory.getActionsFunction(),
				EightPuzzleFunctionFactory.getResultFunction(),
				new DefaultGoalTest(new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 })))
        {
            reverseProblem = new Problem(new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }),
                EightPuzzleFunctionFactory.getActionsFunction(), EightPuzzleFunctionFactory.getResultFunction(),
                new DefaultGoalTest(initialState));
        }
示例#4
0
 /**
  * Calls the goal test of the problem and - if the goal test is effectively
  * a {@link SolutionChecker} - additionally checks, whether the solution is
  * acceptable. Solution checkers can be used to analyze several or all
  * solutions with only one search run.
  */
 public static bool isGoalState(Problem p, Node n)
 {
     bool isGoal = false;
     GoalTest gt = p.getGoalTest();
     if (gt.isGoalState(n.getState()))
     {
         if (gt is SolutionChecker)
         {
             isGoal = ((SolutionChecker)gt).isAcceptableSolution(
                     getSequenceOfActions(n), n.getState());
         }
         else
         {
             isGoal = true;
         }
     }
     return isGoal;
 }
示例#5
0
        /**
         * Returns the children obtained from expanding the specified node in the
         * specified problem.
         *
         * @param node
         *            the node to expand
         * @param problem
         *            the problem the specified node is within.
         *
         * @return the children obtained from expanding the specified node in the
         *         specified problem.
         */
        public List<Node> expand(Node node, Problem problem)
        {
            List<Node> successors = new List<Node>();

            ActionsFunction actionsFunction = problem.getActionsFunction();
            ResultFunction resultFunction = problem.getResultFunction();
            StepCostFunction stepCostFunction = problem.getStepCostFunction();

            foreach (Action action in actionsFunction.actions(node.getState()))
            {
                System.Object successorState = resultFunction.result(node.getState(), action);

                double stepCost = stepCostFunction.c(node.getState(), action, successorState);
                successors.Add(createNode(successorState, node, action, stepCost));
            }

            foreach (NodeListener listener in nodeListeners)
            {
                listener.onNodeExpanded(node);
            }
            counter++;
            return successors;
        }
示例#6
0
 public SearchAgent(Problem p, Search search)
 {
     actionList = search.search(p);
     actionIterator = actionList.GetEnumerator();
     searchMetrics = search.getMetrics();
 }
 protected abstract List<Action> search(Problem problem);
示例#8
0
 /**
  * Returns a list of actions to the goal if the goal was found, a list
  * containing a single NoOp Action if already at the goal, or an empty list
  * if the goal could not be found. This template method provides a base for
  * tree and graph search implementations. It can be customized by overriding
  * some primitive operations, especially {@link #addToFrontier(Node)},
  * {@link #removeFromFrontier()}, and {@link #isFrontierEmpty()}.
  *
  * @param problem
  *            the search problem
  * @param frontier
  *            the collection of nodes that are waiting to be expanded
  *
  * @return a list of actions to the goal if the goal was found, a list
  *         containing a single NoOp Action if already at the goal, or an
  *         empty list if the goal could not be found.
  */
 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 = nodeExpander.createRootNode(problem.getInitialState());
     if (earlyGoalCheck)
     {
         if(SearchUtils.isGoalState(problem, root))
         {
             return getSolution(root);
         }
     }
     addToFrontier(root);
     while(!(frontier.Count == 0))
     {
         // choose a leaf node and remove it from the frontier
         Node nodeToExpand = removeFromFrontier();
         // Only need to check the nodeToExpand if have not already
         // checked before adding to the frontier
         if (!earlyGoalCheck)
         {
             // if the node contains a goal state then return the
             // corresponding solution
             if(SearchUtils.isGoalState(problem, nodeToExpand))
             {
                 return getSolution(nodeToExpand);
             }
         }
         // expand the chosen node, adding the resulting nodes to the
         // frontier
         foreach(Node successor in nodeExpander.expand(nodeToExpand, problem))
         {
             if (earlyGoalCheck)
             {
                 if(SearchUtils.isGoalState(problem, successor))
                 {
                     return getSolution(successor);
                 }
             }
             addToFrontier(successor)
     ;                }
     }
     // if the frontier is empty then return failure
     return SearchUtils.failure();
 }