Java Code Examples for kodkod.instance.Instance#tuples()

The following examples show how to use kodkod.instance.Instance#tuples() . 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: Drivers.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static TupleSet check(UniverseFactory uf,
		Pair<Formula, Pair<Formula, Formula>> answer,
		String relation)
		throws URISyntaxException {
	Instance rels = check(uf, answer);
	if (rels != null) {
		for(Relation r : rels.relations()) {
			if (r.toString().equals(relation)) {
				return rels.tuples(r);
			}
		}
		return null;
	} else {
		return null;
	}
}
 
Example 2
Source File: TranslatorTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 3
Source File: TranslatorTest.java    From kodkod with MIT License 5 votes vote down vote up
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));
}
 
Example 4
Source File: HOLSome4AllTest.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
protected int evalS(Solution sol) {
    Instance inst = sol.instance();
    TupleSet x = inst.tuples(inst.skolems().iterator().next());
    return (Integer) x.iterator().next().atom(0);
}
 
Example 5
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFelix_02222008() {
    List<String> atomlist = Arrays.asList("X1", "X2", "X3");

    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);

    Relation x = Relation.unary("X");
    TupleSet x_upper = factory.noneOf(1);
    x_upper.add(factory.tuple("X1"));
    x_upper.add(factory.tuple("X2"));
    x_upper.add(factory.tuple("X3"));
    bounds.bound(x, x_upper);

    Variable a = Variable.unary("a");
    Variable b = Variable.unary("b");
    Variable c = Variable.unary("c");
    Formula goal = x.lone().not().and(b.union(c).eq(a).forSome(c.oneOf(x)).forAll(b.oneOf(x)).forSome(a.setOf(x)));

    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(0);
    solver.options().setSkolemDepth(2);

    Iterator<Solution> itr = solver.solveAll(goal, bounds);
    int sols = 0;
    while (itr.hasNext()) {
        Solution sol = itr.next();
        Instance inst = sol.instance();
        if (inst == null)
            break;
        sols++;

        for (Relation rel : inst.relations()) {
            if (rel != x) {
                if (rel.arity() == 1) { // rel = a
                    assertEquals(inst.tuples(x), inst.tuples(rel));
                } else { // rel = c
                    final TupleSet dom = factory.noneOf(1);
                    for (Tuple t : inst.tuples(rel)) {
                        dom.add(factory.tuple(t.atom(0)));
                    }
                    assertEquals(inst.tuples(x), dom);
                }
            }
        }
    }
    assertEquals(3, sols);
}
 
Example 6
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testFelix_02222008() {
	List<String> atomlist = Arrays.asList("X1", "X2", "X3");

	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	Relation x = Relation.unary("X");
	TupleSet x_upper = factory.noneOf(1);
	x_upper.add(factory.tuple("X1"));
	x_upper.add(factory.tuple("X2"));
	x_upper.add(factory.tuple("X3"));
	bounds.bound(x, x_upper);

	Variable a = Variable.unary("a");
	Variable b = Variable.unary("b");
	Variable c = Variable.unary("c");
	Formula goal = x.lone().not().and(b.union(c).eq(a).forSome(c.oneOf(x)).forAll(b.oneOf(x)).forSome(a.setOf(x)));

	Solver solver = new Solver();
	solver.options().setSolver(SATFactory.DefaultSAT4J);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
	solver.options().setSymmetryBreaking(0);
	solver.options().setSkolemDepth(2);

	Iterator<Solution> itr = solver.solveAll(goal, bounds);
	int sols = 0;
	while(itr.hasNext()) {
		Solution sol = itr.next();
		Instance inst = sol.instance();
		if (inst==null) break;
		sols++;

		for(Relation rel : inst.relations()) { 
			if (rel!=x) {
				if( rel.arity()==1) { // rel = a
					assertEquals(inst.tuples(x), inst.tuples(rel));
				} else { // rel = c
					final TupleSet dom = factory.noneOf(1);
					for(Tuple t : inst.tuples(rel)) { 
						dom.add(factory.tuple(t.atom(0)));
					}
					assertEquals(inst.tuples(x), dom);
				}
			}
		}
	}
	assertEquals(3, sols);
}