e.printStackTrace();
}
}
//Then Create the planning graph with an empty initial state
PlanningGraph graph = new PlanningGraph(new PropositionLevel());
//And populate it with action levels and proposition levels containing the obvious
//preconditions from the subsequent action level
for (int i = 0; i < concreteOperators.length; i++) {
//We always assume our graph has a proposition level as its last level
PropositionLevel propositionLevel = (PropositionLevel) graph.getGraphLevel(graph.size()-1);
//into which we add the preconditions for this action
propositionLevel.addPropositions(concreteOperators[i].getPreconds());
//We then create an action level to contain this action
ActionLevel actionLevel = new ActionLevel();
actionLevel.addAction(concreteOperators[i]);
graph.addGraphLevel(actionLevel);
//And create another proposition level for its effects
PropositionLevel propositionLevel2 = new PropositionLevel();
propositionLevel2.addPropositions(concreteOperators[i].getEffects());
graph.addGraphLevel(propositionLevel2);
}
//Then walk the graph backwards propagating the preconditions that were not generated
//by the previous action level using noops
for(int i = graph.size()-1; i > 0; i=i-2) {
//We need to get the proposition levels surrounding our action level
//As in: precond <- action <- effect
PropositionLevel effectLevel = (PropositionLevel) graph.getGraphLevel(i);
PropositionLevel precondLevel = (PropositionLevel) graph.getGraphLevel(i-2);
ActionLevel actionLevel = (ActionLevel) graph.getGraphLevel(i-1);
//Then see if each proposition in the effectLevel is connected by some action
//to the precondLevel
for (Iterator<Proposition> iter = effectLevel.getPropositions(); iter.hasNext();) {
Proposition proposition = iter.next();
//If no action is connected to the effect level
if(actionLevel.getGeneratingActions(proposition).size() == 0) {
//We need to propagate this action to the previous level
actionLevel.addNoop(proposition);
precondLevel.addProposition(proposition);
}
}
}
//this last bit looks rather nasty, I should review this when time allows
PropositionLevel level = (PropositionLevel) graph.getGraphLevel(0);
List<Proposition> planPreconditions = new ArrayList<Proposition>(level.size());
for (Iterator<Proposition> iter = level.getPropositions(); iter.hasNext();) {
planPreconditions.add(iter.next());
}