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

The following examples show how to use kodkod.ast.Relation#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: 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: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testFelix_05072008() { 
	Relation A=Relation.unary("A"), first=Relation.unary("OrdFirst"), last=Relation.unary("OrdLast"), next=Relation.nary("OrdNext", 2);

	List<String> atomlist = Arrays.asList("A1", "A2", "A3");
	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	TupleSet all = factory.setOf("A1","A2","A3");
	bounds.boundExactly(A, all);
	bounds.bound(first, all);
	bounds.bound(last, all);
	bounds.bound(next, all.product(all));

	Formula form = next.totalOrder(A,first,last);

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

	Iterator<Solution> sol = solver.solveAll(form, bounds);
	assertTrue(sol.hasNext());
	assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
	assertTrue(sol.hasNext());
	assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
	assertFalse(sol.hasNext());

	//		int i=1;
	//		
	//		while (sol.hasNext()) {
	//			System.out.println("================================== "+i+" ===================================");
	//		  System.out.println(sol.next());
	//		  System.out.flush();
	//		  i++;
	//		}
}
 
Example 3
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testFelix_01062007() {
	Relation x1 = Relation.nary("A",1);
	List<String> atomlist = Arrays.asList("A");
	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	TupleSet x1_upper = factory.noneOf(1);
	x1_upper.add(factory.tuple("A"));
	bounds.bound(x1, x1_upper);

	Solver solver = new Solver();
	solver.options().setSolver(SATFactory.MiniSat);

	Iterator<Solution> sols = solver.solveAll(Formula.TRUE, bounds);
	assertNotNull(sols.next().instance());

	assertNotNull(sols.next().instance());

	assertNull(sols.next().instance());

	//		Solution sol1=sols.next();
	//		System.out.println("Solution1:"+sol1.instance());
	//
	//		Solution sol2=sols.next();
	//		System.out.println("Solution2:"+sol2.instance());
	//
	//		Solution sol3=sols.next();
	//		System.out.println("Solution3:"+sol3.instance());

}
 
Example 4
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testFelix_05152007_3() {
	Relation x5 = Relation.nary("A", 1);

	List<String> atomlist = Arrays.asList("A[0]", "A[1]", "A[2]");

	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("A[0]"));
	x5_upper.add(factory.tuple("A[1]"));
	x5_upper.add(factory.tuple("A[2]"));

	bounds.bound(x5, x5_upper);

	Formula a=x5.some();
	Formula a1 = x5.no();
	Formula b=a1.and(Formula.TRUE.and(Formula.TRUE));
	Formula c=a.and(b);

	Solver solver = new Solver();

	solver.options().setLogTranslation(1);
	solver.options().setSolver(SATFactory.DefaultSAT4J);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

	Solution sol = solver.solve(c,bounds);
	Set<Formula> core = Nodes.minRoots(c, sol.proof().highLevelCore().values());

	assertEquals(2, core.size());
	assertTrue(core.contains(a));
	assertTrue(core.contains(a1));


}
 
