use of kodkod.instance.Tuple in project org.alloytools.alloy by AlloyTools.
the class EvaluatorTest method testEvalProduct.
public final void testEvalProduct() {
// Hilary->Jocelyn = Hilary->Jocelyn
final Set<Tuple> hilaryAndJocelyn = eval(hilary.product(jocelyn));
final Tuple hj = hilaryAndJocelyn.iterator().next();
assertEquals(hilaryAndJocelyn.size(), 1);
assertEquals(hj.atom(0), value(hilary).iterator().next().atom(0));
assertEquals(hj.atom(1), value(jocelyn).iterator().next().atom(0));
// Person->(spouse->shaken) = (Person->spouse)->shaken
assertEquals(eval(person.product(spouse.product(shaken))), eval(person.product(spouse).product(shaken)));
// Person->(spouse + shaken) = Person->spouse + Person->shaken
assertEquals(eval(person.product(spouse.union(shaken))), eval(person.product(spouse).union(person.product(shaken))));
// arity(spouse->shaken) = 4
assertEquals(spouse.product(shaken).arity(), 4);
}
use of kodkod.instance.Tuple in project org.alloytools.alloy by AlloyTools.
the class BenchmarkSymmStats2 method toNauty.
private static void toNauty(Bounds bounds, PrintStream stream) {
int size = bounds.universe().size() + bounds.ints().size();
for (Relation r : bounds.relations()) {
final int upsize = bounds.upperBound(r).size(), lowsize = bounds.lowerBound(r).size();
size += (upsize == lowsize ? upsize : upsize + lowsize) * r.arity();
}
stream.println("n=" + size + " $0 *=13 k = 0 " + size + " +d -a g");
int v = bounds.universe().size();
final IntVector vec = new ArrayIntVector();
vec.add(v);
for (Relation r : bounds.relations()) {
final int arity = r.arity();
final TupleSet up = bounds.upperBound(r), down = bounds.lowerBound(r);
final TupleSet[] sets = up.size() == down.size() || down.size() == 0 ? new TupleSet[] { up } : new TupleSet[] { down, up };
for (TupleSet s : sets) {
for (Tuple t : s) {
for (int i = 0, max = arity - 1; i < max; i++) {
stream.println(v + " : " + (v + 1) + " " + t.atomIndex(i) + ";");
v++;
}
stream.println(v + " : " + t.atomIndex(arity - 1) + ";");
v++;
}
vec.add(v);
}
}
for (TupleSet s : bounds.intBounds().values()) {
stream.println(v + " : " + s.iterator().next().atomIndex(0) + ";");
v++;
vec.add(v);
}
// stream.println(".");
stream.print("f = [ 0:" + (vec.get(0) - 1));
for (int i = 1; i < vec.size(); i++) {
stream.print(" | " + vec.get(i - 1) + ":" + (vec.get(i) - 1));
}
stream.println(" ]");
stream.println("x");
stream.println("o");
stream.println("q");
}
use of kodkod.instance.Tuple in project org.alloytools.alloy by AlloyTools.
the class TranslatorTest method testIntersectionMultiplicity.
private final void testIntersectionMultiplicity(Multiplicity mult, Relation p, Relation q, Tuple intersection) {
final Instance m = solve(p.intersection(q).apply(mult));
assertNotNull(m);
final Set<Tuple> ps = m.tuples(p), qs = m.tuples(q);
assertFalse(ps.isEmpty());
assertFalse(qs.isEmpty());
assertTrue(ps.contains(intersection));
assertTrue(qs.contains(intersection));
}
Aggregations