Package kodkod.instance

Examples of kodkod.instance.TupleSet


    BooleanMatrix matrixBound = upperBound(skolemDecl.expression(), skolemEnv);
    for(int i = depth-1; i >= 0; i--) {
      matrixBound = nonSkolems.get(i).upperBound.cross(matrixBound);
    }

    final TupleSet skolemBound = bounds.universe().factory().setOf(arity, matrixBound.denseIndices());
    bounds.bound(skolem, skolemBound);

    return skolemExpr;
 
View Full Code Here


 
    final Map<IntSet, IntSet> range2domain = new HashMap<IntSet, IntSet>((usize*2) / 3);
   
    // refine the partitions based on the bounds for each integer
    for(IntIterator iter = bounds.ints().iterator(); iter.hasNext();) {
      TupleSet exact = bounds.exactBound(iter.next());
      refinePartitions(exact.indexView(), 1, range2domain);
    }
   
    // refine the partitions based on the upper/lower bounds for each relation
    for(TupleSet s : sort(bounds)) {
      if (parts.size()==usize) return;
View Full Code Here

   * sorted in the order of increasing size.
   */
  private static TupleSet[] sort(Bounds bounds) {
    final List<TupleSet> sets = new ArrayList<TupleSet>(bounds.relations().size());
    for(Relation r : bounds.relations()) {
      final TupleSet lower = bounds.lowerBound(r);
      final TupleSet upper = bounds.upperBound(r);
      if (!lower.isEmpty() && lower.size()<upper.size()) { sets.add(lower); }
      if (!upper.isEmpty()) {  sets.add(upper); }
    }
    final TupleSet[] sorted = sets.toArray(new TupleSet[sets.size()]);
    Arrays.sort(sorted, new Comparator<TupleSet>(){
      public int compare(TupleSet o1, TupleSet o2) {
        return o1.size() - o2.size();
View Full Code Here

  public Instance interpret() {
    final TupleFactory f = bounds.universe().factory();
    final Instance instance = new Instance(bounds.universe());
//    System.out.println(varUsage);
    for(Relation r : bounds.relations()) {
      TupleSet lower = bounds.lowerBound(r);
      IntSet indeces = Ints.bestSet(lower.capacity());
      indeces.addAll(lower.indexView());
      IntSet vars = primaryVarUsage.get(r);
      if (vars!=null) {
        int lit = vars.min();
        for(IntIterator iter = bounds.upperBound(r).indexView().iterator(); iter.hasNext();) {
          final int index = iter.next();
View Full Code Here

        }
    }

    /** Parse tuples. */
    private TupleSet parseTuples(XMLNode tuples, int arity) throws Err {
        TupleSet ans = factory.noneOf(arity);
        for(XMLNode sub:tuples) if (sub.is("tuple")) ans.add(parseTuple(sub, arity));
        return ans;
    }
View Full Code Here

           if (label.equals(STRING.label)) { id2sig.put(id, STRING); return STRING; }
           throw new IOException("Unknown builtin sig: "+label+" (id="+id+")");
        }
        if (depth > nmap.size()) throw new IOException("Sig "+label+" (id="+id+") is in a cyclic inheritance relationship.");
        List<Sig> parents = null;
        TupleSet ts = factory.noneOf(1);
        for(XMLNode sub:node) {
           if (sub.is("atom")) { ts.add(factory.tuple(sub.getAttribute("label"))); continue; }
           if (!sub.is("type")) continue;
           Sig parent = parseSig(sub.getAttribute("ID"), depth+1);
           if (parents==null) parents = new ArrayList<Sig>();
           parents.add(parent);
        }
        if (parents==null) {
           String parentID = node.getAttribute("parentID");
           Sig parent = parseSig(parentID, depth+1);
           if (!(parent instanceof PrimSig)) throw new IOException("Parent of sig "+label+" (id="+id+") must not be a subset sig.");
           for(Expr choice: choices)
              if (choice instanceof PrimSig && parent==((PrimSig)choice).parent && ((Sig)choice).label.equals(label))
                 { ans=(Sig)choice; choices.remove(choice); break; }
           if (ans==null) {
              ans = new PrimSig(label, (PrimSig)parent, isAbstract, isLone, isOne, isSome, isPrivate, isMeta, isEnum);
              allsigs.add(ans);
           }
        } else {
           for(Expr choice:choices)
              if (choice instanceof SubsetSig && ((Sig)choice).label.equals(label) && sameset(parents, ((SubsetSig)choice).parents))
                 { ans=(Sig)choice; choices.remove(choice); break; }
           if (ans==null) {
              ans = new SubsetSig(label, parents, isExact, isLone, isOne, isSome, isPrivate, isMeta);
              allsigs.add(ans);
           }
        }
        id2sig.put(id, ans);
        expr2ts.put(ans, ts);
        if (ans instanceof PrimSig) {
           // Add the atoms in this SIG into all parent sigs
           for(PrimSig ans2 = ((PrimSig)ans).parent; ans2!=null && !ans2.builtin; ans2 = ans2.parent) {
              TupleSet ts2 = expr2ts.get(ans2);
              if (ts2==null) ts2 = ts.clone(); else { ts2 = ts2.clone(); ts2.addAll(ts); }
              expr2ts.put(ans2, ts2);
           }
        }
        return ans;
    }
View Full Code Here

       Field field = null;
       for(Field f: parent.getFields())
           if (f.label.equals(label) && f.type().arity()==arity && choices.contains(f))
              { field=f; choices.remove(f); break; }
       if (field==null) field = parent.addTrickyField(Pos.UNKNOWN, isPrivate, null, null, isMeta, new String[] {label}, UNIV.join(type)) [0];
       TupleSet ts = parseTuples(node, arity);
       expr2ts.put(field, ts);
       return field;
    }
View Full Code Here

       Expr type = null;
       for(XMLNode sub:node) if (sub.is("types")) { Expr t=parseType(sub); if (type==null) type=t; else type=type.plus(t); }
       int arity;
       if (type==null || (arity=type.type().arity())<1) throw new IOException("Skolem "+label+" is maltyped.");
       ExprVar var = ExprVar.make(Pos.UNKNOWN, label, type.type());
       TupleSet ts = parseTuples(node, arity);
       expr2ts.put(var, ts);
       return var;
    }
View Full Code Here

       // parse all the sigs, fields, and skolems
       for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("sig")) parseSig(e.getKey(), 0);
       for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("field")) parseField(e.getKey());
       for(Map.Entry<String,XMLNode> e:nmap.entrySet()) if (e.getValue().is("skolem")) parseSkolem(e.getKey());
       for(Sig s:allsigs) if (!s.builtin) {
          TupleSet ts = expr2ts.remove(s);
          if (ts==null) ts = factory.noneOf(1); // If the sig was NOT mentioned in the XML file...
          Relation r = sol.addRel(s.label, ts, ts);
          sol.addSig(s, r);
          for(Field f: s.getFields()) {
              ts = expr2ts.remove(f);
              if (ts==null) ts=factory.noneOf(f.type().arity()); // If the field was NOT mentioned in the XML file...
              r = sol.addRel(s.label+"."+f.label, ts, ts);
              sol.addField(f, r);
          }
       }
       for(Map.Entry<Expr,TupleSet> e:expr2ts.entrySet()) {
          ExprVar v = (ExprVar)(e.getKey());
          TupleSet ts = e.getValue();
          Relation r = sol.addRel(v.label, ts, ts);
          sol.kr2type(r, v.type());
       }
       // Done!
       sol.solve(null, null, null, false);
View Full Code Here

        if (maxseq < 0)     throw new ErrorSyntax("The maximum sequence length cannot be negative.");
        if (maxseq > max()) throw new ErrorSyntax("With integer bitwidth of "+bitwidth+", you cannot have sequence length longer than "+max());
        kAtoms = ConstList.make(atoms);
        bounds = new Bounds(new Universe(kAtoms));
        factory = bounds.universe().factory();
        TupleSet sigintBounds = factory.noneOf(1);
        TupleSet seqidxBounds = factory.noneOf(1);
        TupleSet stringBounds = factory.noneOf(1);
        final TupleSet next = factory.noneOf(2);
        for(int min=min(), max=max(), i=min; i<=max; i++) { // Safe since we know 1 <= bitwidth <= 30
           Tuple ii = factory.tuple(""+i);
           TupleSet is = factory.range(ii, ii);
           bounds.boundExactly(i, is);
           sigintBounds.add(ii);
           if (i>=0 && i<maxseq) seqidxBounds.add(ii);
           if (i+1<=max) next.add(factory.tuple(""+i, ""+(i+1)));
           if (i==min) bounds.boundExactly(KK_MIN,  is);
View Full Code Here

TOP

Related Classes of kodkod.instance.TupleSet

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.