Java Code Examples for kodkod.engine.Solver#solveAll()
The following examples show how to use
kodkod.engine.Solver#solveAll() .
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: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
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 2
Source File: RegressionTests.java From kodkod with MIT License | 5 votes |
@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 |
@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: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
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 5
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
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().setFlatten(false); 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 6
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
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 7
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@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 8
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@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); }