Package kodkod.ast

Examples of kodkod.ast.Relation


    private final boolean simplify_in(Expression a, Expression b) {
       a = condense(a);
       b = condense(b);
       if (a instanceof Relation) {
          try {
             Relation r = (Relation)a;
             TupleSet ub = sol.query(true, r, false), lb = sol.query(false, r, false), t = sol.approximate(b);
             t.retainAll(ub);
             if (!t.containsAll(lb)) { rep.debug("Comment: Simplify "+a+" "+ub.size()+"->false\n"); return false; } // This means the upperbound is shrunk BELOW the lowerbound.
             if (t.size() < ub.size()) { rep.debug("Comment: Simplify "+a+" "+ub.size()+"->"+t.size()+"\n"); sol.shrink(r,lb,t); }
          } catch(Throwable ex) {
View Full Code Here


        }
        // If subset is exact, then just use the "sum" as is
        if (sig.exact) { sol.addSig(sig, sum); return sum; }
        // Allocate a relation for this subset sig, then bound it
        rep.bound("Sig "+sig+" in "+ts+"\n");
        Relation r = sol.addRel(sig.label, null, ts);
        sol.addSig(sig, r);
        // Add a constraint that it is INDEED a subset of the union of its parents
        sol.addFormula(r.in(sum), sig.isSubset);
        return r;
    }
View Full Code Here

                    TupleSet tmp = sol.query(true, sol.a2k(b), false);
                    if (upper==null) upper=tmp; else upper=upper.product(tmp);
                 }
                 ub.addAll(upper);
              }
              Relation r = sol.addRel(s.label+"."+f.label, null, ub);
              sol.addField(f, isOne ? sol.a2k(s).product(r) : r);
           }
        }
        // Add any additional SIZE constraints
        for(Sig s:sigs) if (!s.builtin) {
View Full Code Here

   */
  public Formula visit(RelationPredicate pred) {
    Formula ret = lookup(pred);
    if (ret!=null) return ret;
 
    final Relation r = (Relation)pred.relation().accept(this);
    switch(pred.name()) {
    case ACYCLIC : 
      ret = (r==pred.relation()) ? pred : r.acyclic();
      break;
    case FUNCTION :
      final RelationPredicate.Function fp = (RelationPredicate.Function) pred;
      final Expression domain = fp.domain().accept(this);
      final Expression range = fp.range().accept(this);
      ret = (r==fp.relation() && domain==fp.domain() && range==fp.range()) ?
          fp :
          (fp.targetMult()==Multiplicity.ONE ? r.function(domain, range) : r.partialFunction(domain,range));
      break;
    case TOTAL_ORDERING :
      final RelationPredicate.TotalOrdering tp = (RelationPredicate.TotalOrdering) pred;
      final Relation ordered = (Relation) tp.ordered().accept(this);
      final Relation first = (Relation)tp.first().accept(this);
      final Relation last = (Relation)tp.last().accept(this);
      ret = (r==tp.relation() && ordered==tp.ordered() && first==tp.first() && last==tp.last()) ?
          tp : r.totalOrder(ordered, first, last);
      break;
    default :
      throw new IllegalArgumentException("unknown relation predicate: " + pred.name());
View Full Code Here

           return k2pos(answer, x);
        }
        if (x.op == ExprList.Op.TOTALORDER) {
            Expression elem = cset(x.args.get(0)), first = cset(x.args.get(1)), next = cset(x.args.get(2));
            if (elem instanceof Relation && first instanceof Relation && next instanceof Relation) {
                Relation lst = frame.addRel("", null, frame.query(true, (Relation)elem, false));
                totalOrderPredicates.add((Relation)elem); totalOrderPredicates.add((Relation)first); totalOrderPredicates.add(lst); totalOrderPredicates.add((Relation)next);
                return k2pos(((Relation)next).totalOrder((Relation)elem, (Relation)first, lst), x);
            }
            Formula f1 = elem.in(first.join(next.reflexiveClosure())); // every element is in the total order
            Formula f2 = next.join(first).no(); // first element has no predecessor
View Full Code Here

TOP

Related Classes of kodkod.ast.Relation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.