Java Code Examples for kodkod.util.ints.Ints#bestSet()

The following examples show how to use kodkod.util.ints.Ints#bestSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeafInterpreter.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link kodkod.engine.bool.BooleanMatrix matrix} m of
 * {@link kodkod.engine.bool.BooleanValue boolean formulas} representing the
 * specified constant expression.
 *
 * @return { m: BooleanMatrix | let dset = [0..this.universe.size()^c.arity) |
 *         m.dimensions.dimensions = [0..c.arity) ->one this.universe.size() &&
 *         c = UNIV => m.elements[dset] = TRUE, c = NONE => m.elements[dset] =
 *         FALSE, c = IDEN => (all i: dset | (some j: int | i =
 *         j*(1+this.universe.size())) => m.elements[i] = TRUE, m.elements[i] =
 *         FALSE), 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);
    }
}
 
Example 2
Source File: LeafInterpreter.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns a {@link kodkod.engine.bool.BooleanMatrix matrix} m of 
 * {@link kodkod.engine.bool.BooleanValue boolean formulas} representing
 * the specified constant expression.    
 * @return { m: BooleanMatrix | let dset = [0..this.universe.size()^c.arity) | 
 *           m.dimensions.dimensions = [0..c.arity) ->one this.universe.size() && 
 *           c = UNIV => m.elements[dset] = TRUE, c = NONE => m.elements[dset] = FALSE,
 *           c = IDEN => (all i: dset | (some j: int | i = j*(1+this.universe.size())) => m.elements[i] = TRUE, m.elements[i] = FALSE),
 *           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);
	}
}
 
Example 3
Source File: TupleSet.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an empty tuple set for storing tuples of the specified arity, over
 * the given universe.
 *
 * @ensures this.universe' = universe && this.arity' = arity && no this.tuples'
 * @throws NullPointerException universe = null
 * @throws IllegalArgumentException arity < 1
 */
TupleSet(Universe universe, int arity) {
    if (arity < 1)
        throw new IllegalArgumentException("arity < 1");
    universe.factory().checkCapacity(arity);
    this.universe = universe;
    this.arity = arity;
    tuples = Ints.bestSet(capacity());
}
 
Example 4
Source File: TupleSet.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Projects this TupleSet onto the given dimension.
 *
 * @return {s: TupleSet | s.arity = 1 && s.universe = this.universe && s.tuples
 *         = { t: Tuple | some q: this.tuples | q.atoms[dimension] =
 *         t.atoms[int] } }
 * @throws IllegalArgumentException dimension < 0 || dimension >= this.arity
 */
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);
}
 
Example 5
Source File: SymmetryDetector.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new SymmetryDetector for the given bounds.
 *
 * @ensures this.bounds' = bounds
 */
private SymmetryDetector(Bounds bounds, Collection<Relation> ignoreAllAtomRelsExcept, Collection<Relation> ignoreRels) {
    this.bounds = bounds;
    this.usize = bounds.universe().size();
    this.ignoreAllAtomRelsExcept = ignoreAllAtomRelsExcept;
    this.ignoreRels = ignoreRels;

    // start with the maximum partition -- the whole universe.
    this.parts = new LinkedList<IntSet>();
    final IntSet set = Ints.bestSet(usize);
    for (int i = 0; i < usize; i++) {
        set.add(i);
    }
    this.parts.add(set);
}
 
Example 6
Source File: TupleSet.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Projects this TupleSet onto the given dimension.
 * @return {s: TupleSet | s.arity = 1 && s.universe = this.universe && 
 *                        s.tuples = { t: Tuple | some q: this.tuples | q.atoms[dimension] = t.atoms[int] } }
 * @throws IllegalArgumentException  dimension < 0 || dimension >= this.arity
 */
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);
}
 
Example 7
Source File: SymmetryDetector.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Constructs a new SymmetryDetector for the given bounds.
 * @ensures this.bounds' = bounds
 */
