Search in sources :

Example 16 with Tuple

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);
}
Also used : Tuple(kodkod.instance.Tuple)

Example 17 with Tuple

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");
}
Also used : ArrayIntVector(kodkod.util.ints.ArrayIntVector) TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) IntVector(kodkod.util.ints.IntVector) ArrayIntVector(kodkod.util.ints.ArrayIntVector) Tuple(kodkod.instance.Tuple)

Example 18 with Tuple

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));
}
Also used : Instance(kodkod.instance.Instance) Tuple(kodkod.instance.Tuple)

Aggregations

Tuple (kodkod.instance.Tuple)18 TupleSet (kodkod.instance.TupleSet)12 Relation (kodkod.ast.Relation)8 TupleFactory (kodkod.instance.TupleFactory)8 Bounds (kodkod.instance.Bounds)6 Instance (kodkod.instance.Instance)5 Solution (kodkod.engine.Solution)4 Universe (kodkod.instance.Universe)4 Sig (edu.mit.csail.sdg.ast.Sig)3 ArrayList (java.util.ArrayList)3 Formula (kodkod.ast.Formula)3 Evaluator (kodkod.engine.Evaluator)3 Field (edu.mit.csail.sdg.ast.Sig.Field)2 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)2 Type (edu.mit.csail.sdg.ast.Type)2 Expression (kodkod.ast.Expression)2 Variable (kodkod.ast.Variable)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 ConstList (edu.mit.csail.sdg.alloy4.ConstList)1 ConstMap (edu.mit.csail.sdg.alloy4.ConstMap)1