Example 5
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testFelix_05152007_2() {
    Relation x5 = Relation.nary("A", 1);

    List<String> atomlist = Arrays.asList("A0", "A1", "A2");

    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("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));

    bounds.bound(x5, x5_upper);

    Formula x7 = x5.eq(x5).not();

    Solver solver = new Solver();

    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

    Solution sol = solver.solve(x7, bounds);
    Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
    assertEquals(1, core.size());
    assertTrue(core.contains(x7));
}
 
Example 6
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testFelix_05152007_1() {
    Relation x5 = Relation.nary("A", 1);

    List<String> atomlist = Arrays.asList("A0", "A1", "A2");

    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("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));

    bounds.bound(x5, x5_upper);

    Formula x7 = x5.some();
    Formula x8 = x5.no();

    Formula x6 = x7.and(x8);

    Solver solver = new Solver();
    solver.options().setLogTranslation(1);

    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

    Solution sol = solver.solve(x6, bounds);

    // System.out.println("Sol="+sol);

    Set<Formula> core = Nodes.minRoots(x6, sol.proof().highLevelCore().values());
    assertEquals(2, core.size());
    assertTrue(core.contains(x7));
    assertTrue(core.contains(x8));

}
 
Example 7
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testFelix_01062007() {
    Relation x1 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);

    TupleSet x1_upper = factory.noneOf(1);
    x1_upper.add(factory.tuple("A"));
    bounds.bound(x1, x1_upper);

    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);

    Iterator<Solution> sols = solver.solveAll(Formula.TRUE, bounds);
    assertNotNull(sols.next().instance());

    assertNotNull(sols.next().instance());

    assertNull(sols.next().instance());

    // Solution sol1=sols.next();
    // System.out.println("Solution1:"+sol1.instance());
    //
    // Solution sol2=sols.next();
    // System.out.println("Solution2:"+sol2.instance());
    //
    // Solution sol3=sols.next();
    // System.out.println("Solution3:"+sol3.instance());

}
 
Example 8
Source File: Solver.java    From kodkod with MIT License 4 votes vote down vote up
/**
 * Returns the trivial solution corresponding to the trivial translation stored in {@code this.translation},
 * and if {@code this.translation.cnf.solve()} is true, sets {@code this.translation} to a new translation 
 * that eliminates the current trivial solution from the set of possible solutions.  The latter has the effect 
 * of forcing either the translator or the solver to come up with the next solution or return UNSAT.
 * If {@code this.translation.cnf.solve()} is false, sets {@code this.translation} to null.
 * @requires this.translation != null
 * @ensures this.translation is modified to eliminate the current trivial solution from the set of possible solutions
 * @return current solution
 */
private Solution nextTrivialSolution() {
	final Translation.Whole transl = this.translation;
	
	final Solution sol = trivial(transl, translTime); // this also frees up solver resources, if unsat
	
	if (sol.instance()==null) {
		translation = null; // unsat, no more solutions
	} else {
		trivial++;
		
		final Bounds bounds = transl.bounds();
		final Bounds newBounds = bounds.clone();
		final List<Formula> changes = new ArrayList<Formula>();

		for(Relation r : bounds.relations()) {
			final TupleSet lower = bounds.lowerBound(r); 
			
			if (lower != bounds.upperBound(r)) { // r may change
				if (lower.isEmpty()) { 
					changes.add(r.some());
				} else {
					final Relation rmodel = Relation.nary(r.name()+"_"+trivial, r.arity());
					newBounds.boundExactly(rmodel, lower);	
					changes.add(r.eq(rmodel).not());
				}
			}
		}
		
		// nothing can change => there can be no more solutions (besides the current trivial one).
		// note that transl.formula simplifies to the constant true with respect to 
		// transl.bounds, and that newBounds is a superset of transl.bounds.
		// as a result, finding the next instance, if any, for transl.formula.and(Formula.or(changes)) 
		// with respect to newBounds is equivalent to finding the next instance of Formula.or(changes) alone.
		final Formula formula = changes.isEmpty() ? Formula.FALSE : Formula.or(changes);
		
		final long startTransl = System.currentTimeMillis();
		translation = Translator.translate(formula, newBounds, transl.options());
		translTime += System.currentTimeMillis() - startTransl;
	} 
	return sol;
}
 