private SymmetryDetector(Bounds bounds) {
	this.bounds = bounds;
	this.usize = bounds.universe().size();
	
       //	start with the maximum partition -- the whole universe.
	this.parts = new LinkedList<IntSet>();
	final IntSet set = Ints.bestSet(usize);
	for(int i = 0; i < usize; i++) { set.add(i); }
	this.parts.add(set);
}
 
Example 8
Source File: SymmetryDetector.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Refines the atomic partitions this.parts based on the contents of the given set.
 * @requires all disj s, q: this.parts[int] | 
 *            some s.ints && some q.ints && (no s.ints & q.ints) &&
 *            this.parts[int].ints = [0..this.bounds.universe.size())
 * @ensures  all disj s, q: this.parts'[int] | 
 *            some s.ints && some q.ints && (no s.ints & q.ints) &&
 *            this.parts'[int].ints = [0..this.bounds.universe.size()) &&
 *            (all i: [0..this.parts'.size()) | 
 *             this.parts'[i].ints in set.ints || no this.parts'[i].ints & set.ints)
 */
private void refinePartitions(IntSet set) {
	for(ListIterator<IntSet> partsIter = parts.listIterator(); partsIter.hasNext(); ) {
		IntSet part = partsIter.next();
		IntSet intersection = Ints.bestSet(part.min(), part.max());
		intersection.addAll(part);
		intersection.retainAll(set);
		if (!intersection.isEmpty() && intersection.size() < part.size()) {
			part.removeAll(intersection);
			partsIter.add(intersection);
		}
	}
}
 
Example 9
Source File: SymmetryDetector.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * Refines the atomic partitions in this.parts based on the contents of the
 * given tupleset, decomposed into its constituent IntSet and arity. The
 * range2domain map is used for intermediate computations for efficiency (to
 * avoid allocating it in each recursive call).
 *
 * @requires all disj s, q: this.parts[int] | some s.ints && some q.ints && (no
 *           s.ints & q.ints) && this.parts[int].ints =
 *           [0..this.bounds.universe.size())
 * @ensures let usize = this.bounds.universe.size(), firstColFactor =
 *          usize^(arit-1) | all disj s, q: this.parts'[int] | some s.ints &&
 *          some q.ints && (no s.ints & q.ints) && this.parts'[int].ints =
 *          [0..usize) && all s: this.parts'[int] | all a1, a2:
 *          this.bounds.universe.atoms[s.ints] | all t1, t2: set.ints | t1 /
 *          firstColFactor = a1 && t2 / firstColFactor = a2 => t1 %
 *          firstColFactor = t2 % firstColFactor || t1 = a1*((1 -
 *          firstColFactor) / (1 - usize)) && t2 = a2*((1 - firstColFactor) / (1
 *          - usize)))
 */
private void refinePartitions(IntSet set, int arity, Map<IntSet,IntSet> range2domain) {
    if (arity == 1) {
        refinePartitions(set);
        return;
    }

    final List<IntSet> otherColumns = new LinkedList<IntSet>();
    int firstColFactor = (int) StrictMath.pow(usize, arity - 1);
    IntSet firstCol = Ints.bestSet(usize);
    for (IntIterator rbIter = set.iterator(); rbIter.hasNext();) {
        firstCol.add(rbIter.next() / firstColFactor);
    }
    refinePartitions(firstCol);

    int idenFactor = (1 - firstColFactor) / (1 - usize);
    for (ListIterator<IntSet> partsIter = parts.listIterator(); partsIter.hasNext();) {
        IntSet part = partsIter.next();
        if (firstCol.contains(part.min())) { // contains one, contains them
                                            // all
            range2domain.clear();
            for (IntIterator atoms = part.iterator(); atoms.hasNext();) {
                int atom = atoms.next();
                IntSet atomRange = Ints.bestSet(firstColFactor);
                for (IntIterator rbIter = set.iterator(atom * firstColFactor, (atom + 1) * firstColFactor - 1); rbIter.hasNext();) {
                    atomRange.add(rbIter.next() % firstColFactor);
                }
                IntSet atomDomain = range2domain.get(atomRange);
                if (atomDomain != null)
                    atomDomain.add(atom);
                else
                    range2domain.put(atomRange, oneOf(usize, atom));
            }
            partsIter.remove();
            IntSet idenPartition = Ints.bestSet(usize);
            for (Map.Entry<IntSet,IntSet> entry : range2domain.entrySet()) {
                if (entry.getValue().size() == 1 && entry.getKey().size() == 1 && entry.getKey().min() == entry.getValue().min() * idenFactor) {
                    idenPartition.add(entry.getValue().min());
                } else {
                    partsIter.add(entry.getValue());
                    otherColumns.add(entry.getKey());
                }
            }
            if (!idenPartition.isEmpty())
                partsIter.add(idenPartition);
        }
    }

    // refine based on the remaining columns
    for (IntSet otherCol : otherColumns) {
        refinePartitions(otherCol, arity - 1, range2domain);
    }
}
 
