Ejemplo n.º 1
0
  public static void addConstantConstraint(
      Map<Var, NodeValue> map, Pair<Var, NodeValue> constraint) {
    if (constraint == null) {
      return;
    }

    addConstantConstraint(map, constraint.getKey(), constraint.getValue());
  }
Ejemplo n.º 2
0
  /**
   * For each clause determine the constant constraints, and return those, that are common to all
   * clauses.
   *
   * @param dnf
   */
  public static Map<Var, NodeValue> extractConstantConstraints(Set<Set<Expr>> dnf) {
    Map<Var, NodeValue> result = new HashMap<Var, NodeValue>();

    Iterator<Set<Expr>> clauseIt = dnf.iterator();
    if (!clauseIt.hasNext()) {
      return result;
    }

    Set<Expr> firstClause = clauseIt.next();
    for (Expr expr : firstClause) {
      Pair<Var, NodeValue> constraint = ExprUtils.extractConstantConstraint(expr);

      addConstantConstraint(result, constraint);
    }

    Set<Var> seenVars = new HashSet<Var>();
    while (clauseIt.hasNext()) {

      if (result.isEmpty()) {
        return result;
      }

      Set<Expr> clause = clauseIt.next();
      for (Expr expr : clause) {
        Pair<Var, NodeValue> constraint = ExprUtils.extractConstantConstraint(expr);
        if (constraint == null || !result.containsKey(constraint.getKey())) {
          continue;
        }

        addConstantConstraint(result, constraint);
        seenVars.add(constraint.getKey());
      }

      result.keySet().retainAll(seenVars);
      seenVars.clear();
    }

    return result;
  }