Java Code Examples for kodkod.instance.TupleSet#size()

The following examples show how to use kodkod.instance.TupleSet#size() . 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: A4TupleSet.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new tupleset as the union of this and that; this and that must be
 * come from the same solution. Note: if that==null, then the method returns
 * this A4TupleSet as-is.
 */
public A4TupleSet plus(A4TupleSet that) throws ErrorAPI {
    if (that == null)
        return this;
    if (sol != that.sol)
        throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets from the same A4Solution.");
    if (arity() != that.arity())
        throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets with the same arity.");
    if (this == that || tuples.size() == 0)
        return that;
    else if (that.tuples.size() == 0)
        return this; // special short cut
    TupleSet ts = tuples.clone();
    ts.addAll(that.tuples);
    if (tuples.size() == ts.size())
        return this;
    if (that.tuples.size() == ts.size())
        return that;
    return new A4TupleSet(ts, sol);
}
 
Example 2
Source File: A4TupleSet.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new tupleset as the subtraction of this and that; this and that
 * must be come from the same solution. Note: if that==null, then the method
 * returns this A4TupleSet as-is.
 */
public A4TupleSet minus(A4TupleSet that) throws ErrorAPI {
    if (that == null)
        return this;
    if (sol != that.sol)
        throw new ErrorAPI("A4TupleSet.minus() requires 2 tuplesets from the same A4Solution.");
    if (arity() != that.arity())
        throw new ErrorAPI("A4TupleSet.minus() requires 2 tuplesets with the same arity.");
    if (tuples.size() == 0 || that.tuples.size() == 0)
        return this; // special short cut
    TupleSet ts = tuples.clone();
    ts.removeAll(that.tuples);
    if (tuples.size() != ts.size())
        return new A4TupleSet(ts, sol);
    else
        return this;
}
 
Example 3
Source File: A4TupleSet.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new tupleset as the intersection of this and that; this and that
 * must be come from the same solution.
 */
public A4TupleSet intersect(A4TupleSet that) throws ErrorAPI {
    if (sol != that.sol)
        throw new ErrorAPI("A4TupleSet.intersect() requires 2 tuplesets from the same A4Solution.");
    if (arity() != that.arity())
        throw new ErrorAPI("A4TupleSet.intersect() requires 2 tuplesets with the same arity.");
    if (this.tuples.size() == 0)
        return this; // special short cut
    if (that.tuples.size() == 0)
        return that; // special short cut
    TupleSet ts = tuples.clone();
    ts.retainAll(that.tuples);
    if (tuples.size() != ts.size())
        return new A4TupleSet(ts, sol);
    else
        return this;
}
 
Example 4
Source File: BoundsComputer.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the lowerbound from bottom-up; it will also set a suitable initial
 * value for each sig's upperbound. Precondition: sig is not a builtin sig
 */
private TupleSet computeLowerBound(List<Tuple> atoms, final PrimSig sig) throws Err {
    int n = sc.sig2scope(sig);
    TupleSet lower = factory.noneOf(1);
    for (PrimSig c : sig.children())
        lower.addAll(computeLowerBound(atoms, c));
    TupleSet upper = lower.clone();
    boolean isExact = sc.isExact(sig);
    if (isExact || sig.isTopLevel())
        for (n = n - upper.size(); n > 0; n--) {
            Tuple atom = atoms.remove(atoms.size() - 1);
            // If MUST<SCOPE and s is exact, then add fresh atoms to both
            // LOWERBOUND and UPPERBOUND.
            // If MUST<SCOPE and s is inexact but toplevel, then add fresh
            // atoms to the UPPERBOUND.
            if (isExact)
                lower.add(atom);
            upper.add(atom);
        }
    lb.put(sig, lower);
    ub.put(sig, upper);
    return lower;
}
 
Example 5
Source File: SymmetryDetector.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns an array that contains unique non-empty tuplesets in the given bounds, 
 * sorted in the order of increasing size.
 * @return unique non-empty tuplesets in the given bounds, 
 * 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();
		}
	});
	return sorted;
}
 
Example 6
Source File: SymmetryDetector.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an array that contains unique non-empty tuplesets in the given
 * bounds, sorted in the order of increasing size.
 *
 * @return unique non-empty tuplesets in the given bounds, sorted in the order
 *         of increasing size.
 */
private TupleSet[] sort(Bounds bounds) {
    final List<TupleSet> sets = new ArrayList<TupleSet>(bounds.relations().size());
    for (Relation r : bounds.relations()) {
        if (r.isAtom() && ignoreAllAtomRelsExcept != null && !ignoreAllAtomRelsExcept.contains(r))
            continue;
        if (ignoreRels != null && ignoreRels.contains(r))
            continue;
        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>() {

        @Override
        public int compare(TupleSet o1, TupleSet o2) {
            return o1.size() - o2.size();
        }
    });
    return sorted;
}
 
Example 7
Source File: BenchmarkSymmStats2.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the size of the partial model (in bits)
 */
private static int pmBits(Bounds bounds) {
    int pm = 0;
    for (TupleSet lower : bounds.lowerBounds().values()) {
        pm += lower.size();
    }
    return pm;
}
 
Example 8
Source File: BenchmarkSymmStats.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the size of the partial model (in bits)
 */
private static int pmBits(Bounds bounds) {
    int pm = 0;
    for (TupleSet lower : bounds.lowerBounds().values()) {
        pm += lower.size();
    }
    return pm;
}