Java Code Examples for kodkod.engine.Solver#solve()
The following examples show how to use
kodkod.engine.Solver#solve() .
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: DNACuts.java From kodkod with MIT License | 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.MiniSat); 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 2
Source File: GEO092.java From kodkod with MIT License | 6 votes |
/** * Usage: ava examples.tptp.GEO192 [# curves] [# points] */ public static void main(String[] args) { if (args.length < 2) usage(); try { final int n = Integer.parseInt(args[0]); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); final GEO092 model = new GEO092(); final Formula f = model.checkProposition2141(); System.out.println(model.proposition2141()); final Bounds b = model.bounds(n); final Solution sol = solver.solve(f,b); System.out.println(sol); //System.out.println((new Evaluator(sol.instance())).evaluate(model.axioms().and(model.theorem213().not()))); } catch (NumberFormatException nfe) { usage(); } }
Example 3
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 4
Source File: MED007.java From org.alloytools.alloy with Apache License 2.0 | 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 5
Source File: ALG212.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Usage: java examples.tptp.ALG212 [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 ALG212 model = new ALG212(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); // solver.options().setSymmetryBreaking(n*n); // solver.options().setFlatten(false); final Formula f = model.checkDistLong(); 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 6
Source File: SET948.java From kodkod with MIT License | 6 votes |
/** * Usage: java examples.tptp.SET948 [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 SET948 model = new SET948(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); // solver.options().setSymmetryBreaking(n*n); // solver.options().setFlatten(false); final Formula f = model.checkT101_zfmisc_1(); 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 7
Source File: ALG197.java From org.alloytools.alloy with Apache License 2.0 | 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 8
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 9
Source File: BlockedNQueens2.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 BlockedNQueens2 model = new BlockedNQueens2(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())); 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 10
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
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 11
Source File: LatinSquare.java From kodkod with MIT License | 5 votes |
/** * Usage: java examples.LatinSquare [order] */ public static void main(String[] args) { if (args.length < 1) usage(); try { final int n = Integer.parseInt(args[0]); if (n < 1) usage(); final LatinSquare model = new LatinSquare(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setSymmetryBreaking(n*n*n); final Formula f = model.latin().and(model.qg5()).and(model.idempotent()); final Bounds b = model.bounds(n); System.out.println(f); final Solution sol = solver.solve(f, b); if (sol.instance()==null) { System.out.println(sol); } else { System.out.println(sol.stats()); final Iterator<Tuple> iter = sol.instance().tuples(model.square).iterator(); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { System.out.print(iter.next().atom(2)); System.out.print("\t"); } System.out.println(); } } } catch (NumberFormatException nfe) { usage(); } }
Example 12
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_01032007() { List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8"))); bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7"))); bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6"))); bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5"))); bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4"))); bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3"))); bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2"))); bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1"))); bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0"))); bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1"))); bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2"))); bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3"))); bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4"))); bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5"))); bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6"))); bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7"))); Expression set = IntConstant.constant(8).toExpression(); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); Solution sol = solver.solve(set.some(), bounds); assertNotNull("expected SATISFIABLE but was " + sol.outcome(), sol.instance()); Evaluator eval = new Evaluator(sol.instance(), solver.options()); TupleSet ts = eval.evaluate(set); assertFalse(ts.size() == 0); }
Example 13
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 14
Source File: HamiltonianCycle2.java From kodkod with MIT License | 5 votes |
/** * Usage: examples.classicnp.HamiltonianCycle2 <graph file> <DIMACS | ASP> <EXT | LOG> */ public static void main(String[] args) { if (args.length!=3) usage(); final HamiltonianCycle2 model; if ("LOG".equals(args[2].toUpperCase())) { model = logEncoding(args[0], Enum.valueOf(Graph.Format.class, args[1].toUpperCase())); } else if ("EXT".equals(args[2].toUpperCase())) { model = extEncoding(args[0], Enum.valueOf(Graph.Format.class, args[1].toUpperCase())); } else { usage(); model = null; } final Formula f = model.cycleDefinition(); final Bounds b = model.bounds(); System.out.println(f); System.out.println(b); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setReporter(new ConsoleReporter()); // solver.options().setFlatten(false); final Solution s = solver.solve(f,b); System.out.println(s.outcome()); System.out.println(s.stats()); if (s.instance()!=null) { final Evaluator eval = new Evaluator(s.instance(), solver.options()); final Expression[] dec = model.pts; System.out.print(eval.evaluate(dec[0])); for(int i = 1; i < dec.length; i++) { System.out.print(" -> " + eval.evaluate(dec[i])); } System.out.println(); } }
Example 15
Source File: RegressionTests.java From kodkod with MIT License | 5 votes |
@Test public final void testFelix_01032007() { List<String> atomlist = Arrays.asList( "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(-8,factory.range(factory.tuple("-8"),factory.tuple("-8"))); bounds.boundExactly(-7,factory.range(factory.tuple("-7"),factory.tuple("-7"))); bounds.boundExactly(-6,factory.range(factory.tuple("-6"),factory.tuple("-6"))); bounds.boundExactly(-5,factory.range(factory.tuple("-5"),factory.tuple("-5"))); bounds.boundExactly(-4,factory.range(factory.tuple("-4"),factory.tuple("-4"))); bounds.boundExactly(-3,factory.range(factory.tuple("-3"),factory.tuple("-3"))); bounds.boundExactly(-2,factory.range(factory.tuple("-2"),factory.tuple("-2"))); bounds.boundExactly(-1,factory.range(factory.tuple("-1"),factory.tuple("-1"))); bounds.boundExactly(0,factory.range(factory.tuple("0"),factory.tuple("0"))); bounds.boundExactly(1,factory.range(factory.tuple("1"),factory.tuple("1"))); bounds.boundExactly(2,factory.range(factory.tuple("2"),factory.tuple("2"))); bounds.boundExactly(3,factory.range(factory.tuple("3"),factory.tuple("3"))); bounds.boundExactly(4,factory.range(factory.tuple("4"),factory.tuple("4"))); bounds.boundExactly(5,factory.range(factory.tuple("5"),factory.tuple("5"))); bounds.boundExactly(6,factory.range(factory.tuple("6"),factory.tuple("6"))); bounds.boundExactly(7,factory.range(factory.tuple("7"),factory.tuple("7"))); Expression set=IntConstant.constant(8).toExpression(); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); Solution sol = solver.solve(set.some(), bounds); Evaluator eval = new Evaluator(sol.instance(), solver.options()); TupleSet ts = eval.evaluate(set); assertFalse(ts.size()==0); }
Example 16
Source File: ListDebug.java From kodkod with MIT License | 5 votes |
Solution debug(int size) { final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSatProver); solver.options().setCoreGranularity(1); solver.options().setLogTranslation(1); return solver.solve(debugSpec(), debugBounds(size)); }
Example 17
Source File: RegressionTests.java From kodkod with MIT License | 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()); // fin = (all e: R | one ((e . f) - (e . f))) && // !(all e: R | one ((e . f) - (e . f))) 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 18
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
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 19
Source File: Hotel.java From kodkod with MIT License | 4 votes |
/** * Usage: java examples.Hotel [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 Hotel model = new Hotel(); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSatProver); solver.options().setLogTranslation(1); final Formula f = model.checkNoBadEntry(); final Bounds b = model.bounds(n); // System.out.println(PrettyPrinter.print(f, 2, 100)); final Solution sol = solver.solve(f, b); System.out.println(sol); if (sol.instance()==null) { final Proof proof = sol.proof(); System.out.println("top-level formulas: " + proof.log().roots().size()); System.out.println("initial core: " + proof.highLevelCore().size()); System.out.print("\nminimizing core ... "); final long start = System.currentTimeMillis(); proof.minimize(new RCEStrategy(proof.log())); final Set<Formula> core = Nodes.minRoots(f, proof.highLevelCore().values()); final long end = System.currentTimeMillis(); System.out.println("done (" + (end-start) + " ms)."); System.out.println("minimal core: " + core.size()); for(Formula u : core) { System.out.println(PrettyPrinter.print(u, 2, 100)); } checkMinimal(core, b); } else { System.out.println(sol); } } catch (NumberFormatException nfe) { usage(); } }
Example 20
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@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()); } }