kodkod.engine.Solution Java Examples
The following examples show how to use
kodkod.engine.Solution.
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: IncrementalOverflowNumTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
@Test public void testBasic() { Options opt = new Options(); opt.setNoOverflow(true); opt.setBitwidth(2); IncrementalSolver solver = IncrementalSolver.solver(opt); Universe univ = new Universe("-2", "-1", "0", "1"); Bounds b = new Bounds(univ); TupleFactory factory = univ.factory(); b.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2"))); b.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1"))); b.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0"))); b.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1"))); Variable n = Variable.unary("n"); Formula f = n.sum().plus(IntConstant.constant(1)).lte(n.sum()).forSome(n.oneOf(Expression.INTS)); Solution sol = solver.solve(f, b); assertNoInstance(sol); }
Example #2
Source File: EnumerationTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public final void testTrivial() { final Relation r = Relation.unary("r"); final Universe u = new Universe(Arrays.asList("a", "b", "c")); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.bound(r, f.setOf("a"), f.allOf(1)); final Formula someR = r.some(); Iterator<Solution> sol = solver.solveAll(someR, b); // has a trivial instance, followed by 2 non-trivial instances assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.UNSATISFIABLE, sol.next().outcome()); assertFalse(sol.hasNext()); }
Example #3
Source File: GraphColoring2.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.classicnp.GraphColoring <filename> <DIMACS | ASP | ASP_EDGES> <# of colors> */ public static void main(String[] args) { if (args.length!=3) usage(); try { final GraphColoring2 model = new GraphColoring2(args[0], Enum.valueOf(Graph.Format.class, args[1].toUpperCase()), Integer.parseInt(args[2])); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setSymmetryBreaking(0); solver.options().setReporter(new ConsoleReporter()); final Formula f = model.coloring(); final Bounds b = model.bounds(); final Solution sol = solver.solve(f, b); System.out.println(sol.outcome()); System.out.println(sol.stats()); //if (sol.instance()!=null) // System.out.println("coloring: "+sol.instance().tuples(model.v2c)); } catch (NumberFormatException e) { usage(); } }
Example #4
Source File: DNACuts.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Usage: java examples.alloy.DNACuts [cut chain length] [# links] */ public static void main(String[] args) { if (args.length < 2) usage(); try { final DNACuts model = new DNACuts(Integer.parseInt(args[0])); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); Formula f = model.show(); Bounds b = model.bounds(Integer.parseInt(args[1])); System.out.println("solving..."); Solution sol = solver.solve(f, b); // System.out.println(f); // System.out.println(b); System.out.println(sol.outcome()); System.out.println(sol.stats()); } catch (NumberFormatException nfe) { usage(); } }
Example #5
Source File: GEO115.java From kodkod with MIT License | 6 votes |
/** * Usage: ava examples.tptp.GEO115 [scope] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final GEO115 model = new GEO115(); final Formula f = model.theorem385(); final Bounds b = model.bounds(n); final Solution sol = solver.solve(f,b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #6
Source File: GEO115.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Usage: ava examples.tptp.GEO115 [scope] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final GEO115 model = new GEO115(); final Formula f = model.theorem385(); final Bounds b = model.bounds(n); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #7
Source File: TranslatorTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
private final void testNary(IntOperator op) { bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3))); bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5))); bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6))); for (int i = 2; i <= 5; i++) { final IntExpression[] exprs = new IntExpression[i]; exprs[0] = r1[0].count(); IntExpression binExpr = r1[0].count(); for (int j = 1; j < i; j++) { binExpr = binExpr.compose(op, r1[j % 4].count()); exprs[j] = r1[j % 4].count(); } IntExpression nExpr = IntExpression.compose(op, exprs); final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds); assertNull(sol.instance()); } }
Example #8
Source File: MED007.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.MED007 [univ size] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); if (n < 1) usage(); final MED007 model = new MED007(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); // solver.options().setSymmetryBreaking(1000); // solver.options().setFlatten(false); final Formula f = model.checkTranssls2_qilt27(); final Bounds b = model.bounds(n); System.out.println(f); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #9
Source File: GEO159.java From kodkod with MIT License | 6 votes |
/** * Usage: ava examples.tptp.GEO159 [scope] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final GEO159 model = new GEO159(); final Formula f = model.checkDefs(); final Bounds b = model.bounds(n); final Solution sol = solver.solve(f,b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #10
Source File: NUM374.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Usage: java examples.tptp.NUM374 [univ size] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); if (n < 1) usage(); final NUM374 model = new NUM374(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setSymmetryBreaking(n * n); final Formula f = model.checkWilkie(); final Bounds b = model.bounds(n); System.out.println(f); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #11
Source File: COM008.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.COM008 [univ size] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); if (n < 1) usage(); final COM008 model = new COM008(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); // solver.options().setSymmetryBreaking(22); // solver.options().setFlatten(false); final Formula f = model.checkGoalToBeProved(); final Bounds b = model.bounds(n); // System.out.println(f); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #12
Source File: CeilingsAndFloors.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.CeilingsAndFloors [# men] [# platforms] */ public static void main(String[] args) { if (args.length < 2) usage(); final CeilingsAndFloors model = new CeilingsAndFloors(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); try { final int m = Integer.parseInt(args[0]); final int p = Integer.parseInt(args[1]); final Formula show = model.checkBelowTooDoublePrime(); final Solution sol = solver.solve(show, model.bounds(m,p)); System.out.println(show); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #13
Source File: NUM374.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.NUM374 [univ size] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); if (n < 1) usage(); final NUM374 model = new NUM374(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setSymmetryBreaking(n*n); final Formula f = model.checkWilkie(); final Bounds b = model.bounds(n); System.out.println(f); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #14
Source File: ALG195.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.ALG195 */ public static void main(String[] args) { try { final ALG195 model = new ALG195(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final Formula f = model.checkCO1(); final Bounds b = model.bounds(); // System.out.println(model.decls()); // System.out.println(model.ax2ax7()); // System.out.println(b); final Solution sol = solver.solve(f, b); if (sol.instance()==null) { System.out.println(sol); } else { System.out.println(sol.stats()); model.display(sol.instance()); } } catch (NumberFormatException nfe) { usage(); } }
Example #15
Source File: IntTest.java From kodkod with MIT License | 6 votes |
private void testIntSum(Options.IntEncoding encoding) { solver.options().setIntEncoding(encoding); final Variable x = Variable.unary("x"); bounds.bound(r1, factory.setOf("13","14","15"), factory.setOf("13","14","15")); Formula f = IntConstant.constant(3).eq(IntConstant.constant(1).sum(x.oneOf(r1))); Solution s = solve(f); assertNotNull(s.instance()); bounds.bound(r1, factory.noneOf(1), factory.setOf("1","3","5")); bounds.boundExactly(1, factory.setOf("1")); bounds.boundExactly(3, factory.setOf("3")); bounds.boundExactly(5, factory.setOf("5")); f = IntConstant.constant(9).eq(x.sum().sum(x.oneOf(r1))); s = solve(f); assertNotNull(s.instance()); assertEquals(s.instance().tuples(r1), factory.setOf("1","3","5")); }
Example #16
Source File: GEO159.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Usage: ava examples.tptp.GEO159 [scope] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final GEO159 model = new GEO159(); final Formula f = model.checkDefs(); final Bounds b = model.bounds(n); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #17
Source File: RegressionTests.java From kodkod with MIT License | 6 votes |
@Test public final void testEmina_10092006() { Relation r = Relation.ternary("r"); final Variable a = Variable.unary("A"); final Variable b = Variable.unary("B"); final Variable c = Variable.unary("C"); final Variable d = Variable.unary("D"); final Formula f0 = (b.join(a.join(r))).eq(d.join(c.join(r))); final Formula f1 = a.in(c).and(b.in(d)); final Formula f = f0.implies(f1). forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)).and(d.oneOf(UNIV))); final Universe u = new Universe(Arrays.asList("a0","a1")); final Bounds bounds = new Bounds(u); bounds.bound(r, u.factory().allOf(3)); // System.out.println(f); System.out.println(bounds); solver.options().setSymmetryBreaking(0); final Solution s = solver.solve(f, bounds); // System.out.println(s); assertEquals(Solution.Outcome.SATISFIABLE, s.outcome()); }
Example #18
Source File: ALG197.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.ALG197 */ public static void main(String[] args) { try { final ALG197 model = new ALG197(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final Formula f = model.checkCO1(); final Bounds b = model.bounds(); final Solution sol = solver.solve(f, b); if (sol.instance()==null) { System.out.println(sol); } else { System.out.println(sol.stats()); model.display(sol.instance()); } } catch (NumberFormatException nfe) { usage(); } }
Example #19
Source File: DiffEg.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.DiffEq [scope] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); if (n < 1) usage(); final DiffEg model = new DiffEg(); final Solver solver = new Solver(); final Formula f = model.runPol(); final Bounds b = model.bounds(n); System.out.println(f); final Solution sol = solver.solve(f, b); System.out.println(sol); } catch (NumberFormatException nfe) { usage(); } }
Example #20
Source File: Netconfig.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Usage: java examples.Netconfig [# sites] [# hq] [# routers] [# time steps] */ public static void main(String[] args) { if (args.length < 4) usage(); final Netconfig model = new Netconfig(); final Solver solver = new Solver(); // solver.options().setSolver(SATFactory.ZChaffMincost); solver.options().setSolver(SATFactory.MiniSat); try { final Formula show = model.show(); final Solution sol = solver.solve(show, model.bounds(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]))); // System.out.println(show); // System.out.println("p cnf " + // (solver.numberOfIntermediateVariables()+solver.numberOfPrimaryVariables()) // + " " + solver.numberOfClauses()); System.out.println(sol.outcome()); System.out.println(sol.stats()); } catch (NumberFormatException nfe) { usage(); } }
Example #21
Source File: NUM378.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.NUM378 */ public static void main(String[] args) { try { final NUM378 model = new NUM378(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final Formula f = model.decls().and(model.inequalities()); final Bounds b = model.bounds(); // System.out.println(f); // System.out.println(b); final Solution sol = solver.solve(f, b); System.out.println(sol.outcome()); System.out.println(sol.stats()); } catch (NumberFormatException nfe) { usage(); } }
Example #22
Source File: RegressionTests.java From kodkod with MIT License | 5 votes |
@Test public final void testVincent_03182006_reduced() { final Relation pCourses = Relation.binary("pCourses"), prereqs = Relation.binary("prereqs"); final List<String> atoms = new ArrayList<String>(14); atoms.add("6.002"); atoms.add("8.02"); atoms.add("6.003"); atoms.add("6.001"); atoms.add("[8.02]"); atoms.add("[6.001]"); atoms.add("[]"); final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); b.bound(pCourses, f.setOf(f.tuple("[8.02]", "8.02"), f.tuple("[6.001]", "6.001"))); b.bound(prereqs, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]"))); // System.out.println(u); solver.options().setSolver(SATFactory.DefaultSAT4J); Solution solution = solver.solve((pCourses.some()).and(prereqs.some()), b); // System.out.println(solution); // SATISFIABLE assertEquals(solution.outcome(), Solution.Outcome.SATISFIABLE); }
Example #23
Source File: IntTest.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
private final void testUnOp(IntOperator op, IntExpression ei, int i, int result, int mask) { final IntExpression e = ei.apply(op); final Formula f = ei.eq(constant(i)).and(e.eq(constant(result))); final Solution s = solve(f); if (overflows(ei, i, result)) { assertNull(f.toString(), s.instance()); } else { assertNotNull(f.toString(), s.instance()); final Evaluator eval = new Evaluator(s.instance(), solver.options()); assertEquals(result & mask, eval.evaluate(e) & mask); } }
Example #24
Source File: HOLSome4AllTest.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
@Test public void testE1ii() { // SAT: some s: ints | all $s: set Node | #$s > s Variable ns = Variable.unary("$s"); Formula f = ns.count().gt(si).forAll(ns.setOf(Node)).forSome(s.oneOf(Expression.INTS)); Solution sol = solve(f); assertEquals(true, sol.sat()); assertEquals(-1, evalS(sol)); }
Example #25
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
private final void doTestAleks_03102013() { Relation r = Relation.unary("R"); Relation s = Relation.binary("f"); Variable v = Variable.unary("e"); Decl decl = v.oneOf(r); Expression shared = v.join(s); Formula expr = (shared.difference(shared)).one().forAll(decl); Formula fin = expr.and(expr.not()); List<Object> atomlist = new LinkedList<Object>(); atomlist.add("R$0"); atomlist.add("R$1"); atomlist.add("R$2"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.bound(r, factory.allOf(1)); bounds.bound(s, factory.allOf(2)); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setSkolemDepth(0); solver.options().setLogTranslation(0); Solution sol = solver.solve(fin, bounds); assertNull(sol.instance()); }
Example #26
Source File: IntTest.java From kodkod with MIT License | 5 votes |
private final void testCompOp(IntCompOperator op, IntExpression ei, IntExpression ej, int i, int j, boolean result) { final Formula e = ei.compare(op, ej); final Formula f = ei.eq(constant(i)).and(ej.eq(constant(j))).and(result ? e : e.not()); final Solution s = solve(f); assertNotNull(s.instance()); final Evaluator eval = new Evaluator(s.instance(), solver.options()); assertFalse(result ^ eval.evaluate(e)); }
Example #27
Source File: BlockedNQueens.java From kodkod with MIT License | 5 votes |
/** * Usage: java BlockedNQueens <file name> */ public static void main(String[] args) { if (args.length < 1) usage(); try { final BlockedNQueens model = new BlockedNQueens(args[0]); final Formula f = model.rules(); final Bounds b = model.bounds(); final Solver s = new Solver(); // System.out.println(b); System.out.println(PrettyPrinter.print(f, 1)); s.options().setSolver(SATFactory.MiniSat); s.options().setBitwidth(33 - Integer.numberOfLeadingZeros((b.universe().size()/2) - 1)); s.options().setReporter(new ConsoleReporter()); final Solution sol = s.solve(f, b); if (sol.instance()!=null) { System.out.println("solution:"); model.print(sol.instance(), s.options()); } else { System.out.println("no solution"); } System.out.println(sol.stats()); } catch (NumberFormatException nfe) { usage(); } }
Example #28
Source File: ExamplesTestWithIncrementalSolver.java From kodkod with MIT License | 5 votes |
/** * Runs LAT258.checkGoalToBeProved for 5. Running it for 6 takes about a minute. */ @Test public void testLAT258() { final LAT258 prob = new LAT258(); final Solution sol = solve(prob.checkGoalToBeProved(), prob.bounds(5)); check(prob.getClass().getSimpleName(), sol, UNSATISFIABLE); }
Example #29
Source File: ReductionAndProofTest.java From kodkod with MIT License | 5 votes |
@Test public final void testProof() { Variable v0 = Variable.unary("v0"), v1 = Variable.unary("v1"), v2 = Variable.unary("v2"); Formula f0 = v0.join(a2b).eq(v1.union(v2)).and(v1.eq(v2).not()); Formula f1 = f0.forSome(v0.oneOf(a).and(v1.oneOf(b)).and(v2.oneOf(b))); Formula f2 = a2b.function(a, b); Formula f3 = f1.and(f2).and(total.totalOrder(ordered, first, last)); Solution sol = null; solver.options().setLogTranslation(0); solver.options().setSolver(SATFactory.MiniSat); sol = solver.solve(f3, bounds); assertEquals(Solution.Outcome.UNSATISFIABLE, sol.outcome()); assertNull(sol.proof()); solver.options().setLogTranslation(1); sol = solver.solve(f3, bounds); assertNull(sol.proof()); solver.options().setSolver(SATFactory.MiniSatProver); sol = solver.solve(f3, bounds); //System.out.println(f3 + ", " + bounds); sol.proof().minimize(new ECFPStrategy()); final Set<Formula> top = Nodes.minRoots(f3, sol.proof().highLevelCore().values()); assertEquals(2, top.size()); assertTrue(top.contains(f1)); assertTrue(top.contains(f2)); // for(Iterator<TranslationLog.Record> itr = sol.proof().core(); itr.hasNext(); ) { // System.out.println(itr.next()); // } }
Example #30
Source File: ExamplesTest.java From kodkod with MIT License | 5 votes |
/** * Runs ALG197.checkCO1. */ @Test public final void testALG197() { final ALG197 prob = new ALG197(); final Solution sol = solve(prob.checkCO1(), prob.bounds()); check(prob.getClass().getSimpleName(), sol, UNSATISFIABLE); }