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

The following examples show how to use kodkod.instance.TupleSet#arity() . 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: A4Solution.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new relation with the given label and the given lower and upper bound.
 *
 * @param label - the label for the new relation; need not be unique
 * @param lower - the lowerbound; can be null if you want it to be the empty set
 * @param upper - the upperbound; cannot be null; must contain everything in
 *            lowerbound
 */
Relation addRel(String label, TupleSet lower, TupleSet upper) throws ErrorFatal {
    if (solved)
        throw new ErrorFatal("Cannot add a Kodkod relation since solve() has completed.");
    Relation rel = Relation.nary(label, upper.arity());
    if (lower == upper) {
        bounds.boundExactly(rel, upper);
    } else if (lower == null) {
        bounds.bound(rel, upper);
    } else {
        if (lower.arity() != upper.arity())
            throw new ErrorFatal("Relation " + label + " must have same arity for lowerbound and upperbound.");
        bounds.bound(rel, lower, upper);
    }
    return rel;
}
 
Example 2
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** Print the tupleset using the name n. */
private void printTupleset(String n, TupleSet ts, Map<Object,String> atomMap) {
    file.printf("TupleSet %s = factory.noneOf(%d);%n", n, ts.arity());
    for (Tuple t : ts) {
        file.printf("%s.add(", n);
        for (int i = 0; i < ts.arity(); i++) {
            if (i != 0)
                file.printf(".product(");
            Object a = t.atom(i);
            String b = atomMap == null ? null : atomMap.get(a);
            file.printf("factory.tuple(\"%s\")", (b == null ? a.toString() : b));
            if (i != 0)
                file.printf(")");
        }
        file.printf(");%n");
    }
}
 
Example 3
Source File: ListEncoding.java    From kodkod with MIT License 5 votes vote down vote up
TupleSet copyFrom(TupleFactory tf, TupleSet other) {
	final int arity = other.arity();
	final TupleSet out = tf.noneOf(arity);
	final Object[] tmp = new Object[arity];
	for(Tuple t : other) { 
		for(int i = 0; i < arity; i++) {
			tmp[i] = t.atom(i);
		}
		out.add(tf.tuple((Object[])tmp));
	}
	return out;
}