Example 9
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testBGP_03172011() {

	Relation x5 = Relation.unary("s012");
	Relation x8 = Relation.unary("zero");
	Relation x9 = Relation.unary("one");
	Relation x12 = Relation.nary("next", 2);

	Universe universe = new Universe(Arrays.asList( "0", "1", "2", "3"));
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	bounds.boundExactly(x5, factory.setOf("0","1","2"));
	bounds.boundExactly(x8, factory.setOf("0"));
	bounds.bound(x9, factory.setOf("1"), factory.setOf("1","2"));

	TupleSet x12_upper = factory.noneOf(2);
	x12_upper.add(factory.tuple("1","2"));
	x12_upper.add(factory.tuple("2","3"));
	bounds.boundExactly(x12, x12_upper);


	Variable x714 = Variable.unary("x714");
	Decls x713 =  x714.oneOf(x8.union(x9));

	Variable x720 = Variable.unary("x720");
	Expression x723 = x8.union(x9);
	Expression x724 = x9.join(x12);
	Expression x722 = x723.union(x724); 
	Expression x721 = x722.difference(x714);
	Decls x719 = x720.oneOf(x721);

	Variable x727 = Variable.unary("x727");
	Expression x732 = x714.union(x720);
	Expression x728 = x5.difference(x732);
	Decls x726 = x727.oneOf(x728);

	Variable x735 = Variable.unary("x735");
	Decls x734 = x735.oneOf(x8);

	Variable x893 = Variable.unary("x893");
	Decls x892 = x893.oneOf(x727);
	Formula x894 = x720.no();
	Formula x891 = x894.forAll(x892);

	Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734));
	Formula x267 = Formula.FALSE.or(x712); 

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

	final Solution sol = solver.solve(x267, bounds);
	assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
}
 
Example 10
Source File: Toughnut.java    From kodkod with MIT License 4 votes vote down vote up
/**
 * Creates an instance of Toughnut.
 */
public Toughnut() {
	this.Cell = Relation.unary("Cell");
	this.covered = Relation.nary("covered", 4);
	this.ord = Relation.binary("ord");
}
 
Example 11
Source File: ALG212.java    From kodkod with MIT License 4 votes vote down vote up
/**
 * Constructs a new instance of ALG212.
 */
public ALG212() {
	f = Relation.nary("f", 4);
}
 
Example 12
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testFelix_03162009() {
	Relation x = Relation.unary("X");
	Relation y = Relation.unary("Y");
	Relation q = Relation.unary("Q");
	Relation f = Relation.nary("f", 2);

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

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

	TupleSet x_upper = factory.noneOf(1);
	x_upper.add(factory.tuple("X"));
	bounds.boundExactly(x, x_upper);

	TupleSet y_upper = factory.noneOf(1);
	y_upper.add(factory.tuple("Y"));
	bounds.boundExactly(y, y_upper);

	TupleSet q_upper = factory.noneOf(1);
	q_upper.add(factory.tuple("X"));
	q_upper.add(factory.tuple("Y"));
	bounds.bound(q, q_upper);

	TupleSet f_upper = factory.noneOf(2);
	f_upper.add(factory.tuple("X").product(factory.tuple("X")));
	f_upper.add(factory.tuple("X").product(factory.tuple("Y")));
	f_upper.add(factory.tuple("Y").product(factory.tuple("X")));
	f_upper.add(factory.tuple("Y").product(factory.tuple("Y")));
	bounds.bound(f, f_upper);

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

	Expression test = f.override(q.product(y));
	TupleSet approx = factory.setOf(test.arity(), Translator.approximate(test, bounds, solver.options()).denseIndices());
	assertEquals(f_upper, approx);
}
 
Example 13
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testEmina_05072008() {
	Relation A=Relation.unary("A"), first=Relation.unary("OrdFirst"), last=Relation.unary("OrdLast"), next=Relation.nary("OrdNext", 2);
	Relation B=Relation.unary("B"), acyclic = Relation.binary("acyclic");

	List<String> atomlist = Arrays.asList("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2");
	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	TupleSet allA = factory.setOf("A1","A2","A3");
	TupleSet allB = factory.setOf("B1","B2","B3");
	TupleSet allC = factory.setOf("C1", "C2");
	bounds.boundExactly(A, allA);
	bounds.bound(first, allA);
	bounds.bound(last, allA);
	bounds.bound(next, allA.product(allA));
	bounds.boundExactly(B, allB);
	bounds.bound(acyclic, allC.product(allC));

	Variable v = Variable.unary("v");
	Formula f0 = Formula.TRUE.forSome(v.setOf(B));
	Formula f1 = next.totalOrder(A, first, last);
	Formula f2 = acyclic.acyclic();
	Formula form = f0.and(f1).and(f2);

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

	Iterator<Solution> sol = solver.solveAll(form, bounds);
	int i=1;

	while (sol.hasNext()) {
		assertTrue(i <= 17);
		sol.next();
		i++;
	}
}
 