Example 10
Source File: SymmetryBreaker.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * If possible, breaks symmetry on the given total ordering predicate and
 * returns a formula f such that the meaning of total with respect to
 * this.bounds is equivalent to the meaning of f with respect to this.bounds'.
 * If symmetry cannot be broken on the given predicate, returns null.
 * <p>
 * We break symmetry on the relation constrained by the given predicate iff
 * total.first, total.last, and total.ordered have the same upper bound, which,
 * when cross-multiplied with itself gives the upper bound of total.relation.
 * Assuming that this is the case, we then break symmetry on total.relation,
 * total.first, total.last, and total.ordered using one of the methods described
 * in {@linkplain #breakMatrixSymmetries(Map, boolean)}; the method used depends
 * on the value of the "agressive" flag. The partition that formed the upper
 * bound of total.ordered is removed from this.symmetries.
 * </p>
 *
 * @return null if symmetry cannot be broken on total; otherwise returns a
 *         formula f such that the meaning of total with respect to this.bounds
 *         is equivalent to the meaning of f with respect to this.bounds'
 * @ensures this.symmetries and this.bounds are modified as desribed in
 *          {@linkplain #breakMatrixSymmetries(Map, boolean)} iff total.first,
 *          total.last, and total.ordered have the same upper bound, which, when
 *          cross-multiplied with itself gives the upper bound of total.relation
 * @see #breakMatrixSymmetries(Map,boolean)
 */
private final Formula breakTotalOrder(RelationPredicate.TotalOrdering total, boolean aggressive) {
    final Relation first = total.first(), last = total.last(), ordered = total.ordered(),
                    relation = total.relation();
    final IntSet domain = bounds.upperBound(ordered).indexView();

    if (symmetricColumnPartitions(ordered) != null && bounds.upperBound(first).indexView().contains(domain.min()) && bounds.upperBound(last).indexView().contains(domain.max())) {

        // construct the natural ordering that corresponds to the ordering
        // of the atoms in the universe
        final IntSet ordering = Ints.bestSet(usize * usize);
        int prev = domain.min();
        for (IntIterator atoms = domain.iterator(prev + 1, usize); atoms.hasNext();) {
            int next = atoms.next();
            ordering.add(prev * usize + next);
            prev = next;
        }

        if (ordering.containsAll(bounds.lowerBound(relation).indexView()) && 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));
            }

        }
    }

    return null;
}
 
Example 11
Source File: SymmetryDetector.java    From kodkod with MIT License 4 votes vote down vote up
/**
 * Refines the atomic partitions in this.parts based on the contents of the given tupleset, 
 * decomposed into its constituent IntSet and arity.  The range2domain map is used for 
 * intermediate computations for efficiency (to avoid allocating it in each recursive call). 
 * @requires all disj s, q: this.parts[int] | 
 *            some s.ints && some q.ints && (no s.ints & q.ints) &&
 *            this.parts[int].ints = [0..this.bounds.universe.size())
 * @ensures  let usize = this.bounds.universe.size(), firstColFactor = usize^(arit-1) |
 *            all disj s, q: this.parts'[int] | 
 *             some s.ints && some q.ints && (no s.ints & q.ints) &&
 *             this.parts'[int].ints = [0..usize) &&
 *             all s: this.parts'[int] | all a1, a2: this.bounds.universe.atoms[s.ints] |
 *               all t1, t2: set.ints | t1 / firstColFactor = a1 && t2 / firstColFactor = a2 =>
 *                 t1 % firstColFactor = t2 % firstColFactor  || 
 *                 t1 = a1*((1 - firstColFactor) / (1 - usize)) && 
 *                 t2 = a2*((1 - firstColFactor) / (1 - usize)))
 */
