Ejemplo n.º 1
0
 /**
  * Helper method that returns the constraint that the sig has exactly "n" elements, or at most "n"
  * elements
  */
 private Formula size(Sig sig, int n, boolean exact) {
   Expression a = sol.a2k(sig);
   if (n <= 0) return a.no();
   if (n == 1) return exact ? a.one() : a.lone();
   Formula f = exact ? Formula.TRUE : null;
   Decls d = null;
   Expression sum = null;
   while (n > 0) {
     n--;
     Variable v = Variable.unary("");
     kodkod.ast.Decl dd = v.oneOf(a);
     if (d == null) d = dd;
     else d = dd.and(d);
     if (sum == null) sum = v;
     else {
       if (f != null) f = v.intersection(sum).no().and(f);
       sum = v.union(sum);
     }
   }
   if (f != null) return sum.eq(a).and(f).forSome(d);
   else return a.no().or(sum.eq(a).forSome(d));
 }