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

The following examples show how to use kodkod.instance.TupleSet#addAll() . 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: 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 3
Source File: ALG197.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the bounds the problem (axioms 1, 4, 9-11, last formula of 14-15, and
 * first formula of 16-22).
 *
 * @return the bounds for the problem
 */
@Override
public final Bounds bounds() {
    final Bounds b = super.bounds();
    final TupleFactory f = b.universe().factory();

    final TupleSet op1h = b.upperBound(op1).clone();
    final TupleSet op2h = b.upperBound(op2).clone();

    final TupleSet op1l = f.setOf(f.tuple("e16", "e16", "e15")); // axiom
                                                                // 14,
                                                                // line
                                                                // 6
    final TupleSet op2l = f.setOf(f.tuple("e26", "e26", "e25")); // axiom
                                                                // 15,
                                                                // line
                                                                // 6

    op1h.removeAll(f.area(f.tuple("e16", "e16", "e10"), f.tuple("e16", "e16", "e16")));
    op1h.addAll(op1l);

    op2h.removeAll(f.area(f.tuple("e26", "e26", "e20"), f.tuple("e26", "e26", "e26")));
    op2h.addAll(op2l);

    b.bound(op1, op1l, op1h);
    b.bound(op2, op2l, op2h);

    final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e15", "e26"));

    // first line of axioms 16-22
    for (int i = 0; i < 7; i++) {
        Tuple t = f.tuple("e16", "e2" + i);
        high.add(t);
        b.bound(h[i], f.setOf(t), high);
        high.remove(t);
    }

    return b;
}
 
Example 4
Source File: BoundsComputer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/** Allocate relations for SubsetSig top-down. */
private Expression allocateSubsetSig(SubsetSig sig) throws Err {
    // We must not visit the same SubsetSig more than once, so if we've been
    // here already, then return the old value right away
    Expression sum = sol.a2k(sig);
    if (sum != null && sum != Expression.NONE)
        return sum;
    // Recursively form the union of all parent expressions
    TupleSet ts = factory.noneOf(1);
    for (Sig parent : sig.parents) {
        Expression p = (parent instanceof PrimSig) ? sol.a2k(parent) : allocateSubsetSig((SubsetSig) parent);
        ts.addAll(sol.query(true, p, false));
        if (sum == null)
            sum = p;
        else
            sum = sum.union(p);
    }
    // If subset is exact, then just use the "sum" as is
    if (sig.exact) {
        sol.addSig(sig, sum);
        return sum;
    }
    // Allocate a relation for this subset sig, then bound it
    rep.bound("Sig " + sig + " in " + ts + "\n");
    Relation r = sol.addRel(sig.label, null, ts);
    sol.addSig(sig, r);
    // Add a constraint that it is INDEED a subset of the union of its
    // parents
    sol.addFormula(r.in(sum), sig.isSubset);
    return r;
}
 
Example 5
Source File: ALG197.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the bounds the problem (axioms 1, 4, 9-11, last formula of 14-15, and first formula of 16-22).
 * @return the bounds for the problem
 */
public final Bounds bounds() {
	final Bounds b = super.bounds();
	final TupleFactory f = b.universe().factory();
	
	final TupleSet op1h = b.upperBound(op1).clone();
	final TupleSet op2h = b.upperBound(op2).clone();
	
	final TupleSet op1l = f.setOf(f.tuple("e16", "e16", "e15")); // axiom 14, line 6
	final TupleSet op2l = f.setOf(f.tuple("e26", "e26", "e25")); // axiom 15, line 6
	
	op1h.removeAll(f.area(f.tuple("e16", "e16", "e10"), f.tuple("e16", "e16", "e16")));
	op1h.addAll(op1l);
	
	op2h.removeAll(f.area(f.tuple("e26", "e26", "e20"), f.tuple("e26", "e26", "e26")));
	op2h.addAll(op2l);
	
	b.bound(op1, op1l, op1h);
	b.bound(op2, op2l, op2h);
	
	final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e15", "e26"));
	
	// first line of axioms 16-22
	for(int i = 0; i < 7; i++) {
		Tuple t = f.tuple("e16", "e2"+i);
		high.add(t);
		b.bound(h[i], f.setOf(t), high);
		high.remove(t);
	}
	
	return b;
}
 
Example 6
Source File: ALG195.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the bounds the problem (axioms 1, 4, 9-13, second formula of 14-15, and first formula of 16-22).
 * @return the bounds for the problem
 */
