Package graphplan.graph

Examples of graphplan.graph.ActionLevel


    PropositionLevel lastLevel = (PropositionLevel) getLastGraphLevelCwa();
    //First we create a new action level from the last proposition level
   
    PropositionLevel initialState = (PropositionLevel) this.getGraphLevel(0);
    int initialStateSize = initialState.size();
    ActionLevel actionLevel = this.actionLevelGeneratorCwa.createNextActionLevel(lastLevel, initialState);
   
    if(initialStateSize != initialState.size()) {
      logger.info("-> Initial State was changed: Maintenance Actions and Mutexes from Level 0 until current Level");
      this.graphLevels = new ArrayList<GraphLevel>();
      this.graphLevels.add(initialState);
View Full Code Here


      //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);
        }
      }
    }
   
View Full Code Here

   * (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;
View Full Code Here

  public LevelGeneratorClosedWorldAssumptionImpl(){}
 
  @SuppressWarnings("rawtypes")
  @Override
  public ActionLevel createNextActionLevel(PropositionLevel propositionLevel, GraphLevel initialState) 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>();
   
    // 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);
    }
   
    opTemplateSet.addAll(opFactory.getRequiringOperatorTemplates(null));

    try {
      if(this.isUsingTypes())  {
        opFactory.setTypes(this.getTypes());
        opFactory.setParameterTypes(this.getParameterTypes());
        opSet.addAll(opFactory.getAllPossibleInstantiations(new ArrayList<Operator>(opTemplateSet), preconds, initialState));
      } else 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);
    }
   
    return actionLevel;
  }
View Full Code Here

    //We have found a plan
    if(propositionLevel.getPrevLevel() == null) {
      return true;
    }
   
    ActionLevel actionLevel = (ActionLevel) propositionLevel.getPrevLevel();
    //If we have collected supporting actions for all subgoals
    //We can proceed the iteration into the graph using the actions
    //recently selected
    if(subGoals.isEmpty()) {
      //If the goals chosen for this level are not minimal, force failure
      if(!isMinimalActionSet(supportActionStack.peek(), subGoalStack.peek())) {
        return false;
      }
     
      //Otherwise, push the dependencies for this subgoal into the
      //stack of subgoals
      this.subGoalStack.push(determineSubgoals(supportActionStack.peek()));
     
      logger.fine("At level "+(propositionLevel.getIndex()-1)+", creeping with operators: "+this.supportActionStack.peek());
     
      //And creep into the graph
      boolean planFound = propositionLevel.getPrevLevel().accept(this);
     
      //If we have not found a plan, unstack the partial data from
      //this attempt.
      if(!planFound) {
        this.subGoalStack.pop();
      }
     
      return planFound;
    } else {
      final Proposition proposition = subGoals.iterator().next();
      subGoals.remove(proposition);
      //Get the actions that generate this proposition to search for a solution
      List<Operator> requiringActions = actionLevel.getGeneratingActions(proposition);
      for(Operator operator: requiringActions) {
        //Check if the operator has not already been selected
        boolean addOper = !supportActionStack.peek().contains(operator);
        if(addOper) {
          //If the selected operator is not already in the plan
          //Check it against other operators in this step of the plan
          boolean isMutex = false;
          for(Operator operator2 : supportActionStack.peek()) {
            //If this support action
            if(actionLevel.isMutex(operator, operator2)) {
              isMutex = true;
              break;
            }
          }
          //If this particular operator was mutex with the ones in the
View Full Code Here

   
    operatorFactory.addOperatorTemplate(operTemplate);
   
    planningGraph = new PlanningGraph(initialState);
   
    ActionLevel actionLevel = new ActionLevel();
    Operator operator = null;
    try {
      operator = OperatorFactory.getInstance().getOperator(
          "move(a,b)");
    } catch (Exception e) {
      fail(e.toString());
    }
    actionLevel.addAction(operator);
    planningGraph.addGraphLevel(actionLevel);
  }
View Full Code Here

   */
  public void expandGraph() throws PlanningGraphException {
    if (getLastGraphLevel().isPropositionLevel()) {
      PropositionLevel lastLevel = (PropositionLevel) getLastGraphLevel();
      //First we create a new action level from the last proposition level
      ActionLevel actionLevel = actionLevelGenerator.createNextActionLevel(lastLevel);
      this.addGraphLevel(actionLevel);
      this.setIndexForOperators(actionLevel);
      //Then we add the action mutexes for these actions
      this.mutexGenerator.addActionMutexes(lastLevel, actionLevel);
      //And then add the subsequent proposition level
View Full Code Here

   
    if(this.memoizationTable.isNoGood(subGoals, propositionLevel.getIndex())) {
      return false;
    }
   
    final ActionLevel actionLevel = (ActionLevel) propositionLevel.getPrevLevel();
   
    ArrayList<Proposition> subGoalsSorted = new ArrayList<Proposition>(subGoals);
   
    /* Heuristic: sort goals by proposition that appears earliest in the planning graph */
    if(Graphplan.sortGoals){
      Collections.sort(subGoalsSorted, new Comparator<Proposition>() {
        public int compare(Proposition o1, Proposition o2) {
          return (o1.getIndex() > o2.getIndex() ? -1: (o1.getIndex() == o2.getIndex() ? 0 : 1));
        }
      });
    }

    /* Heuristic: select firstly propositions that leads to the smallest set of resolvers */
    if(Graphplan.propositionsSmallest){
      Collections.sort(subGoalsSorted, new Comparator<Proposition>() {
        public int compare(Proposition o1, Proposition o2) {
          int o1Size = actionLevel.getGeneratingActions(o1).size();
          int o2Size = actionLevel.getGeneratingActions(o2).size();
          return (o1Size < o2Size ? -1: (o1Size == o2Size ? 0 : 1));
        }
      });
    }
   
View Full Code Here

TOP

Related Classes of graphplan.graph.ActionLevel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.