private ExtendedNode getCorrespondingNodeFromOtherProblem(ExtendedNode node) { ExtendedNode result = explored.Get(1 - node.getProblemIndex()).Get(node.getState()); // Caution: The goal test of the original problem should always include // the root node of the reverse problem as that node might not yet have // been explored yet. This is important if the reverse problem does not // provide reverse actions for all original problem actions. if (result == null && node.getProblemIndex() == ORG_P_IDX && node.getState().Equals(goalStateNode.getState())) { result = goalStateNode; } return(result); }
/** * Computes a node whose sequence of recursive parents corresponds to a * sequence of actions which leads from the initial state of the original * problem to the state of node1 and then to the initial state of the * reverse problem, following reverse actions to parents of node2. Note that * both nodes must be linked to the same state. Success is not guaranteed if * some actions cannot be reversed. */ private Node <S, A> getSolution(IProblem <S, A> orgP, ExtendedNode node1, ExtendedNode node2) { if (!node1.getState().Equals(node2.getState())) { throw new NotSupportedException("states not equal"); } Node <S, A> orgNode = node1.getProblemIndex() == ORG_P_IDX ? node1 : node2; Node <S, A> revNode = node1.getProblemIndex() == REV_P_IDX ? node1 : node2; while (revNode.getParent() != null) { A action = getReverseAction(orgP, revNode); if (action != null) { S nextState = revNode.getParent().getState(); double stepCosts = orgP.getStepCosts(revNode.getState(), action, nextState); orgNode = nodeExpander.createNode(nextState, orgNode, action, stepCosts); revNode = revNode.getParent(); } else { return(null); } } metrics.set(METRIC_PATH_COST, orgNode.getPathCost()); return(orgNode); }
private void setExplored(Node <S, A> node) { ExtendedNode eNode = (ExtendedNode)node; explored.Get(eNode.getProblemIndex()).Put(eNode.getState(), eNode); }
private bool isExplored(Node <S, A> node) { ExtendedNode eNode = (ExtendedNode)node; return(explored.Get(eNode.getProblemIndex()).ContainsKey(eNode.getState())); }