├── .gitignore ├── LICENSE ├── NOTES.md ├── README.md ├── doc ├── kodkod.css ├── kodkod.png └── kodkod │ └── doc │ └── SpecificationTaglet.java ├── examples ├── MANIFEST └── kodkod │ └── examples │ ├── alloy │ ├── AbstractWorldDefinitions.java │ ├── Bigconfig.java │ ├── CeilingsAndFloors.java │ ├── DNACuts.java │ ├── DiffEg.java │ ├── Dijkstra.java │ ├── FileSystem.java │ ├── GroupScheduling.java │ ├── Handshake.java │ ├── Hotel.java │ ├── Lists.java │ ├── Netconfig.java │ ├── Pigeonhole.java │ ├── RingElection.java │ ├── Toughnut.java │ ├── ToyFilesystem.java │ ├── ToyLists.java │ ├── Trees.java │ └── Viktor.java │ ├── bmc │ ├── List.java │ ├── ListCheck.java │ ├── ListDebug.java │ ├── ListEncoding.java │ ├── ListRepair.java │ ├── ListSynth.java │ └── ListViz.java │ ├── csp │ ├── BlockedNQueens.java │ ├── BlockedNQueens2.java │ ├── Graph.java │ ├── GraphColoring.java │ ├── GraphColoring2.java │ ├── HamiltonianCycle.java │ ├── HamiltonianCycle2.java │ ├── LatinSquare.java │ ├── MagicSeries.java │ ├── NQueens.java │ └── SocialGolfer.java │ ├── sudoku │ ├── Sudoku.java │ ├── SudokuDatabase.java │ └── SudokuParser.java │ ├── tptp │ ├── ALG195.java │ ├── ALG195_1.java │ ├── ALG197.java │ ├── ALG212.java │ ├── COM008.java │ ├── GEO091.java │ ├── GEO092.java │ ├── GEO115.java │ ├── GEO158.java │ ├── GEO159.java │ ├── GRA013_026.java │ ├── LAT258.java │ ├── MED001.java │ ├── MED007.java │ ├── MED009.java │ ├── MGT066.java │ ├── NUM374.java │ ├── NUM378.java │ ├── Quasigroups7.java │ ├── SET943.java │ ├── SET948.java │ ├── SET967.java │ └── TOP020.java │ └── xpose │ ├── Transpose4x4.java │ ├── Transpose4x4UnaryL.java │ └── Transpose4x4UnaryLR.java ├── javadoc.xml ├── jni ├── glucose │ ├── Solver.patch │ ├── kodkod_engine_satlab_Glucose.cpp │ ├── kodkod_engine_satlab_Glucose.h │ └── wscript ├── lingeling │ ├── kodkod_engine_satlab_Lingeling.c │ ├── kodkod_engine_satlab_Lingeling.h │ └── wscript ├── minisat │ ├── kodkod_engine_satlab_MiniSat.cpp │ ├── kodkod_engine_satlab_MiniSat.h │ └── wscript ├── minisatp │ ├── kodkod_engine_satlab_MiniSatProver.cpp │ ├── kodkod_engine_satlab_MiniSatProver.h │ └── wscript ├── plingeling │ └── wscript └── wscript ├── src ├── MANIFEST └── kodkod │ ├── ast │ ├── BinaryExpression.java │ ├── BinaryFormula.java │ ├── BinaryIntExpression.java │ ├── ComparisonFormula.java │ ├── Comprehension.java │ ├── ConstantExpression.java │ ├── ConstantFormula.java │ ├── Decl.java │ ├── Decls.java │ ├── ExprToIntCast.java │ ├── Expression.java │ ├── Formula.java │ ├── IfExpression.java │ ├── IfIntExpression.java │ ├── IntComparisonFormula.java │ ├── IntConstant.java │ ├── IntExpression.java │ ├── IntToExprCast.java │ ├── LeafExpression.java │ ├── MultiplicityFormula.java │ ├── NaryExpression.java │ ├── NaryFormula.java │ ├── NaryIntExpression.java │ ├── Node.java │ ├── NotFormula.java │ ├── ProjectExpression.java │ ├── QuantifiedFormula.java │ ├── Relation.java │ ├── RelationPredicate.java │ ├── SumExpression.java │ ├── UnaryExpression.java │ ├── UnaryIntExpression.java │ ├── Variable.java │ ├── operator │ │ ├── ExprCastOperator.java │ │ ├── ExprCompOperator.java │ │ ├── ExprOperator.java │ │ ├── FormulaOperator.java │ │ ├── IntCastOperator.java │ │ ├── IntCompOperator.java │ │ ├── IntOperator.java │ │ ├── Multiplicity.java │ │ ├── Quantifier.java │ │ └── package.html │ ├── package.html │ └── visitor │ │ ├── AbstractCollector.java │ │ ├── AbstractDetector.java │ │ ├── AbstractReplacer.java │ │ ├── AbstractVoidVisitor.java │ │ ├── ReturnVisitor.java │ │ ├── VoidVisitor.java │ │ └── package.html │ ├── engine │ ├── AbortedException.java │ ├── CapacityExceededException.java │ ├── Evaluator.java │ ├── IncrementalSolver.java │ ├── KodkodSolver.java │ ├── Proof.java │ ├── ResolutionBasedProof.java │ ├── Solution.java │ ├── Solver.java │ ├── Statistics.java │ ├── TrivialProof.java │ ├── bool │ │ ├── BinaryGate.java │ │ ├── BooleanAccumulator.java │ │ ├── BooleanConstant.java │ │ ├── BooleanFactory.java │ │ ├── BooleanFormula.java │ │ ├── BooleanMatrix.java │ │ ├── BooleanValue.java │ │ ├── BooleanVariable.java │ │ ├── BooleanVisitor.java │ │ ├── CBCFactory.java │ │ ├── Dimensions.java │ │ ├── ITEGate.java │ │ ├── Int.java │ │ ├── MultiGate.java │ │ ├── NaryGate.java │ │ ├── NotGate.java │ │ ├── Operator.java │ │ ├── RBCFactory.java │ │ ├── TwosComplementInt.java │ │ └── package.html │ ├── config │ │ ├── AbstractReporter.java │ │ ├── ConsoleReporter.java │ │ ├── Options.java │ │ ├── Reporter.java │ │ └── package.html │ ├── fol2sat │ │ ├── Bool2CNFTranslator.java │ │ ├── Environment.java │ │ ├── FOL2BoolCache.java │ │ ├── FOL2BoolTranslator.java │ │ ├── FileLogger.java │ │ ├── FormulaFlattener.java │ │ ├── FreeVariableCollector.java │ │ ├── HigherOrderDeclException.java │ │ ├── LeafInterpreter.java │ │ ├── MemoryLogger.java │ │ ├── RecordFilter.java │ │ ├── Skolemizer.java │ │ ├── SymmetryBreaker.java │ │ ├── SymmetryDetector.java │ │ ├── Translation.java │ │ ├── TranslationLog.java │ │ ├── TranslationLogger.java │ │ ├── TranslationRecord.java │ │ ├── Translator.java │ │ ├── UnboundLeafException.java │ │ └── package.html │ ├── package.html │ ├── satlab │ │ ├── Clause.java │ │ ├── ExternalSolver.java │ │ ├── Glucose.java │ │ ├── LazyTrace.java │ │ ├── Lingeling.java │ │ ├── MiniSat.java │ │ ├── MiniSatProver.java │ │ ├── NativeSolver.java │ │ ├── ReductionStrategy.java │ │ ├── ResolutionTrace.java │ │ ├── SAT4J.java │ │ ├── SATAbortedException.java │ │ ├── SATFactory.java │ │ ├── SATProver.java │ │ ├── SATSolver.java │ │ └── package.html │ └── ucore │ │ ├── AdaptiveRCEStrategy.java │ │ ├── CRRStrategy.java │ │ ├── DynamicRCEStrategy.java │ │ ├── ECFPStrategy.java │ │ ├── HybridStrategy.java │ │ ├── NCEStrategy.java │ │ ├── RCEStrategy.java │ │ ├── SCEStrategy.java │ │ ├── StrategyUtils.java │ │ └── package.html │ ├── instance │ ├── Bounds.java │ ├── Instance.java │ ├── Tuple.java │ ├── TupleFactory.java │ ├── TupleSet.java │ ├── Universe.java │ └── package.html │ └── util │ ├── collections │ ├── ArrayStack.java │ ├── CacheSet.java │ ├── Containers.java │ ├── FixedMap.java │ ├── IdentityHashSet.java │ ├── Indexer.java │ ├── LinkedStack.java │ ├── SingletonIdentitySet.java │ ├── Stack.java │ └── package.html │ ├── ints │ ├── AbstractIntCollection.java │ ├── AbstractIntSet.java │ ├── AbstractIntVector.java │ ├── AbstractSparseSequence.java │ ├── ArrayIntSet.java │ ├── ArrayIntVector.java │ ├── ArraySequence.java │ ├── EntryView.java │ ├── HomogenousSequence.java │ ├── IndexedEntry.java │ ├── IntBitSet.java │ ├── IntCollection.java │ ├── IntIterator.java │ ├── IntRange.java │ ├── IntSet.java │ ├── IntTree.java │ ├── IntTreeSet.java │ ├── IntVector.java │ ├── Ints.java │ ├── RangeSequence.java │ ├── SparseSequence.java │ ├── TreeSequence.java │ └── package.html │ └── nodes │ ├── AnnotatedNode.java │ ├── Nodes.java │ ├── PrettyPrinter.java │ └── package.html ├── test └── kodkod │ └── test │ ├── AllTests.java │ ├── sys │ ├── AllSysTests.java │ ├── ExamplesTest.java │ ├── ExamplesTestWithIncrementalSolver.java │ └── ExamplesTestWithRegularSolver.java │ ├── unit │ ├── AllUnitTests.java │ ├── BooleanCircuitTest.java │ ├── BooleanMatrixTest.java │ ├── EnumerationTest.java │ ├── EvaluatorTest.java │ ├── IncrementalSolverTest.java │ ├── IntTest.java │ ├── NativeSolverTest.java │ ├── ReductionAndProofTest.java │ ├── RegressionTests.java │ ├── SkolemizationTest.java │ ├── SparseSequenceTest.java │ ├── SymmetryBreakingTest.java │ ├── TranslatorTest.java │ └── UCoreTest.java │ └── util │ ├── ProcessRunner.java │ ├── Reflection.java │ └── Solvers.java └── wscript /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | *.class 4 | 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | # Package Files # 9 | *.jar 10 | *.war 11 | *.ear 12 | 13 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 14 | hs_err_pid* 15 | /bin/ 16 | /lib/ 17 | **/build/** 18 | *~ 19 | .DS_Store 20 | .DS_Store? 21 | .lock-waf* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2005 - present Emina Torlak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Kodkod 2 | ======= 3 | 4 | This repository includes the source code for the 5 | [Kodkod](http://emina.github.io/kodkod/) solver for relational 6 | logic. Kodkod provides a clean Java [API](http://emina.github.io/kodkod/doc/) for constructing, 7 | manipulating, and solving relational constraints. The 8 | source code is extensively documented, and the repository includes 9 | many [examples](https://github.com/emina/kodkod/tree/master/examples/kodkod/examples) demonstrating the use of the Kodkod API. 10 | 11 | Kodkod is open-source and available under the [MIT license](LICENSE). However, the implementation relies on third-party SAT solvers ([SAT4J](http://www.sat4j.org), [MiniSat](http://minisat.se), [Glucose](http://www.labri.fr/perso/lsimon/glucose/), and [(P)Lingeling](http://fmv.jku.at/lingeling/)), some of which are released under stricter licenses. Please see the solver licenses for details. 12 | 13 | ### Downloading Kodkod 14 | 15 | The easiest way to get started is to [download](https://github.com/emina/kodkod/releases) the latest release, which includes precompiled binaries for Kodkod and various SAT solvers. You will need Java 8 running on Linux or Mac OS X. 16 | 17 | 18 | ### Building Kodkod 19 | 20 | The following instructions for building Kodkod from source have been 21 | tested on Linux (Fedora 22 with gcc 5.1.1) and on Mac OS X (10.10.5 with clang 6.0 and gcc 4.9). You may 22 | need to modify the build scripts for other operating systems. 23 | 24 | Kodkod uses the [Waf](https://github.com/waf-project/waf) build 25 | system, which requires Python 2.5 or later. You will also need Java 8 26 | and a C/C++ compiler, and your JAVA_HOME environment variable needs to 27 | point to the JDK 8 home directory. 28 | 29 | * Set the JAVA_HOME variable. For example, on OS X: 30 | 31 | ``$ export JAVA_HOME=`/usr/libexec/java_home` `` 32 | 33 | * Clone the kodkod repository: 34 | 35 | `$ git clone https://github.com/emina/kodkod.git` 36 | `$ cd kodkod` 37 | 38 | * Download Waf 1.8.12 and make it executable: 39 | 40 | `$ wget --no-check-certificate https://waf.io/waf-1.8.12` 41 | `$ chmod u+x waf-1.8.12` 42 | `$ alias waf=$PWD/waf-1.8.12` 43 | 44 | * Build the native libraries, ``kodkod.jar``, and ``examples.jar`` and install them into the ``kodkod/lib`` directory: 45 | 46 | `$ waf configure --prefix=. --libdir=lib build install` 47 | 48 | ### Running Kodkod 49 | 50 | [Download](#downloading-kodkod) or [build](#building-kodkod) the ``kodkod.jar`` binary, solver binaries, and the ``examples.jar`` binary. Assuming that the current working directory contains these binaries, run the [Sudoku example](https://github.com/emina/kodkod/blob/master/examples/kodkod/examples/sudoku/Sudoku.java) as follows: 51 | 52 | `$ java -cp kodkod.jar:examples.jar -Djava.library.path=. kodkod.examples.sudoku.Sudoku` 53 | 54 | The program will produce a solution to a sample Sudoku puzzle: 55 | 56 | ``` 57 | p cnf 3452 7954 58 | primary variables: 486 59 | translation time: 176 ms 60 | solving time: 2 ms 61 | +-------+-------+-------+ 62 | | 6 4 7 | 2 1 3 | 9 5 8 | 63 | | 9 1 8 | 5 6 4 | 7 2 3 | 64 | | 2 5 3 | 8 7 9 | 4 6 1 | 65 | +-------+-------+-------+ 66 | | 1 9 5 | 6 4 7 | 8 3 2 | 67 | | 4 8 2 | 3 5 1 | 6 7 9 | 68 | | 7 3 6 | 9 2 8 | 1 4 5 | 69 | +-------+-------+-------+ 70 | | 5 7 4 | 1 9 2 | 3 8 6 | 71 | | 8 2 9 | 7 3 6 | 5 1 4 | 72 | | 3 6 1 | 4 8 5 | 2 9 7 | 73 | +-------+-------+-------+ 74 | ``` 75 | -------------------------------------------------------------------------------- /doc/kodkod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emina/kodkod/6e802440a20ca6a5e6817e410b308fdcef87fade/doc/kodkod.png -------------------------------------------------------------------------------- /examples/MANIFEST: -------------------------------------------------------------------------------- 1 | Name: kodkod examples 2 | Specification-Title: Kodkod Examples 3 | Specification-Version: 2.1 4 | Specification-Vendor: Emina Torlak 5 | Implementation-Title: Kodkod Examples 6 | Implementation-Version: 2.1 7 | Implementation-Vendor: Emina Torlak -------------------------------------------------------------------------------- /examples/kodkod/examples/alloy/Pigeonhole.java: -------------------------------------------------------------------------------- 1 | package kodkod.examples.alloy; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import kodkod.ast.Formula; 7 | import kodkod.ast.Relation; 8 | import kodkod.ast.Variable; 9 | import kodkod.engine.Solution; 10 | import kodkod.engine.Solver; 11 | import kodkod.engine.satlab.SATFactory; 12 | import kodkod.instance.Bounds; 13 | import kodkod.instance.TupleFactory; 14 | import kodkod.instance.TupleSet; 15 | import kodkod.instance.Universe; 16 | 17 | /** 18 | * A KodKod encoding of the pigeonhole problem: module internal/pigeonhole 19 | *
 
 20 |  * sig Pigeon { hole: Hole }
 21 |  * 
 22 |  * sig Hole {}
 23 |  * 
 24 |  * pred aPigeonPerHole() { 
 25 |  * // holes are not shared 
 26 |  *  no disj p1, p2: Pigeon |
 27 |  *   p1.hole = p2.hole }
 28 |  * 
 29 |  * run aPigeonPerHole for exactly 30 Pigeon, exactly 29 Hole
 30 |  * 