Example 14
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFelix_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"),
                    next = Relation.nary("OrdNext", 2);

    List<String> atomlist = Arrays.asList("A1", "A2", "A3");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);

    TupleSet all = factory.setOf("A1", "A2", "A3");
    bounds.boundExactly(A, all);
    bounds.bound(first, all);
    bounds.bound(last, all);
    bounds.bound(next, all.product(all));

    Formula form = next.totalOrder(A, first, last);

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

    Iterator<Solution> sol = solver.solveAll(form, bounds);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
    assertFalse(sol.hasNext());

    // int i=1;
    //
    // while (sol.hasNext()) {
    // System.out.println("================================== "+i+"
    // ===================================");
    // System.out.println(sol.next());
    // System.out.flush();
    // i++;
    // }
}
 
Example 15
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFelix_03162009() {
    Relation x = Relation.unary("X");
    Relation y = Relation.unary("Y");
    Relation q = Relation.unary("Q");
    Relation f = Relation.nary("f", 2);

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

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

    TupleSet x_upper = factory.noneOf(1);
    x_upper.add(factory.tuple("X"));
    bounds.boundExactly(x, x_upper);

    TupleSet y_upper = factory.noneOf(1);
    y_upper.add(factory.tuple("Y"));
    bounds.boundExactly(y, y_upper);

    TupleSet q_upper = factory.noneOf(1);
    q_upper.add(factory.tuple("X"));
    q_upper.add(factory.tuple("Y"));
    bounds.bound(q, q_upper);

    TupleSet f_upper = factory.noneOf(2);
    f_upper.add(factory.tuple("X").product(factory.tuple("X")));
    f_upper.add(factory.tuple("X").product(factory.tuple("Y")));
    f_upper.add(factory.tuple("Y").product(factory.tuple("X")));
    f_upper.add(factory.tuple("Y").product(factory.tuple("Y")));
    bounds.bound(f, f_upper);

    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);
    solver.options().setSkolemDepth(0);

    Expression test = f.override(q.product(y));
    TupleSet approx = factory.setOf(test.arity(), Translator.approximate(test, bounds, solver.options()).denseIndices());
    assertEquals(f_upper, approx);
}
 
Example 16
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testFelix_11122006() {
	Relation x0 = Relation.nary("Q", 1);
	Relation x1 = Relation.nary("B", 1);
	Relation x2 = Relation.nary("A", 1);
	Relation x3 = Relation.nary("QQ", 3);

	List<String> atomlist = Arrays.asList("A", "B", "Q");
	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	TupleSet x0_upper = factory.noneOf(1);
	x0_upper.add(factory.tuple("Q"));
	bounds.boundExactly(x0, x0_upper);

	TupleSet x1_upper = factory.noneOf(1);
	x1_upper.add(factory.tuple("B"));
	bounds.boundExactly(x1, x1_upper);

	TupleSet x2_upper = factory.noneOf(1);
	x2_upper.add(factory.tuple("A"));
	bounds.boundExactly(x2, x2_upper);

	TupleSet x3_upper = factory.noneOf(3);
	x3_upper.add(factory.tuple("Q").product(factory.tuple("A")).product(factory.tuple("A")));
	x3_upper.add(factory.tuple("Q").product(factory.tuple("B")).product(factory.tuple("B")));
	bounds.bound(x3, x3_upper);

	Expression x7=x2.product(x2);
	Expression x8=x0.join(x3);
	Formula x6=x7.in(x8);
	Formula x5=x6.not();

	Expression x18=x1.product(x1);
	Expression x17=x7.union(x18);
	Expression x16=x0.product(x17);

	Formula x15=x3.in(x16);
	Formula x4=x5.and(x15);

	Solver solver = new Solver();

	solver.options().setSolver(SATFactory.DefaultSAT4J);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

	//		System.out.println(bounds);
	//		System.out.println(x4);
	Solution sol = solver.solve(x4,bounds);
	assertEquals(sol.outcome(), Solution.Outcome.SATISFIABLE);
	//		System.out.println(sol.toString());
}
 
