Java Code Examples for kodkod.ast.Variable#nary()

The following examples show how to use kodkod.ast.Variable#nary() . 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: TranslatorTest.java    From kodkod with MIT License 6 votes vote down vote up
@Test
public final void testTranslateProjection() {
	
	assertTrue(isSatisfiable(r3[0].eq(
			r2[0].project(IntConstant.constant(0), IntConstant.constant(1), IntConstant.constant(0)))));
	
	assertTrue(isSatisfiable(r2[1].in(r3[0].project(r1[3].count(), r1[2].count()))));

	final Variable v = Variable.nary("r", 2);
	assertFalse(isSatisfiable(v.transpose().
			eq(v.project(IntConstant.constant(1), IntConstant.constant(0))).not().
			forSome(v.setOf(r2[0]))));
	
	bounds.boundExactly(r3[0], bounds.upperBound(r3[0]));
	bounds.boundExactly(r2[0], bounds.upperBound(r2[0]));
	
	assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(1)).eq(r2[0])));
	assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(4), IntConstant.constant(2)).
			eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
	assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(-1), IntConstant.constant(2)).
			eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
	
}
 
Example 2
Source File: TranslatorTest.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testTranslateProjection() {

        assertTrue(isSatisfiable(r3[0].eq(r2[0].project(IntConstant.constant(0), IntConstant.constant(1), IntConstant.constant(0)))));

        assertTrue(isSatisfiable(r2[1].in(r3[0].project(r1[3].count(), r1[2].count()))));

        final Variable v = Variable.nary("r", 2);
        assertFalse(isSatisfiable(v.transpose().eq(v.project(IntConstant.constant(1), IntConstant.constant(0))).not().forSome(v.setOf(r2[0]))));

        bounds.boundExactly(r3[0], bounds.upperBound(r3[0]));
        bounds.boundExactly(r2[0], bounds.upperBound(r2[0]));

        assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(1)).eq(r2[0])));
        assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(4), IntConstant.constant(2)).eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
        assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(-1), IntConstant.constant(2)).eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));

    }
 
Example 3
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFelix_06192008() {
    Relation x5 = Relation.unary("R");

    List<String> atomlist = Arrays.asList("X");

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

    TupleSet x5_upper = factory.noneOf(1);
    x5_upper.add(factory.tuple("X"));
    bounds.bound(x5, x5_upper);

    Variable x10 = Variable.unary("a");
    Expression x11 = x5.difference(x5);
    Decls x9 = x10.oneOf(x11);
    Variable x14 = Variable.nary("b", 2);
    Expression x15 = x5.product(x5);
    Decls x13 = x14.setOf(x15);
    Expression x19 = x5.product(x5);
    Formula x17 = x14.in(x19);
    Expression x22 = x10.product(x10);
    Formula x21 = x22.eq(x14);
    Formula x16 = x17.and(x21);
    Formula x12 = x16.forSome(x13);
    Formula x7 = x12.forAll(x9);

    // System.out.println(x7);

    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    // solver.options().setFlatten(false);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(20);

    // System.out.println("Depth=0..."); System.out.flush();
    solver.options().setSkolemDepth(0);
    assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome());

    // System.out.println("Depth=1..."); System.out.flush();
    solver.options().setSkolemDepth(1);
    final Solution sol = solver.solve(x7, bounds);
    assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome());
    assertEquals(2, sol.instance().relations().size());
    for (Relation r : sol.instance().relations()) {
        assertTrue(sol.instance().tuples(r).isEmpty());
    }
}
 
Example 4
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testFelix_06192008() {
	Relation x5 = Relation.unary("R");

	List<String> atomlist = Arrays.asList("X");

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

	TupleSet x5_upper = factory.noneOf(1);
	x5_upper.add(factory.tuple("X"));
	bounds.bound(x5, x5_upper);

	Variable x10=Variable.unary("a");
	Expression x11=x5.difference(x5);
	Decls x9=x10.oneOf(x11);
	Variable x14=Variable.nary("b",2);
	Expression x15=x5.product(x5);
	Decls x13=x14.setOf(x15);
	Expression x19=x5.product(x5);
	Formula x17=x14.in(x19);
	Expression x22=x10.product(x10);
	Formula x21=x22.eq(x14);
	Formula x16=x17.and(x21);
	Formula x12=x16.forSome(x13);
	Formula x7= x12.forAll(x9);

	//		System.out.println(x7);

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

	//		System.out.println("Depth=0..."); System.out.flush();
	solver.options().setSkolemDepth(0);
	assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome());

	//		System.out.println("Depth=1..."); System.out.flush();
	solver.options().setSkolemDepth(1);
	final Solution sol = solver.solve(x7, bounds);
	assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome());
	assertEquals(2, sol.instance().relations().size());
	for(Relation r : sol.instance().relations()) { 
		assertTrue(sol.instance().tuples(r).isEmpty());
	}
}