env();
72 |
73 | /**
74 | * @see java.lang.Object#toString()
75 | */
76 | public String toString() {
77 | final StringBuilder ret = new StringBuilder();
78 | ret.append("< node: ");
79 | ret.append(node());
80 | ret.append(", literal: ");
81 | ret.append(literal());
82 | ret.append(", env: ");
83 | ret.append(env());
84 | ret.append(">");
85 | return ret.toString();
86 | }
87 | }
--------------------------------------------------------------------------------
/src/kodkod/engine/fol2sat/UnboundLeafException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.fol2sat;
23 |
24 | import kodkod.ast.LeafExpression;
25 |
26 | /**
27 | * Thrown when a node contains an undeclared variable or a relation with no bounds.
28 | * @specfield leaf: LeafExpression // the unbound leaf that caused the exception to be thrown
29 | * @author Emina Torlak
30 | */
31 | public final class UnboundLeafException extends RuntimeException {
32 | private final LeafExpression leaf;
33 | private static final long serialVersionUID = 2472395272061454465L;
34 |
35 | /**
36 | * Constructs an UnboundLeafException for the given leaf.
37 | * @ensures this.leaf' = leaf
38 | */
39 | UnboundLeafException(String msg, LeafExpression leaf) {
40 | super(msg + ": " +leaf);
41 | this.leaf = leaf;
42 | }
43 |
44 | /**
45 | * Returns this.leaf.
46 | * @return this.leaf
47 | */
48 | public LeafExpression leaf() {
49 | return leaf;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/kodkod/engine/fol2sat/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Provides a facade for translating, evaluating, and approximating Kodkod
9 | formulas, expressions, and int expressions with respect to a given Bounds
10 | (or Instance) and Options.
11 |
12 | Package Specification
13 |
14 | Provides a facade for translating, evaluating, and approximating Kodkod
15 | formulas, expressions, and int expressions with respect to given Bounds
16 | (or Instance) and Options. The {@linkplain kodkod.engine.fol2sat.Translator}
17 | class contains methods for translating a Kodkod formula to CNF, evaluating
18 | a Node with respect to an instance, and over-approximating the value of an
19 | expression based on the upper bounds in a given Bounds object.
20 |
21 | Related Documentation
22 |
23 | @see kodkod.engine.fol2sat.Translator
24 | @see kodkod.engine.fol2sat.Translation
25 | @see kodkod.engine.fol2sat.TranslationLog
26 | @see kodkod.engine.fol2sat.TranslationRecord
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/kodkod/engine/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Provides classes for analyzing and evaluating Kodkod ASTs with
9 | respect to finite bounds or instances.
10 |
11 | Package Specification
12 |
13 | Contains classes for analyzing and evaluating Kodkod ASTs with
14 | respect to finite bounds or instances. A {@linkplain kodkod.engine.Solver Solver}
15 | provides methods for finding finite models and minimal unsatisfiable cores of Kodkod formulas with respect
16 | to given {@linkplain kodkod.instance.Bounds Bounds} and {@linkplain kodkod.engine.config.Options Options}.
17 | An {@linkplain kodkod.engine.IncrementalSolver IncrementalSolver} provides a way to solve a sequence of
18 | related formulas and bounds incrementally, with respect to the same
19 | {@linkplain kodkod.engine.config.Options Options options}.
20 | An {@linkplain kodkod.engine.Evaluator Evaluator} enables the evaluation of formulas, expressions, and
21 | integer expressions with respect to a particular {@linkplain kodkod.instance.Instance Instance} and
22 | {@linkplain kodkod.engine.config.Options Options}.
23 |
24 |
25 |
26 | Related Documentation
27 |
28 | @see kodkod.instance.Bounds
29 | @see kodkod.instance.Instance
30 | @see kodkod.ast.Expression
31 | @see kodkod.ast.IntExpression
32 | @see kodkod.ast.Formula
33 | @see kodkod.engine.Solver
34 | @see kodkod.engine.IncrementalSolver
35 | @see kodkod.engine.Evaluator
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/Glucose.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-2012, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.satlab;
23 |
24 | /**
25 | * Java wrapper for the Glucose solver by G. Audemard and L. Simon.
26 | *
27 | * @author Emina Torlak
28 | */
29 | final class Glucose extends NativeSolver {
30 |
31 | /**
32 | * Constructs a new Glucose wrapper.
33 | */
34 | Glucose() {
35 | super(make());
36 | }
37 |
38 | static {
39 | loadLibrary(Glucose.class);
40 | }
41 |
42 | /**
43 | * {@inheritDoc}
44 | * @see java.lang.Object#toString()
45 | */
46 | public String toString() { return "Glucose"; }
47 |
48 | /**
49 | * Returns a pointer to an instance of the glucose solver.
50 | * @return a pointer to an instance of the glucose solver.
51 | */
52 | private static native long make();
53 |
54 | /**
55 | * {@inheritDoc}
56 | * @see kodkod.engine.satlab.NativeSolver#free(long)
57 | */
58 | native void free(long peer);
59 |
60 | /**
61 | * {@inheritDoc}
62 | * @see kodkod.engine.satlab.NativeSolver#addVariables(long, int)
63 | */
64 | native void addVariables(long peer, int numVariables);
65 |
66 | /**
67 | * {@inheritDoc}
68 | * @see kodkod.engine.satlab.NativeSolver#addClause(long, int[])
69 | */
70 | native boolean addClause(long peer, int[] lits);
71 |
72 | /**
73 | * {@inheritDoc}
74 | * @see kodkod.engine.satlab.NativeSolver#solve(long)
75 | */
76 | native boolean solve(long peer);
77 |
78 | /**
79 | * {@inheritDoc}
80 | * @see kodkod.engine.satlab.NativeSolver#valueOf(long, int)
81 | */
82 | native boolean valueOf(long peer, int literal);
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/Lingeling.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.satlab;
23 |
24 | /**
25 | * Java wrapper for the Lingeling solver by Armin Biere.
26 | *
27 | * @author Emina Torlak
28 | */
29 | final class Lingeling extends NativeSolver {
30 | /**
31 | * Constructs a new Lingeling wrapper.
32 | */
33 | public Lingeling() {
34 | super(make());
35 | }
36 |
37 | static {
38 | loadLibrary(Lingeling.class);
39 | }
40 |
41 |
42 | /**
43 | * {@inheritDoc}
44 | * @see java.lang.Object#toString()
45 | */
46 | public String toString() {
47 | return "lingeling";
48 | }
49 |
50 | /**
51 | * Returns a pointer to an instance of Lingeling.
52 | * @return a pointer to an instance of minisat.
53 | */
54 | private static native long make();
55 |
56 | /**
57 | * {@inheritDoc}
58 | * @see kodkod.engine.satlab.NativeSolver#free(long)
59 | */
60 | native void free(long peer);
61 |
62 | /**
63 | * {@inheritDoc}
64 | * @see kodkod.engine.satlab.NativeSolver#addVariables(long, int)
65 | */
66 | native void addVariables(long peer, int numVariables);
67 |
68 | /**
69 | * {@inheritDoc}
70 | * @see kodkod.engine.satlab.NativeSolver#addClause(long, int[])
71 | */
72 | native boolean addClause(long peer, int[] lits);
73 |
74 | /**
75 | * {@inheritDoc}
76 | * @see kodkod.engine.satlab.NativeSolver#solve(long)
77 | */
78 | native boolean solve(long peer);
79 |
80 | /**
81 | * {@inheritDoc}
82 | * @see kodkod.engine.satlab.NativeSolver#valueOf(long, int)
83 | */
84 | native boolean valueOf(long peer, int literal);
85 | }
86 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/MiniSat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.satlab;
23 |
24 |
25 | /**
26 | * Java wrapper for the MiniSat solver by Niklas Eén and Niklas Sörensson.
27 | * @author Emina Torlak
28 | */
29 | final class MiniSat extends NativeSolver {
30 |
31 | /**
32 | * Constructs a new MiniSAT wrapper.
33 | */
34 | public MiniSat() {
35 | super(make());
36 | }
37 |
38 | static {
39 | loadLibrary(MiniSat.class);
40 | }
41 |
42 |
43 | /**
44 | * {@inheritDoc}
45 | * @see java.lang.Object#toString()
46 | */
47 | public String toString() {
48 | return "MiniSat";
49 | }
50 |
51 | /**
52 | * Returns a pointer to an instance of MiniSAT.
53 | * @return a pointer to an instance of minisat.
54 | */
55 | private static native long make();
56 |
57 | /**
58 | * {@inheritDoc}
59 | * @see kodkod.engine.satlab.NativeSolver#free(long)
60 | */
61 | native void free(long peer);
62 |
63 | /**
64 | * {@inheritDoc}
65 | * @see kodkod.engine.satlab.NativeSolver#addVariables(long, int)
66 | */
67 | native void addVariables(long peer, int numVariables);
68 |
69 | /**
70 | * {@inheritDoc}
71 | * @see kodkod.engine.satlab.NativeSolver#addClause(long, int[])
72 | */
73 | native boolean addClause(long peer, int[] lits);
74 |
75 | /**
76 | * {@inheritDoc}
77 | * @see kodkod.engine.satlab.NativeSolver#solve(long)
78 | */
79 | native boolean solve(long peer);
80 |
81 | /**
82 | * {@inheritDoc}
83 | * @see kodkod.engine.satlab.NativeSolver#valueOf(long, int)
84 | */
85 | native boolean valueOf(long peer, int literal);
86 | }
87 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/ReductionStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.satlab;
23 |
24 | import kodkod.util.ints.IntSet;
25 |
26 |
27 | /**
28 | * Strategy for reducing the unsatisfiable core of
29 | * a {@link SATProver}.
30 | * @specfield traces: ResolutionTrace[]
31 | * @specfield nexts: IntSet[]
32 | * @invariant #traces = #nexts
33 | * @invariant no disj i,j: [0..#nexts) | traces[i] = traces[j] && nexts[i] = nexts[j]
34 | * @see SATProver#reduce(ReductionStrategy)
35 | * @author Emina Torlak
36 | */
37 | public interface ReductionStrategy {
38 |
39 | /**
40 | * Returns the next subtrace of the specified trace to be analyzed, given
41 | * as a set of indices into the trace.
42 | * If there are no more subtraces to be analyzed (i.e. the given trace is
43 | * minimal according to the minimality measure used by this strategy),
44 | * returns the empty set.
45 | * @requires
46 | *
47 | * let t = this.traces[#this.traces-1], n = this.nexts[#this.nexts-1] |
48 | * unsat(t.elts[n].literals) =>
49 | * (all i: n.ints | let j = #{k: n.ints | k < i} | t.elts[i].equals(trace.elts[j]))
50 | * else
51 | * trace = t
52 | *
53 | * @ensures
54 | *
55 | * let next = { i: int | 0 <= i < trace.size()-1 } |
56 | * trace.elts[next].antecedents in trace.elts[next] and
57 | * (some i: [0..#trace) | i !in next and no trace[i].antecedents) and
58 | * this.nexts' = this.nexts + #this.nexts->next and
59 | * this.traces' = this.traces + #this.traces->trace
60 | *
61 | * @return this.nexts'[#this.nexts-1]
62 | */
63 | public IntSet next(ResolutionTrace trace);
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/SATAbortedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.satlab;
23 |
24 | /**
25 | * A runtime exception thrown when a sat solver
26 | * terminates abnormally, usually because it was cancelled.
27 | * @author Emina Torlak
28 | */
29 | public final class SATAbortedException extends RuntimeException {
30 |
31 | private static final long serialVersionUID = 5162235133382021308L;
32 |
33 | /**
34 | * Constructs an aborted exception with no message.
35 | */
36 | SATAbortedException() {}
37 |
38 | /**
39 | * Constructs an aborted exception with the given message.
40 | */
41 | SATAbortedException(String message) {
42 | super(message);
43 | }
44 |
45 | /**
46 | * Constructs an aborted exception with the given cause.
47 | */
48 | SATAbortedException(Throwable cause) {
49 | super(cause);
50 | }
51 |
52 | /**
53 | * Constructs an aborted exception with the given message and cause.
54 | */
55 | SATAbortedException(String message, Throwable cause) {
56 | super(message, cause);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/SATProver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.satlab;
23 |
24 | /**
25 | * Provides an interface to a SAT solver that can generate
26 | * proofs of unsatisfiability.
27 | *
28 | * @specfield variables: set [1..)
29 | * @specfield clauses: set Clause
30 | * @specfield resolvents: set Clause
31 | * @invariant all i: [2..) | i in variables => i-1 in variables
32 | * @invariant all c: clauses + resolvents | all lit: c.lits | lit in variables || -lit in variables
33 | * @invariant all c: clauses + resolvents | all disj i,j: c.lits | abs(i) != abs(j)
34 | * @author Emina Torlak
35 | */
36 | public interface SATProver extends SATSolver {
37 |
38 | /**
39 | * Returns a resolution-based proof of unsatisfiability of this.clauses.
40 | * @requires {@link SATSolver#solve()} has been called, and it returned false
41 | * @return { t: ResolutionTrace | t.prover = this }
42 | * @throws IllegalStateException {@link SATSolver#solve()} has not been called,
43 | * or the last call to {@link SATSolver#solve()} returned true
44 | */
45 | public ResolutionTrace proof();
46 |
47 | /**
48 | * Uses the given reduction strategy to remove irrelevant clauses from
49 | * the set of unsatisfiable clauses stored in this prover.
50 | * A clause c is irrelevant iff this.clauses - c is unsatisfiable.
51 | * The removal algorithm works as follows:
52 | *
53 | * for (IntSet next = strategy.next(this.proof()); !next.isEmpty(); next = strategy.next(this.proof())) {
54 | * let oldClauses = this.clauses, oldResolvents = this.resolvents
55 | * clear this.clauses
56 | * clear this.resolvents
57 | * for(Clause c : this.proof().elts[next]) {
58 | * if (no c.antecedents)
59 | * add c to this.clauses
60 | * else
61 | * add c to this.resolvents
62 | * }
63 | * if (this.solve()) {
64 | * this.clauses = oldClauses
65 | * this.resolvents = oldResolvents
66 | * }
67 | * }
68 | *
69 | * @requires {@link SATSolver#solve()} has been called, and it returned false
70 | * @ensures modifies this.clauses and this.resolvents according to the algorithm described above
71 | * @throws IllegalStateException {@link SATSolver#solve()} has not been called,
72 | * or the last call to {@link SATSolver#solve()} returned true
73 | * @see ReductionStrategy
74 | */
75 | public void reduce(ReductionStrategy strategy);
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/kodkod/engine/satlab/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Provides access to various Java and C++ SAT solvers through a
8 | common SAT Solver interface.
9 |
10 | Package Specification
11 |
12 | Provides access to various Java and C++ SAT solvers through the
13 | {@linkplain kodkod.engine.satlab.SATSolver} and
14 | {@linkplain kodkod.engine.satlab.SATProver} interfaces. The
15 | {@linkplain kodkod.engine.satlab.SATFactory} class contains a selection of
16 | static instances that can be used to generate specific SAT solvers.
17 |
18 | Related Documentation
19 |
20 | @see kodkod.engine.satlab.SATFactory
21 | @see kodkod.engine.satlab.SATSolver
22 | @see kodkod.engine.satlab.SATProver
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/kodkod/engine/ucore/ECFPStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.ucore;
23 |
24 | import kodkod.engine.satlab.ReductionStrategy;
25 | import kodkod.engine.satlab.ResolutionTrace;
26 | import kodkod.util.ints.IntSet;
27 | import kodkod.util.ints.Ints;
28 |
29 | /**
30 | * A non-optimal minimization strategy based on the Empty Clause Cone algorithm.
31 | * @author Emina Torlak
32 | * @see L. Zhang and S. Malik. Extracting small unsatisfiable cores from unsatisfiable
33 | * Boolean formula. In Proceedings of Sixth International Conference on Theory and Applications of
34 | * Satisfiability Testing (SAT '03). 2003.
35 | */
36 | public final class ECFPStrategy implements ReductionStrategy {
37 | private int lastCore;
38 | /**
39 | * Constructs a new instance of the empty clause cone strategy for
40 | * minimizing unsatisfiable cores.
41 | */
42 | public ECFPStrategy() {
43 | lastCore = Integer.MAX_VALUE;
44 | }
45 |
46 | /**
47 | * {@inheritDoc}
48 | * @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
49 | */
50 | public IntSet next(final ResolutionTrace trace) {
51 | final IntSet core = trace.core();
52 | if (lastCore > core.size()) {
53 | lastCore = core.size();
54 | return core;
55 | } else {
56 | lastCore = Integer.MIN_VALUE;
57 | return Ints.EMPTY_SET;
58 | }
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/kodkod/engine/ucore/NCEStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.engine.ucore;
23 |
24 | import kodkod.engine.fol2sat.TranslationLog;
25 | import kodkod.engine.fol2sat.Translator;
26 | import kodkod.engine.satlab.ReductionStrategy;
27 | import kodkod.engine.satlab.ResolutionTrace;
28 | import kodkod.util.ints.IntCollection;
29 | import kodkod.util.ints.IntSet;
30 | import kodkod.util.ints.IntTreeSet;
31 | import kodkod.util.ints.Ints;
32 |
33 | /**
34 | * Naive Core Extraction is a strategy for generating unsat cores that are minimal at the logic level.
35 | * Specifically, let C be a core that is minimal according to this strategy,
36 | * and let F(C) be the top-level logic constraints
37 | * corresponding to C. Then, this strategy guarantees that there is no clause
38 | * c in C such that F(C - c) is a strict subset of F(C). Furthermore, it also
39 | * guarantees that for all f in F(C), F(C) - f is satisfiable. This is a stronger
40 | * guarantee than that of {@linkplain HybridStrategy}. In general, using this strategy
41 | * is more expensive, timewise, than using {@linkplain HybridStrategy}.
42 | *
43 | * This implementation of NCE will work properly only on CNFs generated by the kodkod {@linkplain Translator}.
44 | * @author Emina Torlak
45 | * @see HybridStrategy
46 | */
47 | public final class NCEStrategy implements ReductionStrategy {
48 | private final IntCollection varsToTry;
49 | private final IntSet coreVars;
50 |
51 | /**
52 | * Constructs an NCE strategy that will use the given translation
53 | * log to relate the cnf clauses back to the logic constraints from
54 | * which they were generated.
55 | */
56 | public NCEStrategy(final TranslationLog log) {
57 | varsToTry = StrategyUtils.rootVars(log);
58 | coreVars = new IntTreeSet();//new IntTreeSet(varsToTry);
59 | coreVars.addAll(varsToTry);
60 | }
61 |
62 | /**
63 | * {@inheritDoc}
64 | * @see kodkod.engine.satlab.ReductionStrategy#next(kodkod.engine.satlab.ResolutionTrace)
65 | */
66 | public IntSet next(ResolutionTrace trace) {
67 | if (varsToTry.isEmpty()) return Ints.EMPTY_SET;
68 | // if the last attempt at reduction was unsuccessful,
69 | // add the unit clauses that we tried to discard back to coreVars
70 | coreVars.addAll(StrategyUtils.coreTailUnits(trace));
71 | final int first = varsToTry.iterator().next();//varsToTry.min();
72 | varsToTry.remove(first);
73 | coreVars.remove(first);
74 | // get all axioms corresponding to the clauses that
75 | // form the translations of formulas identified by coreVars
76 | final IntSet relevantClauses = StrategyUtils.clausesFor(trace, coreVars);
77 | assert !relevantClauses.isEmpty() && !relevantClauses.contains(trace.size()-1);
78 | return relevantClauses;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/kodkod/engine/ucore/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Contains strategies for minimizing unsatisfiable cores generated by SAT provers.
8 |
9 | Package Specification
10 |
11 | Contains implementations of various {@linkplain kodkod.engine.satlab.ReductionStrategy strategies}
12 | for minimizing unsatisfiable cores generated by {@linkplain kodkod.engine.satlab.SATProver SAT provers}.
13 |
14 | Related Documentation
15 |
16 | @see kodkod.engine.satlab.ReductionStrategy
17 | @see kodkod.engine.satlab.SATProver
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/kodkod/instance/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Contains classes for creating tuples, sets of tuples, bounds, and instances
8 | drawn from a finite universe of uninterpreted atoms.
9 |
10 | Package Specification
11 |
12 | Contains classes for creating {@linkplain kodkod.instance.Tuple tuples},
13 | {@linkplain kodkod.instance.TupleSet sets of tuples}, {@linkplain kodkod.instance.Bounds bounds}, and
14 | {@linkplain kodkod.instance.Instance instances} drawn from a finite
15 | {@linkplain kodkod.instance.Universe universe} of uninterpreted atoms.
16 |
17 | Related Documentation
18 |
19 | @see kodkod.instance.Universe
20 | @see kodkod.instance.TupleFactory
21 | @see kodkod.instance.Bounds
22 | @see kodkod.instance.Instance
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/kodkod/util/collections/Indexer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.util.collections;
23 |
24 |
25 | /**
26 | * An index generator for a set of keys. An indexer maps each key in its keyset
27 | * to a unique integer in the range [0..#keys)
28 | * @specfield keys: set K
29 | * @specfield indices: keys lone->one [0..#keys)
30 | * @author Emina Torlak
31 | */
32 | public interface Indexer {
33 |
34 |
35 | /**
36 | * Returns the index of the given key, if it is in this.keys.
37 | * Otherwise returns a negative number.
38 | * @return key in this.keys => this.indices[key], {i: int | i < 0 }
39 | */
40 | public abstract int indexOf(K key);
41 |
42 | /**
43 | * Returns the key at the given index.
44 | * @return this.indices.index
45 | * @throws IndexOutOfBoundsException index !in this.indices[this.keys]
46 | */
47 | public abstract K keyAt(int index);
48 |
49 | /**
50 | * Returns the number of keys in this.indexer.
51 | * @return #this.keys
52 | */
53 | public abstract int size();
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/kodkod/util/collections/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Contains specialized collections, such as a set that provides methods for
8 | retrieving elements with a particular hashcode.
9 |
10 | Package Specification
11 |
12 | Contains specialized collections, such as a set that provides methods for
13 | retrieving elements with a particular hashcode. It also provides a
14 | utility class for working with arrays.
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/kodkod/util/ints/IndexedEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.util.ints;
23 |
24 | /**
25 | * An entry in a {@link SparseSequence sparse sequence}.
26 | *
27 | * @specfield index: int
28 | * @specfield value: E
29 | *
30 | * @author Emina Torlak
31 | */
32 | public interface IndexedEntry {
33 |
34 | /**
35 | * Returns the index of this entry.
36 | * @return this.index
37 | */
38 | public abstract int index();
39 |
40 | /**
41 | * Returns the value stored in this entry.
42 | * @return this.value
43 | */
44 | public abstract E value();
45 |
46 | /**
47 | * Compares the specified object with this entry for equality. Returns true if
48 | * the given object is also an indexed entry and the two entries
49 | * have the same indeces and values. More formally, two entries e1 and e2
50 | * are equal if e1.index = e2.index && e1.value = e2.value. This ensures
51 | * that the equals method works properly across different implementations of
52 | * the IndexedEntry interface.
53 | * @return o in IndexedEntry && o.index = this.index && o.value = this.value
54 | */
55 | public abstract boolean equals(Object o);
56 |
57 | /**
58 | * Returns the hash code value for this indexed entry. The hash code of an
59 | * indexed entry e is defined to be:
60 | * e.index ^ (e.value=null ? 0 : e.value.hashCode()).
61 | * This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode()
62 | * for any two IndexedEntries e1 and e2, as required by the general contract of
63 | * Object.hashCode.
64 | */
65 | public abstract int hashCode();
66 | }
67 |
--------------------------------------------------------------------------------
/src/kodkod/util/ints/IntIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Kodkod -- Copyright (c) 2005-present, Emina Torlak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | */
22 | package kodkod.util.ints;
23 |
24 |
25 | /**
26 | * An iterator over integer primitives.
27 | *
28 | * @author Emina Torlak
29 | */
30 | public interface IntIterator {
31 |
32 | /**
33 | * Returns true if this iteration has more elements.
34 | * @return true if this iteration has more elements.
35 | */
36 | public abstract boolean hasNext();
37 |
38 | /**
39 | * Returns the next int in the iteration, if any.
40 | * Otherwise throws a NoSuchElementException.
41 | * @return the next element in the iteration
42 | * @throws java.util.NoSuchElementException the iteration is empty.
43 | */
44 | public abstract int next();
45 |
46 | /**
47 | * Removes the last returned element from the underlying collection.
48 | * @ensures removes the last returned element from the underlying collection.
49 | * @throws UnsupportedOperationException removal is not supported
50 | * @throws IllegalStateException next() has not been called yet or remove()
51 | * has already been called since the last call to next().
52 | */
53 | public abstract void remove();
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/kodkod/util/ints/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Provides implementations of ordered collections for storing integer primitives.
8 |
9 | Package Specification
10 |
11 | Provides several implementations of ordered collections for storing integer primitives.
12 |
13 | Related Documentation
14 |
15 | @see kodkod.util.ints.IntSet
16 | @see kodkod.util.ints.IntVector
17 | @see kodkod.util.ints.SparseSequence
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/kodkod/util/nodes/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Provides utility methods for constructing, analyzing, and pretty printing Kodkod nodes.
8 |
9 | Package Specification
10 |
11 | Provides utility methods for constructing, analyzing, and pretty printing Kodkod nodes.
12 |
13 | Related Documentation
14 |
15 | @see kodkod.util.nodes.Nodes
16 | @see kodkod.util.nodes.AnnotatedNode
17 | @see kodkod.util.nodes.PrettyPrinter
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/test/kodkod/test/AllTests.java:
--------------------------------------------------------------------------------
1 | package kodkod.test;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 | import org.junit.runners.Suite.SuiteClasses;
6 |
7 | import kodkod.test.unit.AllUnitTests;
8 | import kodkod.test.sys.AllSysTests;
9 |
10 | @RunWith(Suite.class)
11 | @SuiteClasses({
12 | AllUnitTests.class,
13 | AllSysTests.class
14 | })
15 |
16 | public class AllTests {}
17 |
--------------------------------------------------------------------------------
/test/kodkod/test/sys/AllSysTests.java:
--------------------------------------------------------------------------------
1 | package kodkod.test.sys;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 | import org.junit.runners.Suite.SuiteClasses;
6 |
7 | @RunWith(Suite.class)
8 | @SuiteClasses({
9 | ExamplesTestWithRegularSolver.class,
10 | ExamplesTestWithIncrementalSolver.class})
11 |
12 | public class AllSysTests {}
13 |
--------------------------------------------------------------------------------
/test/kodkod/test/sys/ExamplesTestWithIncrementalSolver.java:
--------------------------------------------------------------------------------
1 | package kodkod.test.sys;
2 |
3 | import static kodkod.engine.Solution.Outcome.UNSATISFIABLE;
4 | import static org.junit.Assert.assertEquals;
5 | import java.util.ArrayList;
6 | import java.util.Collection;
7 | import java.util.Set;
8 |
9 | import kodkod.ast.Formula;
10 | import kodkod.ast.Relation;
11 | import kodkod.engine.IncrementalSolver;
12 | import kodkod.engine.Solution;
13 | import kodkod.engine.config.Options;
14 | import kodkod.engine.fol2sat.SymmetryDetector;
15 | import kodkod.engine.satlab.SATFactory;
16 | import kodkod.instance.Bounds;
17 | import kodkod.instance.TupleFactory;
18 | import kodkod.instance.TupleSet;
19 | import kodkod.util.ints.IndexedEntry;
20 | import kodkod.util.ints.IntSet;
21 | import kodkod.util.nodes.AnnotatedNode;
22 | import kodkod.util.nodes.Nodes;
23 |
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 | import org.junit.runners.Parameterized;
27 | import org.junit.runners.Parameterized.Parameters;
28 |
29 | import kodkod.test.util.Solvers;
30 |
31 | import kodkod.examples.tptp.LAT258;
32 |
33 | @RunWith(Parameterized.class)
34 | public class ExamplesTestWithIncrementalSolver extends ExamplesTest {
35 |
36 |
37 | private final IncrementalSolver solver;
38 |
39 | public ExamplesTestWithIncrementalSolver(SATFactory solverOpt) {
40 | final Options opt = new Options();
41 | opt.setSolver(solverOpt);
42 | this.solver = IncrementalSolver.solver(opt);
43 | }
44 |
45 | @Parameters
46 | public static Collection