Example 17
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testLingeling_Jasmin_092611() {
	for(int j = 0; j < 1000; j++) {
		Options options = new Options();
		options.setSolver(SATFactory.Lingeling);
		final Solver solver = new Solver(options);
		final int cardinality = 2;
		final List<String> atoms = new ArrayList<String>(cardinality);
		for (int i = 0; i < cardinality; ++i)
			atoms.add(new String("A" + i));
		final Universe universe = new Universe(atoms);
		final TupleFactory factory = universe.factory();
		Bounds bounds = new Bounds(universe);
		final Relation r0 = Relation.nary("r0", 2);
		final Relation a0 = Relation.nary("A0", 1);
		bounds.bound(r0, factory.allOf(2));
		bounds.boundExactly(a0, factory.setOf(universe.atom(0)));

		final Formula formula = Expression.product(a0, a0).in(r0);

		final Solution solution = solver.solve(formula, bounds);

		//        final StringBuilder buf = new StringBuilder();
		//        buf.append("\n---UNIVERSE---\n" + universe.toString() + "\n");
		//        buf.append("\n---BOUNDS---\n" + bounds.toString() + "\n");
		//        buf.append("\n---FORMULA---\n" + formula.toString() + "\n");
		//
		//        buf.append("\n---OUTCOME---\n");
		//        buf.append(solution.outcome());
		//        buf.append("\n");
		//
		//        if (solution.instance() != null) {
		//            buf.append("\n---INSTANCE---\n");
		//            buf.append(solution.instance());
		//            buf.append("\n");
		//        }
		//        if (solution.proof() != null) {
		//            buf.append("\n---PROOF---\n");
		//            buf.append(solution.proof());
		//            buf.append("\n");
		//        }
		//        buf.append("\n---STATS---\n");
		//        buf.append(solution.stats());
		//
		//        System.out.println(buf);

		assertEquals(Solution.Outcome.SATISFIABLE, solution.outcome());
		assertTrue(solution.instance().tuples(r0).size()  > 0 );
	}
}
 
Example 18
Source File: ALG212.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * Constucts a new instance of ALG212.
 */
public ALG212() {
    f = Relation.nary("f", 4);
}
 
Example 19
Source File: GEO159.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a new instance of GEO159.
 */
public GEO159() {
    between = Relation.nary("between_c", 4);
}
 
Example 20
Source File: RegressionTests.java    From kodkod with MIT License 3 votes vote down vote up
@Test
public final void testFelix_05152007_1() {
	Relation x5 = Relation.nary("A", 1);

	List<String> atomlist = Arrays.asList("A0", "A1", "A2");

	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("A2"));
	x5_upper.add(factory.tuple("A1"));
	x5_upper.add(factory.tuple("A0"));

	bounds.bound(x5, x5_upper);

	Formula x7=x5.some();
	Formula x8=x5.no();

	Formula x6=x7.and(x8);

	Solver solver = new Solver();
	solver.options().setLogTranslation(1);

	solver.options().setSolver(SATFactory.MiniSatProver);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

	Solution sol = solver.solve(x6,bounds);

	//		System.out.println("Sol="+sol);

	Set<Formula> core = Nodes.minRoots(x6, sol.proof().highLevelCore().values());
	assertEquals(2, core.size());
	assertTrue(core.contains(x7));
	assertTrue(core.contains(x8));

}