31 | * @author Emina Torlak 32 | */ 33 | public final class Pigeonhole { 34 | // sigs 35 | private final Relation Pigeon, Hole; 36 | // fields 37 | private final Relation hole; 38 | 39 | /** 40 | * Creates an instance of the pigeonhole example. 41 | */ 42 | public Pigeonhole() { 43 | this.Pigeon = Relation.unary("Pigeon"); 44 | this.Hole = Relation.unary("Hole"); 45 | this.hole = Relation.binary("hole"); 46 | } 47 | 48 | /** 49 | * Returns the declaration constraints. 50 | * @return declarations 51 | */ 52 | public Formula declarations() { 53 | return hole.function(Pigeon, Hole); 54 | } 55 | 56 | /** 57 | * Returns the aPigeonPerHole constraints. 58 | * @return aPigeonPerHole 59 | */ 60 | public Formula pigeonPerHole() { 61 | final Variable p1 = Variable.unary("p1"); 62 | final Variable p2 = Variable.unary("p2"); 63 | return (p1.eq(p2).not(). 64 | implies(p1.join(hole).intersection(p2.join(hole)).no())). 65 | forAll(p1.oneOf(Pigeon).and(p2.oneOf(Pigeon))); 66 | } 67 | 68 | /** 69 | * Returns the bounds for the given number of pigeons and holes. 70 | * @return bounds 71 | */ 72 | public Bounds bounds(int pigeons, int holes) { 73 | final List atoms = new ArrayList(pigeons + holes); 74 | for(int i = 0; i < pigeons; i++) { 75 | atoms.add("Pigeon"+i); 76 | } 77 | for(int i = 0; i < holes; i++) { 78 | atoms.add("Hole"+i); 79 | } 80 | final Universe u = new Universe(atoms); 81 | final TupleFactory f = u.factory(); 82 | 83 | final Bounds b = new Bounds(u); 84 | 85 | final TupleSet pbound = f.range(f.tuple("Pigeon0"), f.tuple("Pigeon" + (pigeons-1))); 86 | final TupleSet hbound = f.range(f.tuple("Hole0"), f.tuple("Hole" + (holes-1))); 87 | b.boundExactly(Pigeon, pbound); 88 | b.boundExactly(Hole, hbound); 89 | b.bound(hole, pbound.product(hbound)); 90 | return b; 91 | } 92 | 93 | private static void usage() { 94 | System.out.println("Usage: java tests.Pigeonhole [# pigeons] [# holes]"); 95 | System.exit(1); 96 | } 97 | 98 | /** 99 | * Usage: java tests.Pigeonhole [# pigeons] [# holes] 100 | */ 101 | public static void main(String[] args) { 102 | if (args.length < 2) 103 | usage(); 104 | final Pigeonhole model = new Pigeonhole(); 105 | final Solver solver = new Solver(); 106 | 107 | try { 108 | final int p = Integer.parseInt(args[0]); 109 | final int h = Integer.parseInt(args[1]); 110 | solver.options().setSolver(SATFactory.MiniSat); 111 | solver.options().setSymmetryBreaking(p); 112 | final Formula show = model.declarations().and(model.pigeonPerHole()); 113 | final Solution sol = solver.solve(show, model.bounds(p,h)); 114 | //System.out.println(show); 115 | System.out.println(sol); 116 | 117 | } catch (NumberFormatException nfe) { 118 | usage(); 119 | } 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /examples/kodkod/examples/bmc/ListCheck.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.examples.bmc; 23 | 24 | import kodkod.ast.Formula; 25 | import kodkod.engine.Solution; 26 | import kodkod.engine.Solver; 27 | import kodkod.engine.satlab.SATFactory; 28 | import kodkod.examples.bmc.ListViz.State; 29 | import kodkod.instance.Bounds; 30 | 31 | /** 32 | * Bounded verification demo. 33 | * 34 | * @author Emina Torlak 35 | * 36 | */ 37 | public class ListCheck extends ListEncoding { 38 | 39 | ListCheck() {} 40 | 41 | Formula checkSpec() { 42 | return Formula.and(pre(), loopGuard(), post().not()); 43 | } 44 | 45 | Bounds checkBounds(int size) { return bounds(size); } 46 | 47 | Solution check(int size) { 48 | final Solver solver = new Solver(); 49 | solver.options().setSolver(SATFactory.MiniSat); 50 | return solver.solve(checkSpec(), checkBounds(size)); 51 | } 52 | 53 | private void showCheck(int size) { 54 | final Solution sol = check(size); 55 | System.out.println("************ CHECK REVERSE FOR " + size + " NODES ************"); 56 | System.out.println(sol.outcome()); 57 | System.out.println(); 58 | System.out.println(sol.stats()); 59 | System.out.println(); 60 | ListViz.printInstance(this, sol.instance()); 61 | ListViz.printStateGraph("check-pre", this, sol.instance(), State.PRE); 62 | ListViz.printStateGraph("check-post", this, sol.instance(), State.POST); 63 | } 64 | 65 | public static void main(String[] args) { 66 | ListCheck enc = new ListCheck(); 67 | //ListViz.printEncoding(enc); 68 | enc.showCheck(1); 69 | enc.showCheck(2); 70 | enc.showCheck(3); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /examples/kodkod/examples/bmc/ListRepair.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.examples.bmc; 23 | 24 | import kodkod.ast.Expression; 25 | import kodkod.ast.Formula; 26 | import kodkod.ast.Relation; 27 | import kodkod.engine.Solution; 28 | import kodkod.engine.Solver; 29 | import kodkod.engine.satlab.SATFactory; 30 | import kodkod.examples.bmc.ListViz.State; 31 | import kodkod.instance.Bounds; 32 | import kodkod.instance.Instance; 33 | import kodkod.instance.TupleFactory; 34 | 35 | /** 36 | * Data structure repair demo. 37 | * 38 | * @author Emina Torlak 39 | */ 40 | public class ListRepair extends ListEncoding { 41 | final Relation next3, head0; 42 | 43 | ListRepair() { 44 | 45 | next3 = Relation.binary("next3"); // next3 = free variable 46 | head0 = Relation.binary("head0"); // head0 = free variable 47 | } 48 | 49 | Expression next3() { return next3; } 50 | Expression head0() { return head0; } 51 | 52 | Formula repairSpec() { 53 | return Formula.and(pre(), post()); 54 | } 55 | 56 | Bounds repairBounds(int size) { 57 | final Bounds b = bounds(size); 58 | final ListCheck checker = new ListCheck(); 59 | final Instance cex = checker.check(size).instance(); 60 | assert cex != null; 61 | final TupleFactory t = b.universe().factory(); 62 | b.bound(next3, b.upperBound(next)); 63 | b.bound(head0, b.upperBound(head)); 64 | b.boundExactly(next, copyFrom(t, cex.tuples(checker.next))); 65 | b.boundExactly(head, copyFrom(t, cex.tuples(checker.head))); 66 | b.boundExactly(data, copyFrom(t, cex.tuples(checker.data))); 67 | b.boundExactly(thisList, copyFrom(t, cex.tuples(checker.thisList))); 68 | return b; 69 | } 70 | 71 | Solution repair(int size) { 72 | final Solver solver = new Solver(); 73 | solver.options().setSolver(SATFactory.MiniSat); 74 | return solver.solve(repairSpec(), repairBounds(size)); 75 | } 76 | 77 | private void showRepair(int size) { 78 | final Solution sol = repair(size); 79 | System.out.println("************ REPAIR REVERSE FOR " + size + " NODES ************"); 80 | System.out.println(sol.outcome()); 81 | System.out.println(); 82 | System.out.println(sol.stats()); 83 | System.out.println(); 84 | ListViz.printInstance(this, sol.instance()); 85 | ListViz.printStateGraph("repair-pre", this, sol.instance(), State.PRE); 86 | ListViz.printStateGraph("repair-post", this, sol.instance(), State.POST); 87 | 88 | } 89 | 90 | public static void main(String[] args) { 91 | ListRepair enc = new ListRepair(); 92 | //ListViz.printEncoding(enc); 93 | enc.showRepair(3); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /examples/kodkod/examples/tptp/GEO091.java: -------------------------------------------------------------------------------- 1 | package kodkod.examples.tptp; 2 | 3 | import kodkod.ast.Formula; 4 | import kodkod.ast.Variable; 5 | import kodkod.engine.Solution; 6 | import kodkod.engine.Solver; 7 | import kodkod.engine.satlab.SATFactory; 8 | import kodkod.instance.Bounds; 9 | 10 | /** 11 | * The GEO091+1 problem from http://www.cs.miami.edu/~tptp/ 12 | * 13 | * @author Emina Torlak 14 | */ 15 | public class GEO091 extends GEO158 { 16 | 17 | /** 18 | * Constructs a new instance of GEO091. 19 | */ 20 | public GEO091() { 21 | super(); 22 | // TODO Auto-generated constructor stub 23 | } 24 | 25 | /** 26 | * Returns the conjecture theorem_2_13. 27 | * @return theorem_2_13 28 | */ 29 | public final Formula theorem_2_13() { 30 | // all C, C1, C2: Curve | 31 | // ((C1 + C2)->C in partOf && C in Open && 32 | // !(lone endPoint.C1 & endPoint.C2)) => C1 = C2 33 | final Variable c = Variable.unary("C"); 34 | final Variable c1 = Variable.unary("C1"); 35 | final Variable c2 = Variable.unary("C2"); 36 | final Formula f0 = c1.union(c2).product(c).in(partOf).and(c.in(open)); 37 | final Formula f1 = endPoint.join(c1).intersection(endPoint.join(c2)).lone().not(); 38 | return f0.and(f1).implies(c1.eq(c2)).forAll(c.oneOf(curve).and(c1.oneOf(curve)).and(c2.oneOf(curve))); 39 | } 40 | 41 | /** 42 | * Returns the conjunction of the axioms and the negation of the hypothesis. 43 | * @return axioms() && !theorem_2_13() 44 | */ 45 | public final Formula checkTheorem_2_13() { 46 | return axioms().and(theorem_2_13().not()); 47 | } 48 | 49 | private static void usage() { 50 | System.out.println("java examples.tptp.GEO191 [univ size]"); 51 | System.exit(1); 52 | } 53 | 54 | /** 55 | * Usage: java examples.tptp.GEO191 [univ size] 56 | */ 57 | public static void main(String[] args) { 58 | if (args.length < 1) 59 | usage(); 60 | 61 | try { 62 | final int n = Integer.parseInt(args[0]); 63 | 64 | final Solver solver = new Solver(); 65 | solver.options().setSolver(SATFactory.MiniSat); 66 | final GEO091 model = new GEO091(); 67 | final Formula f = model.checkTheorem_2_13(); 68 | 69 | System.out.println(model.theorem_2_13()); 70 | 71 | final Bounds b = model.bounds(n); 72 | final Solution sol = solver.solve(f,b); 73 | 74 | System.out.println(sol); 75 | //System.out.println((new Evaluator(sol.instance())).evaluate(model.axioms().and(model.theorem213().not()))); 76 | } catch (NumberFormatException nfe) { 77 | usage(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /examples/kodkod/examples/tptp/GEO092.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package kodkod.examples.tptp; 5 | 6 | import kodkod.ast.Expression; 7 | import kodkod.ast.Formula; 8 | import kodkod.ast.Variable; 9 | import kodkod.engine.Solution; 10 | import kodkod.engine.Solver; 11 | import kodkod.engine.satlab.SATFactory; 12 | import kodkod.instance.Bounds; 13 | 14 | /** 15 | * The GEO092+1 problem from http://www.cs.miami.edu/~tptp/ 16 | * 17 | * @author Emina Torlak 18 | */ 19 | public class GEO092 extends GEO158 { 20 | 21 | /** 22 | * Constructs a new instance of GEO091. 23 | */ 24 | public GEO092() { 25 | super(); 26 | // TODO Auto-generated constructor stub 27 | } 28 | 29 | /* 30 | * fof(proposition_2_14_1,conjecture, 31 | ( ! [C1,C2,P] : 32 | ( ( meet(P,C1,C2) 33 | & open(sum(C1,C2)) ) 34 | => ! [Q] : 35 | ( Q != P 36 | => ~ ( incident_c(Q,C1) 37 | & incident_c(Q,C2) ) ) ) )). 38 | */ 39 | /** 40 | * Returns the conjecture proposition_2_14_1. 41 | * @return proposition_2_14_1 42 | */ 43 | public final Formula proposition2141() { 44 | // all c1, c2: curve, p: point | 45 | // p->c1->c2 in meet && c1->c2 in sum.open => 46 | // all q: point - p | c1 + c2 !in q.incident 47 | final Variable c1 = Variable.unary("C1"); 48 | final Variable c2 = Variable.unary("C2"); 49 | final Variable p = Variable.unary("P"); 50 | final Variable q = Variable.unary("Q"); 51 | final Expression e0 = c1.product(c2); 52 | final Formula f0 = p.product(e0).in(meet).and(e0.in(sum.join(open))); 53 | final Formula f1 = c1.union(c2).in(q.join(incident)).not().forAll(q.oneOf(point.difference(p))); 54 | return f0.implies(f1).forAll(c1.oneOf(curve).and(c2.oneOf(curve)).and(p.oneOf(point))); 55 | } 56 | 57 | /** 58 | * Returns the conjunction of the axioms and the negation of the hypothesis. 59 | * @return axioms() && !proposition2141() 60 | */ 61 | public final Formula checkProposition2141() { 62 | return axioms().and(proposition2141().not()); 63 | } 64 | 65 | 66 | private static void usage() { 67 | System.out.println("java examples.tptp.GEO192 [scope]"); 68 | System.exit(1); 69 | } 70 | 71 | /** 72 | * Usage: ava examples.tptp.GEO192 [# curves] [# points] 73 | */ 74 | public static void main(String[] args) { 75 | if (args.length < 2) 76 | usage(); 77 | 78 | try { 79 | final int n = Integer.parseInt(args[0]); 80 | 81 | 82 | final Solver solver = new Solver(); 83 | solver.options().setSolver(SATFactory.MiniSat); 84 | final GEO092 model = new GEO092(); 85 | final Formula f = model.checkProposition2141(); 86 | 87 | System.out.println(model.proposition2141()); 88 | 89 | final Bounds b = model.bounds(n); 90 | final Solution sol = solver.solve(f,b); 91 | 92 | System.out.println(sol); 93 | //System.out.println((new Evaluator(sol.instance())).evaluate(model.axioms().and(model.theorem213().not()))); 94 | } catch (NumberFormatException nfe) { 95 | usage(); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /examples/kodkod/examples/tptp/GEO115.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package kodkod.examples.tptp; 5 | 6 | import kodkod.ast.Expression; 7 | import kodkod.ast.Formula; 8 | import kodkod.ast.Variable; 9 | import kodkod.engine.Solution; 10 | import kodkod.engine.Solver; 11 | import kodkod.engine.satlab.SATFactory; 12 | import kodkod.instance.Bounds; 13 | 14 | /** 15 | * KK encoding of GEO115+1.p from http://www.cs.miami.edu/~tptp/ 16 | * @author Emina Torlak 17 | */ 18 | public final class GEO115 extends GEO159 { 19 | 20 | /** 21 | * Constructs a new instance of GEO115. 22 | */ 23 | public GEO115() { 24 | super(); 25 | // TODO Auto-generated constructor stub 26 | } 27 | 28 | /** 29 | * Returns the conjecture theorem_3_8_5. 30 | * @return theorem_3_8_5 31 | */ 32 | public final Formula theorem385() { 33 | // all c: curve, p, q, r: point | 34 | // c->p->q->r in between => 35 | // incident.c - q in q.(p.(c.between)) + ((c.between).r).q 36 | final Variable c = Variable.unary("C"); 37 | final Variable p = Variable.unary("P"); 38 | final Variable q = Variable.unary("Q"); 39 | final Variable r = Variable.unary("R"); 40 | final Formula f0 = c.product(p).product(q).product(r).in(between); 41 | final Expression e0 = q.join(p.join(c.join(between))); 42 | final Expression e1 = c.join(between).join(r).join(q); 43 | final Formula f1 = incident.join(c).difference(q).in(e0.union(e1)); 44 | return f0.implies(f1).forAll(p.oneOf(point).and(q.oneOf(point)).and(r.oneOf(point)).and(c.oneOf(curve))); 45 | } 46 | 47 | /** 48 | * Returns the conjunction of the axioms and the negation of the hypothesis. 49 | * @return axioms() && !theorem385() 50 | */ 51 | public final Formula checkTheorem385() { 52 | return axioms().and(theorem385().not()); 53 | } 54 | 55 | private static void usage() { 56 | System.out.println("java examples.tptp.GEO115 [# curves] [# points]"); 57 | System.exit(1); 58 | } 59 | 60 | /** 61 | * Usage: ava examples.tptp.GEO115 [scope] 62 | */ 63 | public static void main(String[] args) { 64 | if (args.length < 1) 65 | usage(); 66 | 67 | try { 68 | final int n = Integer.parseInt(args[0]); 69 | 70 | 71 | final Solver solver = new Solver(); 72 | solver.options().setSolver(SATFactory.MiniSat); 73 | 74 | final GEO115 model = new GEO115(); 75 | final Formula f = model.theorem385(); 76 | 77 | final Bounds b = model.bounds(n); 78 | final Solution sol = solver.solve(f,b); 79 | 80 | System.out.println(sol); 81 | 82 | } catch (NumberFormatException nfe) { 83 | usage(); 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /examples/kodkod/examples/tptp/GEO159.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package kodkod.examples.tptp; 5 | 6 | import kodkod.ast.Expression; 7 | import kodkod.ast.Formula; 8 | import kodkod.ast.Relation; 9 | import kodkod.ast.Variable; 10 | import kodkod.engine.Solution; 11 | import kodkod.engine.Solver; 12 | import kodkod.engine.satlab.SATFactory; 13 | import kodkod.instance.Bounds; 14 | import kodkod.instance.TupleSet; 15 | 16 | /** 17 | * The GEO159+1 problem from http://www.cs.miami.edu/~tptp/ 18 | * @author Emina Torlak 19 | */ 20 | public class GEO159 extends GEO158 { 21 | final Relation between; 22 | /* 23 | * beteween : C -> P -> P -> P 24 | */ 25 | /** 26 | * Constructs a new instance of GEO159. 27 | */ 28 | public GEO159() { 29 | between = Relation.nary("between_c", 4); 30 | } 31 | 32 | /** 33 | * Returns the between_c_defn axiom. 34 | * @return between_c_defn 35 | */ 36 | public final Formula betweenDefn() { 37 | // all c, p, q, r: point | 38 | // c->p->q->r in between <=> p != r && some p.endPoint & r.endPoint & q.innerPoint & partOf.c 39 | final Variable c = Variable.unary("C"); 40 | final Variable p = Variable.unary("P"); 41 | final Variable q = Variable.unary("Q"); 42 | final Variable r = Variable.unary("R"); 43 | final Expression e = p.join(endPoint).intersection(r.join(endPoint)). 44 | intersection(q.join(innerPoint)).intersection(partOf.join(c)); 45 | final Formula f0 = c.product(p).product(q).product(r).in(between); 46 | final Formula f1 = p.eq(q).not().and(e.some()); 47 | return f0.iff(f1).forAll(p.oneOf(point).and(q.oneOf(point)).and(r.oneOf(point)).and(c.oneOf(curve))); 48 | } 49 | 50 | /** 51 | * Returns all the 'type' declarations. 52 | * @return the type declarations 53 | */ 54 | public Formula decls() { 55 | return super.decls().and(between.in(curve.product(point).product(point).product(point))); 56 | } 57 | 58 | /** 59 | * Returns the conjunction of all axioms and decls 60 | * @returns the conjunction of all axioms and decls 61 | */ 62 | public Formula checkDefs() { 63 | return super.axioms().and(betweenDefn()).and(someCurve()); 64 | } 65 | 66 | 67 | /** 68 | * Returns a bounds with the given number of maximum curves and points 69 | * @return a bounds with the given number of maximum curves and points 70 | */ 71 | public Bounds bounds(int scope) { 72 | final Bounds b = super.bounds(scope); 73 | final TupleSet c = b.upperBound(curve); 74 | final TupleSet p = b.upperBound(point); 75 | b.bound(between, c.product(p).product(p).product(p)); 76 | return b; 77 | } 78 | 79 | private static void usage() { 80 | System.out.println("java examples.tptp.GEO159 [scope]"); 81 | System.exit(1); 82 | } 83 | 84 | /** 85 | * Usage: ava examples.tptp.GEO159 [scope] 86 | */ 87 | public static void main(String[] args) { 88 | if (args.length < 1) 89 | usage(); 90 | 91 | try { 92 | final int n = Integer.parseInt(args[0]); 93 | 94 | final Solver solver = new Solver(); 95 | solver.options().setSolver(SATFactory.MiniSat); 96 | 97 | final GEO159 model = new GEO159(); 98 | final Formula f = model.checkDefs(); 99 | 100 | final Bounds b = model.bounds(n); 101 | final Solution sol = solver.solve(f,b); 102 | System.out.println(sol); 103 | } catch (NumberFormatException nfe) { 104 | usage(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/kodkod/examples/tptp/MED007.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package kodkod.examples.tptp; 5 | import static kodkod.ast.Expression.UNIV; 6 | import kodkod.ast.Formula; 7 | import kodkod.ast.Variable; 8 | import kodkod.engine.Solution; 9 | import kodkod.engine.Solver; 10 | import kodkod.engine.satlab.SATFactory; 11 | import kodkod.instance.Bounds; 12 | 13 | /** 14 | * A KK encoding of MED007+1.p from http://www.cs.miami.edu/~tptp/ 15 | * @author Emina Torlak 16 | */ 17 | public final class MED007 extends MED001 { 18 | /** 19 | * Constructs a new instance of MED007. 20 | */ 21 | public MED007() { } 22 | 23 | /** 24 | * Returns transsls2_qilt27 conjecture. 25 | * @return transsls2_qilt27 26 | */ 27 | public final Formula transsls2_qilt27() { 28 | final Variable x0 = Variable.unary("X0"); 29 | final Formula f0 = n0.in(s1).and(n0.join(gt).in(conditionhyper)). 30 | and(n0.in(bcapacitysn).not()).and(n0.in(qilt27)); 31 | final Formula f1 = n0.product(x0).in(gt).not().and(x0.in(s2)). 32 | and(x0.join(gt).in(conditionhyper)).and(x0.in(bcapacityne.union(bcapacityex))). 33 | forSome(x0.oneOf(UNIV)); 34 | return f0.implies(f1); 35 | } 36 | 37 | /** 38 | * Returns the conjunction of the axioms and the negation of the hypothesis. 39 | * @return axioms() && !transsls2_qilt27() 40 | */ 41 | public final Formula checkTranssls2_qilt27() { 42 | return axioms().and(transsls2_qilt27().not()); 43 | } 44 | 45 | private static void usage() { 46 | System.out.println("java examples.tptp.MED007 [univ size]"); 47 | System.exit(1); 48 | } 49 | 50 | /** 51 | * Usage: java examples.tptp.MED007 [univ size] 52 | */ 53 | public static void main(String[] args) { 54 | if (args.length < 1) 55 | usage(); 56 | 57 | try { 58 | final int n = Integer.parseInt(args[0]); 59 | if (n < 1) 60 | usage(); 61 | final MED007 model = new MED007(); 62 | final Solver solver = new Solver(); 63 | solver.options().setSolver(SATFactory.MiniSat); 64 | // solver.options().setSymmetryBreaking(1000); 65 | // solver.options().setFlatten(false); 66 | final Formula f = model.checkTranssls2_qilt27(); 67 | final Bounds b = model.bounds(n); 68 | System.out.println(f); 69 | final Solution sol = solver.solve(f, b); 70 | System.out.println(sol); 71 | } catch (NumberFormatException nfe) { 72 | usage(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /examples/kodkod/examples/tptp/MED009.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package kodkod.examples.tptp; 5 | 6 | import static kodkod.ast.Expression.UNIV; 7 | import kodkod.ast.Formula; 8 | import kodkod.ast.Variable; 9 | import kodkod.engine.Solution; 10 | import kodkod.engine.Solver; 11 | import kodkod.engine.satlab.SATFactory; 12 | import kodkod.instance.Bounds; 13 | 14 | /** 15 | * A KK encoding of MED009+1.p from http://www.cs.miami.edu/~tptp/ 16 | * @author Emina Torlak 17 | */ 18 | public final class MED009 extends MED001 { 19 | /** 20 | * Constructs a new instance of MED007. 21 | */ 22 | public MED009() { } 23 | 24 | /** 25 | * Returns transsls2_qige27 conjecture. 26 | * @return transsls2_qige27 27 | */ 28 | public final Formula transsls2_qige27() { 29 | final Variable x0 = Variable.unary("X0"); 30 | final Formula f0 = n0.in(s1).and(n0.join(gt).in(conditionhyper)). 31 | and(n0.in(bcapacitysn).not()).and(n0.in(qilt27).not()); 32 | final Formula f1 = n0.product(x0).in(gt).not().and(x0.in(s2)). 33 | and(x0.join(gt).in(conditionhyper)).and(x0.in(bcapacityne.union(bcapacityex))). 34 | forSome(x0.oneOf(UNIV)); 35 | return f0.implies(f1); 36 | } 37 | /** 38 | * Returns the conjunction of the axioms and the negation of the hypothesis. 39 | * @return axioms() && !transsls2_qige27() 40 | */ 41 | public final Formula checkTranssls2_qige27() { 42 | return axioms().and(transsls2_qige27().not()); 43 | } 44 | 45 | private static void usage() { 46 | System.out.println("java examples.tptp.MED009 [univ size]"); 47 | System.exit(1); 48 | } 49 | 50 | /** 51 | * Usage: java examples.tptp.MED009 [univ size] 52 | */ 53 | public static void main(String[] args) { 54 | if (args.length < 1) 55 | usage(); 56 | 57 | try { 58 | final int n = Integer.parseInt(args[0]); 59 | if (n < 1) 60 | usage(); 61 | final MED009 model = new MED009(); 62 | final Solver solver = new Solver(); 63 | solver.options().setSolver(SATFactory.MiniSat); 64 | // solver.options().setSymmetryBreaking(1000); 65 | // solver.options().setFlatten(false); 66 | final Formula f = model.checkTranssls2_qige27(); 67 | final Bounds b = model.bounds(n); 68 | System.out.println(f); 69 | final Solution sol = solver.solve(f, b); 70 | System.out.println(sol); 71 | } catch (NumberFormatException nfe) { 72 | usage(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /javadoc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /jni/glucose/Solver.patch: -------------------------------------------------------------------------------- 1 | --- glucose-syrup/core/Solver.cc 2014-10-03 02:10:21.000000000 -0700 2 | +++ Solver.cc 2015-09-15 12:24:35.000000000 -0700 3 | @@ -1405,7 +1405,7 @@ 4 | decisions++; 5 | next = pickBranchLit(); 6 | if (next == lit_Undef) { 7 | - printf("c last restart ## conflicts : %d %d \n", conflictC, decisionLevel()); 8 | + // printf("c last restart ## conflicts : %d %d \n", conflictC, decisionLevel()); 9 | // Model found: 10 | return l_True; 11 | } 12 | -------------------------------------------------------------------------------- /jni/glucose/kodkod_engine_satlab_Glucose.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "kodkod_engine_satlab_Glucose.h" 4 | #include "glucose-syrup/core/Solver.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace Glucose; 11 | 12 | /* 13 | * Class: kodkod_engine_satlab_Glucose 14 | * Method: make 15 | * Signature: ()J 16 | */ 17 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_Glucose_make 18 | (JNIEnv *, jclass) { 19 | Solver* solver = new Solver(); 20 | solver->verbosity = 0; 21 | //std::cout << "creating " << ((jlong) solver) << "\n"; 22 | return ((jlong) solver); 23 | } 24 | 25 | /* 26 | * Class: kodkod_engine_satlab_Glucose 27 | * Method: free 28 | * Signature: (J)V 29 | */ 30 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Glucose_free 31 | (JNIEnv *, jobject, jlong solver) { 32 | //std::cout << "destroying " << solver << "\n"; 33 | delete ((Solver*)solver); 34 | } 35 | /* 36 | * Class: kodkod_engine_satlab_Glucose 37 | * Method: addVariables 38 | * Signature: (JI)V 39 | */ 40 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Glucose_addVariables 41 | (JNIEnv *, jobject, jlong solver, jint numVars) { 42 | Solver* solverPtr = (Solver*) solver; 43 | for(int i = 0; i < numVars; ++i) { 44 | solverPtr->newVar(); 45 | } 46 | } 47 | 48 | /* 49 | * Class: kodkod_engine_satlab_Glucose 50 | * Method: addClause 51 | * Signature: (J[I)Z 52 | */ 53 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Glucose_addClause 54 | (JNIEnv * env, jobject, jlong solver, jintArray clause) { 55 | jsize length = env->GetArrayLength(clause); 56 | jint* buf = env->GetIntArrayElements(clause, JNI_FALSE); 57 | Solver* solverPtr = ((Solver*)solver); 58 | vec lits; 59 | for(int i = 0; i < length; ++i) { 60 | int var = *(buf+i); 61 | lits.push((var > 0) ? mkLit(var-1) : ~mkLit(-var-1)); 62 | } 63 | solverPtr->addClause(lits); 64 | env->ReleaseIntArrayElements(clause, buf, 0); 65 | return solverPtr->okay(); 66 | } 67 | 68 | /* 69 | * Class: kodkod_engine_satlab_Glucose 70 | * Method: solve 71 | * Signature: (J)Z 72 | */ 73 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Glucose_solve 74 | (JNIEnv *, jobject, jlong solver) { 75 | //std::cout << "-> p cnf " << ((Solver*)solver)->nVars() << " " << ((Solver*)solver)->nClauses() << "\n"; 76 | return ((Solver*)solver)->solve(); 77 | } 78 | 79 | /* 80 | * Class: kodkod_engine_satlab_Glucose 81 | * Method: valueOf 82 | * Signature: (JI)Z 83 | */ 84 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Glucose_valueOf 85 | (JNIEnv *, jobject, jlong solver, jint var) { 86 | return ((Solver*)solver)->model[var-1]==l_True; 87 | } 88 | -------------------------------------------------------------------------------- /jni/glucose/kodkod_engine_satlab_Glucose.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class kodkod_engine_satlab_Glucose */ 4 | 5 | #ifndef _Included_kodkod_engine_satlab_Glucose 6 | #define _Included_kodkod_engine_satlab_Glucose 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: kodkod_engine_satlab_Glucose 12 | * Method: make 13 | * Signature: ()J 14 | */ 15 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_Glucose_make 16 | (JNIEnv *, jclass); 17 | 18 | /* 19 | * Class: kodkod_engine_satlab_Glucose 20 | * Method: free 21 | * Signature: (J)V 22 | */ 23 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Glucose_free 24 | (JNIEnv *, jobject, jlong); 25 | 26 | /* 27 | * Class: kodkod_engine_satlab_Glucose 28 | * Method: addVariables 29 | * Signature: (JI)V 30 | */ 31 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Glucose_addVariables 32 | (JNIEnv *, jobject, jlong, jint); 33 | 34 | /* 35 | * Class: kodkod_engine_satlab_Glucose 36 | * Method: addClause 37 | * Signature: (J[I)Z 38 | */ 39 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Glucose_addClause 40 | (JNIEnv *, jobject, jlong, jintArray); 41 | 42 | /* 43 | * Class: kodkod_engine_satlab_Glucose 44 | * Method: solve 45 | * Signature: (J)Z 46 | */ 47 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Glucose_solve 48 | (JNIEnv *, jobject, jlong); 49 | 50 | /* 51 | * Class: kodkod_engine_satlab_Glucose 52 | * Method: valueOf 53 | * Signature: (JI)Z 54 | */ 55 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Glucose_valueOf 56 | (JNIEnv *, jobject, jlong, jint); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /jni/glucose/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import shutil, subprocess, os 5 | 6 | def options(opt): 7 | opt.load('compiler_cxx') 8 | opt.load('java') 9 | 10 | def configure(conf): 11 | conf.load('compiler_cxx') 12 | conf.load('java') 13 | conf.check_jni_headers() 14 | sourceclean(conf) 15 | root = conf.path.abspath() 16 | subprocess.check_call(['wget', 'http://www.labri.fr/perso/lsimon/downloads/softwares/glucose-syrup.tgz', '--directory-prefix', root]) 17 | subprocess.check_call(['tar', '-xzf', root + '/glucose-syrup.tgz', '-C', root]) 18 | subprocess.check_call(['patch', '-p0', '-d', root + '/glucose-syrup/core/', '-i', root + '/Solver.patch']) 19 | 20 | def build(bld): 21 | 22 | DEFINES = ['__STDC_LIMIT_MACROS', '__STDC_FORMAT_MACROS'] 23 | INCLUDES = ['.','./glucose-syrup'] 24 | CXXFLAGS = [ '-w', '-O3', '-fPIC'] 25 | 26 | bld.objects(source = ['glucose-syrup/utils/Options.cc', 'glucose-syrup/utils/System.cc'], 27 | target = 'glucose-utils', 28 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 29 | 30 | bld.objects(source = 'glucose-syrup/core/Solver.cc', 31 | target = 'glucose-core', use = 'glucose-utils', 32 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 33 | 34 | bld.shlib(source = 'kodkod_engine_satlab_Glucose.cpp', 35 | target = 'glucose', use = 'glucose-core', uselib = 'JAVA', 36 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 37 | 38 | def distclean(ctx): 39 | from waflib import Scripting 40 | Scripting.distclean(ctx) 41 | sourceclean(ctx) 42 | 43 | def sourceclean(ctx): 44 | shutil.rmtree(ctx.path.abspath() + '/glucose-syrup', True) 45 | try: 46 | os.remove(ctx.path.abspath() + '/glucose-syrup.tgz') 47 | except OSError: 48 | pass 49 | 50 | -------------------------------------------------------------------------------- /jni/lingeling/kodkod_engine_satlab_Lingeling.c: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "code/lglib.h" 4 | #include "kodkod_engine_satlab_Lingeling.h" 5 | #include 6 | #include 7 | 8 | /* 9 | * Class: kodkod_engine_satlab_Lingeling 10 | * Method: make 11 | * Signature: ()J 12 | */ 13 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_Lingeling_make 14 | (JNIEnv * env, jclass jc) { 15 | LGL* lgl = lglinit(); 16 | return ((jlong) lgl); 17 | } 18 | 19 | /* 20 | * Class: kodkod_engine_satlab_Lingeling 21 | * Method: free 22 | * Signature: (J)V 23 | */ 24 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Lingeling_free 25 | (JNIEnv * env, jobject obj, jlong lgl) { 26 | lglrelease((LGL*)lgl); 27 | } 28 | 29 | /* 30 | * Class: kodkod_engine_satlab_Lingeling 31 | * Method: addVariables 32 | * Signature: (JI)V 33 | */ 34 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Lingeling_addVariables 35 | (JNIEnv * env, jobject obj, jlong lgl, jint nvars) { 36 | // ignore calls to addVariables since 37 | // lingeling dynamically adds variables as they appear in clauses. 38 | // this means we have to compensate for it in the value_of method 39 | // and just return false when passed a variable that has not appeared 40 | // in any clause. 41 | } 42 | 43 | /* 44 | * Class: kodkod_engine_satlab_Lingeling 45 | * Method: addClause 46 | * Signature: (J[I)Z 47 | */ 48 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Lingeling_addClause 49 | (JNIEnv * env, jobject obj, jlong lgl, jintArray clause) { 50 | jsize length = (*env)->GetArrayLength(env, clause); 51 | jint* buf = (*env)->GetIntArrayElements(env, clause, JNI_FALSE); 52 | LGL* lglPtr = (LGL*)lgl; 53 | int i; 54 | for(i = 0; i < length; i++) { 55 | int lit = *(buf+i); 56 | //printf("%d ", lit); 57 | lgladd (lglPtr, lit); 58 | } 59 | //printf("0\n"); 60 | lgladd (lglPtr, 0); 61 | (*env)->ReleaseIntArrayElements(env, clause, buf, 0); 62 | return JNI_TRUE; 63 | } 64 | 65 | /* 66 | * Class: kodkod_engine_satlab_Lingeling 67 | * Method: solve 68 | * Signature: (J)Z 69 | */ 70 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Lingeling_solve 71 | (JNIEnv * env, jobject obj, jlong lgl) { 72 | LGL* lglPtr = (LGL*) lgl; 73 | return lglsat(lglPtr)==10; 74 | } 75 | 76 | /* 77 | * Class: kodkod_engine_satlab_Lingeling 78 | * Method: valueOf 79 | * Signature: (JI)Z 80 | */ 81 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Lingeling_valueOf 82 | (JNIEnv * env, jobject obj, jlong lgl, jint var) { 83 | LGL* lglPtr = (LGL*) lgl; 84 | if (var <= lglmaxvar(lglPtr)) 85 | return lglderef(lglPtr, var) > 0; 86 | else 87 | return JNI_FALSE; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /jni/lingeling/kodkod_engine_satlab_Lingeling.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class kodkod_engine_satlab_Lingeling */ 4 | 5 | #ifndef _Included_kodkod_engine_satlab_Lingeling 6 | #define _Included_kodkod_engine_satlab_Lingeling 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: kodkod_engine_satlab_Lingeling 12 | * Method: make 13 | * Signature: ()J 14 | */ 15 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_Lingeling_make 16 | (JNIEnv *, jclass); 17 | 18 | /* 19 | * Class: kodkod_engine_satlab_Lingeling 20 | * Method: free 21 | * Signature: (J)V 22 | */ 23 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Lingeling_free 24 | (JNIEnv *, jobject, jlong); 25 | 26 | /* 27 | * Class: kodkod_engine_satlab_Lingeling 28 | * Method: addVariables 29 | * Signature: (JI)V 30 | */ 31 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_Lingeling_addVariables 32 | (JNIEnv *, jobject, jlong, jint); 33 | 34 | /* 35 | * Class: kodkod_engine_satlab_Lingeling 36 | * Method: addClause 37 | * Signature: (J[I)Z 38 | */ 39 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Lingeling_addClause 40 | (JNIEnv *, jobject, jlong, jintArray); 41 | 42 | /* 43 | * Class: kodkod_engine_satlab_Lingeling 44 | * Method: solve 45 | * Signature: (J)Z 46 | */ 47 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Lingeling_solve 48 | (JNIEnv *, jobject, jlong); 49 | 50 | /* 51 | * Class: kodkod_engine_satlab_Lingeling 52 | * Method: valueOf 53 | * Signature: (JI)Z 54 | */ 55 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_Lingeling_valueOf 56 | (JNIEnv *, jobject, jlong, jint); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /jni/lingeling/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import shutil, subprocess, os 5 | 6 | LINGELING = 'lingeling-ayv-86bf266-140429' 7 | 8 | def options(opt): 9 | opt.load('compiler_c') 10 | opt.load('java') 11 | 12 | def configure(conf): 13 | conf.load('compiler_c') 14 | conf.load('java') 15 | conf.check_jni_headers() 16 | sourceclean(conf) 17 | root = conf.path.abspath() 18 | subprocess.check_call(['wget', 'http://fmv.jku.at/lingeling/' + LINGELING + '.zip', '--directory-prefix', root]) 19 | subprocess.check_call(['unzip', root + '/' + LINGELING + '.zip','code/*', '-d', root]) 20 | 21 | def build(bld): 22 | DEFINES = ['NDBLSCR', 'NLGLOG','NDEBUG', 'NCHKSOL', 'NLGLPICOSAT', 'NLGLDRUPLIG', 'NLGLYALSAT'] 23 | CFLAGS = ['-w', '-O3', '-fPIC'] 24 | INCLUDES = ['.'] 25 | 26 | bld.objects(source = 'code/lglib.c', 27 | target = 'lglib', 28 | includes = INCLUDES, cflags = CFLAGS, defines = DEFINES) 29 | 30 | bld.shlib(source = 'kodkod_engine_satlab_Lingeling.c', 31 | target = 'lingeling', 32 | use = 'lglib', uselib = 'JAVA', 33 | includes = INCLUDES, cflags = CFLAGS, defines = DEFINES) 34 | 35 | def distclean(ctx): 36 | from waflib import Scripting 37 | Scripting.distclean(ctx) 38 | sourceclean(ctx) 39 | 40 | def sourceclean(ctx): 41 | shutil.rmtree(ctx.path.abspath() + '/code', True) 42 | try: 43 | os.remove(ctx.path.abspath() + '/' + LINGELING + '.zip') 44 | except OSError: 45 | pass 46 | -------------------------------------------------------------------------------- /jni/minisat/kodkod_engine_satlab_MiniSat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include "minisat/minisat/core/Solver.h" 17 | #include "kodkod_engine_satlab_MiniSat.h" 18 | 19 | using namespace Minisat; 20 | 21 | 22 | /* 23 | * Class: kodkod_engine_satlab_MiniSat 24 | * Method: make 25 | * Signature: ()J 26 | */ 27 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_MiniSat_make 28 | (JNIEnv *, jclass) { 29 | Solver* solver = new Solver(); 30 | return ((jlong) solver); 31 | } 32 | 33 | /* 34 | * Class: kodkod_engine_satlab_MiniSat 35 | * Method: free 36 | * Signature: (J)V 37 | */ 38 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_MiniSat_free 39 | (JNIEnv *, jobject, jlong solver) { 40 | delete ((Solver*)solver); 41 | } 42 | 43 | /* 44 | * Class: kodkod_engine_satlab_MiniSat 45 | * Method: addVariables 46 | * Signature: (JI)V 47 | */ 48 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_MiniSat_addVariables 49 | (JNIEnv *, jobject, jlong solver, jint numVars) { 50 | Solver* solverPtr = (Solver*) solver; 51 | for(int i = 0; i < numVars; ++i) { 52 | solverPtr->newVar(); 53 | } 54 | } 55 | 56 | /* 57 | * Class: kodkod_engine_satlab_MiniSat 58 | * Method: addClause 59 | * Signature: (J[I)Z 60 | */ 61 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_addClause 62 | (JNIEnv * env, jobject, jlong solver, jintArray clause) { 63 | jsize length = env->GetArrayLength(clause); 64 | jint* buf = env->GetIntArrayElements(clause, JNI_FALSE); 65 | Solver* solverPtr = ((Solver*)solver); 66 | vec lits; 67 | for(int i = 0; i < length; ++i) { 68 | int var = *(buf+i); 69 | lits.push((var > 0) ? mkLit(var-1) : ~mkLit(-var-1)); 70 | } 71 | solverPtr->addClause(lits); 72 | env->ReleaseIntArrayElements(clause, buf, 0); 73 | return solverPtr->okay(); 74 | } 75 | 76 | /* 77 | * Class: kodkod_engine_satlab_MiniSat 78 | * Method: solve 79 | * Signature: (J)Z 80 | */ 81 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_solve 82 | (JNIEnv *, jobject, jlong solver) { 83 | return ((Solver*)solver)->solve(); 84 | } 85 | 86 | /* 87 | * Class: kodkod_engine_satlab_MiniSat 88 | * Method: valueOf 89 | * Signature: (JI)Z 90 | */ 91 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_valueOf 92 | (JNIEnv *, jobject, jlong solver, jint var) { 93 | return ((Solver*)solver)->model[var-1]==l_True; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /jni/minisat/kodkod_engine_satlab_MiniSat.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class kodkod_engine_satlab_MiniSat */ 4 | 5 | #ifndef _Included_kodkod_engine_satlab_MiniSat 6 | #define _Included_kodkod_engine_satlab_MiniSat 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: kodkod_engine_satlab_MiniSat 12 | * Method: make 13 | * Signature: ()J 14 | */ 15 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_MiniSat_make 16 | (JNIEnv *, jclass); 17 | 18 | /* 19 | * Class: kodkod_engine_satlab_MiniSat 20 | * Method: free 21 | * Signature: (J)V 22 | */ 23 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_MiniSat_free 24 | (JNIEnv *, jobject, jlong); 25 | 26 | /* 27 | * Class: kodkod_engine_satlab_MiniSat 28 | * Method: addVariables 29 | * Signature: (JI)V 30 | */ 31 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_MiniSat_addVariables 32 | (JNIEnv *, jobject, jlong, jint); 33 | 34 | /* 35 | * Class: kodkod_engine_satlab_MiniSat 36 | * Method: addClause 37 | * Signature: (J[I)Z 38 | */ 39 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_addClause 40 | (JNIEnv *, jobject, jlong, jintArray); 41 | 42 | /* 43 | * Class: kodkod_engine_satlab_MiniSat 44 | * Method: solve 45 | * Signature: (J)Z 46 | */ 47 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_solve 48 | (JNIEnv *, jobject, jlong); 49 | 50 | /* 51 | * Class: kodkod_engine_satlab_MiniSat 52 | * Method: valueOf 53 | * Signature: (JI)Z 54 | */ 55 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSat_valueOf 56 | (JNIEnv *, jobject, jlong, jint); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /jni/minisat/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import shutil 5 | import subprocess 6 | 7 | def options(opt): 8 | opt.load('compiler_cxx') 9 | opt.load('java') 10 | 11 | def configure(conf): 12 | conf.load('compiler_cxx') 13 | conf.load('java') 14 | conf.check_jni_headers() 15 | MINISAT = conf.path.abspath() + '/minisat' 16 | shutil.rmtree(MINISAT, True) 17 | subprocess.check_call(['git', 'clone', 'https://github.com/stp/minisat.git', MINISAT]) 18 | 19 | 20 | def build(bld): 21 | DEFINES = ['__STDC_LIMIT_MACROS', '__STDC_FORMAT_MACROS'] 22 | INCLUDES = ['.','./minisat'] 23 | CXXFLAGS = [ '-w', '-O3', '-fPIC'] 24 | 25 | bld.objects(source = ['minisat/minisat/utils/Options.cc', 'minisat/minisat/utils/System.cc'], 26 | target = 'minisat-utils', 27 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 28 | 29 | bld.objects(source = 'minisat/minisat/core/Solver.cc', 30 | target = 'minisat-core', use = 'minisat-utils', 31 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 32 | 33 | bld.shlib(source = 'kodkod_engine_satlab_MiniSat.cpp', 34 | target = 'minisat', use = 'minisat-core', uselib = 'JAVA', 35 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 36 | 37 | def distclean(ctx): 38 | from waflib import Scripting 39 | Scripting.distclean(ctx) 40 | shutil.rmtree(ctx.path.abspath() + '/minisat', True) 41 | 42 | 43 | -------------------------------------------------------------------------------- /jni/minisatp/kodkod_engine_satlab_MiniSatProver.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class kodkod_engine_satlab_MiniSatProver */ 4 | 5 | #ifndef _Included_kodkod_engine_satlab_MiniSatProver 6 | #define _Included_kodkod_engine_satlab_MiniSatProver 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: kodkod_engine_satlab_MiniSatProver 12 | * Method: make 13 | * Signature: ()J 14 | */ 15 | JNIEXPORT jlong JNICALL Java_kodkod_engine_satlab_MiniSatProver_make 16 | (JNIEnv *, jclass); 17 | 18 | /* 19 | * Class: kodkod_engine_satlab_MiniSatProver 20 | * Method: free 21 | * Signature: (J)V 22 | */ 23 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_MiniSatProver_free 24 | (JNIEnv *, jobject, jlong); 25 | 26 | /* 27 | * Class: kodkod_engine_satlab_MiniSatProver 28 | * Method: addVariables 29 | * Signature: (JI)V 30 | */ 31 | JNIEXPORT void JNICALL Java_kodkod_engine_satlab_MiniSatProver_addVariables 32 | (JNIEnv *, jobject, jlong, jint); 33 | 34 | /* 35 | * Class: kodkod_engine_satlab_MiniSatProver 36 | * Method: addClause 37 | * Signature: (J[I)Z 38 | */ 39 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSatProver_addClause 40 | (JNIEnv *, jobject, jlong, jintArray); 41 | 42 | /* 43 | * Class: kodkod_engine_satlab_MiniSatProver 44 | * Method: solve 45 | * Signature: (J)Z 46 | */ 47 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSatProver_solve 48 | (JNIEnv *, jobject, jlong); 49 | 50 | /* 51 | * Class: kodkod_engine_satlab_MiniSatProver 52 | * Method: valueOf 53 | * Signature: (JI)Z 54 | */ 55 | JNIEXPORT jboolean JNICALL Java_kodkod_engine_satlab_MiniSatProver_valueOf 56 | (JNIEnv *, jobject, jlong, jint); 57 | 58 | /* 59 | * Class: kodkod_engine_satlab_MiniSatProver 60 | * Method: trace 61 | * Signature: (JZ)[[I 62 | */ 63 | JNIEXPORT jobjectArray JNICALL Java_kodkod_engine_satlab_MiniSatProver_trace 64 | (JNIEnv *, jobject, jlong, jboolean); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | #endif 70 | -------------------------------------------------------------------------------- /jni/minisatp/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import shutil 5 | import subprocess 6 | 7 | def options(opt): 8 | opt.load('compiler_cxx') 9 | opt.load('java') 10 | 11 | def configure(conf): 12 | conf.load('compiler_cxx') 13 | conf.load('java') 14 | conf.check_jni_headers() 15 | MINISAT = conf.path.abspath() + '/minisatp' 16 | shutil.rmtree(MINISAT, True) 17 | subprocess.check_call(['git', 'clone', 'https://github.com/emina/minisatp.git', MINISAT]) 18 | 19 | def build(bld): 20 | DEFINES = ['__STDC_LIMIT_MACROS', '__STDC_FORMAT_MACROS'] 21 | INCLUDES = ['.', './minisatp'] 22 | CXXFLAGS = [ '-w', '-O3', '-fPIC', '-ffloat-store'] 23 | 24 | bld.objects(source = ['minisatp/Solver.C', 'minisatp/Proof.C', 'minisatp/File.C'], 25 | target = 'minisatp-core', 26 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 27 | 28 | bld.shlib(source = 'kodkod_engine_satlab_MiniSatProver.cpp', 29 | target = 'minisatprover', use = 'minisatp-core', uselib = 'JAVA', 30 | includes = INCLUDES, cxxflags = CXXFLAGS, defines = DEFINES) 31 | 32 | 33 | def distclean(ctx): 34 | from waflib import Scripting 35 | Scripting.distclean(ctx) 36 | shutil.rmtree(ctx.path.abspath() + '/minisatp', True) 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /jni/plingeling/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import shutil, subprocess, os 5 | 6 | PLINGELING = 'plingeling-ayv-86bf266-140429' 7 | 8 | def options(opt): 9 | pass 10 | 11 | def configure(conf): 12 | sourceclean(conf) 13 | root = conf.path.abspath() 14 | subprocess.check_call(['wget', 'http://fmv.jku.at/lingeling/' + PLINGELING + '.zip', '--directory-prefix', root]) 15 | subprocess.check_call(['unzip', root + '/' + PLINGELING + '.zip', 'code/*', '-d', root]) 16 | subprocess.check_call(['unzip', root + '/' + PLINGELING + '.zip', 'build.sh', '-d', root]) 17 | 18 | def build(bld): 19 | 20 | def sh(task): 21 | src = task.inputs[0].abspath() 22 | tgt = task.outputs[0].abspath() 23 | subprocess.check_call('cd ' + os.path.dirname(src) + ' && ./' + os.path.basename(src), shell=True) 24 | subprocess.check_call(['mv', os.path.dirname(src) + '/binary/plingeling', tgt]) 25 | return 0 26 | 27 | bld(rule = sh, 28 | source = 'build.sh', 29 | target = 'plingeling') 30 | 31 | bld.install_files('${LIBDIR}', 'plingeling', chmod=755) 32 | 33 | def distclean(ctx): 34 | from waflib import Scripting 35 | Scripting.distclean(ctx) 36 | sourceclean(ctx) 37 | 38 | def sourceclean(ctx): 39 | shutil.rmtree(ctx.path.abspath() + '/binary', True) 40 | shutil.rmtree(ctx.path.abspath() + '/code', True) 41 | try: 42 | os.remove(ctx.path.abspath() + '/' + PLINGELING + '.zip') 43 | except OSError: 44 | pass 45 | try: 46 | os.remove(ctx.path.abspath() + '/build.sh') 47 | except OSError: 48 | pass 49 | -------------------------------------------------------------------------------- /jni/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | 5 | solvers = ['minisat', 'minisatp', 'glucose', 'lingeling', 'plingeling'] 6 | 7 | def options(opt): 8 | opt.recurse(solvers) 9 | 10 | def configure(conf): 11 | conf.recurse(solvers) 12 | 13 | def build(bld): 14 | bld.recurse(solvers) 15 | 16 | def distclean(ctx): 17 | ctx.recurse(solvers) 18 | 19 | -------------------------------------------------------------------------------- /src/MANIFEST: -------------------------------------------------------------------------------- 1 | Name: kodkod 2 | Specification-Title: Kodkod API 3 | Specification-Version: 2.1 4 | Specification-Vendor: Emina Torlak 5 | Implementation-Title: Kodkod API 6 | Implementation-Version: 2.1 7 | Implementation-Vendor: Emina Torlak -------------------------------------------------------------------------------- /src/kodkod/ast/BinaryFormula.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.ast; 23 | 24 | import kodkod.ast.operator.FormulaOperator; 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * A {@link kodkod.ast.Formula formula} with two children. 30 | * 31 | * @specfield left: Formula 32 | * @specfield right: Formula 33 | * @specfield op: FormulaOperator 34 | * @invariant children = 0->left + 1->right 35 | * @author Emina Torlak 36 | */ 37 | public final class BinaryFormula extends Formula { 38 | 39 | private final Formula left; 40 | private final Formula right; 41 | private final FormulaOperator op; 42 | 43 | /** 44 | * Constructs a new binary formula: left op right 45 | * 46 | * @ensures this.left' = left && this.right' = right && this.op' = op 47 | * @throws NullPointerException left = null || right = null || op = null 48 | */ 49 | BinaryFormula(Formula left, FormulaOperator op, Formula right) { 50 | this.left = left; 51 | this.right = right; 52 | this.op = op; 53 | } 54 | 55 | /** 56 | * Returns the left child of this. 57 | * @return this.left 58 | */ 59 | public Formula left() {return left;} 60 | 61 | /** 62 | * Returns the right child of this. 63 | * @return this.right 64 | */ 65 | public Formula right() {return right;} 66 | 67 | /** 68 | * Returns the operator of this. 69 | * @return this.op 70 | */ 71 | public FormulaOperator op() {return op;} 72 | 73 | /** 74 | * {@inheritDoc} 75 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 76 | */ 77 | public F accept(ReturnVisitor visitor) { 78 | return visitor.visit(this); 79 | } 80 | 81 | /** 82 | * {@inheritDoc} 83 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 84 | */ 85 | public void accept(VoidVisitor visitor) { 86 | visitor.visit(this); 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | * @see kodkod.ast.Node#toString() 92 | */ 93 | public String toString() { 94 | return "(" + left + " " + op + " " + right + ")"; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/kodkod/ast/BinaryIntExpression.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.ast; 23 | 24 | 25 | import kodkod.ast.operator.IntOperator; 26 | import kodkod.ast.visitor.ReturnVisitor; 27 | import kodkod.ast.visitor.VoidVisitor; 28 | 29 | /** 30 | * A binary integer expression such as x + y. 31 | * @specfield left: IntExpression 32 | * @specfield right: IntExpression 33 | * @specfield op: IntOperator 34 | * @specfield op.binary() 35 | * @invariant children = 0->left + 1->right 36 | * @author Emina Torlak 37 | */ 38 | public final class BinaryIntExpression extends IntExpression { 39 | private final IntOperator op; 40 | private final IntExpression left, right; 41 | 42 | /** 43 | * Constructs a new binary int formula: left op right 44 | * 45 | * @ensures this.left' = left && this.right' = right && this.op' = op 46 | * @throws NullPointerException left = null || right = null || op = null 47 | */ 48 | public BinaryIntExpression(final IntExpression left, final IntOperator op, final IntExpression right) { 49 | if (!op.binary()) throw new IllegalArgumentException("Not a binary operator: " + op); 50 | this.left = left; 51 | this.right = right; 52 | this.op = op; 53 | } 54 | 55 | /** 56 | * Returns the left child of this. 57 | * @return this.left 58 | */ 59 | public IntExpression left() {return left;} 60 | 61 | /** 62 | * Returns the right child of this. 63 | * @return this.right 64 | */ 65 | public IntExpression right() {return right;} 66 | 67 | /** 68 | * Returns the operator of this. 69 | * @return this.op 70 | */ 71 | public IntOperator op() {return op;} 72 | 73 | /** 74 | * {@inheritDoc} 75 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.ReturnVisitor) 76 | */ 77 | @Override 78 | public I accept(ReturnVisitor visitor) { 79 | return visitor.visit(this); 80 | } 81 | 82 | /** 83 | * {@inheritDoc} 84 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.VoidVisitor) 85 | */ 86 | @Override 87 | public void accept(VoidVisitor visitor) { 88 | visitor.visit(this); 89 | } 90 | 91 | /** 92 | * {@inheritDoc} 93 | * @see kodkod.ast.Node#toString() 94 | */ 95 | public String toString() { 96 | return "(" + left + " " + op + " " + right + ")"; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/kodkod/ast/ComparisonFormula.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.ast; 23 | 24 | import kodkod.ast.operator.ExprCompOperator; 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | 29 | 30 | /** 31 | * A formula that compares two expressions, e.g. x = y 32 | * 33 | * @specfield left: Expression 34 | * @specfield right: Expression 35 | * @specfield op: ExprCompOperator 36 | * @invariant children = 0->left + 1->right 37 | * @author Emina Torlak 38 | */ 39 | public final class ComparisonFormula extends Formula{ 40 | private final Expression left; 41 | private final Expression right; 42 | private final ExprCompOperator op; 43 | 44 | /** 45 | * Constructs a new comparison formula: left op right 46 | * 47 | * @ensures this.left' = left && this.right' = right && this.op' = op 48 | * * @throws NullPointerException left = null || right = null || op = null 49 | * @throws IllegalArgumentException left.arity != right.arity 50 | */ 51 | ComparisonFormula(Expression left, ExprCompOperator op, Expression right) { 52 | if (left.arity()!=right.arity()) { 53 | throw new IllegalArgumentException( 54 | "Arity mismatch: " + left + "::" + left.arity() + 55 | " and " + right + "::" + right.arity()); 56 | } 57 | this.left = left; 58 | this.right = right; 59 | this.op = op; 60 | } 61 | 62 | /** 63 | * Returns the left child of this. 64 | * @return this.left 65 | */ 66 | public Expression left() {return left;} 67 | 68 | /** 69 | * Returns the right child of this. 70 | * @return this.right 71 | */ 72 | public Expression right() {return right;} 73 | 74 | /** 75 | * Returns the operator of this. 76 | * @return this.op 77 | */ 78 | public ExprCompOperator op() {return op;} 79 | 80 | /** 81 | * {@inheritDoc} 82 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 83 | */ 84 | public F accept(ReturnVisitor visitor) { 85 | return visitor.visit(this); 86 | } 87 | 88 | /** 89 | * {@inheritDoc} 90 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 91 | */ 92 | public void accept(VoidVisitor visitor) { 93 | visitor.visit(this); 94 | } 95 | 96 | /** 97 | * {@inheritDoc} 98 | * @see kodkod.ast.Node#toString() 99 | */ 100 | public String toString() { 101 | return "(" + left + " " + op + " " + right + ")"; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/kodkod/ast/ConstantExpression.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.ast; 23 | 24 | 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * A constant valued expression. 30 | * 31 | * @invariant no children 32 | * @author Emina Torlak 33 | */ 34 | public final class ConstantExpression extends LeafExpression { 35 | 36 | /** 37 | * Constructs a constant expression with the given arity. 38 | */ 39 | ConstantExpression(String name, int arity) { 40 | super(name, arity); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | * @see kodkod.ast.Expression#accept(kodkod.ast.visitor.ReturnVisitor) 46 | */ 47 | public E accept(ReturnVisitor visitor) { 48 | return visitor.visit(this); 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 54 | */ 55 | public void accept(VoidVisitor visitor) { 56 | visitor.visit(this); 57 | } 58 | 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/kodkod/ast/ConstantFormula.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.ast; 23 | 24 | 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * A constant {@link kodkod.ast.Formula formula}, true or false. 30 | * 31 | * @invariant no children 32 | * @author Emina Torlak 33 | */ 34 | public abstract class ConstantFormula extends Formula { 35 | private final boolean value; 36 | /** 37 | * Constructs a constant formula with the given value. 38 | */ 39 | ConstantFormula(boolean value) { 40 | this.value = value; 41 | } 42 | 43 | /** 44 | * Returns the boolean value that corresponds to this 45 | * constant formula. 46 | * @return this=TRUE => true, false 47 | */ 48 | public final boolean booleanValue() { return value; } 49 | 50 | /** 51 | * {@inheritDoc} 52 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 53 | */ 54 | public F accept(ReturnVisitor visitor) { 55 | return visitor.visit(this); 56 | } 57 | 58 | /** 59 | * {@inheritDoc} 60 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 61 | */ 62 | public void accept(VoidVisitor visitor) { 63 | visitor.visit(this); 64 | } 65 | 66 | /** 67 | * {@inheritDoc} 68 | * @see kodkod.ast.Node#toString() 69 | */ 70 | public String toString() { 71 | return String.valueOf(booleanValue()); 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/kodkod/ast/ExprToIntCast.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.ast; 23 | 24 | 25 | import kodkod.ast.operator.ExprCastOperator; 26 | import kodkod.ast.visitor.ReturnVisitor; 27 | import kodkod.ast.visitor.VoidVisitor; 28 | 29 | /** 30 | * An {@link kodkod.ast.IntExpression } representing the 31 | * cardinality of an {@link kodkod.ast.Expression} or the 32 | * sum of all the integer atoms contained in the expression. 33 | * @specfield expression: Expression 34 | * @specfield op: ExprCastOperator 35 | * @invariant children = 0->expression 36 | * @author Emina Torlak 37 | */ 38 | public final class ExprToIntCast extends IntExpression { 39 | private final Expression expression; 40 | private final ExprCastOperator op; 41 | /** 42 | * Constructs a new cardinality expression. 43 | * 44 | * @ensures this.expression' = expression && this.op' = op 45 | * @throws NullPointerException expression = null || op = null 46 | * @throws IllegalArgumentException op = SUM && child.arity != 1 47 | */ 48 | ExprToIntCast(Expression child, ExprCastOperator op) { 49 | if (child.arity()>1 && op==ExprCastOperator.SUM) 50 | throw new IllegalArgumentException("cannot apply " + op + " to " + child); 51 | this.expression = child; 52 | this.op = op; 53 | } 54 | 55 | /** 56 | * Returns this.expression. 57 | * @return this.expression 58 | */ 59 | public Expression expression() {return expression;} 60 | 61 | /** 62 | * Returns this.op. 63 | * @return this.op 64 | */ 65 | public ExprCastOperator op() { return op; } 66 | 67 | 68 | /** 69 | * {@inheritDoc} 70 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.ReturnVisitor) 71 | */ 72 | @Override 73 | public I accept(ReturnVisitor visitor) { 74 | return visitor.visit(this); 75 | } 76 | 77 | /** 78 | * {@inheritDoc} 79 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.VoidVisitor) 80 | */ 81 | @Override 82 | public void accept(VoidVisitor visitor) { 83 | visitor.visit(this); 84 | } 85 | 86 | /** 87 | * {@inheritDoc} 88 | * @see kodkod.ast.Node#toString() 89 | */ 90 | public String toString() { 91 | return op + "("+expression.toString()+")"; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/kodkod/ast/IfIntExpression.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.ast; 23 | 24 | import kodkod.ast.visitor.ReturnVisitor; 25 | import kodkod.ast.visitor.VoidVisitor; 26 | 27 | /** 28 | * An int expression whose value depends on the truth of a condition. 29 | * 30 | * @specfield condition: Formula 31 | * @specfield thenExpr: IntExpression 32 | * @specfield elseExpr: IntExpression 33 | * @invariant children = 0->condition + 1->thenExpr + 2->elseExpr 34 | * @author Emina Torlak 35 | */ 36 | public final class IfIntExpression extends IntExpression { 37 | private final Formula condition; 38 | private final IntExpression thenExpr, elseExpr; 39 | 40 | /** 41 | * @ensures this.condition' = condition && this.thenExpr' = thenExpr && 42 | * this.elseExpr' = elseExpr 43 | */ 44 | IfIntExpression(Formula condition, IntExpression thenExpr, 45 | IntExpression elseExpr) { 46 | this.condition = condition; 47 | this.thenExpr = thenExpr; 48 | this.elseExpr = elseExpr; 49 | } 50 | 51 | /** 52 | * Returns the if-condition. 53 | * @return this.condition 54 | */ 55 | public Formula condition() { 56 | return condition; 57 | } 58 | 59 | /** 60 | * Returns the then-expression. 61 | * @return this.thenExpr 62 | */ 63 | public IntExpression thenExpr() { 64 | return thenExpr; 65 | } 66 | 67 | /** 68 | * Returns the else-expression. 69 | * @return this.elseExpr 70 | */ 71 | public IntExpression elseExpr() { 72 | return elseExpr; 73 | } 74 | 75 | /** 76 | * {@inheritDoc} 77 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.ReturnVisitor) 78 | */ 79 | @Override 80 | public I accept(ReturnVisitor visitor) { 81 | return visitor.visit(this); 82 | } 83 | 84 | /** 85 | * {@inheritDoc} 86 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.VoidVisitor) 87 | */ 88 | @Override 89 | public void accept(VoidVisitor visitor) { 90 | visitor.visit(this); 91 | } 92 | 93 | /** 94 | * {@inheritDoc} 95 | * @see kodkod.ast.Node#toString() 96 | */ 97 | public String toString() { 98 | return "(if " + condition + " then " + thenExpr + " else " + elseExpr + ")"; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/kodkod/ast/IntComparisonFormula.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.ast; 23 | 24 | 25 | 26 | import kodkod.ast.operator.IntCompOperator; 27 | import kodkod.ast.visitor.ReturnVisitor; 28 | import kodkod.ast.visitor.VoidVisitor; 29 | 30 | /** 31 | * An integer comparison formula, e.g. x = y, x <= y, etc. 32 | * 33 | * @specfield left: IntExpression 34 | * @specfield right: IntExpression 35 | * @specfield op: IntCompOperator 36 | * @invariant children = 0->left + 1->right 37 | * @author Emina Torlak 38 | */ 39 | public final class IntComparisonFormula extends Formula { 40 | private final IntCompOperator op; 41 | private final IntExpression left, right; 42 | 43 | /** 44 | * Constructs a new int comparison formula: left op right 45 | * 46 | * @ensures this.left' = left && this.right' = right && this.op' = op 47 | * @throws NullPointerException left = null || right = null || op = null 48 | */ 49 | IntComparisonFormula(final IntExpression left, final IntCompOperator op, final IntExpression right) { 50 | this.left = left; 51 | this.right = right; 52 | this.op = op; 53 | } 54 | 55 | /** 56 | * Returns the left child of this. 57 | * @return this.left 58 | */ 59 | public IntExpression left() {return left;} 60 | 61 | /** 62 | * Returns the right child of this. 63 | * @return this.right 64 | */ 65 | public IntExpression right() {return right;} 66 | 67 | /** 68 | * Returns the operator of this. 69 | * @return this.op 70 | */ 71 | public IntCompOperator op() {return op;} 72 | 73 | /** 74 | * {@inheritDoc} 75 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 76 | */ 77 | public F accept(ReturnVisitor visitor) { 78 | return visitor.visit(this); 79 | } 80 | 81 | /** 82 | * {@inheritDoc} 83 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 84 | */ 85 | public void accept(VoidVisitor visitor) { 86 | visitor.visit(this); 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | * @see kodkod.ast.Node#toString() 92 | */ 93 | public String toString() { 94 | return "(" + left + " " + op + " " + right + ")"; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/kodkod/ast/IntConstant.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.ast; 23 | 24 | 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * An integer constant (literal). 30 | * @specfield value: int 31 | * @invariant no children 32 | * @author Emina Torlak 33 | */ 34 | public final class IntConstant extends IntExpression { 35 | private final int value; 36 | 37 | /** 38 | * Constructs an int constant. 39 | * @ensures this.value' = value 40 | */ 41 | private IntConstant(int value) { 42 | this.value = value; 43 | } 44 | 45 | /** 46 | * Returns an IntConstant corresponding to the given value. 47 | * @return {c: IntConstant | c.value = value} 48 | */ 49 | public static IntConstant constant(int value) { 50 | return new IntConstant(value); 51 | } 52 | 53 | /** 54 | * Returns this.value. 55 | * @return this.value 56 | */ 57 | public int value() { 58 | return value; 59 | } 60 | 61 | /** 62 | * Return true if o is an IntConstant with the same value as this. 63 | * @return o in IntConstant && o.value = this.value 64 | */ 65 | public boolean equals(Object o) { 66 | if (o==this) 67 | return true; 68 | else if (o instanceof IntConstant) 69 | return value==((IntConstant) o).value; 70 | else 71 | return false; 72 | } 73 | 74 | /** 75 | * Return this.value 76 | * @return this.value 77 | */ 78 | public int hashCode() { 79 | return value; 80 | } 81 | 82 | /** 83 | * {@inheritDoc} 84 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.ReturnVisitor) 85 | */ 86 | @Override 87 | public I accept(ReturnVisitor visitor) { 88 | return visitor.visit(this); 89 | } 90 | 91 | /** 92 | * {@inheritDoc} 93 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.VoidVisitor) 94 | */ 95 | @Override 96 | public void accept(VoidVisitor visitor) { 97 | visitor.visit(this); 98 | } 99 | 100 | /** 101 | * {@inheritDoc} 102 | * @see kodkod.ast.Node#toString() 103 | */ 104 | public String toString() { 105 | return String.valueOf(value); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/kodkod/ast/IntToExprCast.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.ast; 23 | 24 | import kodkod.ast.operator.IntCastOperator; 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * Represents the conversion from an {@link kodkod.ast.IntExpression int expression } 30 | * to an {@link kodkod.ast.Expression expression}. The meaning of the resulting 31 | * expression is a singleton set containing the atom that represents the integer 32 | * given by the wrapped int expression, if the conversion operator is INTCAST. 33 | * Otherwise, the meaning is the set of powers of 2 that make up the given integer expression. 34 | * @specfield intExpr: IntExpression 35 | * @specfield op: IntCastOperator 36 | * @invariant children = 0->intExpr 37 | * @invariant arity = 1 38 | * @author Emina Torlak 39 | */ 40 | public final class IntToExprCast extends Expression { 41 | private final IntExpression intExpr; 42 | private final IntCastOperator op; 43 | /** 44 | * Constructs a new IntToExprCast. 45 | * @requires intExpr != null && op != null 46 | * @ensures this.intexpr' = intExpr 47 | */ 48 | IntToExprCast(IntExpression intExpr, IntCastOperator op) { 49 | this.intExpr = intExpr; 50 | this.op = op; 51 | } 52 | 53 | /** 54 | * Returns 1. 55 | * @return 1 56 | */ 57 | @Override 58 | public int arity() { 59 | return 1; 60 | } 61 | 62 | /** 63 | * Returns this.intExpr. 64 | * @return this.intExpr 65 | */ 66 | public IntExpression intExpr() { 67 | return intExpr; 68 | } 69 | 70 | /** 71 | * Returns this.op 72 | * @return this.op 73 | */ 74 | public final IntCastOperator op() { 75 | return op; 76 | } 77 | 78 | /** 79 | * {@inheritDoc} 80 | * @see kodkod.ast.Expression#accept(kodkod.ast.visitor.ReturnVisitor) 81 | */ 82 | public E accept(ReturnVisitor visitor) { 83 | return visitor.visit(this); 84 | } 85 | 86 | /** 87 | * {@inheritDoc} 88 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 89 | */ 90 | public void accept(VoidVisitor visitor) { 91 | visitor.visit(this); 92 | } 93 | 94 | /** 95 | * {@inheritDoc} 96 | * @see kodkod.ast.Node#toString() 97 | */ public String toString() { 98 | return op + "[" + intExpr + "]"; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/kodkod/ast/LeafExpression.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.ast; 23 | 24 | /** 25 | * An expression with no children. 26 | * {@link kodkod.ast.Relation Relation} and {@link kodkod.ast.Variable Variable} 27 | * are examples of leaf expressions. Two leaf expressions are equal 28 | * if and only if they refer to the same object. That is, 29 | * leaf1.equals(leaf2) <=> leaf1 == leaf2. A leaf has a name, which is 30 | * basically a comment for the purpose of printing, viewing, etc. The name 31 | * has no meaning otherwise. 32 | * 33 | * @specfield name: String 34 | * @specfield arity: int 35 | * @specfield no children 36 | * @author Emina Torlak 37 | */ 38 | public abstract class LeafExpression extends Expression { 39 | 40 | private final int arity; 41 | private final String name; 42 | 43 | /** 44 | * Constructs a leaf with the specified name and arity 45 | * 46 | * @ensures this.name' = name && this.arity' = arity 47 | * @throws IllegalArgumentException arity < 1 48 | */ 49 | LeafExpression(String name, int arity) { 50 | if (arity < 1) { 51 | throw new IllegalArgumentException("Arity must be at least 1: " + arity); 52 | } 53 | this.name = name; 54 | this.arity = arity; 55 | } 56 | 57 | 58 | /** 59 | * Returns the arity of this leaf. 60 | * @return this.arity 61 | */ 62 | public final int arity() { 63 | return arity; 64 | } 65 | 66 | /** 67 | * Returns the name of this leaf. 68 | * @return this.name 69 | */ 70 | public final String name() { 71 | return name; 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | * @see kodkod.ast.Node#toString() 77 | */ 78 | public String toString() { 79 | return name; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/kodkod/ast/MultiplicityFormula.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.ast; 23 | 24 | 25 | import kodkod.ast.operator.Multiplicity; 26 | import kodkod.ast.visitor.ReturnVisitor; 27 | import kodkod.ast.visitor.VoidVisitor; 28 | 29 | 30 | /** 31 | * A multiplicity formula, e.g. some x 32 | * 33 | * @specfield expression: Expression 34 | * @specfield multiplicity: (ONE + LONE + SOME + NO) 35 | * @invariant children = 0->expression 36 | * @author Emina Torlak 37 | */ 38 | public final class MultiplicityFormula extends Formula { 39 | private final Expression expression; 40 | private final Multiplicity multiplicity; 41 | 42 | /** 43 | * Constructs a new multiplicity formula: multiplicity expression 44 | * 45 | * @ensures this.expression' = expression && this.multiplicity' = multiplicity 46 | * @throws NullPointerException multiplicity = null || expression = null 47 | * @throws IllegalArgumentException multiplicity = SET 48 | */ 49 | MultiplicityFormula(Multiplicity multiplicity, Expression expression) { 50 | if (multiplicity==Multiplicity.SET) throw new IllegalArgumentException("invalid expression mulitplicity: SET"); 51 | if (multiplicity== null || expression == null) throw new NullPointerException("null arg"); 52 | this.multiplicity = multiplicity; 53 | this.expression = expression; 54 | } 55 | 56 | /** 57 | * Returns the mulitplicity of this. 58 | * @return this.multiplicity 59 | */ 60 | public Multiplicity multiplicity() { return multiplicity; } 61 | 62 | /** 63 | * Returns the expression of this. 64 | * @return this.expression 65 | */ 66 | public Expression expression() { return expression; } 67 | 68 | /** 69 | * {@inheritDoc} 70 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 71 | */ 72 | public F accept(ReturnVisitor visitor) { 73 | return visitor.visit(this); 74 | } 75 | 76 | /** 77 | * {@inheritDoc} 78 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 79 | */ 80 | public void accept(VoidVisitor visitor) { 81 | visitor.visit(this); 82 | } 83 | 84 | /** 85 | * {@inheritDoc} 86 | * @see kodkod.ast.Node#toString() 87 | */ 88 | public String toString() { 89 | return multiplicity + " " + expression; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/kodkod/ast/Node.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.ast; 23 | 24 | import kodkod.ast.visitor.ReturnVisitor; 25 | import kodkod.ast.visitor.VoidVisitor; 26 | 27 | 28 | /** 29 | * A node in the abstract syntax tree (DAG). A node 30 | * can accept a ReturnVisitor and have a sequence of 31 | * zero or more children. 32 | * 33 | * @specfield children: int ->lone Node 34 | * @specfield components: set Node 35 | * @invariant children.Node = { i: int | 0 <= i < #children } 36 | * @invariant components= children[int] 37 | * @author Emina Torlak 38 | */ 39 | public abstract class Node { 40 | 41 | /** 42 | * Accepts the given visitor and returns the result 43 | * of the visit (i.e. the result of the call visitor.visit(this)) 44 | * @return the result of being visited by the given visitor 45 | * @throws NullPointerException visitor = null 46 | */ 47 | public abstract Object accept(ReturnVisitor visitor); 48 | 49 | /** 50 | * Accepts the given void visitor by calling visitor.visit(this). 51 | * @throws NullPointerException visitor = null 52 | */ 53 | public abstract void accept(VoidVisitor visitor); 54 | 55 | /** 56 | * Returns a string representation of this node. 57 | * For a pretty-printed string, use {@linkplain kodkod.util.nodes.PrettyPrinter}. 58 | * @return a string representation of this node 59 | * @see kodkod.util.nodes.PrettyPrinter 60 | */ 61 | public abstract String toString(); 62 | } 63 | -------------------------------------------------------------------------------- /src/kodkod/ast/NotFormula.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.ast; 23 | 24 | 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | 29 | /** 30 | * Negation of a {@link kodkod.ast.Formula formula}. 31 | * 32 | * @specfield formula: Formula 33 | * @invariant children = 0->formula 34 | * @author Emina Torlak 35 | */ 36 | public final class NotFormula extends Formula { 37 | private final Formula formula; 38 | 39 | /** 40 | * Constructs a new formula: !formula 41 | * 42 | * @ensures this.formula' = formula 43 | * @throws NullPointerException formula = null 44 | */ 45 | NotFormula(Formula child) { 46 | if (child == null) throw new NullPointerException("formula"); 47 | this.formula = child; 48 | } 49 | 50 | /** 51 | * Returns this.formula. 52 | * @return this.formula 53 | */ 54 | public Formula formula() { return formula; } 55 | 56 | /** 57 | * {@inheritDoc} 58 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 59 | */ 60 | public F accept(ReturnVisitor visitor) { 61 | return visitor.visit(this); 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 67 | */ 68 | public void accept(VoidVisitor visitor) { 69 | visitor.visit(this); 70 | } 71 | 72 | /** 73 | * {@inheritDoc} 74 | * @see kodkod.ast.Node#toString() 75 | */ 76 | public String toString() { 77 | return "!" + formula; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/kodkod/ast/QuantifiedFormula.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.ast; 23 | 24 | 25 | import kodkod.ast.operator.Quantifier; 26 | import kodkod.ast.visitor.ReturnVisitor; 27 | import kodkod.ast.visitor.VoidVisitor; 28 | 29 | 30 | /** 31 | * A quantified formula. 32 | * 33 | * @specfield decls: Declarations 34 | * @specfield formula: Formula 35 | * @specfield quantifier: Quantifier 36 | * @invariant children = 0->decls + 1->formula 37 | * @author Emina Torlak 38 | */ 39 | public final class QuantifiedFormula extends Formula { 40 | private final Quantifier quantifier; 41 | private final Decls decls; 42 | private final Formula formula; 43 | 44 | /** 45 | * Constructs a new quantified formula: quantifier decls | formula 46 | * 47 | * @ensures this.quantifier' = quantifier && this.decls' = decls && 48 | * this.formula' = formula 49 | * @throws NullPointerException quantifier = null || decls = null || formula = null 50 | */ 51 | QuantifiedFormula(Quantifier quantifier, Decls declarations, Formula formula) { 52 | if (quantifier == null || declarations == null || formula == null) { 53 | throw new NullPointerException("null arg"); 54 | } 55 | this.quantifier = quantifier; 56 | this.decls = declarations; 57 | this.formula = formula; 58 | } 59 | 60 | /** 61 | * Returns this.formula. 62 | * @return this.formula 63 | */ 64 | public Formula formula() { return formula; } 65 | 66 | /** 67 | * Returns this.decls. 68 | * @return this.decls 69 | */ 70 | public Decls decls() { return decls;} 71 | 72 | /** 73 | * Returns this.quantifier. 74 | * @return this.quantifier 75 | */ 76 | public Quantifier quantifier() { return quantifier; } 77 | 78 | /** 79 | * {@inheritDoc} 80 | * @see kodkod.ast.Formula#accept(kodkod.ast.visitor.ReturnVisitor) 81 | */ 82 | public F accept(ReturnVisitor visitor) { 83 | return visitor.visit(this); 84 | } 85 | 86 | /** 87 | * {@inheritDoc} 88 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 89 | */ 90 | public void accept(VoidVisitor visitor) { 91 | visitor.visit(this); 92 | } 93 | 94 | /** 95 | * {@inheritDoc} 96 | * @see kodkod.ast.Node#toString() 97 | */ 98 | public String toString() { 99 | return "(" + quantifier + " " + decls + " | " + formula + ")"; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/kodkod/ast/SumExpression.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.ast; 23 | 24 | import kodkod.ast.operator.Multiplicity; 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * Denotes the integer obtained by summing the values of an iteger expression ie 30 | * for all values of a scalar x drawn from a set e. 31 | * @specfield intExpr: IntExpression 32 | * @specfield decls: Decls 33 | * @specfield children = 0->decls + 1->intExpr 34 | * @invariant all d: decls.children[int] | d.multiplicity = 1 35 | * @author Emina Torlak 36 | */ 37 | public final class SumExpression extends IntExpression { 38 | private final Decls decls; 39 | private final IntExpression intExpr; 40 | 41 | /** 42 | * Constructs a sum expression 43 | * @ensures this.decls' = decls && this.intExpr' = intExpr 44 | * @throws IllegalArgumentException some d: decls.children | d.multiplicty != ONE 45 | */ 46 | SumExpression(Decls decls, IntExpression intExpr) { 47 | for(Decl d : decls) { 48 | if (d.multiplicity()!=Multiplicity.ONE) 49 | throw new IllegalArgumentException(d + " is not a scalar declaration."); 50 | } 51 | this.decls = decls; 52 | this.intExpr = intExpr; 53 | } 54 | 55 | /** 56 | * Returns this.decls. 57 | * @return this.decls 58 | */ 59 | public final Decls decls() { 60 | return decls; 61 | } 62 | 63 | /** 64 | * Returns this.intExpr. 65 | * @return this.intExpr 66 | */ 67 | public final IntExpression intExpr() { 68 | return intExpr; 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.ReturnVisitor) 74 | */ 75 | @Override 76 | public I accept(ReturnVisitor visitor) { 77 | return visitor.visit(this); 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.VoidVisitor) 83 | */ 84 | @Override 85 | public void accept(VoidVisitor visitor) { 86 | visitor.visit(this); 87 | } 88 | 89 | /** 90 | * {@inheritDoc} 91 | * @see kodkod.ast.Node#toString() 92 | */ 93 | public String toString() { 94 | return "(sum " + decls + " | " + intExpr + ")"; 95 | } 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/kodkod/ast/UnaryExpression.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.ast; 23 | 24 | 25 | import kodkod.ast.operator.ExprOperator; 26 | import kodkod.ast.visitor.ReturnVisitor; 27 | import kodkod.ast.visitor.VoidVisitor; 28 | 29 | /** 30 | * An {@link kodkod.ast.Expression expression} with one child. 31 | * 32 | * @specfield expression: Expression 33 | * @specfield op: ExprOperator 34 | * @invariant op.unary() 35 | * @invariant children = 0->Expression 36 | * @author Emina Torlak 37 | */ 38 | public final class UnaryExpression extends Expression { 39 | private final Expression expression; 40 | private final ExprOperator op; 41 | private final int arity; 42 | 43 | /** 44 | * Constructs a new unary expression: op expression 45 | * 46 | * @ensures this.expression' = expression && this.op' = op 47 | * @throws NullPointerException expression = null || op = null 48 | * @throws IllegalArgumentException op in {TRANSPOSE, CLOSURE, REFLEXIVE_CLOSURE} && child.arity != 2 49 | */ 50 | UnaryExpression(ExprOperator op, Expression child) { 51 | if (!op.unary()) { 52 | throw new IllegalArgumentException("Not a unary operator: " + op); 53 | } 54 | if (child.arity()!=2) { 55 | throw new IllegalArgumentException("Invalid arity: " + child + "::" + child.arity()); 56 | } 57 | this.expression = child; 58 | this.op = op; 59 | this.arity = 2; 60 | } 61 | 62 | /** 63 | * Returns the arity of this expression. 64 | * @return this.arity 65 | * @see kodkod.ast.Expression#arity() 66 | */ 67 | public int arity() { 68 | return arity; 69 | } 70 | 71 | /** 72 | * Returns this.expression. 73 | * @return this.expression 74 | */ 75 | public Expression expression() {return expression;} 76 | 77 | /** 78 | * Returns this.op. 79 | * @return this.op 80 | */ 81 | public ExprOperator op() {return op;} 82 | 83 | 84 | /** 85 | * {@inheritDoc} 86 | * @see kodkod.ast.Expression#accept(kodkod.ast.visitor.ReturnVisitor) 87 | */ 88 | public E accept(ReturnVisitor visitor) { 89 | return visitor.visit(this); 90 | } 91 | 92 | /** 93 | * {@inheritDoc} 94 | * @see kodkod.ast.Node#accept(kodkod.ast.visitor.VoidVisitor) 95 | */ 96 | public void accept(VoidVisitor visitor) { 97 | visitor.visit(this); 98 | } 99 | 100 | /** 101 | * {@inheritDoc} 102 | * @see kodkod.ast.Node#toString() 103 | */ 104 | public String toString() { 105 | return op.toString() + expression.toString(); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/kodkod/ast/UnaryIntExpression.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.ast; 23 | 24 | import kodkod.ast.operator.IntOperator; 25 | import kodkod.ast.visitor.ReturnVisitor; 26 | import kodkod.ast.visitor.VoidVisitor; 27 | 28 | /** 29 | * A unary integer intExpr, e.g. -x. 30 | * @specfield intExpr: IntExpression 31 | * @specfield op: IntOperator 32 | * @invariant op.unary() 33 | * @invariant children = 0->intExpr 34 | * @author Emina Torlak 35 | */ 36 | public final class UnaryIntExpression extends IntExpression { 37 | private final IntOperator op; 38 | private final IntExpression intExpr; 39 | 40 | /** 41 | * Constructs a new unary int formula: op intExpr 42 | * @ensures this.op' = op && this.intExpr' = intExpr 43 | */ 44 | UnaryIntExpression(IntOperator op, IntExpression intExpr) { 45 | if (!op.unary()) throw new IllegalArgumentException("Not a unary operator: " + op); 46 | this.op = op; 47 | this.intExpr = intExpr; 48 | } 49 | 50 | /** 51 | * Returns the operator of this. 52 | * @return this.op 53 | */ 54 | public IntOperator op() {return op;} 55 | 56 | /** 57 | * Returns this.intExpr. 58 | * @return this.intExpr 59 | */ 60 | public IntExpression intExpr() {return intExpr;} 61 | 62 | /** 63 | * {@inheritDoc} 64 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.ReturnVisitor) 65 | */ 66 | @Override 67 | public I accept(ReturnVisitor visitor) { 68 | return visitor.visit(this); 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | * @see kodkod.ast.IntExpression#accept(kodkod.ast.visitor.VoidVisitor) 74 | */ 75 | @Override 76 | public void accept(VoidVisitor visitor) { 77 | visitor.visit(this); 78 | } 79 | 80 | /** 81 | * {@inheritDoc} 82 | * @see kodkod.ast.Node#toString() 83 | */ 84 | public String toString() { 85 | return (op==IntOperator.NEG||op==IntOperator.NOT) ? "(" + op + intExpr + ")" : op + "(" + intExpr + ")" ; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/kodkod/ast/operator/ExprCastOperator.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.ast.operator; 23 | 24 | /** 25 | * Enumerates expression 'cast' operators. 26 | */ 27 | public enum ExprCastOperator { 28 | /** The cardinality operator (#). */ 29 | CARDINALITY { public String toString() { return "#"; } }, 30 | /** The sum operator. */ 31 | SUM { public String toString() { return "sum"; } }; 32 | 33 | } -------------------------------------------------------------------------------- /src/kodkod/ast/operator/ExprCompOperator.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.ast.operator; 23 | 24 | /** 25 | * Enumerates relational comparison operators. 26 | */ 27 | public enum ExprCompOperator { 28 | /** Subset operator (in). */ 29 | SUBSET { public String toString() { return "in"; } }, 30 | /** Equality operator (=). */ 31 | EQUALS { public String toString() { return "="; } }; 32 | } -------------------------------------------------------------------------------- /src/kodkod/ast/operator/ExprOperator.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.ast.operator; 23 | 24 | 25 | 26 | 27 | /** 28 | * Enumerates unary (~, ^, *), binary (+, &, ++, ->, -, .) and nary (+, &, ++, ->) expression operators. 29 | * @specfield op: (int->lone Expression) -> Expression 30 | * @invariant all args: seq Expression, out: Expression | args->out in op => (out.children = args && out.op = this) 31 | */ 32 | public enum ExprOperator { 33 | /** Relational union (+) operator. */ 34 | UNION { public String toString() { return "+"; } }, 35 | /** Relational intersection (&) operator. */ 36 | INTERSECTION { public String toString() { return "&"; } }, 37 | /** Relational override (++) operator. */ 38 | OVERRIDE { public String toString() { return "++"; } }, 39 | /** Relational product (->) operator. */ 40 | PRODUCT { public String toString() { return "->"; } }, 41 | /** Relational difference (-) operator. */ 42 | DIFFERENCE { public String toString() { return "-"; } }, 43 | /** Relational join (.) operator. */ 44 | JOIN { public String toString() { return "."; } }, 45 | /** Transpose (~) operator. */ 46 | TRANSPOSE { public String toString() { return "~";} }, 47 | /** Transitive closure (^) operator. */ 48 | CLOSURE { public String toString() { return "^";} }, 49 | /** Reflexive transitive closure (*) operator. */ 50 | REFLEXIVE_CLOSURE { public String toString() { return "*";} }; 51 | 52 | 53 | static final int unary = TRANSPOSE.index() | CLOSURE.index() | REFLEXIVE_CLOSURE.index(); 54 | 55 | static final int binary = ~unary; 56 | 57 | static final int nary = UNION.index() | INTERSECTION.index() | OVERRIDE.index() | PRODUCT.index(); 58 | 59 | private final int index() { return 1<, <=>) and nary (&&, ||) logical operators. 28 | * @specfield op: (int->lone Formula) -> Formula 29 | * @invariant all args: seq Formula, out: Formula | args->out in op => (out.children = args && out.op = this) 30 | */ 31 | public enum FormulaOperator { 32 | /** Logical AND operator. */ 33 | AND { public String toString() { return "&&"; } }, 34 | /** Logical OR operator. */ 35 | OR { public String toString() { return "||"; } }, 36 | /** Logical bi-implication operator. */ 37 | IFF { public String toString() { return "<=>"; } }, 38 | /** Logical implication operator. */ 39 | IMPLIES { public String toString() { return "=>"; } }; 40 | 41 | static final int nary = (1<, <=, >=. 26 | */ 27 | public enum IntCompOperator { 28 | /** `=' operator */ 29 | EQ { public String toString() { return "="; } }, 30 | /** `<' operator */ 31 | LT { public String toString() { return "<"; } }, 32 | /** `<=' operator */ 33 | LTE { public String toString() { return "<="; } }, 34 | /** `>' operator */ 35 | GT { public String toString() { return ">"; } }, 36 | /** `>=' operator */ 37 | GTE { public String toString() { return ">="; } }; 38 | } -------------------------------------------------------------------------------- /src/kodkod/ast/operator/Multiplicity.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.ast.operator; 23 | 24 | /** 25 | * Represents the multiplicity of an expression 26 | * in a {@link kodkod.ast.MultiplicityFormula} or 27 | * the multiplicity of a variable in a {@link kodkod.ast.Decl }. 28 | * 29 | * @author Emina Torlak 30 | */ 31 | public enum Multiplicity { 32 | /** no expr: expr contains no elements. The 'no' multiplicity can only be used in a multiplicity formula. */ 33 | NO { public String toString() { return "no"; }}, 34 | /** lone expr: expr contains at most one element. */ 35 | LONE { public String toString() { return "lone"; }}, 36 | /** one expr: expr contains exactly one element. */ 37 | ONE { public String toString() { return "one"; }}, 38 | /** some expr: expr contains at least one element. */ 39 | SOME { public String toString() { return "some"; }}, 40 | /** v: set expr: v is a subset of expr. The 'set' multiplicity can only be used in a declaration. */ 41 | SET { public String toString() { return "set"; }} 42 | } -------------------------------------------------------------------------------- /src/kodkod/ast/operator/Quantifier.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.ast.operator; 23 | 24 | /** 25 | * Enumerates logical quantifiers. 26 | */ 27 | public enum Quantifier { 28 | /** Universal quantifier. */ 29 | ALL { public String toString() { return "all"; }}, 30 | /** Existential quantifier. */ 31 | SOME { public String toString() { return "some"; }} 32 | } -------------------------------------------------------------------------------- /src/kodkod/ast/operator/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Contains operators for Kodkod formulas, expressions, and integer expressions. 9 | 10 |

Package Specification

11 | 12 |

Contains operators for Kodkod formulas, expressions, and integer expressions.

13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/kodkod/ast/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Contains classes for creating Kodkod formulas, expressions, 9 | and integer expressions. 10 | 11 |

Package Specification

12 | 13 |

Contains the classes for creating a Kodkod abstract syntax 14 | tree (AST). An object such as a quantified formula or a union expression is called a node. 15 | The {@linkplain kodkod.ast.Node} class is the root of the Kodkod syntax hierarchy.

16 | 17 |

All classes in this package are immutable. Their instances 18 | are created by calling factory methods of the classes {@linkplain kodkod.ast.Relation}, {@linkplain kodkod.ast.Variable}, 19 | {@linkplain kodkod.ast.Expression}, {@linkplain kodkod.ast.IntExpression}, and {@linkplain kodkod.ast.Formula}. Nodes can be freely shared between 20 | multiple parents (so a Kodkod AST is actually a directed acyclic graph).

21 | 22 |

Related Documentation

23 | 24 | @see kodkod.ast.Relation 25 | @see kodkod.ast.Variable 26 | @see kodkod.ast.Expression 27 | @see kodkod.ast.IntExpression 28 | @see kodkod.ast.Formula 29 | @see kodkod.ast.Node 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/kodkod/ast/visitor/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Contains visitors for Kodkod formulas, expressions, and integer expressions. 9 | 10 |

Package Specification

11 | 12 |

Provides two interfaces for traversing the Kodkod AST using 13 | the visitor pattern. A {@linkplain kodkod.ast.visitor.VoidVisitor} visits the nodes but returns no values. A 14 | {@linkplain kodkod.ast.visitor.ReturnVisitor} can be parametrized to return values of specific types for 15 | {@linkplain kodkod.ast.Decls}, {@linkplain kodkod.ast.Expression}, {@linkplain kodkod.ast.IntExpression}, 16 | and {@linkplain kodkod.ast.Formula} nodes.

17 | 18 |

Several skeletal implementations of the VoidVisitor and ReturnVisitor interfaces 19 | are also provided. These traverse the AST in a depth-first manner and optionally cache 20 | the results of visiting specified nodes. The caching functionality makes it convenient 21 | to implement visitors that visit shared nodes only once.

22 | 23 |

Related Documentation

24 | 25 | @see kodkod.ast.visitor.VoidVisitor 26 | @see kodkod.ast.visitor.ReturnVisitor 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/kodkod/engine/AbortedException.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; 23 | 24 | /** 25 | * Indicates that a solving or evaluation task has been aborted. 26 | * @author Emina Torlak 27 | */ 28 | public final class AbortedException extends RuntimeException { 29 | 30 | private static final long serialVersionUID = 201522560152091247L; 31 | 32 | /** 33 | * Constructs an aborted exception with no message. 34 | */ 35 | AbortedException() {} 36 | 37 | /** 38 | * Constructs an aborted exception with the given message. 39 | */ 40 | AbortedException(String message) { 41 | super(message); 42 | } 43 | 44 | /** 45 | * Constructs an aborted exception with the given cause. 46 | */ 47 | AbortedException(Throwable cause) { 48 | super(cause); 49 | } 50 | 51 | /** 52 | * Constructs an aborted exception with the given message and cause. 53 | */ 54 | AbortedException(String message, Throwable cause) { 55 | super(message, cause); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/kodkod/engine/CapacityExceededException.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; 23 | 24 | import kodkod.util.ints.IntVector; 25 | 26 | /** 27 | * Indicates that a problem construction or translation task failed because 28 | * the capacity of the index representation was exceeded. 29 | * @specfield dims: IntVector // contains a vector of dimensions which exceed the representation capacity 30 | * @author Emina Torlak 31 | */ 32 | public final class CapacityExceededException extends RuntimeException { 33 | 34 | private static final long serialVersionUID = -8098615204149641969L; 35 | private final IntVector dims; 36 | 37 | /** 38 | * Constructs a CapacityExceededException from the given dimensions. 39 | */ 40 | public CapacityExceededException(IntVector dims) { 41 | this.dims = dims; 42 | } 43 | 44 | /** 45 | * Constructs a CapacityExceededException with the given message and dimensions. 46 | */ 47 | public CapacityExceededException(String arg0, IntVector dims) { 48 | super(arg0); 49 | this.dims = dims; 50 | } 51 | 52 | /** 53 | * Constructs a CapacityExceededException with the given cause. 54 | */ 55 | public CapacityExceededException(Throwable arg0, IntVector dims) { 56 | super(arg0); 57 | this.dims = dims; 58 | } 59 | 60 | /** 61 | * Constructs a CapacityExceededException with the given message and cause. 62 | */ 63 | public CapacityExceededException(String arg0, Throwable arg1, IntVector dims) { 64 | super(arg0, arg1); 65 | this.dims = dims; 66 | } 67 | 68 | /** 69 | * Returns the vector of dimensions which, when multiplied together, exceed 70 | * the representation capacity. 71 | * @return this.dims 72 | */ 73 | public final IntVector dims() { return dims; } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/kodkod/engine/bool/BooleanConstant.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.bool; 23 | 24 | /** 25 | * A boolean constant, true or false. The integer 26 | * label of the true and false constants are Integer.MAX_VALUE and -Integer.MAX_VALUE, respectively. 27 | * The two boolean constants, TRUE and FALSE, are shared among all factories. 28 | * 29 | * @specfield value: boolean 30 | * @invariant this.op = Operator.CONST 31 | * @invariant value => Integer.MAX_VALUE, -Integer.MAX_VALUE 32 | * @author Emina Torlak 33 | */ 34 | public final class BooleanConstant extends BooleanValue { 35 | final int label; 36 | 37 | public static final BooleanConstant TRUE = new BooleanConstant(true); 38 | public static final BooleanConstant FALSE = new BooleanConstant(false); 39 | 40 | /** 41 | * Constructs a BooleanConstant that represent the given boolean 42 | * value. 43 | * @ensures value => this.label' = Integer.MAX_VALUE, this.label' = -Integer.MAX_VALUE 44 | */ 45 | private BooleanConstant(boolean value) { 46 | this.label = (value ? Integer.MAX_VALUE : -Integer.MAX_VALUE); 47 | } 48 | 49 | /** 50 | * Returns the negation of this value. 51 | * @return c: BooleanConstant | [[c]] = ![[this]] 52 | */ 53 | @Override 54 | BooleanValue negation() { 55 | return this==TRUE ? FALSE : TRUE; 56 | } 57 | 58 | /** 59 | * Returns the primitive boolean representation of this label. 60 | * @return this.label == Integer.MAX_VALUE 61 | */ 62 | public boolean booleanValue() { return label > 0; } 63 | 64 | /** 65 | * Returns the BooleanConstant that represents the given boolean value. 66 | * @return {c: BooleanConstant | value => c.label = Integer.MAX_VALUE, c.label = -Integer.MAX_VALUE } 67 | */ 68 | public static BooleanConstant constant(boolean value) { 69 | return value ? TRUE : FALSE; 70 | } 71 | 72 | /** 73 | * Returns the label for this value. 74 | * @return this.label 75 | */ 76 | @Override 77 | public int label() { 78 | return label; 79 | } 80 | 81 | /** 82 | * Returns a string representation of this boolean value. 83 | * @return a string representation of this boolean value. 84 | */ 85 | public String toString() { 86 | return label>0 ? "T" : "F"; 87 | } 88 | 89 | /** 90 | * Returns Operator.CONST. 91 | * @return Operator.CONST 92 | */ 93 | @Override 94 | public Operator op() { 95 | return Operator.CONST; 96 | } 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/kodkod/engine/bool/BooleanValue.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.bool; 23 | 24 | /** 25 | * Represents a boolean value, which may be a {@link kodkod.engine.bool.BooleanFormula formula} 26 | * or a {@link kodkod.engine.bool.BooleanConstant constant}. Boolean formulas are produced by 27 | * {@link kodkod.engine.bool.BooleanFactory circuit factories}. Each value is associated with 28 | * an integer label; the labels are unique within a given factory. 29 | * A boolean value with a negative label -|l| represents the negation of the value with the positive 30 | * label |l|. Non-constant values are not shared among factories. 31 | * 32 | * @specfield op: Operator 33 | * @specfield label: [-Integer.MAX_VALUE, Integer.MAX_VALUE] 34 | * @invariant no c: BooleanValue - this | some components.c & components.this && c.label = this.label 35 | * @author Emina Torlak 36 | */ 37 | public abstract class BooleanValue implements Comparable { 38 | 39 | BooleanValue() {} 40 | 41 | /** 42 | * Returns the negation of this boolean value 43 | * @return { f: BooleanFormula | [[f]] = ![[this]] } 44 | */ 45 | abstract BooleanValue negation(); 46 | 47 | /** 48 | * Returns the label for this value. 49 | * @return this.label 50 | */ 51 | public abstract int label(); 52 | 53 | /** 54 | * Returns the operator representing the function 55 | * computed by this gate. 56 | * @return this.op 57 | */ 58 | public abstract Operator op(); 59 | 60 | /** 61 | * Boolean components are ordered according to their labels. 62 | * Note that the ordering is well defined on components produced by the same factory. 63 | * Specifically, this comparison function is consistent with equals for the components 64 | * produced by the same factory, but may not be for the components produced by different factories. 65 | * @return 0 if the label of this and other are the same, a negative 66 | * integer if the label of this is smaller than the label of other; and 67 | * a positive integer otherwise. 68 | */ 69 | public final int compareTo(BooleanValue other) { 70 | return label() - other.label(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/kodkod/engine/bool/BooleanVisitor.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.bool; 23 | 24 | /** 25 | * Visits {@link kodkod.engine.bool.BooleanFormula boolean formulas}. 26 | * In addition to passing themselves as the argument to the visitor, 27 | * the boolean values also pass along satelite information of type A. 28 | * 29 | * @author Emina Torlak 30 | */ 31 | public interface BooleanVisitor { 32 | 33 | /** 34 | * Visits the multigate and returns the result. 35 | * @return the result of visiting the given multigate 36 | */ 37 | public T visit(MultiGate multigate, A arg); 38 | 39 | /** 40 | * Visits the if-then-else gate and returns the result. 41 | * @return the result of visiting the given ITEGate 42 | */ 43 | public T visit(ITEGate ite, A arg); 44 | 45 | /** 46 | * Visits the inverter and returns the result. 47 | * @return the result of visiting the given inverter 48 | */ 49 | public T visit(NotGate negation, A arg); 50 | 51 | /** 52 | * Visits the variable and returns the result. 53 | * @return the result of visiting the given variable 54 | */ 55 | public T visit(BooleanVariable variable, A arg); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/kodkod/engine/bool/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Provides classes for constructing and composing boolean matrices, boolean circuits, and 9 | boolean representations of integers. 10 | 11 |

Package Specification

12 | 13 |

Contains classes that represent {@linkplain kodkod.engine.bool.BooleanMatrix boolean matrices}, 14 | {@linkplain kodkod.engine.bool.BooleanValue boolean circuits}, and {@linkplain kodkod.engine.bool.Int boolean 15 | representation of integers}. Matrices, circuits, and integers are constructed via factory methods of the 16 | {@linkplain kodkod.engine.bool.BooleanFactory} class.

17 | 18 |

Related Documentation

19 | 20 | @see kodkod.engine.bool.BooleanFactory 21 | @see kodkod.engine.bool.BooleanValue 22 | @see kodkod.engine.bool.BooleanMatrix 23 | @see kodkod.engine.bool.Int 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/kodkod/engine/config/AbstractReporter.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.config; 23 | 24 | 25 | import java.util.List; 26 | import java.util.Set; 27 | 28 | import kodkod.ast.Decl; 29 | import kodkod.ast.Formula; 30 | import kodkod.ast.Relation; 31 | import kodkod.engine.bool.BooleanFormula; 32 | import kodkod.instance.Bounds; 33 | import kodkod.util.ints.IntSet; 34 | 35 | /** 36 | * A skeleton implementation of the {@link Reporter} interface. 37 | * The default implementation for each method has an empty body.s 38 | * @author Emina Torlak 39 | */ 40 | public abstract class AbstractReporter implements Reporter { 41 | 42 | /** 43 | * Constructs a new abstract reporter. 44 | */ 45 | protected AbstractReporter() {} 46 | 47 | /** 48 | * {@inheritDoc} 49 | * @see kodkod.engine.config.Reporter#detectingSymmetries(kodkod.instance.Bounds) 50 | */ 51 | public void detectingSymmetries(Bounds bounds){} 52 | 53 | /** 54 | * {@inheritDoc} 55 | * @see kodkod.engine.config.Reporter#detectedSymmetries(java.util.Set) 56 | */ 57 | public void detectedSymmetries(Set parts) {} 58 | 59 | /** 60 | * @see kodkod.engine.config.Reporter#generatingSBP() 61 | */ 62 | public void generatingSBP() {} 63 | 64 | /** 65 | * {@inheritDoc} 66 | * @see kodkod.engine.config.Reporter#skolemizing(kodkod.ast.Decl, kodkod.ast.Relation, java.util.List) 67 | */ 68 | public void skolemizing(Decl decl, Relation skolem, List context) {} 69 | 70 | /** 71 | * @see kodkod.engine.config.Reporter#solvingCNF(int, int, int) 72 | */ 73 | public void solvingCNF(int primaryVars, int vars, int clauses) {} 74 | 75 | /** 76 | * @see kodkod.engine.config.Reporter#optimizingBoundsAndFormula() 77 | */ 78 | public void optimizingBoundsAndFormula() {} 79 | 80 | /** 81 | * @see kodkod.engine.config.Reporter#translatingToBoolean(kodkod.ast.Formula, kodkod.instance.Bounds) 82 | */ 83 | public void translatingToBoolean(Formula formula, Bounds bounds) {} 84 | 85 | /** 86 | * @see kodkod.engine.config.Reporter#translatingToCNF(kodkod.engine.bool.BooleanFormula) 87 | */ 88 | public void translatingToCNF(BooleanFormula circuit) {} 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/kodkod/engine/config/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Provides a mechanism for configuring the kodkod engine and for passing messages 9 | between the engine and the client. 10 | 11 |

Package Specification

12 | 13 |

Provides a mechanism for configuring the kodkod engine and for passing messages 14 | between the engine and the client. The class {@linkplain kodkod.engine.config.Options} 15 | stores information about various user-level translation and analysis options. It can be 16 | used to choose the SAT solver, control symmetry breaking, etc. The interface 17 | {@linkplain kodkod.engine.config.Reporter} enables passing of messages between the kodkod engine 18 | and the client via callback methods.

19 | 20 |

Related Documentation

21 | 22 | @see kodkod.engine.config.Options 23 | @see kodkod.engine.config.Reporter 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/kodkod/engine/fol2sat/HigherOrderDeclException.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.Decl; 25 | import kodkod.ast.operator.Multiplicity; 26 | 27 | /** 28 | * Thrown when a node contains a higher order declaration that cannot 29 | * be skolemized, or it can be skolemized but skolemization is disabled. 30 | * 31 | * @specfield decl: Decl // higher order decl that caused the exception to be thrown 32 | * @author Emina Torlak 33 | */ 34 | public final class HigherOrderDeclException extends RuntimeException { 35 | private final Decl decl; 36 | private static final long serialVersionUID = 1892780864484615171L; 37 | 38 | /** 39 | * Constructs a HigherOrderDeclException for the given decl. 40 | * @requires decl.multiplicity != ONE 41 | * @ensures this.decl' = decl 42 | */ 43 | HigherOrderDeclException(Decl decl) { 44 | super("Higher order declaration: " + decl); 45 | assert decl.multiplicity() != Multiplicity.ONE; 46 | this.decl = decl; 47 | } 48 | 49 | /** 50 | * Returns this.decl 51 | * @return this.decl 52 | */ 53 | public Decl decl() { 54 | return decl; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/kodkod/engine/fol2sat/RecordFilter.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 java.util.Map; 25 | 26 | import kodkod.ast.Formula; 27 | import kodkod.ast.Node; 28 | import kodkod.ast.Variable; 29 | import kodkod.instance.TupleSet; 30 | 31 | /** 32 | * A filter for TranslationRecords, based on the value of a record's node and literal fields. 33 | **/ 34 | public interface RecordFilter { 35 | /** 36 | * Returns true if the records with the given node, formula derived from the node, literal, and environment 37 | * should be returned by iterators produced by the {@linkplain TranslationLog#replay()} method. 38 | * @return true if the records with the given node, formula derived from the node, literal, and environment 39 | * should be returned by iterators produced by {@linkplain TranslationLog#replay()}. 40 | */ 41 | public abstract boolean accept(Node node, Formula translated, int literal, Map env); 42 | 43 | /** 44 | * A record filter that accepts all records. 45 | */ 46 | public static RecordFilter ALL = new RecordFilter() { 47 | /** 48 | * Returns true. 49 | * @return true 50 | */ 51 | public boolean accept(Node node, Formula translated, int literal, Map env) { 52 | return true; 53 | } 54 | }; 55 | 56 | } -------------------------------------------------------------------------------- /src/kodkod/engine/fol2sat/TranslationLogger.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.Formula; 25 | import kodkod.engine.Solver; 26 | import kodkod.engine.bool.BooleanMatrix; 27 | import kodkod.engine.bool.BooleanValue; 28 | 29 | /** 30 | * Logs the translations of all descendants of a user-provided formula that 31 | * are either formulas or that desugar to formulas. 32 | * @specfield originalFormula: Formula // the {@linkplain Solver#solve(Formula, kodkod.instance.Bounds) original} formula, provided by the user 33 | * @specfield originalBounds: Bounds // the {@linkplain Solver#solve(Formula, kodkod.instance.Bounds) original} bounds, provided by the user 34 | * @specfield formula: Formula // desugaring of this.formula that was translated 35 | * @specfield bounds: Bounds // translation bounds 36 | * @specfield records: (formula.*children & Formula) -> BooleanValue -> Environment 37 | * @invariant Solver.solve(formula, bounds).instance() == null iff Solver.solve(originalFormula, originalBounds).instance() == null 38 | * @author Emina Torlak 39 | */ 40 | abstract class TranslationLogger { 41 | 42 | /** 43 | * Optionally records the translation of the source of the 44 | * given transformed formula to the given boolean value 45 | * in the specified environment. 46 | * @requires f in this.formula.*children 47 | * @ensures this.records' = this.records or this.records' = this.records + f -> translation -> freeVariables(f)<:env 48 | * @throws IllegalArgumentException some aspect of the given translation event prevents it from being logged 49 | * @throws IllegalStateException this log has been closed 50 | */ 51 | abstract void log(Formula f, BooleanValue translation, Environment env); 52 | 53 | /** 54 | * Closes this logger and releases associated resources. Attempts to call {@link #log(Formula, BooleanValue, Environment)} 55 | * after the log has been closed may result in an IllegalStateException. 56 | * @ensures closes this logger and releases associated resources. 57 | */ 58 | abstract void close(); 59 | 60 | /** 61 | * Returns a TranslationLog view of this.records. 62 | * @return a TranslationLog view of this.records. 63 | */ 64 | abstract TranslationLog log(); 65 | } 66 | -------------------------------------------------------------------------------- /src/kodkod/engine/fol2sat/TranslationRecord.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 java.util.Map; 25 | 26 | import kodkod.ast.Formula; 27 | import kodkod.ast.Node; 28 | import kodkod.ast.Variable; 29 | import kodkod.instance.TupleSet; 30 | 31 | /** 32 | * Record of a translation event. Each translation event is described by four pieces of information: 33 | *
    34 | *
  1. the {@linkplain Formula formula} that was translated;
  2. 35 | *
  3. the {@linkplain Node node} from which the translated formula was derived by skolemization or through some other optimization;
  4. 36 | *
  5. the environment in which the given formula is translated, given as a binding of free variables to scalars (singleton, unary tuplesets);
  6. 37 | *
  7. the CNF literal, expressed as an integer, that represents the meaning of the given formula in the given environment.
  8. 38 | *
39 | * 40 | * @specfield node: Node // node that was transformed to this.translated 41 | * @specfield translated: Formula // the translated formula obtain from this.node 42 | * @specfield literal: int // cnf literal representing the meaning of this.node in this.env 43 | * @specfield env: Variable ->one TupleSet // bindings for free, non-skolemized variables 44 | * // for which this.node (or its desugared form) evaluates to this.literal 45 | * @author Emina Torlak 46 | */ 47 | public abstract class TranslationRecord { 48 | 49 | /** 50 | * Returns this.node. 51 | * @return this.node. 52 | */ 53 | public abstract Node node(); 54 | 55 | /** 56 | * Returns this.translated. 57 | * @return this.translated 58 | */ 59 | public abstract Formula translated(); 60 | 61 | /** 62 | * Returns this.literal. 63 | * @return this.literal 64 | */ 65 | public abstract int literal(); 66 | 67 | /** 68 | * Returns a map view of this.env. 69 | * @return this.env 70 | */ 71 | public abstract Map 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 solversToTestWith() { 47 | final Collection ret = new ArrayList(); 48 | for(SATFactory factory : Solvers.allAvailableSolvers()) { 49 | if (factory.incremental()) { 50 | ret.add(new Object[]{factory}); 51 | //System.out.println(factory); 52 | } 53 | } 54 | 55 | return ret; 56 | } 57 | 58 | protected Solution solve(Formula formula, Bounds bounds) { 59 | final Set parts = SymmetryDetector.partition(bounds); 60 | final Bounds inc = new Bounds(bounds.universe()); 61 | final TupleFactory t = inc.universe().factory(); 62 | for(IndexedEntry e : inc.intBounds()) { 63 | inc.boundExactly(e.index(), e.value()); 64 | } 65 | for(IntSet part : parts) { 66 | // dummy relations to set up initial symmetry classes 67 | inc.boundExactly(Relation.unary("r" + part.min()), t.setOf(1, part)); 68 | } 69 | 70 | 71 | Solution sol = solver.solve(Formula.TRUE, inc); 72 | assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.outcome()); 73 | //System.out.println("FORMULAS: " + Nodes.roots(formula).size()); 74 | for(Formula f : Nodes.roots(formula)) { 75 | inc.relations().clear(); 76 | if (!bounds.relations().isEmpty()) { 77 | final Set rels = AnnotatedNode.annotate(f).relations(); 78 | rels.retainAll(bounds.relations()); 79 | for(Relation r : rels) { 80 | inc.bound(r, bounds.lowerBound(r), bounds.upperBound(r)); 81 | } 82 | bounds.relations().removeAll(rels); 83 | } 84 | //System.out.println(f + ", " + inc.relations() + "\n"); 85 | sol = solver.solve(f, inc); 86 | if (sol.unsat()) { 87 | break; 88 | } 89 | } 90 | return sol; 91 | } 92 | 93 | /** 94 | * Runs LAT258.checkGoalToBeProved for 5. Running it for 6 takes about a minute. 95 | */ 96 | @Test 97 | public void testLAT258() { 98 | final LAT258 prob = new LAT258(); 99 | final Solution sol = solve(prob.checkGoalToBeProved(), prob.bounds(5)); 100 | check(prob.getClass().getSimpleName(), sol, UNSATISFIABLE); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /test/kodkod/test/sys/ExamplesTestWithRegularSolver.java: -------------------------------------------------------------------------------- 1 | package kodkod.test.sys; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | 6 | import kodkod.ast.Formula; 7 | import kodkod.engine.Solution; 8 | import kodkod.engine.Solver; 9 | import kodkod.engine.satlab.SATFactory; 10 | import kodkod.instance.Bounds; 11 | 12 | import org.junit.runner.RunWith; 13 | import org.junit.runners.Parameterized; 14 | import org.junit.runners.Parameterized.Parameters; 15 | 16 | import kodkod.test.util.Solvers; 17 | 18 | @RunWith(Parameterized.class) 19 | public class ExamplesTestWithRegularSolver extends ExamplesTest { 20 | 21 | 22 | private final Solver solver; 23 | 24 | public ExamplesTestWithRegularSolver(SATFactory solverOpt) { 25 | this.solver = new Solver(); 26 | this.solver.options().setSolver(solverOpt); 27 | } 28 | 29 | @Parameters 30 | public static Collection solversToTestWith() { 31 | final Collection ret = new ArrayList(); 32 | for(SATFactory factory : Solvers.allAvailableSolvers()) { 33 | ret.add(new Object[]{factory}); 34 | //System.out.println(factory); 35 | } 36 | return ret; 37 | } 38 | 39 | protected Solution solve(Formula formula, Bounds bounds) { 40 | return solver.solve(formula, bounds); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /test/kodkod/test/unit/AllUnitTests.java: -------------------------------------------------------------------------------- 1 | package kodkod.test.unit; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.junit.runners.Suite; 5 | 6 | @RunWith(Suite.class) 7 | @Suite.SuiteClasses({ 8 | SparseSequenceTest.class, 9 | BooleanCircuitTest.class, 10 | BooleanMatrixTest.class, 11 | TranslatorTest.class, 12 | EvaluatorTest.class, 13 | SymmetryBreakingTest.class, 14 | SkolemizationTest.class, 15 | EnumerationTest.class, 16 | IntTest.class, 17 | NativeSolverTest.class, 18 | UCoreTest.class, 19 | ReductionAndProofTest.class, 20 | IncrementalSolverTest.class, 21 | RegressionTests.class, 22 | }) 23 | 24 | public class AllUnitTests {} 25 | -------------------------------------------------------------------------------- /test/kodkod/test/unit/EnumerationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package kodkod.test.unit; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | import static org.junit.Assert.assertFalse; 8 | import static org.junit.Assert.assertNotNull; 9 | import static org.junit.Assert.assertNull; 10 | import static org.junit.Assert.assertTrue; 11 | 12 | import java.util.Arrays; 13 | import java.util.Iterator; 14 | 15 | import kodkod.ast.Formula; 16 | import kodkod.ast.Relation; 17 | import kodkod.engine.Solution; 18 | import kodkod.engine.Solver; 19 | import kodkod.engine.satlab.SATFactory; 20 | import kodkod.instance.Bounds; 21 | import kodkod.instance.TupleFactory; 22 | import kodkod.instance.Universe; 23 | 24 | import org.junit.Test; 25 | 26 | import kodkod.examples.alloy.CeilingsAndFloors; 27 | import kodkod.examples.alloy.Dijkstra; 28 | 29 | /** 30 | * Tests the solution enumeration functionality of the Solver class. 31 | * @author Emina Torlak 32 | */ 33 | public class EnumerationTest { 34 | private final Solver solver; 35 | /** 36 | * Constructs a new EnumerationTest. 37 | */ 38 | public EnumerationTest( ) { 39 | solver = new Solver(); 40 | solver.options().setSolver(SATFactory.MiniSat); 41 | } 42 | 43 | @Test 44 | public final void testCeilingsAndFloors() { 45 | final CeilingsAndFloors model = new CeilingsAndFloors(); 46 | final Formula f = model.checkBelowTooAssertion(); 47 | 48 | // has exactly one instance 49 | Iterator sol = solver.solveAll(f, model.bounds(2,2)); 50 | assertNotNull(sol.next().instance()); 51 | assertNull(sol.next().instance()); 52 | assertFalse(sol.hasNext()); 53 | 54 | // has more than one instance 55 | sol = solver.solveAll(f, model.bounds(3,3)); 56 | assertNotNull(sol.next().instance()); 57 | assertNotNull(sol.next().instance()); 58 | assertTrue(sol.hasNext()); 59 | 60 | // has no instances 61 | sol = solver.solveAll(model.checkBelowTooDoublePrime(), model.bounds(3,3)); 62 | assertNull(sol.next().instance()); 63 | } 64 | 65 | @Test 66 | public final void testDijkstra() { 67 | final Dijkstra model = new Dijkstra(); 68 | final Formula f = model.showDijkstra(); 69 | 70 | Iterator sol = solver.solveAll(f, model.bounds(5,2,2)); 71 | // has more than one instance 72 | assertNotNull(sol.next().instance()); 73 | assertNotNull(sol.next().instance()); 74 | assertTrue(sol.hasNext()); 75 | 76 | } 77 | 78 | @Test 79 | public final void testTrivial() { 80 | final Relation r = Relation.unary("r"); 81 | final Universe u = new Universe(Arrays.asList("a","b","c")); 82 | final TupleFactory f = u.factory(); 83 | final Bounds b = new Bounds(u); 84 | b.bound(r, f.setOf("a"), f.allOf(1)); 85 | final Formula someR = r.some(); 86 | 87 | Iterator sol = solver.solveAll(someR, b); 88 | // has a trivial instance, followed by 2 non-trivial instances 89 | assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.next().outcome()); 90 | assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); 91 | assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); 92 | assertEquals(Solution.Outcome.UNSATISFIABLE, sol.next().outcome()); 93 | assertFalse(sol.hasNext()); 94 | 95 | } 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /test/kodkod/test/util/Solvers.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.test.util; 23 | 24 | import java.lang.reflect.Field; 25 | import java.lang.reflect.Method; 26 | import java.lang.reflect.Modifier; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | import kodkod.engine.satlab.SATFactory; 31 | 32 | /** 33 | * Detects which solvers are available on the system 34 | * and returns their factories. 35 | * 36 | * @author Emina Torlak 37 | */ 38 | public class Solvers { 39 | 40 | /** 41 | * Returns a list view of all solver factories available for use on this system. 42 | * @return a list view of all solver factories available for use on this system. 43 | */ 44 | public static final List allAvailableSolvers() { 45 | final List ret = new ArrayList<>(); 46 | for(Field f : SATFactory.class.getFields()) { 47 | try { 48 | final SATFactory factory = (SATFactory) f.get(null); 49 | if (SATFactory.available(factory)) 50 | ret.add(factory); 51 | } catch (Exception e) { 52 | continue; 53 | } 54 | } 55 | for(Method m : SATFactory.class.getDeclaredMethods()) { 56 | if (!Modifier.isPublic(m.getModifiers())) continue; 57 | try { 58 | final SATFactory factory = (SATFactory) m.invoke(null); 59 | if (SATFactory.available(factory)) 60 | ret.add(factory); 61 | } catch (Exception e) { 62 | continue; 63 | } 64 | } 65 | return ret; 66 | } 67 | 68 | /** 69 | * Prints the list of all solvers found on this system. 70 | */ 71 | public static void main(String[] args) { 72 | System.out.println(allAvailableSolvers().toString()); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | import os.path 4 | 5 | def options(opt): 6 | opt.load('java') 7 | opt.recurse('jni') 8 | 9 | def configure(conf): 10 | conf.load('java') 11 | conf.recurse('jni') 12 | 13 | def build(bld): 14 | bld.recurse('jni') 15 | 16 | bld(rule = 'wget http://download.forge.ow2.org/sat4j/${TGT}', 17 | target = 'sat4j-core-v20130525.zip') 18 | bld(rule = 'unzip ${SRC} -x *src.jar', 19 | source = 'sat4j-core-v20130525.zip', 20 | target = 'org.sat4j.core.jar') 21 | bld.add_group() 22 | 23 | bld(features = 'javac jar', 24 | name = 'kodkod', 25 | srcdir = 'src', 26 | outdir = 'kodkod', 27 | compat = '1.8', 28 | classpath = ['.', 'org.sat4j.core.jar'], 29 | manifest = 'src/MANIFEST', 30 | basedir = 'kodkod', 31 | destfile = 'kodkod.jar') 32 | 33 | bld(features = 'javac jar', 34 | name = 'examples', 35 | use = 'kodkod', 36 | srcdir = 'examples', 37 | outdir = 'examples', 38 | compat = '1.8', 39 | classpath = ['.', 'kodkod.jar'], 40 | manifest = 'examples/MANIFEST', 41 | basedir = 'examples', 42 | destfile = 'examples.jar') 43 | 44 | bld.install_files('${LIBDIR}', ['kodkod.jar', 'examples.jar']) 45 | 46 | def distclean(ctx): 47 | from waflib import Scripting 48 | Scripting.distclean(ctx) 49 | ctx.recurse('jni') 50 | 51 | 52 | from waflib.Build import BuildContext 53 | class TestContext(BuildContext): 54 | cmd = 'test' 55 | fun = 'test' 56 | 57 | def test(bld): 58 | """compiles and runs tests""" 59 | 60 | bld(rule = 'wget -O junit.jar "http://search.maven.org/remotecontent?filepath=junit/junit/4.12/junit-4.12.jar"', 61 | target = 'junit.jar') 62 | bld(rule = 'wget -O hamcrest-core.jar "http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"', 63 | target = 'hamcrest-core.jar') 64 | bld.add_group() 65 | 66 | cp = ['.', 'kodkod.jar', 'examples.jar', 'org.sat4j.core.jar', 'junit.jar', 'hamcrest-core.jar'] 67 | bld(features = 'javac', 68 | name = 'test', 69 | srcdir = 'test', 70 | classpath = cp, 71 | use = ['kodkod', 'examples']) 72 | bld.add_group() 73 | 74 | bld(rule = 'java -cp {classpath} -Djava.library.path={libpath} {junit} {test}'.format(classpath = ':'.join(cp), 75 | libpath = bld.env.LIBDIR, 76 | junit = 'org.junit.runner.JUnitCore', 77 | test = 'kodkod.test.AllTests'), 78 | always = True) 79 | 80 | 81 | 82 | --------------------------------------------------------------------------------