Package graphplan.domain.jason

Examples of graphplan.domain.jason.OperatorImpl


        Exp precontidion = (Exp) ((Action)actionDef).getPrecondition();
        Exp effect = (Exp) ((Action)actionDef).getEffect();
       
        List<String> parameterTypes = new ArrayList<String>();
       
        OperatorImpl operatorImpl = new OperatorImpl(actionDef.getName());
        List<Term> termsOp = new ArrayList<Term>();
        for(pddl4j.exp.term.Term term: actionDef.getParameters()){
          termsOp.add(new VarTerm(term.getImage().replace("?", "").toUpperCase()));
          parameterTypes.add(term.getTypeSet().toString());
         
          Set<String> setVar = this.types.get(term.getTypeSet().toString());
         
          for(Constant c: this.pddlObject.getTypedDomain(term.getTypeSet())){
            if(setVar == null){
              setVar = new HashSet<String>();
              setVar.add(c.toString());
              this.types.put(term.getTypeSet().toString(), setVar);
            } else setVar.add(c.toString());
          }
        }

        this.parameterTypes.put(actionDef.getName(), parameterTypes);
       
        operatorImpl.addTerms(termsOp);
       
        operatorImpl.getPreconds().addAll(this.getPropositionFromDomainExp(precontidion));
        operatorImpl.getEffects().addAll(this.getPropositionFromDomainExp(effect));
       
        operators.add(operatorImpl);
      }
     
      logger.finest("\n--> Init\n");
View Full Code Here


    for (int i = 0; i < effects.length; i++) {
      PropositionImpl effect = new PropositionImpl(effects[i]);
      effectProps.add(effect);
    }
   
    OperatorImpl operator = new OperatorImpl(oper, precondProps, effectProps);
   
    return operator;
  }
View Full Code Here

      return operatorInstances.get(noopSignature);
    } else {
      List<Proposition> precondsEffects = new ArrayList<Proposition>(1);
      precondsEffects.add(proposition);
      Structure signature = Structure.parse(noopSignature);
      OperatorImpl operator = new OperatorImpl(signature, precondsEffects, precondsEffects);
      this.operatorInstances.put(noopSignature, operator);
      return operator;
    }
  }
View Full Code Here

      //Otherwise, we have to create a new one from a template
      Structure signature = Structure.parse(operatorSignature);
      //If a template exists matching the supplied indicator
      if(this.operatorTemplates.containsKey(signature.getPredicateIndicator().toString())) {
        //We get the template
        OperatorImpl template = (OperatorImpl) this.operatorTemplates.get(signature.getPredicateIndicator().toString());
        //And start copying it
        Structure templateSignature = new Structure(template);
        Unifier un = new Unifier();
        //The signature should unify with the template
        if(!un.unifies(signature, templateSignature)) {
          //This should not happen in a properly described domain
          throw new OperatorFactoryException("Failed to unify "+templateSignature+" with operator "+templateSignature+" instantiating "+operatorSignature);
        }
        templateSignature.apply(un);
        PropositionFactory propositionFactory = PropositionFactory.getInstance();
       
        //Then get the preconditions in the template
        List<Proposition> templatePreconds = template.getPreconds();
        List<Proposition> concretePreconds = new ArrayList<Proposition>(templatePreconds.size());
        //And apply the unifier to them
        for (Iterator iter = templatePreconds.iterator(); iter
            .hasNext();) {
          PropositionImpl precond = (PropositionImpl) iter.next();
          Literal literal = new LiteralImpl(precond);
          literal.apply(un);
          PropositionImpl concretePrecond = (PropositionImpl)propositionFactory.getProposition(literal.toString());
          // XXX Uncomment the code to debug operator instantiation, it is removed to avoid wasting time here
//          if(!concretePrecond.isGround()) {
//            //throw new OperatorFactoryException("We have a non-concrete precond in operator "+signature+": "+concretePrecond);
//            System.err.println("We have a non-concrete precond in operator "+signature+": "+concretePrecond);
//          }
          concretePreconds.add(concretePrecond);
        }
       
        List<Proposition> templateEffects = template.getEffects();
        List<Proposition> concreteEffects = new ArrayList<Proposition>(templateEffects.size());
       
        for (Iterator iter = templateEffects.iterator(); iter
            .hasNext();) {
          PropositionImpl effect = (PropositionImpl) iter.next();
          Literal literal = new LiteralImpl(effect);
          literal.apply(un);
          PropositionImpl concreteEffect = (PropositionImpl)propositionFactory.getProposition(literal.toString());
          // XXX Uncomment the code to debug operator instantiation, it is removed to avoid wasting time here
//          if(!concreteEffect.isGround()) {
//            //throw new OperatorFactoryException("We have a non-concrete effect in operator "+signature+": "+concreteEffect);
//            System.err.println("We have a non-concrete effect in operator "+signature+": "+concreteEffect);
//          }
          concreteEffects.add(concreteEffect);
        }
       
        OperatorImpl operatorImpl = new OperatorImpl(templateSignature, concretePreconds, concreteEffects);
        this.operatorInstances.put(operatorImpl.getSignature(), operatorImpl);
        return operatorImpl;
      } else {
        throw new OperatorFactoryException("No operator template for "+operatorSignature);
      }
      //return null;
