Package kodkod.instance

Examples of kodkod.instance.TupleFactory


   * a mapping from (this.variableUsage().keySet() & Relation) to sets of Tuples.
   * @throws IllegalStateException - this.solver.solve() has not been called or the
   * outcome of the last call was not <code>true</code>.
   */
  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();
          if (!indeces.contains(index) && solver.valueOf(lit++))
            indeces.add(index);
        }
      }
      instance.add(r, f.setOf(r.arity(), indeces));
    }
    return instance;
  }
View Full Code Here


        bounds.upperBound(relation).indexView().containsAll(ordering)) {
       
        // remove the ordered partition from the set of symmetric partitions
        removePartition(domain.min());
       
        final TupleFactory f = bounds.universe().factory();
       
        if (aggressive) {
          bounds.boundExactly(first, f.setOf(f.tuple(1, domain.min())));
          bounds.boundExactly(last, f.setOf(f.tuple(1, domain.max())));
          bounds.boundExactly(ordered, bounds.upperBound(total.ordered()));
          bounds.boundExactly(relation, f.setOf(2, ordering));
         
          return Formula.TRUE;
         
        } else {
          final Relation firstConst = Relation.unary("SYM_BREAK_CONST_"+first.name());
          final Relation lastConst = Relation.unary("SYM_BREAK_CONST_"+last.name());
          final Relation ordConst = Relation.unary("SYM_BREAK_CONST_"+ordered.name());
          final Relation relConst = Relation.binary("SYM_BREAK_CONST_"+relation.name());
          bounds.boundExactly(firstConst, f.setOf(f.tuple(1, domain.min())));
          bounds.boundExactly(lastConst, f.setOf(f.tuple(1, domain.max())));
          bounds.boundExactly(ordConst, bounds.upperBound(total.ordered()));
          bounds.boundExactly(relConst, f.setOf(2, ordering));
         
          return Formula.and(first.eq(firstConst), last.eq(lastConst), ordered.eq(ordConst), relation.eq(relConst));
//          return first.eq(firstConst).and(last.eq(lastConst)).and( ordered.eq(ordConst)).and( relation.eq(relConst));
        }
View Full Code Here

       // Find the starting element
       Tuple head = null;
       TupleSet right = b.project(1);
       for(Tuple x: u) if (!right.contains(x)) {head = x; break;}
       if (head==null) return null;
       final TupleFactory f = head.universe().factory();
       // Form the list
       list.add(head);
       while(true) {
          // Find head.next
          Tuple headnext = null;
          for(Tuple x: b) if (x.atom(0)==head.atom(0)) { headnext = f.tuple(x.atom(1)); break; }
          // If we've reached the end of the chain, and indeed we've formed exactly n elements (and all are in u), we're done
          if (headnext==null) return list.size()==n ? list : null;
          // If we've accumulated more than n elements, or if we reached an element not in u, then we declare failure
          if (list.size()==n || !u.contains(headnext)) return null;
          // Move on to the next step
View Full Code Here

                ans.add(newT);
            }
            return ans;
        }
        @Override public boolean simplify(A4Reporter rep, A4Solution sol, List<Formula> unused) throws Err {
            TupleFactory factory = sol.getFactory();
            TupleSet oldUniv = convert(factory, Sig.UNIV);
            Set<Object> oldAtoms = new HashSet<Object>(); for(Tuple t: oldUniv) oldAtoms.add(t.atom(0));
            for(Sig s: allSigs) {
                // The case below is STRICTLY an optimization; the entire statement can be removed without affecting correctness
                if (s.isOne!=null && s.getFields().size()==2)
                  for(int i=0; i+3<totalOrderPredicates.size(); i=i+4)
                      if (totalOrderPredicates.get(i+1)==right(sol.a2k(s.getFields().get(0))) && totalOrderPredicates.get(i+3)==right(sol.a2k(s.getFields().get(1)))) {
                          TupleSet allelem = sol.query(true, totalOrderPredicates.get(i), true);
                          if (allelem.size()==0) continue;
                          Tuple first=null, prev=null; TupleSet next=factory.noneOf(2);
                          for(Tuple t:allelem) {
                              if (prev==null) first=t; else next.add(prev.product(t));
                              prev=t;
                          }
                          try {
                              sol.shrink(totalOrderPredicates.get(i+1), factory.range(first,first), factory.range(first,first));
                              sol.shrink(totalOrderPredicates.get(i+2), factory.range(prev,prev), factory.range(prev,prev));
                              sol.shrink(totalOrderPredicates.get(i+3), next, next);
                          } catch(Throwable ex) {
                              // Error here is not fatal
                          }
                      }
View Full Code Here

        return null;
    }

    /** If one of the solution is a solution to the given problem, return it, else return null. */
    static Solution trial (A4Reporter rep, A4Solution frame, Formula formula, Solver solver, boolean check) {
        TupleFactory fac = frame.getFactory();
        Solution sol = null;
        Iterable<Sig> sigs = frame.getAllReachableSigs();
        if (hasSig(sigs, "this/Book")!=null) {
            Tuple B0N0A0 = t_tuple(fac, "Book$0", "Name$0", "Addr$0");
            Tuple B0N1A0 = t_tuple(fac, "Book$0", "Name$1", "Addr$0");
View Full Code Here

TOP

Related Classes of kodkod.instance.TupleFactory

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.