Пример #1
0
  /**
   * Grounds the parameter by assigning the values in the assignment to the unknown variables
   *
   * @param input the grounding assignment
   * @return the grounded parameter
   */
  public Parameter ground(Assignment input) {
    if (input.containsVars(expression.getVariables())) {
      try {
        double result = expression.evaluate(input);
        return new FixedParameter(result);
      } catch (IllegalArgumentException e) {
        log.warning("cannot ground " + expression + " with " + input);
      }
    }

    String filled = expression.toString();
    for (String u : input.getVariables()) {
      filled.replaceAll(u, input.getValue(u).toString());
    }
    return new ComplexParameter(filled);
  }
Пример #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;
    }