public List <Node> expandNode(Node node, Problem problem) { List <Node> childNodes = 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); childNodes.Add(new Node(successorState, node, action, stepCost)); } metrics.set(METRIC_NODES_EXPANDED, metrics .getInt(METRIC_NODES_EXPANDED) + 1); return(childNodes); }
/** * 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.State)) { System.Object successorState = resultFunction.result(node.State, action); double stepCost = stepCostFunction.c(node.State, action, successorState); successors.Add(createNode(successorState, node, action, stepCost)); } foreach (NodeListener listener in nodeListeners) { listener.onNodeExpanded(node); } counter++; return(successors); }