private void refinePartitions(IntSet set, int arity, Map<IntSet, IntSet> range2domain) {
	if (arity==1) {
		refinePartitions(set);
		return;
	}
	
	final List<IntSet> otherColumns = new LinkedList<IntSet>();
	int firstColFactor = (int) StrictMath.pow(usize, arity-1);
	IntSet firstCol = Ints.bestSet(usize);
	for(IntIterator rbIter = set.iterator(); rbIter.hasNext(); ) {
		firstCol.add(rbIter.next() / firstColFactor);
	}
	refinePartitions(firstCol);
	
	int idenFactor = (1 - firstColFactor) / (1 - usize);
	for(ListIterator<IntSet> partsIter = parts.listIterator(); partsIter.hasNext(); ) {
		IntSet part = partsIter.next();
		if (firstCol.contains(part.min())) { // contains one, contains them all
			range2domain.clear();
			for(IntIterator atoms = part.iterator(); atoms.hasNext(); ) {
				int atom = atoms.next();
				IntSet atomRange = Ints.bestSet(firstColFactor);
				for(IntIterator rbIter = set.iterator(atom*firstColFactor, (atom+1)*firstColFactor - 1); 
				rbIter.hasNext(); ) {
					atomRange.add(rbIter.next() % firstColFactor);
				}
				IntSet atomDomain = range2domain.get(atomRange);
				if (atomDomain != null) atomDomain.add(atom);
				else range2domain.put(atomRange, oneOf(usize, atom));
			}
			partsIter.remove();
			IntSet idenPartition = Ints.bestSet(usize);
			for(Map.Entry<IntSet, IntSet> entry : range2domain.entrySet()) {
				if (entry.getValue().size()==1 && entry.getKey().size()==1 &&
					entry.getKey().min() == entry.getValue().min() * idenFactor) {
					idenPartition.add(entry.getValue().min());
				} else {
					partsIter.add(entry.getValue());
					otherColumns.add(entry.getKey());
				}
			}
			if (!idenPartition.isEmpty())
				partsIter.add(idenPartition);			
		}
	}
	
	// refine based on the remaining columns
	for(IntSet otherCol : otherColumns) {
		refinePartitions(otherCol, arity-1, range2domain);
	}
}
 
