Ejemplo n.º 1
0
 /**
  * Inserts the node at the tail of the frontier if the corresponding state
  * is not already a frontier state and was not yet explored.
  */
 protected override void addToFrontier(Node node)
 {
     if (!explored.Contains(node.getState()) && !frontierStates.Contains(node.getState()))
     {
     frontier.Enqueue(node);
     frontierStates.Add(node.getState());
     updateMetrics(frontier.Count);
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 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;
        }