* (non-Javadoc)
* @see graphplan.graph.algorithm.ActionLevelGenerator#createNextActionLevel(graphplan.graph.PropositionLevel)
*/
@Override
public ActionLevel createNextActionLevel(PropositionLevel propositionLevel) throws PlanningGraphException {
final ActionLevel actionLevel = new ActionLevel();
final OperatorFactory opFactory = OperatorFactory.getInstance();
final HashSet<Operator> opTemplateSet = new HashSet<Operator>();
final Set<Operator> opSet = new HashSet<Operator>();
final ArrayList<Proposition> preconds = new ArrayList<Proposition>();
//TODO Change this to scan by operator rather than by proposition
// For every proposition
for (Proposition proposition : propositionLevel) {
final List<Operator> templates;
//Gather potential operator templates
templates = opFactory.getRequiringOperatorTemplates(proposition);
opTemplateSet.addAll(templates);
//Add all noops
opSet.add(opFactory.getNoop(proposition));
//And prepare the list of preconditons for later
preconds.add(proposition);
}
// XXX Why the hell do we use a null parameter here?
opTemplateSet.addAll(opFactory.getRequiringOperatorTemplates(null));
/*for (Proposition proposition : propositionLevel) {
preconds.add(proposition);
}*/
//Piece of crap algorithm used before has been replaced by this call
try {
opSet.addAll(opFactory.getAllPossibleInstantiations(new ArrayList<Operator>(opTemplateSet), preconds));
} catch (OperatorFactoryException e) {
throw new PlanningGraphException(e.getMessage(),propositionLevel.getIndex()+1);
}
for (Operator operator : opSet) {
actionLevel.addAction(operator);
}
// TODO discover how to properly instantiate operator templates
// TODO optimize this algorithm
return actionLevel;