Example 12
Source File: SymmetryBreaker.java    From kodkod with MIT License 4 votes vote down vote up
/**
	 * If possible, breaks symmetry on the given total ordering predicate and returns a formula
	 * f such that the meaning of total with respect to this.bounds is equivalent to the
	 * meaning of f with respect to this.bounds'. If symmetry cannot be broken on the given predicate, returns null.  
	 * 
	 * <p>We break symmetry on the relation constrained by the given predicate iff 
	 * total.first, total.last, and total.ordered have the same upper bound, which, when 
	 * cross-multiplied with itself gives the upper bound of total.relation. Assuming that this is the case, 
	 * we then break symmetry on total.relation, total.first, total.last, and total.ordered using one of the methods
	 * described in {@linkplain #breakMatrixSymmetries(Map, boolean)}; the method used depends
	 * on the value of the "aggressive" flag.
	 * The partition that formed the upper bound of total.ordered is removed from this.symmetries.</p>
	 * 
	 * @return null if symmetry cannot be broken on total; otherwise returns a formula
	 * f such that the meaning of total with respect to this.bounds is equivalent to the
	 * meaning of f with respect to this.bounds' 
	 * @ensures this.symmetries and this.bounds are modified as described in {@linkplain #breakMatrixSymmetries(Map, boolean)}
	 * iff total.first, total.last, and total.ordered have the same upper bound, which, when 
	 * cross-multiplied with itself gives the upper bound of total.relation
	 * 
	 * @see #breakMatrixSymmetries(Map,boolean)
	 */
	private final Formula breakTotalOrder(RelationPredicate.TotalOrdering total, boolean aggressive) {
		final Relation first = total.first(), last = total.last(), ordered = total.ordered(), relation = total.relation();
		final IntSet domain = bounds.upperBound(ordered).indexView();		
	
		if (symmetricColumnPartitions(ordered)!=null && 
			bounds.upperBound(first).indexView().contains(domain.min()) && 
			bounds.upperBound(last).indexView().contains(domain.max())) {
			
			// construct the natural ordering that corresponds to the ordering of the atoms in the universe
			final IntSet ordering = Ints.bestSet(usize*usize);
			int prev = domain.min();
			for(IntIterator atoms = domain.iterator(prev+1, usize); atoms.hasNext(); ) {
				int next = atoms.next();
				ordering.add(prev*usize + next);
				prev = next;
			}
			
			if (ordering.containsAll(bounds.lowerBound(relation).indexView()) &&
				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));
				}

			}
		}
		
		return null;
	}
 
Example 13
Source File: SymmetryDetector.java    From org.alloytools.alloy with Apache License 2.0 3 votes vote down vote up
/**
 * Refines the atomic partitions this.parts based on the contents of the given
 * set.
 *
 * @requires all disj s, q: this.parts[int] | some s.ints && some q.ints && (no
 *           s.ints & q.ints) && this.parts[int].ints =
 *           [0..this.bounds.universe.size())
 * @ensures all disj s, q: this.parts'[int] | some s.ints && some q.ints && (no
 *          s.ints & q.ints) && this.parts'[int].ints =
 *          [0..this.bounds.universe.size()) && (all i: [0..this.parts'.size())
 *          | this.parts'[i].ints in set.ints || no this.parts'[i].ints &
 *          set.ints)
 */
private void refinePartitions(IntSet set) {
    for (ListIterator<IntSet> partsIter = parts.listIterator(); partsIter.hasNext();) {
        IntSet part = partsIter.next();
        IntSet intersection = Ints.bestSet(part.min(), part.max());
        intersection.addAll(part);
        intersection.retainAll(set);
        if (!intersection.isEmpty() && intersection.size() < part.size()) {
            part.removeAll(intersection);
            partsIter.add(intersection);
        }
    }
}
 
Example 14
Source File: TupleSet.java    From kodkod with MIT License 3 votes vote down vote up
/**
 * Constructs an empty tuple set for storing tuples
 * of the specified arity, over the given universe.
 * 
 * @ensures this.universe' = universe && this.arity' = arity && no this.tuples'
 * @throws NullPointerException  universe = null
 * @throws IllegalArgumentException  arity < 1
 */
TupleSet(Universe universe, int arity) {
	if (arity < 1) throw new IllegalArgumentException("arity < 1");
	universe.factory().checkCapacity(arity);
	this.universe = universe;
	this.arity = arity;
	tuples = Ints.bestSet(capacity());
}
 
Example 15
Source File: SymmetryDetector.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an IntSet that can store elements in the range [0..size), and that
 * holds the given number.
 *
 * @requries 0 <= num < size
 * @return {s: IntSet | s.ints = num }
 */
private static final IntSet oneOf(int size, int num) {
    final IntSet set = Ints.bestSet(size);
    set.add(num);
    return set;
}
 
Example 16
Source File: SymmetryDetector.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns an IntSet that can store elements
 * in the range [0..size), and that holds
 * the given number.
 * @requires 0 <= num < size
 * @return {s: IntSet | s.ints = num } 
 */
private static final IntSet oneOf(int size, int num) {
	final IntSet set = Ints.bestSet(size);
	set.add(num);
	return set;
}