Exemple #1
0
 /** Helper method for groundedUnify. */
 private boolean groundedUnify(APLVar t, SubstList<Term> theta) {
   Term subst = theta.get(t.getName());
   if (subst != null) return groundedUnify(subst, theta);
   else {
     theta.put(t.getName(), this);
     return true;
   }
 }
Exemple #2
0
 /**
  * Selects an applicable PC-rule. A PC-rule is applicable if the head matches the
  * event/message/abstract action <code>a</code> and the guard is satisfied by the beliefs of the
  * module. Returns a copy of the rule with fresh (unique) variables such that is does not
  * interfere with the variables that already occur in the plan from which the abstract action is
  * called.
  *
  * @param beliefbase the beliefs
  * @param a the event/message/abstract action
  * @param unfreshVars the list variables that cannot be used anymore
  * @param theta the substitution for applying the rule
  * @return the selected PC-rule
  * @throws NoRuleException thrown if no rule is specified for <code>a</code>
  */
 public PCrule selectRule(
     Beliefbase beliefbase, APLFunction a, ArrayList<String> unfreshVars, SubstList<Term> theta)
     throws NoRuleException {
   boolean norulefound = true;
   for (PCrule pcrule : rules) {
     SubstList<Term> theta2 = new SubstList<Term>();
     PCrule variant = pcrule.getVariant(unfreshVars);
     Query guard = variant.getGuard().clone();
     APLFunction head = variant.getHead();
     if (a == null) continue; // TODO why???
     if (Unifier.unify(head, a.clone(), theta2)) {
       norulefound = false;
       guard.applySubstitution(theta2);
       if (beliefbase.doQuery(guard, theta2)) {
         theta.putAll(theta2);
         return variant;
       }
     }
   }
   if (norulefound) throw new NoRuleException();
   return null;
 }