View Full Code Here

 
  public List<Operator> getRequiringOperatorTemplates(Proposition precond) {
    List<Operator> templates = new ArrayList<Operator>();
    //Scan every operator template
    for(Enumeration<OperatorImpl> e = operatorTemplates.elements(); e.hasMoreElements(); ) {
      OperatorImpl oper = e.nextElement();
      //if the parameter is null or a true proposition
      //return any empty preconditions operator
      if(precond == null) {
        if(oper.getPreconds().isEmpty()) {
          templates.add(oper);
        }
        continue;
      }     
      //or trying to unify the supplied precondition with any of the preconditions
      for (Proposition oPrecond : oper.getPreconds()) {
        if(precond.unifies(oPrecond)) {
          templates.add(oper);
        }
      }
    }
View Full Code Here

      int n = this.parameterTypes.get(op.getFunctor()).size();
      TermInstanceIterator it = new TermInstanceIterator(op.getFunctor(), n);

      while(it.hasNext()){
        termInstances = it.next();
        OperatorImpl newOp = new OperatorImpl(op.getFunctor());
        List<Term> newTerms = new ArrayList<Term>();
       
        for(int i=0; i<n; i++)
          newTerms.add(termInstances[i]);

        newOp.addTerms(newTerms);
        List<String> termsOp = new ArrayList<String>();
        for(int i=0; i<newOp.getTerms().toArray().length; i++)
          termsOp.add(op.getTerms().toArray()[i].toString() +"@"+ newOp.getTerms().toArray()[i].toString());
       
        BitSet pe = new BitSet();
        BitSet ne = new BitSet();
        for(Proposition e: op.getEffects()){
          if(e.negated()) ne.set(getIndexProposition(e, getTerms(termsOp, e.getTerms()), false));
          else pe.set(getIndexProposition(e, getTerms(termsOp, e.getTerms()), true));
        }

        this.positiveEffects.put(newOp.toString(), pe);
        this.negativeEffects.put(newOp.toString(), ne);

        BitSet pp = new BitSet();
        BitSet np = new BitSet();
        for(Proposition p: op.getPreconds()){
          if(p.negated()) np.set(getIndexProposition(p, getTerms(termsOp, p.getTerms()), false));
          else pp.set(getIndexProposition(p, getTerms(termsOp, p.getTerms()), true));
        }

        this.positivePrecond.put(newOp.toString(), pp);
        this.negativePrecond.put(newOp.toString(), np);

        this.operators.add(newOp);
      }
    }
   
View Full Code Here

 
  public List<Operator> getCausingOperatorsTemplates(Proposition effect) {
    List<Operator> templates = new ArrayList<Operator>();
    //Scan every operator template
    for(Enumeration<OperatorImpl> e = operatorTemplates.elements(); e.hasMoreElements(); ) {
      OperatorImpl oper = e.nextElement();
      //and trying to unify the supplied effect with any of the effects
      for (Proposition oEffect : oper.getEffects()) {
        if(effect.unifies(oEffect)) {
          templates.add(oper);
        }
      }
    }
View Full Code Here

            }

            if(!addInstance) continue;
          }
         
          final OperatorImpl copy = (OperatorImpl) operator.clone();
          Structure struct = new Structure(copy.getFunctor());
          for(Term term : termInstances) {
            struct.addTerm(term);
          }
         
          Unifier unifier = new Unifier();
          if(unifier.unifies(copy, struct)) {
            copy.apply(unifier);
          } else {
            System.err.println("Big mess!");
          }
         
          for(Proposition proposition : copy.getPreconds()) {
            PropositionImpl realProp = (PropositionImpl) proposition;
            realProp.apply(unifier);
            addInstance = preconds.contains(proposition);
           
            if(proposition.negated() && !addInstance) {
              /*Closed World Assumption*/
              if(initialState != null && initialState.isPropositionLevel()){
                PropositionLevel initial = (PropositionLevel) initialState;
                PropositionImpl positiveProposition = new PropositionImpl(proposition.getFunctor());
                positiveProposition.setTerms(proposition.getTerms());

                if(!initial.hasProposition(positiveProposition)){
                  initial.addProposition(proposition);
                }
              }
              //addInstance = true;
            }
            if(!addInstance) {
              break;
            }
          }
          if(addInstance) {
            copy.apply(unifier);
            instances.add(getOperator(copy.getSignature()));
          }
        }
      }
    }
    return instances;
View Full Code Here

TOP

Related Classes of graphplan.domain.jason.OperatorImpl

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.