Example #1
0
 /**
  * Returns the set of groundings that can be derived from the rule and the specific input
  * assignment.
  *
  * @param input the input assignment
  * @return the possible groundings for the rule
  */
 private RuleGrounding getGroundings(Assignment input) {
   RuleGrounding groundings = new RuleGrounding();
   for (RuleCase c : cases) {
     groundings.add(c.getGroundings(input));
   }
   return groundings;
 }
Example #2
0
    /**
     * Returns the groundings associated with the rule case, given the input assignment
     *
     * @param input the input assignment
     * @return the resulting groundings
     */
    public RuleGrounding getGroundings(Assignment input) {
      RuleGrounding groundings = new RuleGrounding();
      groundings.add(condition.getGroundings(input));

      if (ruleType == RuleType.UTIL) {
        boolean actionVars = input.containsVars(output.getOutputVariables());
        for (Effect e : getEffects()) {
          if (actionVars) {
            Condition co = e.convertToCondition();
            RuleGrounding effectGrounding = co.getGroundings(input);
            groundings.add(effectGrounding);
          } else {
            Set<String> slots = e.getValueSlots();
            slots.removeAll(input.getVariables());
            groundings.add(Assignment.createOneValue(slots, ""));
          }
        }
      }
      return groundings;
    }
Example #3
0
  /**
   * Returns the first rule output whose condition matches the input assignment provided as
   * argument. The output contains the grounded list of effects associated with the satisfied
   * condition.
   *
   * @param input the input assignment
   * @return the matched rule output.
   */
  public RuleOutput getOutput(Assignment input) {

    RuleOutput output = new RuleOutput(ruleType);
    RuleGrounding groundings = getGroundings(input);
    for (Assignment g : groundings.getAlternatives()) {

      Assignment full = !(g.isEmpty()) ? new Assignment(input, g) : input;

      RuleOutput match =
          cases
              .stream()
              .filter(c -> c.condition.isSatisfiedBy(full))
              .map(c -> c.output)
              .findFirst()
              .orElse(new RuleOutput(ruleType));

      match = match.ground(full);
      output.addOutput(match);
    }

    return output;
  }