Package kodkod.util.ints

Examples of kodkod.util.ints.IntSet


      final Translation translation = Translator.translate(formula, bounds, options);
      final long endTransl = System.currentTimeMillis();

      final SATMinSolver cnf = (SATMinSolver)translation.cnf();
      for(Relation r : bounds.relations()) {
        IntSet vars = translation.primaryVariables(r);
        if (vars != null) {
          int rcost = cost.edgeCost(r);
          for(IntIterator iter = vars.iterator();  iter.hasNext(); ) {
            cnf.setCost(iter.next(), rcost);
          }
        }
      }
     
View Full Code Here


   */
  public TupleSet project(int dimension) {
    if (dimension < 0 || dimension >= arity) {
      throw new IllegalArgumentException("dimension < 0 || dimension >= this.arity");
    }
    final IntSet projection = Ints.bestSet(universe.size());
    final TupleFactory factory = universe.factory();
    for(IntIterator indexIter = tuples.iterator(); indexIter.hasNext();) {
      projection.add(factory.project(indexIter.next(), arity, dimension));
    }
    return new TupleSet(universe,1,projection);
  }
View Full Code Here

   * @return c.elements in this.tuples
   * @throws IllegalArgumentException - some t: c.elements | t.universe != this.universe || t.arity != this.arity
   */
  @Override
  public boolean containsAll(Collection<?> c) {
    final IntSet cTuples = extractTuples(c);
    return cTuples==null ? super.containsAll(c) : tuples.containsAll(cTuples);
  }
View Full Code Here

   * @return c.elements !in this.tuples
   * @throws IllegalArgumentException - some t: c.elements | t.universe != this.universe || t.arity != this.arity
   */
  @Override
  public boolean addAll(Collection<? extends Tuple> c) {
    final IntSet cTuples = extractTuples(c);
    return cTuples==null ? super.addAll(c) : tuples.addAll(cTuples);
  }
View Full Code Here

   * @return some c.elements & this.tuples
   * @throws IllegalArgumentException - some t: c.elements | t.universe != this.universe || t.arity != this.arity
   */
  @Override
  public boolean removeAll(Collection<?> c) {
    final IntSet cTuples = extractTuples(c);
    return cTuples==null ? super.removeAll(c) : tuples.removeAll(cTuples);
  }
View Full Code Here

   * @return this.tuples !in c.elements
   * @throws IllegalArgumentException - some t: c.elements | t.universe != this.universe || t.arity != this.arity
   */
  @Override
  public boolean retainAll(Collection<?> c) {
    final IntSet cTuples = extractTuples(c);
    return cTuples==null ? super.retainAll(c) : tuples.retainAll(cTuples);
  }
View Full Code Here

   * @throws UnboundLeafException - r !in this.relations
   */
  public final BooleanMatrix interpret(Relation r) {
    if (!lowers.containsKey(r))
      throw new UnboundLeafException("Unbound relation: ", r);
    final IntSet lowerBound = lowers.get(r).indexView();
    final IntSet upperBound = uppers.get(r).indexView();
   
    final BooleanMatrix m = factory.matrix(Dimensions.square(universe().size(), r.arity()), upperBound, lowerBound);
   
    if (upperBound.size() > lowerBound.size()) {
      int varId = vars.get(r).min();
      for (IntIterator indeces = upperBound.iterator(); indeces.hasNext();) {
        int tupleIndex = indeces.next();
        if (!lowerBound.contains(tupleIndex)) 
          m.set(tupleIndex, factory.variable(varId++));
      }
    }
View Full Code Here

   *           c = INT => (all i: dset | (some j: int | this.interpret(j)=i) => m.elements[i] = TRUE, m.elements[i] = FALSE }
   */
  public final BooleanMatrix interpret(ConstantExpression c) {
    final int univSize = universe().size();
    if (c==Expression.UNIV) {
      final IntSet all =  Ints.rangeSet(Ints.range(0, univSize-1));
      return factory().matrix(Dimensions.square(univSize, 1), all, all);
    } else if (c==Expression.IDEN) {
      final Dimensions dim2 = Dimensions.square(univSize, 2);
      final IntSet iden = Ints.bestSet(dim2.capacity());
      for(int i = 0; i < univSize; i++) {
        iden.add(i*univSize + i);
      }     
      return factory().matrix(dim2, iden, iden);
    } else if (c==Expression.NONE) {
      return factory().matrix(Dimensions.square(univSize, 1), Ints.EMPTY_SET, Ints.EMPTY_SET);
    } else if (c==Expression.INTS) {
      final IntSet ints = Ints.bestSet(univSize);
      for(IntIterator iter = ints().iterator(); iter.hasNext(); ) {
        ints.add(interpret(iter.next()));
      }
      return factory().matrix(Dimensions.square(univSize, 1), ints, ints);
    } else {
      throw new IllegalArgumentException("unknown constant expression: " + c);
    }
View Full Code Here

          return roots.contains(translated) && coreUnits.contains(Math.abs(literal));
        }
       
      };
      coreRoots = new LinkedHashMap<Formula, Node>();
      final IntSet seenUnits = new IntTreeSet();
      for(Iterator<TranslationRecord> itr = log().replay(unitFilter); itr.hasNext(); ) {
        // it is possible that two top-level formulas have identical meaning,
        // and are represented with the same core unit; in that case, we want only
        // one of them in the core.
        final TranslationRecord rec = itr.next();
        if (seenUnits.add(rec.literal())) {
          coreRoots.put(rec.translated(), rec.node());
       
      }
      coreRoots = Collections.unmodifiableMap(coreRoots);
    }
View Full Code Here

   *   v = abs(r.literal) and
   *   no r': log.records | r'.node = r.node && log.replay.r' > log.replay.r }
   * </pre>
   */
  public static IntSet rootVars(TranslationLog log) {
    final IntSet rootVars = new IntTreeSet();
    final Set<Formula> roots = log.roots();
    final Map<Formula,int[]> maxRootVar = new LinkedHashMap<Formula,int[]>(roots.size());
    final RecordFilter filter = new RecordFilter() {
      public boolean accept(Node node, Formula translated, int literal, Map<Variable, TupleSet> env) {
        return roots.contains(translated) && env.isEmpty();
      }
    };
    for(Iterator<TranslationRecord> itr = log.replay(filter); itr.hasNext();) {
      TranslationRecord record = itr.next();
      int[] var = maxRootVar.get(record.translated());
      if (var==null) {
        var = new int[1];
        maxRootVar.put(record.translated(), var);
      }
      var[0] = StrictMath.abs(record.literal());
    }
   
    for(int[] var : maxRootVar.values()) {
      int topVar = var[0];
      if (topVar != Integer.MAX_VALUE) // formula simplified to TRUE
        rootVars.add(var[0]);
    }
   
//    for(Map.Entry<Formula,int[]> entry : maxRootVar.entrySet()) {
//      final int topVar = entry.getValue()[0];
//      if (topVar != Integer.MAX_VALUE) // formula simplified to TRUE
View Full Code Here

TOP

Related Classes of kodkod.util.ints.IntSet

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.