public final Bounds bounds() {
	final Bounds b = super.bounds();
	final TupleFactory f = b.universe().factory();
	
	final TupleSet op1h = b.upperBound(op1).clone();
	final TupleSet op2h = b.upperBound(op2).clone();
	
	for(int i = 0; i < 7; i++) {
		op1h.remove(f.tuple("e1"+i, "e1"+i, "e1"+i)); // axiom 12
		op2h.remove(f.tuple("e2"+i, "e2"+i, "e2"+i)); // axiom 13
	}
	
	final TupleSet op1l = f.setOf(f.tuple("e15", "e15", "e11")); // axiom 14, line 2
	final TupleSet op2l = f.setOf(f.tuple("e25", "e25", "e21")); // axiom 15, line 2
	
	op1h.removeAll(f.area(f.tuple("e15", "e15", "e10"), f.tuple("e15", "e15", "e16")));
	op1h.addAll(op1l);
	
	op2h.removeAll(f.area(f.tuple("e25", "e25", "e20"), f.tuple("e25", "e25", "e26")));
	op2h.addAll(op2l);
	
	b.bound(op1, op1l, op1h);
	b.bound(op2, op2l, op2h);
	
	final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e14", "e26"));
	high.addAll(f.area(f.tuple("e16", "e20"), f.tuple("e16", "e26")));
	
	// first line of axioms 16-22
	for(int i = 0; i < 7; i++) {
		Tuple t = f.tuple("e15", "e2"+i);
		high.add(t);
		b.bound(h[i], f.setOf(t), high);
		high.remove(t);
	}
	
	return b;
}
 
Example 7
Source File: GroupScheduling.java    From kodkod with MIT License 5 votes vote down vote up
public Bounds bounds() {
	final int p = ng*ng, r = ng + 1;
	final List<String> a = new ArrayList<String>((ng+1)*(ng+1));
	for(int i = 0; i < p; i++) { 
		a.add("p"+i);
	}
	for(int i = 0; i < ng; i++) { 
		a.add("g"+i);
	}
	for(int i = 0; i < r; i++) { 
		a.add("r"+i);
	}
	final Universe u = new Universe(a);
	final TupleFactory f = u.factory();
	final Bounds b = new Bounds(u);
	b.boundExactly(person, f.range(f.tuple("p0"), f.tuple("p" + (p-1))));
	b.boundExactly(group, f.range(f.tuple("g0"), f.tuple("g" + (ng-1))));
	b.boundExactly(round, f.range(f.tuple("r0"), f.tuple("r" + (r-1))));
	b.bound(assign, b.upperBound(person).product(b.upperBound(round)).product(b.upperBound(group)));
	final TupleSet low = f.noneOf(3);
	for(int i = 0; i < r; i++) {
		low.add(f.tuple("p0", "r"+i, "g0"));
		final int start = i*(ng-1) + 1, end = (i+1)*(ng-1);
		low.addAll(f.range(f.tuple("p"+start), f.tuple("p"+end)).product(f.setOf("r"+i)).product(f.setOf("g0")));
	}
	final TupleSet high = f.noneOf(3);
	high.addAll(low);
	high.addAll(f.range(f.tuple("p1"), f.tuple("p" + (p-1))).product(b.upperBound(round)).product(b.upperBound(group)));
	b.bound(assign, low, high);
	return b;
}
 
Example 8
Source File: ALG195.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the bounds the problem (axioms 1, 4, 9-13, second formula of 14-15,
 * and first formula of 16-22).
 *
 * @return the bounds for the problem
 */
@Override
public final Bounds bounds() {
    final Bounds b = super.bounds();
    final TupleFactory f = b.universe().factory();

    final TupleSet op1h = b.upperBound(op1).clone();
    final TupleSet op2h = b.upperBound(op2).clone();

    for (int i = 0; i < 7; i++) {
        op1h.remove(f.tuple("e1" + i, "e1" + i, "e1" + i)); // axiom 12
        op2h.remove(f.tuple("e2" + i, "e2" + i, "e2" + i)); // axiom 13
    }

    final TupleSet op1l = f.setOf(f.tuple("e15", "e15", "e11")); // axiom
                                                                // 14,
                                                                // line
                                                                // 2
    final TupleSet op2l = f.setOf(f.tuple("e25", "e25", "e21")); // axiom
                                                                // 15,
                                                                // line
                                                                // 2

    op1h.removeAll(f.area(f.tuple("e15", "e15", "e10"), f.tuple("e15", "e15", "e16")));
    op1h.addAll(op1l);

    op2h.removeAll(f.area(f.tuple("e25", "e25", "e20"), f.tuple("e25", "e25", "e26")));
    op2h.addAll(op2l);

    b.bound(op1, op1l, op1h);
    b.bound(op2, op2l, op2h);

    final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e14", "e26"));
    high.addAll(f.area(f.tuple("e16", "e20"), f.tuple("e16", "e26")));

    // first line of axioms 16-22
    for (int i = 0; i < 7; i++) {
        Tuple t = f.tuple("e15", "e2" + i);
        high.add(t);
        b.bound(h[i], f.setOf(t), high);
        high.remove(t);
    }

    return b;
}