├── .github └── workflows │ └── rust.yml ├── .gitignore ├── .gitmodules ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── lib ├── glucose-syrup-4.1 │ ├── .gitignore │ ├── Changelog │ ├── LICENCE │ ├── README │ ├── core │ │ ├── BoundedQueue.h │ │ ├── Constants.h │ │ ├── Dimacs.h │ │ ├── Makefile │ │ ├── Solver.cc │ │ ├── Solver.h │ │ ├── SolverStats.h │ │ └── SolverTypes.h │ ├── mtl │ │ ├── Alg.h │ │ ├── Alloc.h │ │ ├── Clone.h │ │ ├── Heap.h │ │ ├── IntTypes.h │ │ ├── Map.h │ │ ├── Queue.h │ │ ├── Sort.h │ │ ├── Vec.h │ │ ├── VecThreads.h │ │ ├── XAlloc.h │ │ ├── config.mk │ │ └── template.mk │ ├── parallel │ │ ├── ClausesBuffer.cc │ │ ├── ClausesBuffer.h │ │ ├── Main.cc │ │ ├── Makefile │ │ ├── MultiSolvers.cc │ │ ├── MultiSolvers.h │ │ ├── ParallelSolver.cc │ │ ├── ParallelSolver.h │ │ ├── SharedCompanion.cc │ │ ├── SharedCompanion.h │ │ ├── SolverCompanion.cc │ │ ├── SolverCompanion.h │ │ ├── SolverConfiguration.cc │ │ └── SolverConfiguration.h │ ├── simp │ │ ├── Main.cc │ │ ├── Makefile │ │ ├── SimpSolver.cc │ │ └── SimpSolver.h │ └── utils │ │ ├── Makefile │ │ ├── Options.cc │ │ ├── Options.h │ │ ├── ParseUtils.h │ │ ├── System.cc │ │ └── System.h ├── minisat-c-bindings │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── minisat.cc │ └── minisat.h ├── zconf.h └── zlib.h ├── src ├── cnf.rs └── lib.rs └── wrapper.h /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | strategy: 15 | matrix: 16 | os: [ubuntu-latest, macos-latest] 17 | runs-on: ${{ matrix.os }} 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | submodules: recursive 23 | - name: Build 24 | run: cargo build --verbose 25 | - name: Run tests 26 | run: cargo test --verbose 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/minisat"] 2 | path = lib/minisat 3 | url = https://github.com/agurfinkel/minisat.git 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "minisat" 3 | version = "0.5.0" 4 | authors = ["Bjørnar Luteberget "] 5 | build = "build.rs" 6 | description = "MiniSat Rust interface. Solves a boolean satisfiability problem given in conjunctive normal form." 7 | readme="README.md" 8 | documentation="https://docs.rs/minisat" 9 | repository="https://github.com/luteberget/minisat-rs/" 10 | categories=["api-bindings","science"] 11 | license="MIT" 12 | 13 | [build-dependencies] 14 | cc="1" 15 | bindgen="^0.58" 16 | 17 | [features] 18 | glucose = [] 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Bjørnar Steinnes Luteberget 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [MiniSat](http://minisat.se) Rust interface. 2 | Solves a boolean satisfiability problem given in conjunctive normal form. 3 | 4 | ```rust 5 | extern crate minisat; 6 | use std::iter::once; 7 | fn main() { 8 | let mut sat = minisat::Solver::new(); 9 | let a = sat.new_lit(); 10 | let b = sat.new_lit(); 11 | 12 | // Solves ((a OR not b) AND b) 13 | sat.add_clause(vec![a, !b]); 14 | sat.add_clause(vec![b]); 15 | 16 | match sat.solve() { 17 | Ok(m) => { 18 | assert_eq!(m.value(&a), true); 19 | assert_eq!(m.value(&b), true); 20 | }, 21 | Err(()) => panic!("UNSAT"), 22 | } 23 | } 24 | ``` 25 | 26 | This crate compiles the MiniSat sources directly and binds through 27 | the [minisat-c-bindings](https://github.com/niklasso/minisat-c-bindings) interface. 28 | The low-level C bindings are available through the [`sys`](sys/index.html) module. 29 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | extern crate cc; 2 | extern crate bindgen; 3 | 4 | use std::env; 5 | use std::path::PathBuf; 6 | 7 | 8 | #[cfg(not(feature = "glucose"))] 9 | pub fn main() { 10 | cc::Build::new() 11 | .cpp(true) 12 | .include("lib/minisat") 13 | .include("lib") 14 | .file("lib/minisat/minisat/core/Solver.cc") 15 | .file("lib/minisat/minisat/simp/SimpSolver.cc") 16 | .file("lib/minisat/minisat/utils/System.cc") 17 | //.file("lib/minisat/minisat/utils/Options.cc") 18 | .file("lib/minisat-c-bindings/minisat.cc") 19 | .define("__STDC_LIMIT_MACROS", None) 20 | .define("__STDC_FORMAT_MACROS", None) 21 | .include("/usr/include") 22 | .compile("minisat"); 23 | 24 | let bindings = bindgen::Builder::default() 25 | .clang_arg("-Ilib/minisat-c-bindings") 26 | .header("wrapper.h") 27 | .generate() 28 | .expect("Could not create bindings to library"); 29 | 30 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 31 | bindings 32 | .write_to_file(out_path.join("bindings.rs")) 33 | .expect("Couldn't write bindings!"); 34 | 35 | } 36 | 37 | #[cfg(feature = "glucose")] 38 | pub fn main() { 39 | cc::Build::new() 40 | .cpp(true) 41 | //.include("lib/minisat") 42 | .include("lib/glucose-syrup-4.1") 43 | .include("lib") 44 | .file("lib/glucose-syrup-4.1/core/Solver.cc") 45 | .file("lib/glucose-syrup-4.1/simp/SimpSolver.cc") 46 | .file("lib/glucose-syrup-4.1/utils/System.cc") 47 | //.file("lib/minisat/minisat/utils/Options.cc") 48 | .file("lib/minisat-c-bindings/minisat.cc") 49 | .flag("-std=c++11") 50 | .define("__STDC_LIMIT_MACROS", None) 51 | .define("__STDC_FORMAT_MACROS", None) 52 | .define("USE_GLUCOSE", None) 53 | .include("/usr/include") 54 | .compile("minisat"); 55 | 56 | let bindings = bindgen::Builder::default() 57 | .clang_arg("-Ilib/minisat-c-bindings") 58 | .header("wrapper.h") 59 | .generate() 60 | .expect("Could not create bindings to library"); 61 | 62 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 63 | bindings 64 | .write_to_file(out_path.join("bindings.rs")) 65 | .expect("Couldn't write bindings!"); 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/.gitignore: -------------------------------------------------------------------------------- 1 | ._* 2 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/Changelog: -------------------------------------------------------------------------------- 1 | Version 4.1 2 | - Adaptative (activated by default) strategies. See SAT 2016 paper. 3 | 4 | Version 4.0 5 | - Add a Multithread version, called syrup (many glucose ;-) 6 | See SAT14 paper: Lazy Clause Exchange Policy for parallel SAT solvers. 7 | 8 | - Can work indepentently in sequential or with many cores 9 | 10 | Version 3.0 (2013) 11 | - Add incremental features. 12 | See SAT13 paper: Improving Glucose for Incremental SAT Solving with Assumptions: Application to MUS Extraction 13 | 14 | - Add certified UNSAT proof. 15 | 16 | Version 2.3 (2012) 17 | - Add new restart strategy 18 | See CP12 paper: Refining Restarts Strategies For SAT and UNSAT 19 | 20 | - Add additionnal features to speed the search 21 | 22 | Version 2.0 (2011) 23 | - Add additionnal features (freeze potential good clauses for one turn) 24 | 25 | - Based on Minisat 2.2 26 | 27 | Version 1.0 (2009) 28 | - Based on Minisat 2.0 29 | First release of glucose. 30 | See ijcai 2009 paper: Predicting Learnt Clauses Quality in Modern SAT Solver 31 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/LICENCE: -------------------------------------------------------------------------------- 1 | Glucose -- Copyright (c) 2009-2017, Gilles Audemard, Laurent Simon 2 | CRIL - Univ. Artois, France 3 | LRI - Univ. Paris Sud, France (2009-2013) 4 | Labri - Univ. Bordeaux, France 5 | 6 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 7 | CRIL - Univ. Artois, France 8 | Labri - Univ. Bordeaux, France 9 | 10 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 11 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 12 | is based on. (see below). 13 | 14 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 15 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 16 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 17 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | - The above and below copyrights notices and this permission notice shall be included in all 21 | copies or substantial portions of the Software; 22 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 23 | be used in any competitive event (sat competitions/evaluations) without the express permission of 24 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 25 | using Glucose Parallel as an embedded SAT engine (single core or not). 26 | 27 | 28 | --------------- Original Minisat Copyrights 29 | 30 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 31 | Copyright (c) 2007-2010, Niklas Sorensson 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 34 | associated documentation files (the "Software"), to deal in the Software without restriction, 35 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 36 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 37 | furnished to do so, subject to the following conditions: 38 | 39 | The above copyright notice and this permission notice shall be included in all copies or 40 | substantial portions of the Software. 41 | 42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 43 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 44 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 45 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 46 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 47 | 48 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/README: -------------------------------------------------------------------------------- 1 | Directory overview: 2 | ================== 3 | 4 | mtl/ Minisat Template Library 5 | core/ A core version of the solver glucose (no main here) 6 | simp/ An extended solver with simplification capabilities 7 | parallel/ A multicore version of glucose 8 | README 9 | LICENSE 10 | Changelog 11 | 12 | To build (release version: without assertions, statically linked, etc): 13 | ====================================================================== 14 | Like minisat.... 15 | 16 | cd { simp | parallel } 17 | make rs 18 | 19 | Usage: 20 | ====== 21 | 22 | in simp directory: ./glucose --help 23 | 24 | in parallel directory: ./glucose-syrup --help -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/core/BoundedQueue.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[BoundedQueue.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | 51 | #ifndef BoundedQueue_h 52 | #define BoundedQueue_h 53 | 54 | #include "mtl/Vec.h" 55 | 56 | //================================================================================================= 57 | 58 | namespace Glucose { 59 | 60 | template 61 | class bqueue { 62 | vec elems; 63 | int first; 64 | int last; 65 | unsigned long long sumofqueue; 66 | int maxsize; 67 | int queuesize; // Number of current elements (must be < maxsize !) 68 | bool expComputed; 69 | double exp,value; 70 | public: 71 | bqueue(void) : first(0), last(0), sumofqueue(0), maxsize(0), queuesize(0),expComputed(false) { } 72 | 73 | void initSize(int size) {growTo(size);exp = 2.0/(size+1);} // Init size of bounded size queue 74 | 75 | void push(T x) { 76 | expComputed = false; 77 | if (queuesize==maxsize) { 78 | assert(last==first); // The queue is full, next value to enter will replace oldest one 79 | sumofqueue -= elems[last]; 80 | if ((++last) == maxsize) last = 0; 81 | } else 82 | queuesize++; 83 | sumofqueue += x; 84 | elems[first] = x; 85 | if ((++first) == maxsize) {first = 0;last = 0;} 86 | } 87 | 88 | T peek() { assert(queuesize>0); return elems[last]; } 89 | void pop() {sumofqueue-=elems[last]; queuesize--; if ((++last) == maxsize) last = 0;} 90 | 91 | unsigned long long getsum() const {return sumofqueue;} 92 | unsigned int getavg() const {return (unsigned int)(sumofqueue/((unsigned long long)queuesize));} 93 | int maxSize() const {return maxsize;} 94 | double getavgDouble() const { 95 | double tmp = 0; 96 | for(int i=0;i 25 | 26 | #include "utils/ParseUtils.h" 27 | #include "core/SolverTypes.h" 28 | 29 | namespace Glucose { 30 | 31 | //================================================================================================= 32 | // DIMACS Parser: 33 | 34 | template 35 | static void readClause(B& in, Solver& S, vec& lits) { 36 | int parsed_lit, var; 37 | lits.clear(); 38 | for (;;){ 39 | parsed_lit = parseInt(in); 40 | if (parsed_lit == 0) break; 41 | var = abs(parsed_lit)-1; 42 | while (var >= S.nVars()) S.newVar(); 43 | lits.push( (parsed_lit > 0) ? mkLit(var) : ~mkLit(var) ); 44 | } 45 | } 46 | 47 | template 48 | static void parse_DIMACS_main(B& in, Solver& S) { 49 | vec lits; 50 | int vars = 0; 51 | int clauses = 0; 52 | int cnt = 0; 53 | for (;;){ 54 | skipWhitespace(in); 55 | if (*in == EOF) break; 56 | else if (*in == 'p'){ 57 | if (eagerMatch(in, "p cnf")){ 58 | vars = parseInt(in); 59 | clauses = parseInt(in); 60 | // SATRACE'06 hack 61 | // if (clauses > 4000000) 62 | // S.eliminate(true); 63 | }else{ 64 | printf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3); 65 | } 66 | } else if (*in == 'c' || *in == 'p') 67 | skipLine(in); 68 | else{ 69 | cnt++; 70 | readClause(in, S, lits); 71 | S.addClause_(lits); } 72 | } 73 | if (vars != S.nVars()) 74 | fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of variables.\n"); 75 | if (cnt != clauses) 76 | fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of clauses.\n"); 77 | } 78 | 79 | // Inserts problem into solver. 80 | // 81 | template 82 | static void parse_DIMACS(gzFile input_stream, Solver& S) { 83 | StreamBuffer in(input_stream); 84 | parse_DIMACS_main(in, S); } 85 | 86 | //================================================================================================= 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/core/Makefile: -------------------------------------------------------------------------------- 1 | PHONY: 2 | @echo "** Careful ** Since 4.0 you have to use the simp or parallel directory only for typing make" 3 | 4 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/core/SolverStats.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[Solver.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | #ifndef SOLVERSTATS_H 51 | #define SOLVERSTATS_H 52 | 53 | #include "mtl/Map.h" 54 | #include 55 | namespace Glucose { 56 | 57 | class SolverStats { 58 | protected: 59 | Map map; 60 | 61 | public: 62 | 63 | SolverStats(std::string all[],int sz) : map() { 64 | addStats(all,sz); 65 | } 66 | 67 | void addStats(std::string names[],int sz) { 68 | for(int i = 0;i map[name]) 86 | map[name] = val; 87 | } 88 | 89 | void minimize(const std::string name,uint64_t val) { 90 | if(val < map[name]) 91 | map[name] = val; 92 | } 93 | 94 | }; 95 | 96 | } 97 | 98 | #endif /* SOLVERSTATS_H */ 99 | 100 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Alg.h: -------------------------------------------------------------------------------- 1 | /*******************************************************************************************[Alg.h] 2 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_Alg_h 22 | #define Glucose_Alg_h 23 | 24 | #include "mtl/Vec.h" 25 | 26 | namespace Glucose { 27 | 28 | //================================================================================================= 29 | // Useful functions on vector-like types: 30 | 31 | //================================================================================================= 32 | // Removing and searching for elements: 33 | // 34 | 35 | template 36 | static inline void remove(V& ts, const T& t) 37 | { 38 | int j = 0; 39 | for (; j < ts.size() && ts[j] != t; j++); 40 | assert(j < ts.size()); 41 | for (; j < ts.size()-1; j++) ts[j] = ts[j+1]; 42 | ts.pop(); 43 | } 44 | 45 | 46 | template 47 | static inline bool find(V& ts, const T& t) 48 | { 49 | int j = 0; 50 | for (; j < ts.size() && ts[j] != t; j++); 51 | return j < ts.size(); 52 | } 53 | 54 | 55 | //================================================================================================= 56 | // Copying vectors with support for nested vector types: 57 | // 58 | 59 | // Base case: 60 | template 61 | static inline void copy(const T& from, T& to) 62 | { 63 | to = from; 64 | } 65 | 66 | // Recursive case: 67 | template 68 | static inline void copy(const vec& from, vec& to, bool append = false) 69 | { 70 | if (!append) 71 | to.clear(); 72 | for (int i = 0; i < from.size(); i++){ 73 | to.push(); 74 | copy(from[i], to.last()); 75 | } 76 | } 77 | 78 | template 79 | static inline void append(const vec& from, vec& to){ copy(from, to, true); } 80 | 81 | //================================================================================================= 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Alloc.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************************[Alloc.h] 2 | Copyright (c) 2008-2010, Niklas Sorensson 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or 11 | substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 17 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | **************************************************************************************************/ 19 | 20 | 21 | #ifndef Glucose_Alloc_h 22 | #define Glucose_Alloc_h 23 | 24 | #include "mtl/XAlloc.h" 25 | #include "mtl/Vec.h" 26 | 27 | namespace Glucose { 28 | 29 | //================================================================================================= 30 | // Simple Region-based memory allocator: 31 | 32 | template 33 | class RegionAllocator 34 | { 35 | T* memory; 36 | uint32_t sz; 37 | uint32_t cap; 38 | uint32_t wasted_; 39 | 40 | void capacity(uint32_t min_cap); 41 | 42 | public: 43 | // TODO: make this a class for better type-checking? 44 | typedef uint32_t Ref; 45 | enum { Ref_Undef = UINT32_MAX }; 46 | enum { Unit_Size = sizeof(uint32_t) }; 47 | 48 | explicit RegionAllocator(uint32_t start_cap = 1024*1024) : memory(NULL), sz(0), cap(0), wasted_(0){ capacity(start_cap); } 49 | ~RegionAllocator() 50 | { 51 | if (memory != NULL) 52 | ::free(memory); 53 | } 54 | 55 | 56 | uint32_t size () const { return sz; } 57 | uint32_t getCap () const { return cap;} 58 | uint32_t wasted () const { return wasted_; } 59 | 60 | Ref alloc (int size); 61 | void free (int size) { wasted_ += size; } 62 | 63 | // Deref, Load Effective Address (LEA), Inverse of LEA (AEL): 64 | T& operator[](Ref r) { assert(r >= 0 && r < sz); return memory[r]; } 65 | const T& operator[](Ref r) const { assert(r >= 0 && r < sz); return memory[r]; } 66 | 67 | T* lea (Ref r) { assert(r >= 0 && r < sz); return &memory[r]; } 68 | const T* lea (Ref r) const { assert(r >= 0 && r < sz); return &memory[r]; } 69 | Ref ael (const T* t) { assert((void*)t >= (void*)&memory[0] && (void*)t < (void*)&memory[sz-1]); 70 | return (Ref)(t - &memory[0]); } 71 | 72 | void moveTo(RegionAllocator& to) { 73 | if (to.memory != NULL) ::free(to.memory); 74 | to.memory = memory; 75 | to.sz = sz; 76 | to.cap = cap; 77 | to.wasted_ = wasted_; 78 | 79 | memory = NULL; 80 | sz = cap = wasted_ = 0; 81 | } 82 | 83 | void copyTo(RegionAllocator& to) const { 84 | // if (to.memory != NULL) ::free(to.memory); 85 | to.memory = (T*)xrealloc(to.memory, sizeof(T)*cap); 86 | memcpy(to.memory,memory,sizeof(T)*cap); 87 | to.sz = sz; 88 | to.cap = cap; 89 | to.wasted_ = wasted_; 90 | } 91 | 92 | 93 | 94 | }; 95 | 96 | template 97 | void RegionAllocator::capacity(uint32_t min_cap) 98 | { 99 | if (cap >= min_cap) return; 100 | uint32_t prev_cap = cap; 101 | while (cap < min_cap){ 102 | // NOTE: Multiply by a factor (13/8) without causing overflow, then add 2 and make the 103 | // result even by clearing the least significant bit. The resulting sequence of capacities 104 | // is carefully chosen to hit a maximum capacity that is close to the '2^32-1' limit when 105 | // using 'uint32_t' as indices so that as much as possible of this space can be used. 106 | uint32_t delta = ((cap >> 1) + (cap >> 3) + 2) & ~1; 107 | cap += delta; 108 | 109 | if (cap <= prev_cap) 110 | throw OutOfMemoryException(); 111 | } 112 | //printf(" .. (%p) cap = %u\n", this, cap); 113 | 114 | assert(cap > 0); 115 | memory = (T*)xrealloc(memory, sizeof(T)*cap); 116 | } 117 | 118 | 119 | template 120 | typename RegionAllocator::Ref 121 | RegionAllocator::alloc(int size) 122 | { 123 | //printf("ALLOC called (this = %p, size = %d)\n", this, size); fflush(stdout); 124 | assert(size > 0); 125 | capacity(sz + size); 126 | 127 | uint32_t prev_sz = sz; 128 | sz += size; 129 | 130 | // Handle overflow: 131 | if (sz < prev_sz) 132 | throw OutOfMemoryException(); 133 | 134 | return prev_sz; 135 | } 136 | 137 | 138 | //================================================================================================= 139 | } 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Clone.h: -------------------------------------------------------------------------------- 1 | #ifndef Glucose_Clone_h 2 | #define Glucose_Clone_h 3 | 4 | 5 | namespace Glucose { 6 | 7 | class Clone { 8 | public: 9 | virtual Clone* clone() const = 0; 10 | }; 11 | }; 12 | 13 | #endif -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Heap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************************[Heap.h] 2 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_Heap_h 22 | #define Glucose_Heap_h 23 | 24 | #include "mtl/Vec.h" 25 | 26 | namespace Glucose { 27 | 28 | //================================================================================================= 29 | // A heap implementation with support for decrease/increase key. 30 | 31 | 32 | template 33 | class Heap { 34 | Comp lt; // The heap is a minimum-heap with respect to this comparator 35 | vec heap; // Heap of integers 36 | vec indices; // Each integers position (index) in the Heap 37 | 38 | // Index "traversal" functions 39 | static inline int left (int i) { return i*2+1; } 40 | static inline int right (int i) { return (i+1)*2; } 41 | static inline int parent(int i) { return (i-1) >> 1; } 42 | 43 | 44 | 45 | void percolateUp(int i) 46 | { 47 | int x = heap[i]; 48 | int p = parent(i); 49 | 50 | while (i != 0 && lt(x, heap[p])){ 51 | heap[i] = heap[p]; 52 | indices[heap[p]] = i; 53 | i = p; 54 | p = parent(p); 55 | } 56 | heap [i] = x; 57 | indices[x] = i; 58 | } 59 | 60 | 61 | void percolateDown(int i) 62 | { 63 | int x = heap[i]; 64 | while (left(i) < heap.size()){ 65 | int child = right(i) < heap.size() && lt(heap[right(i)], heap[left(i)]) ? right(i) : left(i); 66 | if (!lt(heap[child], x)) break; 67 | heap[i] = heap[child]; 68 | indices[heap[i]] = i; 69 | i = child; 70 | } 71 | heap [i] = x; 72 | indices[x] = i; 73 | } 74 | 75 | 76 | public: 77 | Heap(const Comp& c) : lt(c) { } 78 | 79 | int size () const { return heap.size(); } 80 | bool empty () const { return heap.size() == 0; } 81 | bool inHeap (int n) const { return n < indices.size() && indices[n] >= 0; } 82 | int operator[](int index) const { assert(index < heap.size()); return heap[index]; } 83 | 84 | 85 | void decrease (int n) { assert(inHeap(n)); percolateUp (indices[n]); } 86 | void increase (int n) { assert(inHeap(n)); percolateDown(indices[n]); } 87 | 88 | void copyTo(Heap& copy) const {heap.copyTo(copy.heap);indices.copyTo(copy.indices);} 89 | 90 | // Safe variant of insert/decrease/increase: 91 | void update(int n) 92 | { 93 | if (!inHeap(n)) 94 | insert(n); 95 | else { 96 | percolateUp(indices[n]); 97 | percolateDown(indices[n]); } 98 | } 99 | 100 | 101 | void insert(int n) 102 | { 103 | indices.growTo(n+1, -1); 104 | assert(!inHeap(n)); 105 | 106 | indices[n] = heap.size(); 107 | heap.push(n); 108 | percolateUp(indices[n]); 109 | } 110 | 111 | 112 | int removeMin() 113 | { 114 | int x = heap[0]; 115 | heap[0] = heap.last(); 116 | indices[heap[0]] = 0; 117 | indices[x] = -1; 118 | heap.pop(); 119 | if (heap.size() > 1) percolateDown(0); 120 | return x; 121 | } 122 | 123 | 124 | // Rebuild the heap from scratch, using the elements in 'ns': 125 | void build(vec& ns) { 126 | for (int i = 0; i < heap.size(); i++) 127 | indices[heap[i]] = -1; 128 | heap.clear(); 129 | 130 | for (int i = 0; i < ns.size(); i++){ 131 | indices[ns[i]] = i; 132 | heap.push(ns[i]); } 133 | 134 | for (int i = heap.size() / 2 - 1; i >= 0; i--) 135 | percolateDown(i); 136 | } 137 | 138 | void clear(bool dealloc = false) 139 | { 140 | for (int i = 0; i < heap.size(); i++) 141 | indices[heap[i]] = -1; 142 | heap.clear(dealloc); 143 | } 144 | }; 145 | 146 | 147 | //================================================================================================= 148 | } 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/IntTypes.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************[IntTypes.h] 2 | Copyright (c) 2009-2010, Niklas Sorensson 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or 11 | substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 17 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | **************************************************************************************************/ 19 | 20 | #ifndef Glucose_IntTypes_h 21 | #define Glucose_IntTypes_h 22 | 23 | #ifdef __sun 24 | // Not sure if there are newer versions that support C99 headers. The 25 | // needed features are implemented in the headers below though: 26 | 27 | # include 28 | # include 29 | # include 30 | 31 | #else 32 | 33 | # include 34 | # include 35 | 36 | #endif 37 | 38 | #include 39 | 40 | #ifndef PRIu64 41 | #define PRIu64 "lu" 42 | #define PRIi64 "ld" 43 | #endif 44 | //================================================================================================= 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Map.h: -------------------------------------------------------------------------------- 1 | /*******************************************************************************************[Map.h] 2 | Copyright (c) 2006-2010, Niklas Sorensson 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or 11 | substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 17 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | **************************************************************************************************/ 19 | 20 | #ifndef Glucose_Map_h 21 | #define Glucose_Map_h 22 | 23 | #include "mtl/IntTypes.h" 24 | #include "mtl/Vec.h" 25 | #include 26 | #include 27 | 28 | namespace Glucose { 29 | 30 | //================================================================================================= 31 | // Default hash/equals functions 32 | // 33 | 34 | static inline uint32_t hash(std::string x) {std::hash hasher;return hasher(x); } 35 | 36 | template struct Hash { uint32_t operator()(const K& k) const { return hash(k); } }; 37 | template struct Equal { bool operator()(const K& k1, const K& k2) const { return k1 == k2; } }; 38 | 39 | template struct DeepHash { uint32_t operator()(const K* k) const { return hash(*k); } }; 40 | template struct DeepEqual { bool operator()(const K* k1, const K* k2) const { return *k1 == *k2; } }; 41 | 42 | static inline uint32_t hash(uint32_t x){ return x; } 43 | static inline uint32_t hash(uint64_t x){ return (uint32_t)x; } 44 | static inline uint32_t hash(int32_t x) { return (uint32_t)x; } 45 | static inline uint32_t hash(int64_t x) { return (uint32_t)x; } 46 | 47 | 48 | //================================================================================================= 49 | // Some primes 50 | // 51 | 52 | static const int nprimes = 25; 53 | static const int primes [nprimes] = { 31, 73, 151, 313, 643, 1291, 2593, 5233, 10501, 21013, 42073, 84181, 168451, 337219, 674701, 1349473, 2699299, 5398891, 10798093, 21596719, 43193641, 86387383, 172775299, 345550609, 691101253 }; 54 | 55 | //================================================================================================= 56 | // Hash table implementation of Maps 57 | // 58 | 59 | template, class E = Equal > 60 | class Map { 61 | public: 62 | struct Pair { K key; D data; }; 63 | 64 | private: 65 | H hash; 66 | E equals; 67 | 68 | vec* table; 69 | int cap; 70 | int size; 71 | 72 | // Don't allow copying (error prone): 73 | Map& operator = (Map& other) { assert(0); } 74 | Map (Map& other) { assert(0); } 75 | 76 | bool checkCap(int new_size) const { return new_size > cap; } 77 | 78 | int32_t index (const K& k) const { return hash(k) % cap; } 79 | void _insert (const K& k, const D& d) { 80 | vec& ps = table[index(k)]; 81 | ps.push(); ps.last().key = k; ps.last().data = d; } 82 | 83 | void rehash () { 84 | const vec* old = table; 85 | 86 | int old_cap = cap; 87 | int newsize = primes[0]; 88 | for (int i = 1; newsize <= cap && i < nprimes; i++) 89 | newsize = primes[i]; 90 | 91 | table = new vec[newsize]; 92 | cap = newsize; 93 | 94 | for (int i = 0; i < old_cap; i++){ 95 | for (int j = 0; j < old[i].size(); j++){ 96 | _insert(old[i][j].key, old[i][j].data); }} 97 | 98 | delete [] old; 99 | 100 | // printf(" --- rehashing, old-cap=%d, new-cap=%d\n", cap, newsize); 101 | } 102 | 103 | 104 | public: 105 | 106 | Map () : table(NULL), cap(0), size(0) {} 107 | Map (const H& h, const E& e) : hash(h), equals(e), table(NULL), cap(0), size(0){} 108 | ~Map () { delete [] table; } 109 | 110 | // PRECONDITION: the key must already exist in the map. 111 | const D& operator [] (const K& k) const 112 | { 113 | assert(size != 0); 114 | const D* res = NULL; 115 | const vec& ps = table[index(k)]; 116 | for (int i = 0; i < ps.size(); i++) 117 | if (equals(ps[i].key, k)) 118 | res = &ps[i].data; 119 | // if(res==NULL) printf("%s\n",k.c_str()); 120 | assert(res != NULL); 121 | return *res; 122 | } 123 | 124 | // PRECONDITION: the key must already exist in the map. 125 | D& operator [] (const K& k) 126 | { 127 | assert(size != 0); 128 | D* res = NULL; 129 | vec& ps = table[index(k)]; 130 | for (int i = 0; i < ps.size(); i++) 131 | if (equals(ps[i].key, k)) 132 | res = &ps[i].data; 133 | // if(res==NULL) printf("%s\n",k.c_str()); 134 | 135 | assert(res != NULL); 136 | return *res; 137 | } 138 | 139 | // PRECONDITION: the key must *NOT* exist in the map. 140 | void insert (const K& k, const D& d) { if (checkCap(size+1)) rehash(); _insert(k, d); size++; } 141 | bool peek (const K& k, D& d) const { 142 | if (size == 0) return false; 143 | const vec& ps = table[index(k)]; 144 | for (int i = 0; i < ps.size(); i++) 145 | if (equals(ps[i].key, k)){ 146 | d = ps[i].data; 147 | return true; } 148 | return false; 149 | } 150 | 151 | bool has (const K& k) const { 152 | if (size == 0) return false; 153 | const vec& ps = table[index(k)]; 154 | for (int i = 0; i < ps.size(); i++) 155 | if (equals(ps[i].key, k)) 156 | return true; 157 | return false; 158 | } 159 | 160 | // PRECONDITION: the key must exist in the map. 161 | void remove(const K& k) { 162 | assert(table != NULL); 163 | vec& ps = table[index(k)]; 164 | int j = 0; 165 | for (; j < ps.size() && !equals(ps[j].key, k); j++); 166 | assert(j < ps.size()); 167 | ps[j] = ps.last(); 168 | ps.pop(); 169 | size--; 170 | } 171 | 172 | void clear () { 173 | cap = size = 0; 174 | delete [] table; 175 | table = NULL; 176 | } 177 | 178 | int elems() const { return size; } 179 | int bucket_count() const { return cap; } 180 | 181 | // NOTE: the hash and equality objects are not moved by this method: 182 | void moveTo(Map& other){ 183 | delete [] other.table; 184 | 185 | other.table = table; 186 | other.cap = cap; 187 | other.size = size; 188 | 189 | table = NULL; 190 | size = cap = 0; 191 | } 192 | 193 | // NOTE: given a bit more time, I could make a more C++-style iterator out of this: 194 | const vec& bucket(int i) const { return table[i]; } 195 | }; 196 | 197 | //================================================================================================= 198 | } 199 | 200 | #endif 201 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Queue.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************************[Queue.h] 2 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_Queue_h 22 | #define Glucose_Queue_h 23 | 24 | #include "mtl/Vec.h" 25 | 26 | namespace Glucose { 27 | 28 | //================================================================================================= 29 | 30 | template 31 | class Queue { 32 | vec buf; 33 | int first; 34 | int end; 35 | 36 | public: 37 | typedef T Key; 38 | 39 | Queue() : buf(1), first(0), end(0) {} 40 | 41 | void clear (bool dealloc = false) { buf.clear(dealloc); buf.growTo(1); first = end = 0; } 42 | int size () const { return (end >= first) ? end - first : end - first + buf.size(); } 43 | 44 | 45 | 46 | const T& operator [] (int index) const { assert(index >= 0); assert(index < size()); return buf[(first + index) % buf.size()]; } 47 | T& operator [] (int index) { assert(index >= 0); assert(index < size()); return buf[(first + index) % buf.size()]; } 48 | 49 | T peek () const { assert(first != end); return buf[first]; } 50 | void pop () { assert(first != end); first++; if (first == buf.size()) first = 0; } 51 | 52 | 53 | void copyTo(Queue& copy) const { 54 | copy.first = first; 55 | copy.end = end; 56 | buf.memCopyTo(copy.buf); 57 | } 58 | 59 | 60 | void insert(T elem) { // INVARIANT: buf[end] is always unused 61 | buf[end++] = elem; 62 | if (end == buf.size()) end = 0; 63 | if (first == end){ // Resize: 64 | vec tmp((buf.size()*3 + 1) >> 1); 65 | //**/printf("queue alloc: %d elems (%.1f MB)\n", tmp.size(), tmp.size() * sizeof(T) / 1000000.0); 66 | int i = 0; 67 | for (int j = first; j < buf.size(); j++) tmp[i++] = buf[j]; 68 | for (int j = 0 ; j < end ; j++) tmp[i++] = buf[j]; 69 | first = 0; 70 | end = buf.size(); 71 | tmp.moveTo(buf); 72 | } 73 | } 74 | }; 75 | 76 | 77 | //================================================================================================= 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Sort.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************************[Sort.h] 2 | Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_Sort_h 22 | #define Glucose_Sort_h 23 | 24 | #include "mtl/Vec.h" 25 | 26 | //================================================================================================= 27 | // Some sorting algorithms for vec's 28 | 29 | 30 | namespace Glucose { 31 | 32 | template 33 | struct LessThan_default { 34 | bool operator () (T x, T y) { return x < y; } 35 | }; 36 | 37 | 38 | template 39 | void selectionSort(T* array, int size, LessThan lt) 40 | { 41 | int i, j, best_i; 42 | T tmp; 43 | 44 | for (i = 0; i < size-1; i++){ 45 | best_i = i; 46 | for (j = i+1; j < size; j++){ 47 | if (lt(array[j], array[best_i])) 48 | best_i = j; 49 | } 50 | tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp; 51 | } 52 | } 53 | template static inline void selectionSort(T* array, int size) { 54 | selectionSort(array, size, LessThan_default()); } 55 | 56 | template 57 | void sort(T* array, int size, LessThan lt) 58 | { 59 | if (size <= 15) 60 | selectionSort(array, size, lt); 61 | 62 | else{ 63 | T pivot = array[size / 2]; 64 | T tmp; 65 | int i = -1; 66 | int j = size; 67 | 68 | for(;;){ 69 | do i++; while(lt(array[i], pivot)); 70 | do j--; while(lt(pivot, array[j])); 71 | 72 | if (i >= j) break; 73 | 74 | tmp = array[i]; array[i] = array[j]; array[j] = tmp; 75 | } 76 | 77 | sort(array , i , lt); 78 | sort(&array[i], size-i, lt); 79 | } 80 | } 81 | template static inline void sort(T* array, int size) { 82 | sort(array, size, LessThan_default()); } 83 | 84 | 85 | //================================================================================================= 86 | // For 'vec's: 87 | 88 | 89 | template void sort(vec& v, LessThan lt) { 90 | sort((T*)v, v.size(), lt); } 91 | template void sort(vec& v) { 92 | sort(v, LessThan_default()); } 93 | 94 | 95 | //================================================================================================= 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/Vec.h: -------------------------------------------------------------------------------- 1 | /*******************************************************************************************[Vec.h] 2 | Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_Vec_h 22 | #define Glucose_Vec_h 23 | 24 | #include 25 | #include 26 | 27 | #include "mtl/IntTypes.h" 28 | #include "mtl/XAlloc.h" 29 | #include 30 | 31 | namespace Glucose { 32 | 33 | //================================================================================================= 34 | // Automatically resizable arrays 35 | // 36 | // NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with realloc) 37 | 38 | template 39 | class vec { 40 | T* data; 41 | int sz; 42 | int cap; 43 | 44 | // Don't allow copying (error prone): 45 | vec& operator = (vec& other) { assert(0); return *this; } 46 | vec (vec& other) { assert(0); } 47 | 48 | // Helpers for calculating next capacity: 49 | static inline int imax (int x, int y) { int mask = (y-x) >> (sizeof(int)*8-1); return (x&mask) + (y&(~mask)); } 50 | //static inline void nextCap(int& cap){ cap += ((cap >> 1) + 2) & ~1; } 51 | static inline void nextCap(int& cap){ cap += ((cap >> 1) + 2) & ~1; } 52 | 53 | public: 54 | // Constructors: 55 | vec() : data(NULL) , sz(0) , cap(0) { } 56 | explicit vec(int size) : data(NULL) , sz(0) , cap(0) { growTo(size); } 57 | vec(int size, const T& pad) : data(NULL) , sz(0) , cap(0) { growTo(size, pad); } 58 | ~vec() { clear(true); } 59 | 60 | // Pointer to first element: 61 | operator T* (void) { return data; } 62 | 63 | // Size operations: 64 | int size (void) const { return sz; } 65 | void shrink (int nelems) { assert(nelems <= sz); for (int i = 0; i < nelems; i++) sz--, data[sz].~T(); } 66 | void shrink_ (int nelems) { assert(nelems <= sz); sz -= nelems; } 67 | int capacity (void) const { return cap; } 68 | void capacity (int min_cap); 69 | void growTo (int size); 70 | void growTo (int size, const T& pad); 71 | void clear (bool dealloc = false); 72 | 73 | // Stack interface: 74 | void push (void) { if (sz == cap) capacity(sz+1); new (&data[sz]) T(); sz++; } 75 | void push (const T& elem) { if (sz == cap) capacity(sz+1); data[sz++] = elem; } 76 | void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; } 77 | void pop (void) { assert(sz > 0); sz--, data[sz].~T(); } 78 | 79 | void remove(const T &elem) { 80 | int tmp; 81 | for(tmp = 0;tmp& copy) const { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; } 107 | void moveTo(vec& dest) { dest.clear(true); dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; } 108 | void memCopyTo(vec& copy) const{ 109 | copy.capacity(cap); 110 | copy.sz = sz; 111 | memcpy(copy.data,data,sizeof(T)*cap); 112 | } 113 | 114 | }; 115 | 116 | 117 | template 118 | void vec::capacity(int min_cap) { 119 | if (cap >= min_cap) return; 120 | int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 121 | if (add > INT_MAX - cap || ((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM) 122 | throw OutOfMemoryException(); 123 | } 124 | 125 | 126 | template 127 | void vec::growTo(int size, const T& pad) { 128 | if (sz >= size) return; 129 | capacity(size); 130 | for (int i = sz; i < size; i++) data[i] = pad; 131 | sz = size; } 132 | 133 | 134 | template 135 | void vec::growTo(int size) { 136 | if (sz >= size) return; 137 | capacity(size); 138 | for (int i = sz; i < size; i++) new (&data[i]) T(); 139 | sz = size; } 140 | 141 | 142 | template 143 | void vec::clear(bool dealloc) { 144 | if (data != NULL){ 145 | for (int i = 0; i < sz; i++) data[i].~T(); 146 | sz = 0; 147 | if (dealloc) free(data), data = NULL, cap = 0; } } 148 | 149 | //================================================================================================= 150 | } 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/VecThreads.h: -------------------------------------------------------------------------------- 1 | /*******************************************************************************************[VecThreads.h] 2 | * Threads safe version used in Glucose-Syrup, 2015, Gilles Audemard, Laurent Simon 3 | Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson 4 | Copyright (c) 2007-2010, Niklas Sorensson 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 7 | associated documentation files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 9 | sublicense, and/or sell 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 copies or 13 | substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 16 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 19 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | **************************************************************************************************/ 21 | 22 | #ifndef Glucose_VecThreads_h 23 | #define Glucose_VecThreads_h 24 | 25 | #include 26 | #include 27 | 28 | #include "mtl/IntTypes.h" 29 | #include "mtl/XAlloc.h" 30 | #include 31 | 32 | namespace Glucose { 33 | 34 | //================================================================================================= 35 | // Automatically resizable arrays 36 | // 37 | // NOTE! Don't use this vector on datatypes that cannot be re-located in memory (with realloc) 38 | 39 | template 40 | class vecThreads { 41 | T* data; 42 | int sz; 43 | int cap; 44 | bool lock; 45 | int nbusers; 46 | 47 | // Don't allow copying (error prone): 48 | vecThreads& operator = (vecThreads& other) { assert(0); return *this; } 49 | vecThreads (vecThreads& other) { assert(0); } 50 | 51 | // Helpers for calculating next capacity: 52 | static inline int imax (int x, int y) { int mask = (y-x) >> (sizeof(int)*8-1); return (x&mask) + (y&(~mask)); } 53 | //static inline void nextCap(int& cap){ cap += ((cap >> 1) + 2) & ~1; } 54 | static inline void nextCap(int& cap){ cap += ((cap >> 1) + 2) & ~1; } 55 | 56 | public: 57 | // Constructors: 58 | vecThreads() : data(NULL) , sz(0) , cap(0), lock(false), nbusers(0) { } 59 | explicit vecThreads(int size) : data(NULL) , sz(0) , cap(0), lock(false), nbusers(0) { growTo(size); } 60 | vecThreads(int size, const T& pad) : data(NULL) , sz(0) , cap(0), lock(false), nbusers(0) { growTo(size, pad); } 61 | ~vecThreads() { clear(true); } 62 | 63 | // Pointer to first element: 64 | operator T* (void) { return data; } 65 | 66 | // Size operations: 67 | int size (void) const { return sz; } 68 | void shrink (int nelems) { assert(nelems <= sz); for (int i = 0; i < nelems; i++) sz--, data[sz].~T(); } 69 | void shrink_ (int nelems) { assert(nelems <= sz); sz -= nelems; } 70 | int capacity (void) const { return cap; } 71 | void capacity (int min_cap); 72 | void capacityProtected (int min_cap); 73 | void growTo (int size); 74 | void growTo (int size, const T& pad); 75 | void clear (bool dealloc = false); 76 | 77 | // Stack interface: 78 | void push (void) { if (sz == cap) capacity(sz+1); new (&data[sz]) T(); sz++; } 79 | void push (const T& elem) { if (sz == cap) capacity(sz+1); data[sz++] = elem; } 80 | void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; } 81 | void pop (void) { assert(sz > 0); sz--, data[sz].~T(); } 82 | 83 | void startMaintenance(); 84 | void endMaintenance(); 85 | void startLoop(); 86 | void endLoop(); 87 | 88 | void remove(const T &elem) { 89 | int tmp; 90 | for(tmp = 0;tmp& copy) const { copy.clear(); copy.growTo(sz); 116 | startLoop();for (int i = 0; i < sz; i++) copy[i] = data[i]; endLoop();} 117 | void moveTo(vecThreads& dest) { 118 | assert(false); // This cannot be made thread safe from here. 119 | dest.clear(true); 120 | startMaintenance(); 121 | dest.data = data; dest.sz = sz; dest.cap = cap; data = NULL; sz = 0; cap = 0; 122 | endMaintenance(); } 123 | void memCopyTo(vecThreads& copy) const{ 124 | copy.capacity(cap); 125 | copy.sz = sz; 126 | memcpy(copy.data,data,sizeof(T)*cap); 127 | } 128 | 129 | }; 130 | 131 | template 132 | void vecThreads::startLoop() { 133 | bool retry = true; 134 | while (retry) { 135 | while(!__sync_bool_compare_and_swap(&lock,false, true)); 136 | if (nbusers >= 0) {nbusers++; retry=false;} 137 | lock = false; 138 | } 139 | } 140 | 141 | template 142 | void vecThreads::endLoop() { 143 | while(!__sync_bool_compare_and_swap(&lock,false, true)); 144 | nbusers--; 145 | lock = false; 146 | } 147 | 148 | template 149 | inline void vecThreads::startMaintenance() { 150 | bool retry = true; 151 | while (retry) { 152 | while(!__sync_bool_compare_and_swap(&lock,false, true)); 153 | if (nbusers == 0) {nbusers--; retry=false;} 154 | lock = false; 155 | } 156 | } 157 | 158 | template 159 | inline void vecThreads::endMaintenance() { 160 | while(!__sync_bool_compare_and_swap(&lock,false, true)); 161 | nbusers++; 162 | lock = false; 163 | } 164 | template 165 | inline void vecThreads::capacityProtected(int min_cap) { 166 | startMaintenance(); 167 | capacity(min_cap); 168 | endMaintenance(); 169 | } 170 | 171 | template 172 | void vecThreads::capacity(int min_cap) { 173 | if (cap >= min_cap) return; 174 | 175 | int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 176 | if (add > INT_MAX - cap || ((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM) 177 | throw OutOfMemoryException(); 178 | 179 | } 180 | 181 | 182 | template 183 | void vecThreads::growTo(int size, const T& pad) { 184 | if (sz >= size) return; 185 | startMaintenance(); 186 | capacity(size); 187 | for (int i = sz; i < size; i++) data[i] = pad; 188 | sz = size; 189 | endMaintenance(); 190 | } 191 | 192 | 193 | template 194 | void vecThreads::growTo(int size) { 195 | if (sz >= size) return; 196 | startMaintenance(); 197 | capacity(size); 198 | for (int i = sz; i < size; i++) new (&data[i]) T(); 199 | sz = size; 200 | endMaintenance(); 201 | } 202 | 203 | 204 | template 205 | void vecThreads::clear(bool dealloc) { 206 | if (data != NULL){ 207 | startMaintenance(); 208 | for (int i = 0; i < sz; i++) data[i].~T(); 209 | sz = 0; 210 | if (dealloc) free(data), data = NULL, cap = 0; 211 | endMaintenance();} } 212 | 213 | //================================================================================================= 214 | } 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/XAlloc.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************************[XAlloc.h] 2 | Copyright (c) 2009-2010, Niklas Sorensson 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or 11 | substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 17 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | **************************************************************************************************/ 19 | 20 | 21 | #ifndef Glucose_XAlloc_h 22 | #define Glucose_XAlloc_h 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace Glucose { 29 | 30 | //================================================================================================= 31 | // Simple layer on top of malloc/realloc to catch out-of-memory situtaions and provide some typing: 32 | 33 | class OutOfMemoryException{}; 34 | static inline void* xrealloc(void *ptr, size_t size) 35 | { 36 | void* mem = realloc(ptr, size); 37 | if (mem == NULL && errno == ENOMEM){ 38 | throw OutOfMemoryException(); 39 | }else { 40 | return mem; 41 | } 42 | } 43 | 44 | //================================================================================================= 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/config.mk: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is for system specific configurations. For instance, on 3 | ## some systems the path to zlib needs to be added. Example: 4 | ## 5 | ## CFLAGS += -I/usr/local/include 6 | ## LFLAGS += -L/usr/local/lib 7 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/mtl/template.mk: -------------------------------------------------------------------------------- 1 | ## 2 | ## Template makefile for Standard, Profile, Debug, Release, and Release-static versions 3 | ## 4 | ## eg: "make rs" for a statically linked release version. 5 | ## "make d" for a debug version (no optimizations). 6 | ## "make" for the standard version (optimized, but with debug information and assertions active) 7 | 8 | PWD = $(shell pwd) 9 | EXEC ?= $(notdir $(PWD)) 10 | 11 | CSRCS = $(wildcard $(PWD)/*.cc) 12 | DSRCS = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc))) 13 | CHDRS = $(wildcard $(PWD)/*.h) 14 | COBJS = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o) 15 | 16 | PCOBJS = $(addsuffix p, $(COBJS)) 17 | DCOBJS = $(addsuffix d, $(COBJS)) 18 | RCOBJS = $(addsuffix r, $(COBJS)) 19 | 20 | CXX ?= g++ 21 | CFLAGS ?= -Wall -Wno-parentheses -std=c++11 22 | LFLAGS ?= -Wall -lpthread 23 | 24 | COPTIMIZE ?= -O3 25 | 26 | CFLAGS += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS 27 | LFLAGS += -lz 28 | 29 | .PHONY : s p d r rs clean 30 | 31 | s: $(EXEC) 32 | p: $(EXEC)_profile 33 | d: $(EXEC)_debug 34 | r: $(EXEC)_release 35 | rs: $(EXEC)_static 36 | 37 | libs: lib$(LIB)_standard.a 38 | libp: lib$(LIB)_profile.a 39 | libd: lib$(LIB)_debug.a 40 | libr: lib$(LIB)_release.a 41 | 42 | ## Compile options 43 | %.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG 44 | %.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG 45 | %.od: CFLAGS +=-O0 -g -D DEBUG 46 | %.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG 47 | 48 | ## Link options 49 | $(EXEC): LFLAGS += -g 50 | $(EXEC)_profile: LFLAGS += -g -pg 51 | $(EXEC)_debug: LFLAGS += -g 52 | #$(EXEC)_release: LFLAGS += ... 53 | $(EXEC)_static: LFLAGS += --static 54 | 55 | ## Dependencies 56 | $(EXEC): $(COBJS) 57 | $(EXEC)_profile: $(PCOBJS) 58 | $(EXEC)_debug: $(DCOBJS) 59 | $(EXEC)_release: $(RCOBJS) 60 | $(EXEC)_static: $(RCOBJS) 61 | 62 | lib$(LIB)_standard.a: $(filter-out */Main.o, $(COBJS)) 63 | lib$(LIB)_profile.a: $(filter-out */Main.op, $(PCOBJS)) 64 | lib$(LIB)_debug.a: $(filter-out */Main.od, $(DCOBJS)) 65 | lib$(LIB)_release.a: $(filter-out */Main.or, $(RCOBJS)) 66 | 67 | 68 | ## Build rule 69 | %.o %.op %.od %.or: %.cc 70 | @echo Compiling: $(subst $(MROOT)/,,$@) 71 | @$(CXX) $(CFLAGS) -c -o $@ $< 72 | 73 | ## Linking rules (standard/profile/debug/release) 74 | $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static: 75 | @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" 76 | @$(CXX) $^ $(LFLAGS) -o $@ 77 | 78 | ## Library rules (standard/profile/debug/release) 79 | lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a: 80 | @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )" 81 | @$(AR) -rcsv $@ $^ 82 | 83 | ## Library Soft Link rule: 84 | libs libp libd libr: 85 | @echo "Making Soft Link: $^ -> lib$(LIB).a" 86 | @ln -sf $^ lib$(LIB).a 87 | 88 | ## Clean rule 89 | allclean: clean 90 | 91 | @rm -f ../simp/*.o ../simp/*.or ../simp/*.od ../core/*.o ../core/*.or ../core/*.od 92 | clean: 93 | rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \ 94 | $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk 95 | 96 | ## Make dependencies 97 | depend.mk: $(CSRCS) $(CHDRS) 98 | @echo Making dependencies 99 | @$(CXX) $(CFLAGS) -I$(MROOT) \ 100 | $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk 101 | @for dir in $(DEPDIR); do \ 102 | if [ -r $(MROOT)/$${dir}/depend.mk ]; then \ 103 | echo Depends on: $${dir}; \ 104 | cat $(MROOT)/$${dir}/depend.mk >> depend.mk; \ 105 | fi; \ 106 | done 107 | 108 | -include $(MROOT)/mtl/config.mk 109 | -include depend.mk 110 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/ClausesBuffer.cc: -------------------------------------------------------------------------------- 1 | /**********************************************************************************[ClausesBuffer.cc] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | /* ClausesBuffer 51 | * 52 | * This class is responsible for exchanging clauses between threads. 53 | * It is based on a fixed-length FIFO array of literals. 54 | * If the FIFO is full, then old clauses are removed (even if it was not yet sent to all threads) 55 | * 56 | * a clause " l1 l2 l3" is pushed in the FIFO with the following 6 unsigned integers 57 | * 3 nseen origin l1 l2 l3 58 | * + 3 is the size of the pushed clause 59 | * + nseen is the number of thread which imported this clause (initialized with nthreads-1) 60 | * (when set to 0, the clause is removed from the fifo) 61 | * + origin is the thread id of the thread which added this clause to the fifo 62 | * + l1 l2 l3 are the literals of the clause 63 | * 64 | * ********************************************************************************************** 65 | * **CAREFUL** This class is not thread-safe. In glucose-syrup, the SharedCompanion is 66 | * responsible for ensuring atomicity of main functions 67 | * ********************************************************************************************** 68 | * 69 | * */ 70 | 71 | #include "parallel/ClausesBuffer.h" 72 | 73 | //================================================================================================= 74 | 75 | using namespace Glucose; 76 | 77 | extern BoolOption opt_whenFullRemoveOlder; 78 | extern IntOption opt_fifoSizeByCore; 79 | 80 | // index : size clause 81 | // index + 1 : nbSeen 82 | // index + 2 : threadId 83 | // index + 3 : .. index + 3 + size : Lit of clause 84 | ClausesBuffer::ClausesBuffer(int _nbThreads, unsigned int _maxsize) : first(0), last(_maxsize-1), 85 | maxsize(_maxsize), queuesize(0), 86 | removedClauses(0), 87 | forcedRemovedClauses(0), nbThreads(_nbThreads), 88 | whenFullRemoveOlder(opt_whenFullRemoveOlder), fifoSizeByCore(opt_fifoSizeByCore) { 89 | lastOfThread.growTo(_nbThreads); 90 | for(int i=0;i= maxsize) 120 | return i - maxsize; 121 | return i; 122 | } 123 | 124 | void ClausesBuffer::removeLastClause() { 125 | assert(queuesize > 0); 126 | do { 127 | unsigned int size = (unsigned int) elems[nextIndex(last)]; 128 | unsigned int nextlast = addIndex(last, size+headerSize); 129 | 130 | for(int i=0;i 0); 139 | queuesize --; 140 | } 141 | removedClauses ++; 142 | assert(last >= 0); 143 | assert(last < maxsize); 144 | assert(last == nextlast); 145 | } while (queuesize > 0 && (elems[addIndex(last,2)] == 0)); 146 | 147 | } 148 | 149 | 150 | // Pushes a single uint to the fifo 151 | inline void ClausesBuffer::noCheckPush(uint32_t x) { 152 | elems[first] = x; 153 | first = nextIndex(first); 154 | } 155 | 156 | // Pops a single uint from the fifo 157 | inline uint32_t ClausesBuffer::noCheckPop(uint32_t & index) { 158 | index = nextIndex(index); 159 | uint32_t ret = elems[index]; 160 | return ret; 161 | } 162 | 163 | 164 | 165 | // Return true if the clause was succesfully added 166 | bool ClausesBuffer::pushClause(int threadId, Clause & c) { 167 | if (!whenFullRemoveOlder && (queuesize + c.size() + headerSize >= maxsize)) 168 | return false; // We need to remove some old clauses 169 | while (queuesize + c.size() + headerSize >= maxsize) { // We need to remove some old clauses 170 | forcedRemovedClauses ++; 171 | removeLastClause(); 172 | assert(queuesize > 0); 173 | } 174 | noCheckPush(c.size()); 175 | noCheckPush(nbThreads>1?nbThreads-1:1); 176 | noCheckPush(threadId); 177 | for(int i=0;i (%d, %d)\n", first, last); 182 | } 183 | 184 | bool ClausesBuffer::getClause(int threadId, int & threadOrigin, vec & resultClause, bool firstFound) { 185 | assert(lastOfThread.size() > threadId); 186 | unsigned int thislast = lastOfThread[threadId]; 187 | assert(!firstFound || thislast == last); // FIXME: Gilles has this assertion on his cluster 188 | 189 | // Early exiting 190 | if (nextIndex(thislast) == first) return false; 191 | 192 | if ( ( thislast < last && last < first) || 193 | ( first < thislast && thislast < last ) || 194 | ( last < first && first < thislast) ) { 195 | // Special case where last has moved and lastOfThread[threadId] is no more valid (is behind) 196 | thislast = last; 197 | } 198 | assert(!firstFound); 199 | // Go to next clause for this thread id 200 | if (!firstFound) { 201 | while (nextIndex(thislast) != first && elems[addIndex(thislast,3)] == ((unsigned int)threadId)) { // 3 = 2 + 1 202 | thislast = addIndex(thislast, elems[nextIndex(thislast)] + headerSize); // 203 | assert(thislast >= 0); 204 | assert(thislast < maxsize); 205 | } 206 | assert(nextIndex(thislast)==first || elems[addIndex(thislast,3)] != (unsigned int)threadId); 207 | } 208 | 209 | if (nextIndex(thislast) == first) { 210 | lastOfThread[threadId] = thislast; 211 | return false; 212 | } 213 | assert(elems[addIndex(thislast,3)] != ((unsigned int) threadId)); 214 | unsigned int previouslast = thislast; 215 | bool removeAfter = false; 216 | int csize = noCheckPop(thislast); 217 | removeAfter = (--elems[addIndex(thislast,1)] == 0); // We are sure this is not one of our own clause 218 | thislast = nextIndex(thislast); // Skips the removeAfter fieldr 219 | threadOrigin = noCheckPop(thislast); 220 | assert(threadOrigin != threadId); 221 | resultClause.clear(); 222 | for(int i=0;i elems; 66 | unsigned int first; 67 | unsigned int last; 68 | unsigned int maxsize; 69 | unsigned int queuesize; // Number of current elements (must be < maxsize !) 70 | unsigned int removedClauses; 71 | unsigned int forcedRemovedClauses; 72 | static const int headerSize = 3; 73 | int nbThreads; 74 | bool whenFullRemoveOlder; 75 | unsigned int fifoSizeByCore; 76 | vec lastOfThread; // Last value for a thread 77 | 78 | public: 79 | ClausesBuffer(int _nbThreads, unsigned int _maxsize); 80 | ClausesBuffer(); 81 | 82 | void setNbThreads(int _nbThreads); 83 | unsigned int nextIndex(unsigned int i); 84 | unsigned int addIndex(unsigned int i, unsigned int a); 85 | void removeLastClause(); 86 | 87 | void noCheckPush(uint32_t x); 88 | uint32_t noCheckPop(unsigned int & index); 89 | 90 | // Return true if the clause was succesfully added 91 | bool pushClause(int threadId, Clause & c); 92 | bool getClause(int threadId, int & threadOrigin, vec & resultClause, bool firstFound = false); 93 | 94 | int maxSize() const {return maxsize;} 95 | uint32_t getCap(); 96 | void growTo(int size) { 97 | assert(0); // Not implemented (essentially for efficiency reasons) 98 | elems.growTo(size); 99 | first=0; maxsize=size; queuesize = 0;last = 0; 100 | for(int i=0;i 51 | 52 | #include 53 | #include 54 | 55 | 56 | #include "utils/System.h" 57 | #include "utils/ParseUtils.h" 58 | #include "utils/Options.h" 59 | #include "core/Dimacs.h" 60 | #include "core/SolverTypes.h" 61 | 62 | #include "simp/SimpSolver.h" 63 | #include "parallel/ParallelSolver.h" 64 | #include "parallel/MultiSolvers.h" 65 | 66 | using namespace Glucose; 67 | 68 | 69 | 70 | static MultiSolvers* pmsolver; 71 | 72 | // Terminate by notifying the solver and back out gracefully. This is mainly to have a test-case 73 | // for this feature of the Solver as it may take longer than an immediate call to '_exit()'. 74 | //static void SIGINT_interrupt(int signum) { pmsolver->interrupt(); } 75 | 76 | 77 | // Note that '_exit()' rather than 'exit()' has to be used. The reason is that 'exit()' calls 78 | // destructors and may cause deadlocks if a malloc/free function happens to be running (these 79 | // functions are guarded by locks for multithreaded use). 80 | static void SIGINT_exit(int signum) { 81 | printf("\n"); printf("*** INTERRUPTED ***\n"); 82 | if (pmsolver->verbosity() > 0){ 83 | pmsolver->printFinalStats(); 84 | printf("\n"); printf("*** INTERRUPTED ***\n"); } 85 | _exit(1); } 86 | 87 | 88 | //================================================================================================= 89 | // Main: 90 | 91 | 92 | int main(int argc, char** argv) 93 | { 94 | double realTimeStart = realTime(); 95 | printf("c\nc This is glucose-syrup 4.0 (glucose in many threads) -- based on MiniSAT (Many thanks to MiniSAT team)\nc\n"); 96 | try { 97 | setUsageHelp("c USAGE: %s [options] \n\n where input may be either in plain or gzipped DIMACS.\n"); 98 | // printf("This is MiniSat 2.0 beta\n"); 99 | 100 | #if defined(__linux__) 101 | fpu_control_t oldcw, newcw; 102 | _FPU_GETCW(oldcw); newcw = (oldcw & ~_FPU_EXTENDED) | _FPU_DOUBLE; _FPU_SETCW(newcw); 103 | printf("c WARNING: for repeatability, setting FPU to use double precision\n"); 104 | #endif 105 | // Extra options: 106 | // 107 | IntOption verb ("MAIN", "verb", "Verbosity level (0=silent, 1=some, 2=more).", 1, IntRange(0, 2)); 108 | BoolOption mod ("MAIN", "model", "show model.", false); 109 | IntOption vv ("MAIN", "vv", "Verbosity every vv conflicts", 10000, IntRange(1,INT32_MAX)); 110 | BoolOption pre ("MAIN", "pre", "Completely turn on/off any preprocessing.", true); 111 | 112 | IntOption cpu_lim("MAIN", "cpu-lim","Limit on CPU time allowed in seconds.\n", INT32_MAX, IntRange(0, INT32_MAX)); 113 | IntOption mem_lim("MAIN", "mem-lim","Limit on memory usage in megabytes.\n", INT32_MAX, IntRange(0, INT32_MAX)); 114 | 115 | parseOptions(argc, argv, true); 116 | 117 | MultiSolvers msolver; 118 | pmsolver = & msolver; 119 | msolver.setVerbosity(verb); 120 | msolver.setVerbEveryConflicts(vv); 121 | msolver.setShowModel(mod); 122 | 123 | double initial_time = cpuTime(); 124 | 125 | // Use signal handlers that forcibly quit until the solver will be able to respond to 126 | // interrupts: 127 | signal(SIGINT, SIGINT_exit); 128 | signal(SIGXCPU,SIGINT_exit); 129 | 130 | // Set limit on CPU-time: 131 | if (cpu_lim != INT32_MAX){ 132 | rlimit rl; 133 | getrlimit(RLIMIT_CPU, &rl); 134 | if (rl.rlim_max == RLIM_INFINITY || (rlim_t)cpu_lim < rl.rlim_max){ 135 | rl.rlim_cur = cpu_lim; 136 | if (setrlimit(RLIMIT_CPU, &rl) == -1) 137 | printf("c WARNING! Could not set resource limit: CPU-time.\n"); 138 | } } 139 | 140 | // Set limit on virtual memory: 141 | if (mem_lim != INT32_MAX){ 142 | rlim_t new_mem_lim = (rlim_t)mem_lim * 1024*1024; 143 | rlimit rl; 144 | getrlimit(RLIMIT_AS, &rl); 145 | if (rl.rlim_max == RLIM_INFINITY || new_mem_lim < rl.rlim_max){ 146 | rl.rlim_cur = new_mem_lim; 147 | if (setrlimit(RLIMIT_AS, &rl) == -1) 148 | printf("c WARNING! Could not set resource limit: Virtual memory.\n"); 149 | } } 150 | 151 | if (argc == 1) 152 | printf("c Reading from standard input... Use '--help' for help.\n"); 153 | 154 | gzFile in = (argc == 1) ? gzdopen(0, "rb") : gzopen(argv[1], "rb"); 155 | if (in == NULL) 156 | printf("c ERROR! Could not open file: %s\n", argc == 1 ? "" : argv[1]), exit(1); 157 | 158 | if (msolver.verbosity() > 0){ 159 | printf("c ========================================[ Problem Statistics ]===========================================\n"); 160 | printf("c | |\n"); } 161 | 162 | parse_DIMACS(in, msolver); 163 | gzclose(in); 164 | 165 | 166 | 167 | FILE* res = (argc >= 3) ? fopen(argv[argc-1], "wb") : NULL; 168 | 169 | if (msolver.verbosity() > 0){ 170 | printf("c | Number of variables: %12d |\n", msolver.nVars()); 171 | printf("c | Number of clauses: %12d |\n", msolver.nClauses()); } 172 | 173 | double parsed_time = cpuTime(); 174 | if (msolver.verbosity() > 0){ 175 | printf("c | Parse time: %12.2f s |\n", parsed_time - initial_time); 176 | printf("c | |\n"); } 177 | 178 | // Change to signal-handlers that will only notify the solver and allow it to terminate 179 | // voluntarily: 180 | //signal(SIGINT, SIGINT_interrupt); 181 | //signal(SIGXCPU,SIGINT_interrupt); 182 | 183 | 184 | int ret2 = msolver.simplify(); 185 | msolver.use_simplification = pre; 186 | if(ret2) 187 | msolver.eliminate(); 188 | if(pre) { 189 | double simplified_time = cpuTime(); 190 | if (msolver.verbosity() > 0){ 191 | printf("c | Simplification time: %12.2f s |\n", simplified_time - parsed_time); 192 | printf("c | |\n"); } 193 | } 194 | 195 | if (!ret2 || !msolver.okay()){ 196 | //if (S.certifiedOutput != NULL) fprintf(S.certifiedOutput, "0\n"), fclose(S.certifiedOutput); 197 | if (res != NULL) fprintf(res, "UNSAT\n"), fclose(res); 198 | if (msolver.verbosity() > 0){ 199 | printf("c =========================================================================================================\n"); 200 | printf("Solved by unit propagation\n"); 201 | printf("c real time : %g s\n", realTime() - realTimeStart); 202 | printf("c cpu time : %g s\n", cpuTime()); 203 | printf("\n"); } 204 | printf("s UNSATISFIABLE\n"); 205 | exit(20); 206 | } 207 | 208 | // vec dummy; 209 | lbool ret = msolver.solve(); 210 | 211 | 212 | printf("c\n"); 213 | printf("c real time : %g s\n", realTime() - realTimeStart); 214 | printf("c cpu time : %g s\n", cpuTime()); 215 | if (msolver.verbosity() > 0){ 216 | msolver.printFinalStats(); 217 | printf("\n"); } 218 | 219 | //-------------- Result is put in a external file 220 | /* I must admit I have to print the model of one thread... But which one? FIXME !! 221 | if (res != NULL){ 222 | if (ret == l_True){ 223 | fprintf(res, "SAT\n"); 224 | for (int i = 0; i < S.nVars(); i++) 225 | if (S.model[i] != l_Undef) 226 | fprintf(res, "%s%s%d", (i==0)?"":" ", (S.model[i]==l_True)?"":"-", i+1); 227 | fprintf(res, " 0\n"); 228 | }else if (ret == l_False) 229 | fprintf(res, "UNSAT\n"); 230 | else 231 | fprintf(res, "INDET\n"); 232 | fclose(res); 233 | 234 | //-------------- Want certified output 235 | } else { 236 | */ 237 | printf(ret == l_True ? "s SATISFIABLE\n" : ret == l_False ? "s UNSATISFIABLE\n" : "s INDETERMINATE\n"); 238 | 239 | if(msolver.getShowModel() && ret==l_True) { 240 | printf("v "); 241 | for (int i = 0; i < msolver.model.size() ; i++) { 242 | assert(msolver.model[i] != l_Undef); 243 | if (msolver.model[i] != l_Undef) 244 | printf("%s%s%d", (i==0)?"":" ", (msolver.model[i]==l_True)?"":"-", i+1); 245 | } 246 | printf(" 0\n"); 247 | } 248 | 249 | 250 | 251 | #ifdef NDEBUG 252 | exit(ret == l_True ? 10 : ret == l_False ? 20 : 0); // (faster than "return", which will invoke the destructor for 'Solver') 253 | #else 254 | return (ret == l_True ? 10 : ret == l_False ? 20 : 0); 255 | #endif 256 | } catch (OutOfMemoryException&){ 257 | printf("c ===================================================================================================\n"); 258 | printf("INDETERMINATE\n"); 259 | exit(0); 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/Makefile: -------------------------------------------------------------------------------- 1 | EXEC = glucose-syrup 2 | DEPDIR = mtl utils core simp 3 | MROOT = $(PWD)/.. 4 | include $(MROOT)/mtl/template.mk 5 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/MultiSolvers.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[MultiSolvers.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | #ifndef MultiSolvers_h 51 | #define MultiSolvers_h 52 | 53 | #include "parallel/ParallelSolver.h" 54 | 55 | namespace Glucose { 56 | class SolverConfiguration; 57 | 58 | class MultiSolvers { 59 | friend class SolverConfiguration; 60 | 61 | public: 62 | MultiSolvers(ParallelSolver *s); 63 | MultiSolvers(); 64 | ~MultiSolvers(); 65 | 66 | void printFinalStats(); 67 | 68 | void setVerbosity(int i); 69 | int verbosity(); 70 | void setVerbEveryConflicts(int i); 71 | void setShowModel(int i) {showModel = i;} 72 | int getShowModel() {return showModel;} 73 | // Problem specification: 74 | // 75 | Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode. 76 | bool addClause (const vec& ps); // Add a clause to the solver. NOTE! 'ps' may be shrunk by this method! 77 | bool addClause_( vec& ps); 78 | 79 | bool simplify (); // Removes already satisfied clauses. 80 | 81 | int nVars () const; // The current number of variables. 82 | int nClauses () const; // The current number of variables. 83 | ParallelSolver *getPrimarySolver(); 84 | 85 | void generateAllSolvers(); 86 | 87 | // Solving: 88 | // 89 | lbool solve (); // Search without assumptions. 90 | bool eliminate(); // Perform variable elimination 91 | void adjustParameters(); 92 | void adjustNumberOfCores(); 93 | void interrupt() {} 94 | vec model; // If problem is satisfiable, this vector contains the model (if any). 95 | inline bool okay() { 96 | if(!ok) return ok; 97 | for(int i = 0;iokay()) { 99 | ok = false; 100 | return false; 101 | } 102 | } 103 | return true; 104 | 105 | } 106 | 107 | bool use_simplification; 108 | 109 | 110 | protected: 111 | friend class ParallelSolver; 112 | friend class SolverCompanion; 113 | 114 | struct Stats { 115 | uint64_t min, max, avg, std, med; 116 | Stats(uint64_t _min = 0,uint64_t _max = 0,uint64_t _avg = 0,uint64_t _std = 0,uint64_t _med = 0) : 117 | min(_min), max(_max), avg(_avg), std(_std), med(_med) {} 118 | }; 119 | 120 | void printStats(); 121 | int ok; 122 | lbool result; 123 | int maxnbthreads; // Maximal number of threads 124 | int nbthreads; // Current number of threads 125 | int nbsolvers; // Number of CDCL solvers 126 | int nbcompanions; // Number of companions 127 | int nbcompbysolver; // Number of companions by solvers 128 | bool immediateSharingGlue ; 129 | int allClonesAreBuilt; 130 | bool showModel; // show model on/off 131 | 132 | int winner; 133 | 134 | vec add_tmp; 135 | 136 | double var_decay; // Inverse of the variable activity decay factor. (default 1 / 0.95) 137 | double clause_decay; // Inverse of the clause activity decay factor. (1 / 0.999) 138 | double cla_inc; // Amount to bump next clause with. 139 | double var_inc; // Amount to bump next variable with. 140 | double random_var_freq; // The frequency with which the decision heuristic tries to choose a random variable. (default 0.02) 141 | int restart_first; // The initial restart limit. (default 100) 142 | double restart_inc; // The factor with which the restart limit is multiplied in each restart. (default 1.5) 143 | double learntsize_factor; // The intitial limit for learnt clauses is a factor of the original clauses. (default 1 / 3) 144 | double learntsize_inc; // The limit for learnt clauses is multiplied with this factor each restart. (default 1.1) 145 | bool expensive_ccmin; // Controls conflict clause minimization. (default TRUE) 146 | int polarity_mode; // Controls which polarity the decision heuristic chooses. See enum below for allowed modes. (default polarity_false) 147 | unsigned int maxmemory; 148 | unsigned int maxnbsolvers; 149 | int verb; 150 | int verbEveryConflicts; 151 | int numvar; // Number of variables 152 | int numclauses; // Number of clauses 153 | 154 | enum { polarity_true = 0, polarity_false = 1, polarity_user = 2, polarity_rnd = 3 }; 155 | 156 | //ClauseAllocator ca; 157 | SharedCompanion * sharedcomp; 158 | 159 | void informEnd(lbool res); 160 | ParallelSolver* retrieveSolver(int i); 161 | 162 | pthread_mutex_t m; // mutex for any high level sync between all threads (like reportf) 163 | pthread_mutex_t mfinished; // mutex on which main process may wait for... As soon as one process finishes it release the mutex 164 | pthread_cond_t cfinished; // condition variable that says that a thread has finished 165 | 166 | vec solvers; // set of plain solvers 167 | vec solvercompanions; // set of companion solvers 168 | vec threads; // all threads of this process 169 | vec threadIndexOfSolver; // threadIndexOfSolver[solvers[i]] is the index in threads[] of the solver i 170 | vec threadIndexOfSolverCompanion; // threadIndexOfSolverCompanion[solvercompanions[i]] is the index in threads[] of the solvercompanion i 171 | }; 172 | 173 | inline bool MultiSolvers::addClause (const vec& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); } 174 | 175 | inline void MultiSolvers::setVerbosity(int i) {verb = i;} 176 | inline void MultiSolvers::setVerbEveryConflicts(int i) {verbEveryConflicts=i;} 177 | inline int MultiSolvers::nVars () const { return numvar; } 178 | inline int MultiSolvers::nClauses () const { return numclauses; } 179 | inline int MultiSolvers::verbosity() {return verb;} 180 | inline ParallelSolver* MultiSolvers::getPrimarySolver() {return solvers[0];} 181 | 182 | 183 | } 184 | #endif 185 | 186 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/ParallelSolver.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************[ParallelSolver.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | #ifndef PARALLELSOLVER_H 51 | #define PARALLELSOLVER_H 52 | 53 | #include "core/SolverTypes.h" 54 | #include "core/Solver.h" 55 | #include "simp/SimpSolver.h" 56 | #include "parallel/SharedCompanion.h" 57 | namespace Glucose { 58 | 59 | enum ParallelStats{ 60 | nbexported=coreStatsSize, 61 | nbimported, 62 | nbexportedunit, 63 | nbimportedunit, 64 | nbimportedInPurgatory, 65 | nbImportedGoodClauses 66 | } ; 67 | #define parallelStatsSize (coreStatsSize + 6) 68 | 69 | //================================================================================================= 70 | //class MultiSolvers; 71 | //class SolverCompanion; 72 | // class MultiSolvers; 73 | 74 | class ParallelSolver : public SimpSolver { 75 | friend class MultiSolvers; 76 | friend class SolverCompanion; 77 | friend class SharedCompanion; 78 | // friend class ReasoningCompanion; 79 | // friend class SolverConfiguration; 80 | 81 | protected : 82 | // Multithread : 83 | int thn; // internal thread number 84 | //MultiSolvers* belongsto; // Not working (due to incomplete types) 85 | SharedCompanion *sharedcomp; 86 | bool coreFUIP; // true if one core is specialized for branching on all FUIP 87 | bool ImTheSolverFUIP; 88 | pthread_mutex_t *pmfinished; // mutex on which main process may wait for... As soon as one process finishes it release the mutex 89 | pthread_cond_t *pcfinished; // condition variable that says that a thread as finished 90 | 91 | public: 92 | // Constructor/Destructor: 93 | // 94 | ParallelSolver(int threadId); 95 | ParallelSolver(const ParallelSolver &s); 96 | ~ParallelSolver(); 97 | 98 | /** 99 | * Clone function 100 | */ 101 | virtual Clone* clone() const { 102 | return new ParallelSolver(*this); 103 | } 104 | 105 | int threadNumber () const; 106 | void setThreadNumber (int i); 107 | void reportProgress(); 108 | void reportProgressArrayImports(vec &totalColumns); 109 | virtual void reduceDB(); 110 | virtual lbool solve_ (bool do_simp = true, bool turn_off_simp = false); 111 | 112 | vec importedClause; // Temporary clause used to copy each imported clause 113 | unsigned int goodlimitlbd; // LBD score of the "good" clauses, locally 114 | int goodlimitsize; 115 | bool purgatory; // mode of operation 116 | bool shareAfterProbation; // Share any none glue clause only after probation (seen 2 times in conflict analysis) 117 | bool plingeling; // plingeling strategy for sharing clauses (experimental) 118 | int nbTimesSeenBeforeExport; 119 | // Stats front end 120 | // uint64_t getNbExported() { return nbexported;} 121 | // uint64_t getNbImported() { return nbimported;} 122 | // uint64_t getNbExportedUnit() {return nbexportedunit;} 123 | 124 | uint32_t firstSharing, limitSharingByGoodLBD, limitSharingByFixedLimitLBD, limitSharingByFixedLimitSize; 125 | uint32_t probationByFollowingRoads, probationByFriend; 126 | uint32_t survivorLayers; // Number of layers for a common clause to survive 127 | bool dontExportDirectReusedClauses ; // When true, directly reused clauses are not exported 128 | uint64_t nbNotExportedBecauseDirectlyReused; 129 | 130 | 131 | vec goodImportsFromThreads; // Stats of good importations from other threads 132 | 133 | virtual void parallelImportClauseDuringConflictAnalysis(Clause &c,CRef confl); 134 | virtual bool parallelImportClauses(); // true if the empty clause was received 135 | virtual void parallelImportUnaryClauses(); 136 | virtual void parallelExportUnaryClause(Lit p); 137 | virtual void parallelExportClauseDuringSearch(Clause &c); 138 | virtual bool parallelJobIsFinished(); 139 | virtual bool panicModeIsEnabled(); 140 | 141 | bool shareClause(Clause & c); // true if the clause was succesfully sent 142 | 143 | 144 | 145 | }; 146 | 147 | 148 | inline int ParallelSolver::threadNumber () const {return thn;} 149 | inline void ParallelSolver::setThreadNumber (int i) {thn = i;} 150 | } 151 | #endif /* PARALLELSOLVER_H */ 152 | 153 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/SharedCompanion.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[SharedCompanion.cc] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | #include "core/Solver.h" 51 | #include "parallel/ParallelSolver.h" 52 | #include "core/SolverTypes.h" 53 | #include "parallel/ClausesBuffer.h" 54 | #include "parallel/SharedCompanion.h" 55 | 56 | 57 | using namespace Glucose; 58 | 59 | SharedCompanion::SharedCompanion(int _nbThreads) : 60 | nbThreads(_nbThreads), 61 | bjobFinished(false), 62 | jobFinishedBy(NULL), 63 | panicMode(false), // The bug in the SAT2014 competition :) 64 | jobStatus(l_Undef), 65 | random_seed(9164825) { 66 | 67 | pthread_mutex_init(&mutexSharedClauseCompanion,NULL); // This is the shared companion lock 68 | pthread_mutex_init(&mutexSharedUnitCompanion,NULL); // This is the shared companion lock 69 | pthread_mutex_init(&mutexSharedCompanion,NULL); // This is the shared companion lock 70 | pthread_mutex_init(&mutexJobFinished,NULL); // This is the shared companion lock 71 | if (_nbThreads> 0) { 72 | setNbThreads(_nbThreads); 73 | fprintf(stdout,"c Shared companion initialized: handling of clauses of %d threads.\nc %d ints for the sharing clause buffer (not expandable) .\n", _nbThreads, clausesBuffer.maxSize()); 74 | } 75 | 76 | } 77 | 78 | void SharedCompanion::setNbThreads(int _nbThreads) { 79 | nbThreads = _nbThreads; 80 | clausesBuffer.setNbThreads(_nbThreads); 81 | } 82 | 83 | void SharedCompanion::printStats() { 84 | } 85 | 86 | // No multithread safe 87 | bool SharedCompanion::addSolver(ParallelSolver* s) { 88 | watchedSolvers.push(s); 89 | pthread_mutex_t* mu = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); 90 | pthread_mutex_init(mu,NULL); 91 | assert(s->thn == watchedSolvers.size()-1); // all solvers must have been registered in the good order 92 | nextUnit.push(0); 93 | 94 | return true; 95 | } 96 | void SharedCompanion::newVar(bool sign) { 97 | isUnary .push(l_Undef); 98 | } 99 | 100 | void SharedCompanion::addLearnt(ParallelSolver *s,Lit unary) { 101 | pthread_mutex_lock(&mutexSharedUnitCompanion); 102 | if (isUnary[var(unary)]==l_Undef) { 103 | unitLit.push(unary); 104 | isUnary[var(unary)] = sign(unary)?l_False:l_True; 105 | } 106 | pthread_mutex_unlock(&mutexSharedUnitCompanion); 107 | } 108 | 109 | Lit SharedCompanion::getUnary(ParallelSolver *s) { 110 | int sn = s->thn; 111 | Lit ret = lit_Undef; 112 | 113 | pthread_mutex_lock(&mutexSharedUnitCompanion); 114 | if (nextUnit[sn] < unitLit.size()) 115 | ret = unitLit[nextUnit[sn]++]; 116 | pthread_mutex_unlock(&mutexSharedUnitCompanion); 117 | return ret; 118 | } 119 | 120 | // Specialized functions for this companion 121 | // must be multithread safe 122 | // Add a clause to the threads-wide clause database (all clauses, through) 123 | bool SharedCompanion::addLearnt(ParallelSolver *s, Clause & c) { 124 | int sn = s->thn; // thread number of the solver 125 | bool ret = false; 126 | assert(watchedSolvers.size()>sn); 127 | 128 | pthread_mutex_lock(&mutexSharedClauseCompanion); 129 | ret = clausesBuffer.pushClause(sn, c); 130 | pthread_mutex_unlock(&mutexSharedClauseCompanion); 131 | return ret; 132 | } 133 | 134 | 135 | bool SharedCompanion::getNewClause(ParallelSolver *s, int & threadOrigin, vec& newclause) { // gets a new interesting clause for solver s 136 | int sn = s->thn; 137 | 138 | // First, let's get the clauses on the big blackboard 139 | pthread_mutex_lock(&mutexSharedClauseCompanion); 140 | bool b = clausesBuffer.getClause(sn, threadOrigin, newclause); 141 | pthread_mutex_unlock(&mutexSharedClauseCompanion); 142 | 143 | return b; 144 | } 145 | 146 | bool SharedCompanion::jobFinished() { 147 | bool ret = false; 148 | pthread_mutex_lock(&mutexJobFinished); 149 | ret = bjobFinished; 150 | pthread_mutex_unlock(&mutexJobFinished); 151 | return ret; 152 | } 153 | 154 | bool SharedCompanion::IFinished(ParallelSolver *s) { 155 | bool ret = false; 156 | pthread_mutex_lock(&mutexJobFinished); 157 | if (!bjobFinished) { 158 | ret = true; 159 | bjobFinished = true; 160 | jobFinishedBy = s; 161 | } 162 | pthread_mutex_unlock(&mutexJobFinished); 163 | return ret; 164 | } 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/SharedCompanion.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[SharedCompanion.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | /* This class is responsible for protecting (by mutex) information exchange between threads. 51 | * It also allows each solver to send / receive clause / unary clauses. 52 | * 53 | * Only one sharedCompanion is created for all the solvers 54 | */ 55 | 56 | 57 | #ifndef SharedCompanion_h 58 | #define SharedCompanion_h 59 | #include "core/SolverTypes.h" 60 | #include "parallel/ParallelSolver.h" 61 | #include "parallel/SolverCompanion.h" 62 | #include "parallel/ClausesBuffer.h" 63 | 64 | namespace Glucose { 65 | 66 | 67 | class SharedCompanion : public SolverCompanion { 68 | friend class MultiSolvers; 69 | friend class ParallelSolver; 70 | public: 71 | SharedCompanion(int nbThreads=0); 72 | void setNbThreads(int _nbThreads); // Sets the number of threads (cannot by changed once the solver is running) 73 | void newVar(bool sign); // Adds a var (used to keep track of unary variables) 74 | void printStats(); // Printing statistics of all solvers 75 | 76 | bool jobFinished(); // True if the job is over 77 | bool IFinished(ParallelSolver *s); // returns true if you are the first solver to finish 78 | bool addSolver(ParallelSolver*); // attach a solver to accompany 79 | void addLearnt(ParallelSolver *s,Lit unary); // Add a unary clause to share 80 | bool addLearnt(ParallelSolver *s, Clause & c); // Add a clause to the shared companion, as a database manager 81 | 82 | bool getNewClause(ParallelSolver *s, int &th, vec & nc); // gets a new interesting clause for solver s 83 | Lit getUnary(ParallelSolver *s); // Gets a new unary literal 84 | inline ParallelSolver* winner(){return jobFinishedBy;} // Gets the first solver that called IFinished() 85 | 86 | protected: 87 | 88 | ClausesBuffer clausesBuffer; // A big blackboard for all threads sharing non unary clauses 89 | int nbThreads; // Number of threads 90 | 91 | // A set of mutex variables 92 | pthread_mutex_t mutexSharedCompanion; // mutex for any high level sync between all threads (like reportf) 93 | pthread_mutex_t mutexSharedClauseCompanion; // mutex for reading/writing clauses on the blackboard 94 | pthread_mutex_t mutexSharedUnitCompanion; // mutex for reading/writing unit clauses on the blackboard 95 | pthread_mutex_t mutexJobFinished; 96 | 97 | bool bjobFinished; 98 | ParallelSolver *jobFinishedBy; 99 | bool panicMode; // panicMode means no more increasing space needed 100 | lbool jobStatus; // globale status of the job 101 | 102 | // Shared clauses are a queue of lits... 103 | // friend class wholearnt; 104 | vec nextUnit; // indice of next unit clause to retrieve for solver number i 105 | vec unitLit; // Set of unit literals found so far 106 | vec isUnary; // sign of the unary var (if proved, or l_Undef if not) 107 | double random_seed; 108 | 109 | // Returns a random float 0 <= x < 1. Seed must never be 0. 110 | static inline double drand(double& seed) { 111 | seed *= 1389796; 112 | int q = (int)(seed / 2147483647); 113 | seed -= (double)q * 2147483647; 114 | return seed / 2147483647; } 115 | 116 | // Returns a random integer 0 <= x < size. Seed must never be 0. 117 | static inline int irand(double& seed, int size) { 118 | return (int)(drand(seed) * size); } 119 | 120 | }; 121 | } 122 | #endif 123 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/SolverCompanion.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[SolverCompanion.cc] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | /* This class is a general companion for a solver. 51 | * The idea is to be able to have different kind of companions: 52 | * - SharedCompanion that shares clauses between threads 53 | * - NetworkCompanion (Not in this version) that sends clauses over the network 54 | * 55 | * The implementaton is trivial. Just keep track of watched Solvers by the companion. 56 | **/ 57 | 58 | #include "parallel/SolverCompanion.h" 59 | 60 | using namespace Glucose; 61 | 62 | SolverCompanion::SolverCompanion() 63 | {} 64 | 65 | SolverCompanion::~SolverCompanion() 66 | {} 67 | 68 | 69 | bool SolverCompanion::addSolver(ParallelSolver* s) { 70 | watchedSolvers.push(s); 71 | return true; 72 | } 73 | 74 | int SolverCompanion::runOnceCompanion() { 75 | int errcode = 0; 76 | for(int indexSolver = 0; indexSolver watchedSolvers; 76 | }; 77 | } 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/SolverConfiguration.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[SolverConfiguration.cc] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | #include "parallel/MultiSolvers.h" 51 | #include "core/Solver.h" 52 | //#include "parallel/ParallelSolver.h" 53 | #include "parallel/SolverConfiguration.h" 54 | 55 | using namespace Glucose; 56 | 57 | 58 | void SolverConfiguration::configure(MultiSolvers *ms, int nbsolvers) { 59 | for(int i = 1;isolvers[i]->randomizeFirstDescent = true; 61 | ms->solvers[i]->adaptStrategies = (i%2==0); // Just half of the cores are in adaptive mode 62 | ms->solvers[i]->forceUnsatOnNewDescent = (i%4==0); // Just half of adaptive cores have the unsat force 63 | } 64 | if (nbsolvers > 8) { // configuration for the second phase of the sat race 2015 65 | for(int i=0;isolvers[i]->goodlimitlbd = 5; 67 | ms->solvers[i]->goodlimitsize = 15; 68 | } 69 | } 70 | 71 | } 72 | 73 | 74 | void SolverConfiguration::configureSAT15Adapt(MultiSolvers *ms, int nbsolvers) { 75 | for(int i = 1;isolvers[i]->randomizeFirstDescent = true; 77 | ms->solvers[i]->adaptStrategies = (i%2==0); // Just half of the cores are in adaptive mode 78 | } 79 | if (nbsolvers > 8) { // configuration for the second phase of the sat race 2015 80 | for(int i=0;isolvers[i]->goodlimitlbd = 5; 82 | ms->solvers[i]->goodlimitsize = 15; 83 | } 84 | } 85 | } 86 | 87 | 88 | void SolverConfiguration::configureSAT15Default(MultiSolvers *ms, int nbsolvers) { 89 | for(int i = 1;isolvers[i]->randomizeFirstDescent = true; 91 | 92 | if (nbsolvers > 8) { // configuration for the second phase of the sat race 2015 93 | for(int i=0;isolvers[i]->goodlimitlbd = 5; 95 | ms->solvers[i]->goodlimitsize = 15; 96 | 97 | } 98 | } 99 | 100 | } 101 | 102 | void SolverConfiguration::configureSAT14(MultiSolvers *ms, int nbsolvers) { 103 | 104 | if (nbsolvers < 2 ) return; 105 | 106 | ms->solvers[1]->var_decay = 0.94; 107 | ms->solvers[1]->max_var_decay = 0.96; 108 | ms->solvers[1]->firstReduceDB=600; 109 | 110 | if (nbsolvers < 3 ) return; 111 | 112 | ms->solvers[2]->var_decay = 0.90; 113 | ms->solvers[2]->max_var_decay = 0.97; 114 | ms->solvers[2]->firstReduceDB=500; 115 | 116 | if (nbsolvers < 4 ) return; 117 | 118 | ms->solvers[3]->var_decay = 0.85; 119 | ms->solvers[3]->max_var_decay = 0.93; 120 | ms->solvers[3]->firstReduceDB=400; 121 | 122 | if (nbsolvers < 5 ) return; 123 | 124 | // Glucose 2.0 (+ blocked restarts) 125 | ms->solvers[4]->var_decay = 0.95; 126 | ms->solvers[4]->max_var_decay = 0.95; 127 | ms->solvers[4]->firstReduceDB=4000; 128 | ms->solvers[4]->lbdQueue.growTo(100); 129 | ms->solvers[4]->sizeLBDQueue = 100; 130 | ms->solvers[4]->K = 0.7; 131 | ms->solvers[4]->incReduceDB = 500; 132 | 133 | if (nbsolvers < 6 ) return; 134 | 135 | ms->solvers[5]->var_decay = 0.93; 136 | ms->solvers[5]->max_var_decay = 0.96; 137 | ms->solvers[5]->firstReduceDB=100; 138 | ms->solvers[5]->incReduceDB = 500; 139 | 140 | if (nbsolvers < 7 ) return; 141 | 142 | ms->solvers[6]->var_decay = 0.75; 143 | ms->solvers[6]->max_var_decay = 0.94; 144 | ms->solvers[6]->firstReduceDB=2000; 145 | 146 | if (nbsolvers < 8 ) return; 147 | 148 | ms->solvers[7]->var_decay = 0.94; 149 | ms->solvers[7]->max_var_decay = 0.96; 150 | ms->solvers[7]->firstReduceDB=800; 151 | 152 | if (nbsolvers < 9) return; 153 | 154 | // ms->solvers[8]->reduceOnSize = true; // NOT USED ANYMORE 155 | 156 | if (nbsolvers < 10 ) return; 157 | 158 | // ms->solvers[9]->reduceOnSize = true; // NOT USED ANYMORE 159 | // ms->solvers[9]->reduceOnSizeSize = 14; 160 | 161 | if (nbsolvers < 11 ) return; 162 | 163 | double noisevar_decay = 0.005; 164 | int noiseReduceDB = 50; 165 | for (int i=10;isolvers[i]-> var_decay = ms->solvers[i%8]->var_decay; 167 | ms->solvers[i]-> max_var_decay = ms->solvers[i%8]->max_var_decay; 168 | ms->solvers[i]-> firstReduceDB= ms->solvers[i%8]->firstReduceDB; 169 | ms->solvers[i]->var_decay += noisevar_decay; 170 | ms->solvers[i]->firstReduceDB+=noiseReduceDB; 171 | if ((i+1) % 8 == 0) { 172 | noisevar_decay += 0.006; 173 | noiseReduceDB += 25; 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/parallel/SolverConfiguration.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[SolverConfiguration.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | 51 | #ifndef SolverConfiguration_h 52 | #define SolverConfiguration_h 53 | 54 | 55 | 56 | namespace Glucose { 57 | 58 | class MultiSolvers; 59 | 60 | class SolverConfiguration { 61 | 62 | public : 63 | static void configure(MultiSolvers *ms, int nbsolvers); 64 | 65 | // Special configurations 66 | static void configureSAT14(MultiSolvers *ms, int nbsolvers); 67 | void configureSAT15Adapt(MultiSolvers *ms, int nbsolvers); 68 | void configureSAT15Default(MultiSolvers *ms, int nbsolvers); 69 | 70 | }; 71 | 72 | } 73 | #endif 74 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/simp/Makefile: -------------------------------------------------------------------------------- 1 | EXEC = glucose 2 | DEPDIR = mtl utils core 3 | MROOT = $(PWD)/.. 4 | 5 | include $(MROOT)/mtl/template.mk 6 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/simp/SimpSolver.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[SimpSolver.h] 2 | Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon 3 | CRIL - Univ. Artois, France 4 | LRI - Univ. Paris Sud, France (2009-2013) 5 | Labri - Univ. Bordeaux, France 6 | 7 | Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon 8 | CRIL - Univ. Artois, France 9 | Labri - Univ. Bordeaux, France 10 | 11 | Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of 12 | Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it 13 | is based on. (see below). 14 | 15 | Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel 16 | version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software 17 | without restriction, including the rights to use, copy, modify, merge, publish, distribute, 18 | sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | - The above and below copyrights notices and this permission notice shall be included in all 22 | copies or substantial portions of the Software; 23 | - The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot 24 | be used in any competitive event (sat competitions/evaluations) without the express permission of 25 | the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event 26 | using Glucose Parallel as an embedded SAT engine (single core or not). 27 | 28 | 29 | --------------- Original Minisat Copyrights 30 | 31 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 32 | Copyright (c) 2007-2010, Niklas Sorensson 33 | 34 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 35 | associated documentation files (the "Software"), to deal in the Software without restriction, 36 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 37 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all copies or 41 | substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 44 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 46 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 47 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | **************************************************************************************************/ 49 | 50 | #ifndef Glucose_SimpSolver_h 51 | #define Glucose_SimpSolver_h 52 | 53 | #include "mtl/Queue.h" 54 | #include "core/Solver.h" 55 | #include "mtl/Clone.h" 56 | 57 | namespace Glucose { 58 | 59 | //================================================================================================= 60 | 61 | 62 | class SimpSolver : public Solver { 63 | public: 64 | // Constructor/Destructor: 65 | // 66 | SimpSolver(); 67 | ~SimpSolver(); 68 | 69 | SimpSolver(const SimpSolver &s); 70 | 71 | 72 | /** 73 | * Clone function 74 | */ 75 | virtual Clone* clone() const { 76 | return new SimpSolver(*this); 77 | } 78 | 79 | 80 | // Problem specification: 81 | // 82 | virtual Var newVar (bool polarity = true, bool dvar = true); // Add a new variable with parameters specifying variable mode. 83 | bool addClause (const vec& ps); 84 | bool addEmptyClause(); // Add the empty clause to the solver. 85 | bool addClause (Lit p); // Add a unit clause to the solver. 86 | bool addClause (Lit p, Lit q); // Add a binary clause to the solver. 87 | bool addClause (Lit p, Lit q, Lit r); // Add a ternary clause to the solver. 88 | virtual bool addClause_( vec& ps); 89 | bool substitute(Var v, Lit x); // Replace all occurences of v with x (may cause a contradiction). 90 | 91 | // Variable mode: 92 | // 93 | void setFrozen (Var v, bool b); // If a variable is frozen it will not be eliminated. 94 | bool isEliminated(Var v) const; 95 | 96 | // Solving: 97 | // 98 | bool solve (const vec& assumps, bool do_simp = true, bool turn_off_simp = false); 99 | lbool solveLimited(const vec& assumps, bool do_simp = true, bool turn_off_simp = false); 100 | bool solve ( bool do_simp = true, bool turn_off_simp = false); 101 | bool solve (Lit p , bool do_simp = true, bool turn_off_simp = false); 102 | bool solve (Lit p, Lit q, bool do_simp = true, bool turn_off_simp = false); 103 | bool solve (Lit p, Lit q, Lit r, bool do_simp = true, bool turn_off_simp = false); 104 | bool eliminate (bool turn_off_elim = false); // Perform variable elimination based simplification. 105 | 106 | // Memory managment: 107 | // 108 | virtual void garbageCollect(); 109 | 110 | 111 | // Generate a (possibly simplified) DIMACS file: 112 | // 113 | #if 0 114 | void toDimacs (const char* file, const vec& assumps); 115 | void toDimacs (const char* file); 116 | void toDimacs (const char* file, Lit p); 117 | void toDimacs (const char* file, Lit p, Lit q); 118 | void toDimacs (const char* file, Lit p, Lit q, Lit r); 119 | #endif 120 | 121 | // Mode of operation: 122 | // 123 | int parsing; 124 | int grow; // Allow a variable elimination step to grow by a number of clauses (default to zero). 125 | int clause_lim; // Variables are not eliminated if it produces a resolvent with a length above this limit. 126 | // -1 means no limit. 127 | int subsumption_lim; // Do not check if subsumption against a clause larger than this. -1 means no limit. 128 | double simp_garbage_frac; // A different limit for when to issue a GC during simplification (Also see 'garbage_frac'). 129 | 130 | bool use_asymm; // Shrink clauses by asymmetric branching. 131 | bool use_rcheck; // Check if a clause is already implied. Prett costly, and subsumes subsumptions :) 132 | bool use_elim; // Perform variable elimination. 133 | // Statistics: 134 | // 135 | int merges; 136 | int asymm_lits; 137 | int eliminated_vars; 138 | bool use_simplification; 139 | 140 | protected: 141 | 142 | // Helper structures: 143 | // 144 | struct ElimLt { 145 | const vec& n_occ; 146 | explicit ElimLt(const vec& no) : n_occ(no) {} 147 | 148 | // TODO: are 64-bit operations here noticably bad on 32-bit platforms? Could use a saturating 149 | // 32-bit implementation instead then, but this will have to do for now. 150 | uint64_t cost (Var x) const { return (uint64_t)n_occ[toInt(mkLit(x))] * (uint64_t)n_occ[toInt(~mkLit(x))]; } 151 | bool operator()(Var x, Var y) const { return cost(x) < cost(y); } 152 | 153 | // TODO: investigate this order alternative more. 154 | // bool operator()(Var x, Var y) const { 155 | // int c_x = cost(x); 156 | // int c_y = cost(y); 157 | // return c_x < c_y || c_x == c_y && x < y; } 158 | }; 159 | 160 | struct ClauseDeleted { 161 | const ClauseAllocator& ca; 162 | explicit ClauseDeleted(const ClauseAllocator& _ca) : ca(_ca) {} 163 | bool operator()(const CRef& cr) const { return ca[cr].mark() == 1; } }; 164 | 165 | // Solver state: 166 | // 167 | int elimorder; 168 | vec elimclauses; 169 | vec touched; 170 | OccLists, ClauseDeleted> 171 | occurs; 172 | vec n_occ; 173 | Heap elim_heap; 174 | Queue subsumption_queue; 175 | vec frozen; 176 | vec eliminated; 177 | int bwdsub_assigns; 178 | int n_touched; 179 | 180 | // Temporaries: 181 | // 182 | CRef bwdsub_tmpunit; 183 | 184 | // Main internal methods: 185 | // 186 | virtual lbool solve_ (bool do_simp = true, bool turn_off_simp = false); 187 | bool asymm (Var v, CRef cr); 188 | bool asymmVar (Var v); 189 | void updateElimHeap (Var v); 190 | void gatherTouchedClauses (); 191 | bool merge (const Clause& _ps, const Clause& _qs, Var v, vec& out_clause); 192 | bool merge (const Clause& _ps, const Clause& _qs, Var v, int& size); 193 | bool backwardSubsumptionCheck (bool verbose = false); 194 | bool eliminateVar (Var v); 195 | void extendModel (); 196 | 197 | void removeClause (CRef cr,bool inPurgatory=false); 198 | bool strengthenClause (CRef cr, Lit l); 199 | void cleanUpClauses (); 200 | bool implied (const vec& c); 201 | virtual void relocAll (ClauseAllocator& to); 202 | }; 203 | 204 | 205 | //================================================================================================= 206 | // Implementation of inline methods: 207 | 208 | 209 | inline bool SimpSolver::isEliminated (Var v) const { return eliminated[v]; } 210 | inline void SimpSolver::updateElimHeap(Var v) { 211 | assert(use_simplification); 212 | // if (!frozen[v] && !isEliminated(v) && value(v) == l_Undef) 213 | if (elim_heap.inHeap(v) || (!frozen[v] && !isEliminated(v) && value(v) == l_Undef)) 214 | elim_heap.update(v); } 215 | 216 | 217 | inline bool SimpSolver::addClause (const vec& ps) { ps.copyTo(add_tmp); return addClause_(add_tmp); } 218 | inline bool SimpSolver::addEmptyClause() { add_tmp.clear(); return addClause_(add_tmp); } 219 | inline bool SimpSolver::addClause (Lit p) { add_tmp.clear(); add_tmp.push(p); return addClause_(add_tmp); } 220 | inline bool SimpSolver::addClause (Lit p, Lit q) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); return addClause_(add_tmp); } 221 | inline bool SimpSolver::addClause (Lit p, Lit q, Lit r) { add_tmp.clear(); add_tmp.push(p); add_tmp.push(q); add_tmp.push(r); return addClause_(add_tmp); } 222 | inline void SimpSolver::setFrozen (Var v, bool b) { frozen[v] = (char)b; if (use_simplification && !b) { updateElimHeap(v); } } 223 | 224 | inline bool SimpSolver::solve ( bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); return solve_(do_simp, turn_off_simp) == l_True; } 225 | inline bool SimpSolver::solve (Lit p , bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); return solve_(do_simp, turn_off_simp) == l_True; } 226 | inline bool SimpSolver::solve (Lit p, Lit q, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); return solve_(do_simp, turn_off_simp) == l_True; } 227 | inline bool SimpSolver::solve (Lit p, Lit q, Lit r, bool do_simp, bool turn_off_simp) { budgetOff(); assumptions.clear(); assumptions.push(p); assumptions.push(q); assumptions.push(r); return solve_(do_simp, turn_off_simp) == l_True; } 228 | inline bool SimpSolver::solve (const vec& assumps, bool do_simp, bool turn_off_simp){ 229 | budgetOff(); assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp) == l_True; } 230 | 231 | inline lbool SimpSolver::solveLimited (const vec& assumps, bool do_simp, bool turn_off_simp){ 232 | assumps.copyTo(assumptions); return solve_(do_simp, turn_off_simp); } 233 | 234 | //================================================================================================= 235 | } 236 | 237 | #endif 238 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/utils/Makefile: -------------------------------------------------------------------------------- 1 | EXEC = system_test 2 | DEPDIR = mtl 3 | 4 | include $(MROOT)/mtl/template.mk 5 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/utils/Options.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************************************[Options.cc] 2 | Copyright (c) 2008-2010, Niklas Sorensson 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 5 | associated documentation files (the "Software"), to deal in the Software without restriction, 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or 11 | substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 14 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 17 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | **************************************************************************************************/ 19 | 20 | #include "mtl/Sort.h" 21 | #include "utils/Options.h" 22 | #include "utils/ParseUtils.h" 23 | 24 | using namespace Glucose; 25 | 26 | void Glucose::parseOptions(int& argc, char** argv, bool strict) 27 | { 28 | int i, j; 29 | for (i = j = 1; i < argc; i++){ 30 | const char* str = argv[i]; 31 | if (match(str, "--") && match(str, Option::getHelpPrefixString()) && match(str, "help")){ 32 | if (*str == '\0') 33 | printUsageAndExit(argc, argv); 34 | else if (match(str, "-verb")) 35 | printUsageAndExit(argc, argv, true); 36 | } else { 37 | bool parsed_ok = false; 38 | 39 | for (int k = 0; !parsed_ok && k < Option::getOptionList().size(); k++){ 40 | parsed_ok = Option::getOptionList()[k]->parse(argv[i]); 41 | 42 | // fprintf(stderr, "checking %d: %s against flag <%s> (%s)\n", i, argv[i], Option::getOptionList()[k]->name, parsed_ok ? "ok" : "skip"); 43 | } 44 | 45 | if (!parsed_ok) 46 | if (strict && match(argv[i], "-")) 47 | fprintf(stderr, "ERROR! Unknown flag \"%s\". Use '--%shelp' for help.\n", argv[i], Option::getHelpPrefixString()), exit(1); 48 | else 49 | argv[j++] = argv[i]; 50 | } 51 | } 52 | 53 | argc -= (i - j); 54 | } 55 | 56 | 57 | void Glucose::setUsageHelp (const char* str){ Option::getUsageString() = str; } 58 | void Glucose::setHelpPrefixStr (const char* str){ Option::getHelpPrefixString() = str; } 59 | void Glucose::printUsageAndExit (int argc, char** argv, bool verbose) 60 | { 61 | const char* usage = Option::getUsageString(); 62 | if (usage != NULL) 63 | fprintf(stderr, usage, argv[0]); 64 | 65 | sort(Option::getOptionList(), Option::OptionLt()); 66 | 67 | const char* prev_cat = NULL; 68 | const char* prev_type = NULL; 69 | 70 | for (int i = 0; i < Option::getOptionList().size(); i++){ 71 | const char* cat = Option::getOptionList()[i]->category; 72 | const char* type = Option::getOptionList()[i]->type_name; 73 | 74 | if (cat != prev_cat) 75 | fprintf(stderr, "\n%s OPTIONS:\n\n", cat); 76 | else if (type != prev_type) 77 | fprintf(stderr, "\n"); 78 | 79 | Option::getOptionList()[i]->help(verbose); 80 | 81 | prev_cat = Option::getOptionList()[i]->category; 82 | prev_type = Option::getOptionList()[i]->type_name; 83 | } 84 | 85 | fprintf(stderr, "\nHELP OPTIONS:\n\n"); 86 | fprintf(stderr, " --%shelp Print help message.\n", Option::getHelpPrefixString()); 87 | fprintf(stderr, " --%shelp-verb Print verbose help message.\n", Option::getHelpPrefixString()); 88 | fprintf(stderr, "\n"); 89 | exit(0); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/utils/ParseUtils.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************[ParseUtils.h] 2 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_ParseUtils_h 22 | #define Glucose_ParseUtils_h 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | namespace Glucose { 31 | 32 | //------------------------------------------------------------------------------------------------- 33 | // A simple buffered character stream class: 34 | 35 | static const int buffer_size = 1048576; 36 | 37 | 38 | class StreamBuffer { 39 | gzFile in; 40 | unsigned char buf[buffer_size]; 41 | int pos; 42 | int size; 43 | 44 | void assureLookahead() { 45 | if (pos >= size) { 46 | pos = 0; 47 | size = gzread(in, buf, sizeof(buf)); } } 48 | 49 | public: 50 | explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); } 51 | 52 | int operator * () const { return (pos >= size) ? EOF : buf[pos]; } 53 | void operator ++ () { pos++; assureLookahead(); } 54 | int position () const { return pos; } 55 | }; 56 | 57 | 58 | //------------------------------------------------------------------------------------------------- 59 | // End-of-file detection functions for StreamBuffer and char*: 60 | 61 | 62 | static inline bool isEof(StreamBuffer& in) { return *in == EOF; } 63 | static inline bool isEof(const char* in) { return *in == '\0'; } 64 | 65 | //------------------------------------------------------------------------------------------------- 66 | // Generic parse functions parametrized over the input-stream type. 67 | 68 | 69 | template 70 | static void skipWhitespace(B& in) { 71 | while ((*in >= 9 && *in <= 13) || *in == 32) 72 | ++in; } 73 | 74 | 75 | template 76 | static void skipLine(B& in) { 77 | for (;;){ 78 | if (isEof(in)) return; 79 | if (*in == '\n') { ++in; return; } 80 | ++in; } } 81 | 82 | template 83 | static double parseDouble(B& in) { // only in the form X.XXXXXe-XX 84 | bool neg= false; 85 | double accu = 0.0; 86 | double currentExponent = 1; 87 | int exponent; 88 | 89 | skipWhitespace(in); 90 | if(*in == EOF) return 0; 91 | if (*in == '-') neg = true, ++in; 92 | else if (*in == '+') ++in; 93 | if (*in < '1' || *in > '9') printf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3); 94 | accu = (double)(*in - '0'); 95 | ++in; 96 | if (*in != '.') printf("PARSE ERROR! Unexpected char: %c\n", *in),exit(3); 97 | ++in; // skip dot 98 | currentExponent = 0.1; 99 | while (*in >= '0' && *in <= '9') 100 | accu = accu + currentExponent * ((double)(*in - '0')), 101 | currentExponent /= 10, 102 | ++in; 103 | if (*in != 'e') printf("PARSE ERROR! Unexpected char: %c\n", *in),exit(3); 104 | ++in; // skip dot 105 | exponent = parseInt(in); // read exponent 106 | accu *= pow(10,exponent); 107 | return neg ? -accu:accu; 108 | } 109 | 110 | 111 | template 112 | static int parseInt(B& in) { 113 | int val = 0; 114 | bool neg = false; 115 | skipWhitespace(in); 116 | if (*in == '-') neg = true, ++in; 117 | else if (*in == '+') ++in; 118 | if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3); 119 | while (*in >= '0' && *in <= '9') 120 | val = val*10 + (*in - '0'), 121 | ++in; 122 | return neg ? -val : val; } 123 | 124 | 125 | // String matching: in case of a match the input iterator will be advanced the corresponding 126 | // number of characters. 127 | template 128 | static bool match(B& in, const char* str) { 129 | int i; 130 | for (i = 0; str[i] != '\0'; i++) 131 | if (in[i] != str[i]) 132 | return false; 133 | 134 | in += i; 135 | 136 | return true; 137 | } 138 | 139 | // String matching: consumes characters eagerly, but does not require random access iterator. 140 | template 141 | static bool eagerMatch(B& in, const char* str) { 142 | for (; *str != '\0'; ++str, ++in) 143 | if (*str != *in) 144 | return false; 145 | return true; } 146 | 147 | 148 | //================================================================================================= 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/utils/System.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[System.cc] 2 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #include "utils/System.h" 22 | 23 | #if defined(__linux__) 24 | 25 | #include 26 | #include 27 | 28 | using namespace Glucose; 29 | 30 | // TODO: split the memory reading functions into two: one for reading high-watermark of RSS, and 31 | // one for reading the current virtual memory size. 32 | 33 | static inline int memReadStat(int field) 34 | { 35 | char name[256]; 36 | pid_t pid = getpid(); 37 | int value; 38 | 39 | sprintf(name, "/proc/%d/statm", pid); 40 | FILE* in = fopen(name, "rb"); 41 | if (in == NULL) return 0; 42 | 43 | for (; field >= 0; field--) 44 | if (fscanf(in, "%d", &value) != 1) 45 | printf("ERROR! Failed to parse memory statistics from \"/proc\".\n"), exit(1); 46 | fclose(in); 47 | return value; 48 | } 49 | 50 | 51 | static inline int memReadPeak(void) 52 | { 53 | char name[256]; 54 | pid_t pid = getpid(); 55 | 56 | sprintf(name, "/proc/%d/status", pid); 57 | FILE* in = fopen(name, "rb"); 58 | if (in == NULL) return 0; 59 | 60 | // Find the correct line, beginning with "VmPeak:": 61 | int peak_kb = 0; 62 | while (!feof(in) && fscanf(in, "VmPeak: %d kB", &peak_kb) != 1) 63 | while (!feof(in) && fgetc(in) != '\n') 64 | ; 65 | fclose(in); 66 | 67 | return peak_kb; 68 | } 69 | 70 | double Glucose::memUsed() { return (double)memReadStat(0) * (double)getpagesize() / (1024*1024); } 71 | double Glucose::memUsedPeak() { 72 | double peak = memReadPeak() / 1024; 73 | return peak == 0 ? memUsed() : peak; } 74 | 75 | #elif defined(__FreeBSD__) 76 | 77 | double Glucose::memUsed(void) { 78 | struct rusage ru; 79 | getrusage(RUSAGE_SELF, &ru); 80 | return (double)ru.ru_maxrss / 1024; } 81 | double MiniSat::memUsedPeak(void) { return memUsed(); } 82 | 83 | 84 | #elif defined(__APPLE__) 85 | #include 86 | 87 | double Glucose::memUsed(void) { 88 | malloc_statistics_t t; 89 | malloc_zone_statistics(NULL, &t); 90 | return (double)t.max_size_in_use / (1024*1024); } 91 | 92 | #else 93 | double Glucose::memUsed() { 94 | return 0; } 95 | #endif 96 | -------------------------------------------------------------------------------- /lib/glucose-syrup-4.1/utils/System.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************************[System.h] 2 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 3 | Copyright (c) 2007-2010, Niklas Sorensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Glucose_System_h 22 | #define Glucose_System_h 23 | 24 | #if defined(__linux__) 25 | #include 26 | #endif 27 | 28 | #include "mtl/IntTypes.h" 29 | 30 | //------------------------------------------------------------------------------------------------- 31 | 32 | namespace Glucose { 33 | 34 | static inline double cpuTime(void); // CPU-time in seconds. 35 | static inline double realTime(void); 36 | extern double memUsed(); // Memory in mega bytes (returns 0 for unsupported architectures). 37 | extern double memUsedPeak(); // Peak-memory in mega bytes (returns 0 for unsupported architectures). 38 | 39 | } 40 | 41 | //------------------------------------------------------------------------------------------------- 42 | // Implementation of inline functions: 43 | 44 | #if defined(_MSC_VER) || defined(__MINGW32__) 45 | #include 46 | 47 | static inline double Glucose::cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; } 48 | 49 | #else 50 | #include 51 | #include 52 | #include 53 | 54 | static inline double Glucose::cpuTime(void) { 55 | struct rusage ru; 56 | getrusage(RUSAGE_SELF, &ru); 57 | return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; } 58 | 59 | #endif 60 | 61 | // Laurent: I know that this will not compile directly under Windows... sorry for that 62 | static inline double Glucose::realTime() { 63 | struct timeval tv; 64 | gettimeofday(&tv, NULL); 65 | return (double)tv.tv_sec + (double) tv.tv_usec / 1000000; } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /lib/minisat-c-bindings/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | config.mk 4 | lib*.so* 5 | lib*.a 6 | -------------------------------------------------------------------------------- /lib/minisat-c-bindings/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: lr ld lp lsh config all 2 | all: lr lsh 3 | static: lr 4 | 5 | ## Load Previous Configuration #################################################################### 6 | 7 | -include config.mk 8 | 9 | ## Configurable options ########################################################################### 10 | 11 | # Directory to store object files, libraries, executables, and dependencies: 12 | BUILD_DIR ?= build 13 | 14 | # Include debug-symbols in release builds 15 | MBINDC_RELSYM ?= -g 16 | 17 | # Sets of compile flags for different build types 18 | MBINDC_REL ?= -O3 -D NDEBUG 19 | MBINDC_DEB ?= -O0 -D DEBUG 20 | MBINDC_PRF ?= -O3 -D NDEBUG 21 | MBINDC_FPIC ?= -fpic 22 | 23 | # Dependencies 24 | MINISAT_INCLUDE?= 25 | MINISAT_LIB ?=-lminisat 26 | 27 | # GNU Standard Install Prefix 28 | prefix ?= /usr/local 29 | 30 | ## Write Configuration ########################################################################### 31 | 32 | config: 33 | @( echo 'BUILD_DIR?=$(BUILD_DIR)' ; \ 34 | echo 'MBINDC_RELSYM?=$(MBINDC_RELSYM)' ; \ 35 | echo 'MBINDC_REL?=$(MBINDC_REL)' ; \ 36 | echo 'MBINDC_DEB?=$(MBINDC_DEB)' ; \ 37 | echo 'MBINDC_PRF?=$(MBINDC_PRF)' ; \ 38 | echo 'MBINDC_FPIC?=$(MBINDC_FPIC)' ; \ 39 | echo 'MINISAT_INCLUDE?=$(MINISAT_INCLUDE)'; \ 40 | echo 'MINISAT_LIB?=$(MINISAT_LIB)' ; \ 41 | echo 'prefix?=$(prefix)' ) > config.mk 42 | 43 | ## Configurable options end ####################################################################### 44 | 45 | INSTALL ?= install 46 | 47 | # GNU Standard Install Variables 48 | exec_prefix ?= $(prefix) 49 | includedir ?= $(prefix)/include 50 | bindir ?= $(exec_prefix)/bin 51 | libdir ?= $(exec_prefix)/lib 52 | datarootdir ?= $(prefix)/share 53 | mandir ?= $(datarootdir)/man 54 | 55 | # Target file names 56 | MBINDC_SLIB = libminisat-c.a# Name of MiniSat C-bindings static library. 57 | MBINDC_DLIB = libminisat-c.so# Name of MiniSat C-bindings shared library. 58 | 59 | # Shared Library Version 60 | SOMAJOR=1 61 | SOMINOR=0 62 | SORELEASE=.0 63 | 64 | MBINDC_CXXFLAGS = -I. -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -Wall -Wno-parentheses -Wextra $(MINISAT_INCLUDE) 65 | MBINDC_LDFLAGS = -Wall -lz $(MINISAT_LIB) 66 | 67 | ifeq ($(VERB),) 68 | ECHO=@ 69 | VERB=@ 70 | else 71 | ECHO=# 72 | VERB= 73 | endif 74 | 75 | SRCS = $(wildcard *.cc) 76 | HDRS = $(wildcard *.h) 77 | OBJS = $(SRCS:.cc=.o) 78 | 79 | lr: $(BUILD_DIR)/release/lib/$(MBINDC_SLIB) 80 | ld: $(BUILD_DIR)/debug/lib/$(MBINDC_SLIB) 81 | lp: $(BUILD_DIR)/profile/lib/$(MBINDC_SLIB) 82 | lsh: $(BUILD_DIR)/dynamic/lib/$(MBINDC_DLIB).$(SOMAJOR).$(SOMINOR)$(SORELEASE) 83 | 84 | ## Build-type Compile-flags: 85 | $(BUILD_DIR)/release/%.o: MBINDC_CXXFLAGS +=$(MBINDC_REL) $(MBINDC_RELSYM) 86 | $(BUILD_DIR)/debug/%.o: MBINDC_CXXFLAGS +=$(MBINDC_DEB) -g 87 | $(BUILD_DIR)/profile/%.o: MBINDC_CXXFLAGS +=$(MBINDC_PRF) -pg 88 | $(BUILD_DIR)/dynamic/%.o: MBINDC_CXXFLAGS +=$(MBINDC_REL) $(MBINDC_FPIC) 89 | 90 | ## Library dependencies 91 | $(BUILD_DIR)/release/lib/$(MBINDC_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/release/$(o)) 92 | $(BUILD_DIR)/debug/lib/$(MBINDC_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/debug/$(o)) 93 | $(BUILD_DIR)/profile/lib/$(MBINDC_SLIB): $(foreach o,$(OBJS),$(BUILD_DIR)/profile/$(o)) 94 | $(BUILD_DIR)/dynamic/lib/$(MBINDC_DLIB).$(SOMAJOR).$(SOMINOR)$(SORELEASE): $(foreach o,$(OBJS),$(BUILD_DIR)/dynamic/$(o)) 95 | 96 | ## Compile rules (these should be unified, buit I have not yet found a way which works in GNU Make) 97 | $(BUILD_DIR)/release/%.o: %.cc 98 | $(ECHO) echo Compiling: $@ 99 | $(VERB) mkdir -p $(dir $@) $(dir $(BUILD_DIR)/dep/$*.d) 100 | $(VERB) $(CXX) $(MBINDC_CXXFLAGS) $(CXXFLAGS) -c -o $@ $< -MMD -MF $(BUILD_DIR)/dep/$*.d 101 | 102 | $(BUILD_DIR)/profile/%.o: %.cc 103 | $(ECHO) echo Compiling: $@ 104 | $(VERB) mkdir -p $(dir $@) $(dir $(BUILD_DIR)/dep/$*.d) 105 | $(VERB) $(CXX) $(MBINDC_CXXFLAGS) $(CXXFLAGS) -c -o $@ $< -MMD -MF $(BUILD_DIR)/dep/$*.d 106 | 107 | $(BUILD_DIR)/debug/%.o: %.cc 108 | $(ECHO) echo Compiling: $@ 109 | $(VERB) mkdir -p $(dir $@) $(dir $(BUILD_DIR)/dep/$*.d) 110 | $(VERB) $(CXX) $(MBINDC_CXXFLAGS) $(CXXFLAGS) -c -o $@ $< -MMD -MF $(BUILD_DIR)/dep/$*.d 111 | 112 | $(BUILD_DIR)/dynamic/%.o: %.cc 113 | $(ECHO) echo Compiling: $@ 114 | $(VERB) mkdir -p $(dir $@) $(dir $(BUILD_DIR)/dep/$*.d) 115 | $(VERB) $(CXX) $(MBINDC_CXXFLAGS) $(CXXFLAGS) -c -o $@ $< -MMD -MF $(BUILD_DIR)/dep/$*.d 116 | 117 | ## Static Library rule 118 | %/lib/$(MBINDC_SLIB): 119 | $(ECHO) echo Linking Static Library: $@ 120 | $(VERB) mkdir -p $(dir $@) 121 | $(VERB) $(AR) -rcs $@ $^ 122 | 123 | ## Shared Library rule 124 | $(BUILD_DIR)/dynamic/lib/$(MBINDC_DLIB).$(SOMAJOR).$(SOMINOR)$(SORELEASE): 125 | $(ECHO) echo Linking Shared Library: $@ 126 | $(VERB) mkdir -p $(dir $@) 127 | $(VERB) $(CXX) -o $@ -shared -Wl,-soname,$(MBINDC_DLIB).$(SOMAJOR) $^ $(MBINDC_LDFLAGS) 128 | 129 | install: install-headers install-lib install-lib-static 130 | install-static: install-headers install-lib-static 131 | 132 | install-headers: 133 | # Create directories 134 | $(INSTALL) -d $(DESTDIR)$(includedir)/mcl 135 | # Install headers 136 | for h in $(HDRS) ; do \ 137 | $(INSTALL) -m 644 $$h $(DESTDIR)$(includedir)/$$h ; \ 138 | done 139 | 140 | install-lib: $(BUILD_DIR)/dynamic/lib/$(MBINDC_DLIB).$(SOMAJOR).$(SOMINOR)$(SORELEASE) 141 | $(INSTALL) -d $(DESTDIR)$(libdir) 142 | $(INSTALL) -m 644 $(BUILD_DIR)/dynamic/lib/$(MBINDC_DLIB).$(SOMAJOR).$(SOMINOR)$(SORELEASE) $(DESTDIR)$(libdir) 143 | ln -sf $(MBINDC_DLIB).$(SOMAJOR).$(SOMINOR)$(SORELEASE) $(DESTDIR)$(libdir)/$(MBINDC_DLIB).$(SOMAJOR) 144 | ln -sf $(MBINDC_DLIB).$(SOMAJOR) $(DESTDIR)$(libdir)/$(MBINDC_DLIB) 145 | 146 | install-lib-static: $(BUILD_DIR)/release/lib/$(MBINDC_SLIB) 147 | $(INSTALL) -d $(DESTDIR)$(libdir) 148 | $(INSTALL) -m 644 $(BUILD_DIR)/release/lib/$(MBINDC_SLIB) $(DESTDIR)$(libdir) 149 | 150 | ## Include generated dependencies 151 | ## NOTE: dependencies are assumed to be the same in all build modes at the moment! 152 | -include $(foreach s, $(SRCS:.cc=.d), $(BUILD_DIR)/dep/$s) 153 | -------------------------------------------------------------------------------- /lib/minisat-c-bindings/README: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Quick Install 3 | 4 | - Install MiniSat. Below the location of MiniSat headers and library 5 | files is referred to as $MINC and $MLIB respectively. If installed 6 | in a system-wide default location these locations are not necessary 7 | to specify by the user, and the configuration step becomes simpler. 8 | 9 | - Configure the library dependencies: 10 | 11 | [ the exact details here may be simplified in the future ] 12 | 13 | > make config MINISAT_INCLUDE=-I$MINC 14 | > make config MINISAT_LIB="-L$MLIB -lminisat" 15 | 16 | - Decide where to install the files . The simplest approach is to use 17 | GNU standard locations and just set a "prefix" for the root install 18 | directory (reffered to as $PREFIX below). More control can be 19 | achieved by overriding other of the GNU standard install locations 20 | (includedir, bindir, etc). Configuring with just a prefix: 21 | 22 | > make config prefix=$PREFIX 23 | 24 | - Compiling and installing: 25 | 26 | > make install 27 | 28 | ================================================================================ 29 | Configuration 30 | 31 | - Multiple configuration steps can be joined into one call to "make 32 | config" by appending multiple variable assignments on the same line. 33 | 34 | - The configuration is stored in the file "config.mk". Look here if 35 | you want to know what the current configuration looks like. 36 | 37 | - To reset from defaults simply remove the "config.mk" file or call 38 | "make distclean". 39 | 40 | - Recompilation can be done without the configuration step. 41 | 42 | [ TODO: describe configartion possibilities for compile flags / modes ] 43 | 44 | ================================================================================ 45 | Building 46 | 47 | [ TODO: describe seperate build modes ] 48 | 49 | ================================================================================ 50 | Install 51 | 52 | [ TODO: ? ] 53 | -------------------------------------------------------------------------------- /lib/minisat-c-bindings/minisat.cc: -------------------------------------------------------------------------------- 1 | /**************************************************************************************[minisat.cc] 2 | Copyright (c) 2008-2010, Niklas Sorensson 3 | 2008, Koen Claessen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #include 22 | 23 | #ifdef USE_GLUCOSE 24 | #include "glucose-syrup-4.1/simp/SimpSolver.h" 25 | using namespace Glucose; 26 | #else 27 | #include "minisat/simp/SimpSolver.h" 28 | using namespace Minisat; 29 | #endif 30 | 31 | 32 | struct minisat_solver_t : public SimpSolver { 33 | vec clause; 34 | vec assumps; 35 | }; 36 | 37 | extern "C" { 38 | 39 | #include "minisat.h" 40 | 41 | // This implementation of lbool may or not may be an exact mirror of the C++ implementation: 42 | // 43 | extern const minisat_lbool minisat_l_True = 1; 44 | extern const minisat_lbool minisat_l_False = 0; 45 | extern const minisat_lbool minisat_l_Undef = -1; 46 | 47 | static inline minisat_lbool toC(lbool a) 48 | { 49 | return a == l_True ? minisat_l_True 50 | : a == l_False ? minisat_l_False 51 | : minisat_l_Undef; 52 | } 53 | 54 | static inline lbool fromC(minisat_lbool a) 55 | { 56 | return a == minisat_l_True ? l_True 57 | : a == minisat_l_False ? l_False 58 | : l_Undef; 59 | } 60 | 61 | 62 | // TODO: why are these here? 63 | minisat_lbool minisat_get_l_True (void){ return minisat_l_True; } 64 | minisat_lbool minisat_get_l_False (void){ return minisat_l_False; } 65 | minisat_lbool minisat_get_l_Undef (void){ return minisat_l_Undef; } 66 | 67 | // Solver C-API wrapper functions: 68 | // 69 | minisat_solver* minisat_new (void){ return new minisat_solver_t(); } 70 | void minisat_delete (minisat_solver *s){ delete s; } 71 | minisat_Var minisat_newVar (minisat_solver *s){ return s->newVar(); } 72 | minisat_Lit minisat_newLit (minisat_solver *s){ return toInt(mkLit(s->newVar())); } 73 | minisat_Lit minisat_mkLit (minisat_Var x){ return toInt(mkLit(x)); } 74 | minisat_Lit minisat_mkLit_args (minisat_Var x, int sign){ return toInt(mkLit(x,sign)); } 75 | minisat_Lit minisat_negate (minisat_Lit p){ return toInt(~toLit(p)); } 76 | minisat_Var minisat_var (minisat_Lit p){ return var(toLit(p)); } 77 | int minisat_sign (minisat_Lit p){ return sign(toLit(p)); } 78 | void minisat_addClause_begin (minisat_solver *s){ s->clause.clear(); } 79 | void minisat_addClause_addLit(minisat_solver *s, minisat_Lit p){ s->clause.push(toLit(p)); } 80 | int minisat_addClause_commit(minisat_solver *s){ return s->addClause_(s->clause); } 81 | int minisat_simplify (minisat_solver *s){ return s->simplify(); } 82 | 83 | // NOTE: Currently these run with default settings for implicitly calling preprocessing. Turn off 84 | // before if you don't need it. This may change in the future. 85 | void minisat_solve_begin (minisat_solver *s){ s->assumps.clear(); } 86 | void minisat_solve_addLit (minisat_solver *s, minisat_Lit p){ s->assumps.push(toLit(p)); } 87 | int minisat_solve_commit (minisat_solver *s){ return s->solve(s->assumps); } 88 | minisat_lbool minisat_limited_solve_commit (minisat_solver *s){ return toC(s->solveLimited(s->assumps)); } 89 | 90 | int minisat_okay (minisat_solver *s){ return s->okay(); } 91 | 92 | #ifdef USE_GLUCOSE 93 | #else 94 | void minisat_setPolarity (minisat_solver *s, minisat_Var v, minisat_lbool lb){ s->setPolarity(v, fromC(lb)); } 95 | #endif 96 | 97 | void minisat_setDecisionVar (minisat_solver *s, minisat_Var v, int b){ s->setDecisionVar(v, b); } 98 | minisat_lbool minisat_value_Var (minisat_solver *s, minisat_Var x){ return toC(s->value(x)); } 99 | minisat_lbool minisat_value_Lit (minisat_solver *s, minisat_Lit p){ return toC(s->value(toLit(p))); } 100 | minisat_lbool minisat_modelValue_Var (minisat_solver *s, minisat_Var x){ return toC(s->modelValue(x)); } 101 | minisat_lbool minisat_modelValue_Lit (minisat_solver *s, minisat_Lit p){ return toC(s->modelValue(toLit(p))); } 102 | int minisat_num_assigns (minisat_solver *s){ return s->nAssigns(); } 103 | int minisat_num_clauses (minisat_solver *s){ return s->nClauses(); } 104 | int minisat_num_learnts (minisat_solver *s){ return s->nLearnts(); } 105 | int minisat_num_vars (minisat_solver *s){ return s->nVars(); } 106 | int minisat_num_freeVars (minisat_solver *s){ return s->nFreeVars(); } 107 | int minisat_conflict_len (minisat_solver *s){ return s->conflict.size(); } 108 | minisat_Lit minisat_conflict_nthLit (minisat_solver *s, int i){ return toInt(s->conflict[i]); } 109 | void minisat_set_verbosity (minisat_solver *s, int v){ s->verbosity = v; } 110 | int minisat_get_verbosity (minisat_solver *s){ return s->verbosity; } 111 | int minisat_num_conflicts (minisat_solver *s){ return s->conflicts; } 112 | int minisat_num_decisions (minisat_solver *s){ return s->decisions; } 113 | int minisat_num_restarts (minisat_solver *s){ return s->starts; } 114 | int minisat_num_propagations(minisat_solver *s){ return s->propagations; } 115 | void minisat_set_conf_budget (minisat_solver* s, int x){ s->setConfBudget(x); } 116 | void minisat_set_prop_budget (minisat_solver* s, int x){ s->setPropBudget(x); } 117 | void minisat_no_budget (minisat_solver* s){ s->budgetOff(); } 118 | void minisat_set_rnd_init_act(minisat_solver *s, int b){ s->rnd_init_act = b != 0; } 119 | void minisat_set_random_seed (minisat_solver *s, double x){ s->random_seed = x; } 120 | 121 | // Resource constraints: 122 | void minisat_interrupt(minisat_solver* s) {s->interrupt (); } 123 | void minisat_clearInterrupt(minisat_solver* s) {s->clearInterrupt (); } 124 | 125 | // SimpSolver methods: 126 | void minisat_setFrozen (minisat_solver* s, minisat_Var v, minisat_bool b) { s->setFrozen(v, b); } 127 | minisat_bool minisat_isEliminated (minisat_solver* s, minisat_Var v) { return s->isEliminated(v); } 128 | minisat_bool minisat_eliminate (minisat_solver* s, minisat_bool turn_off_elim){ return s->eliminate(turn_off_elim); } 129 | 130 | // Convenience functions for actual c-programmers (not language interfacing people): 131 | // 132 | int minisat_solve(minisat_solver *s, int len, minisat_Lit *ps) 133 | { 134 | s->assumps.clear(); 135 | for (int i = 0; i < len; i++) 136 | s->assumps.push(toLit(ps[i])); 137 | return s->solve(s->assumps); 138 | } 139 | 140 | 141 | minisat_lbool minisat_limited_solve(minisat_solver *s, int len, minisat_Lit *ps) 142 | { 143 | s->assumps.clear(); 144 | for (int i = 0; i < len; i++) 145 | s->assumps.push(toLit(ps[i])); 146 | return toC(s->solveLimited(s->assumps)); 147 | } 148 | 149 | 150 | int minisat_addClause(minisat_solver *s, int len, minisat_Lit *ps) 151 | { 152 | s->clause.clear(); 153 | for (int i = 0; i < len; i++) 154 | s->clause.push(toLit(ps[i])); 155 | return s->addClause_(s->clause); 156 | } 157 | 158 | 159 | } 160 | -------------------------------------------------------------------------------- /lib/minisat-c-bindings/minisat.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************[minisat.h] 2 | Copyright (c) 2008-2011, Niklas Sorensson 3 | 2008, Koen Claessen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 8 | sublicense, and/or sell 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 all copies or 12 | substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 18 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | **************************************************************************************************/ 20 | 21 | #ifndef Minisat_C_Bindings_h 22 | #define Minisat_C_Bindings_h 23 | 24 | // SolverTypes: 25 | // 26 | typedef struct minisat_solver_t minisat_solver; 27 | #ifdef Minisat_Opaque 28 | #define opaque(x) struct { x f; } 29 | #else 30 | #define opaque(x) x 31 | #endif 32 | typedef opaque(int) minisat_Var; 33 | typedef opaque(int) minisat_Lit; 34 | typedef opaque(int) minisat_lbool; 35 | typedef opaque(int) minisat_bool; // Only for clarity in the declarations below (this is just a plain c-bool). 36 | #undef opaque 37 | 38 | // Constants: (can these be made inline-able?) 39 | // 40 | 41 | extern const minisat_lbool minisat_l_True; 42 | extern const minisat_lbool minisat_l_False; 43 | extern const minisat_lbool minisat_l_Undef; 44 | 45 | 46 | minisat_solver* minisat_new (void); 47 | void minisat_delete (minisat_solver* s); 48 | 49 | minisat_Var minisat_newVar (minisat_solver *s); 50 | minisat_Lit minisat_newLit (minisat_solver *s); 51 | 52 | minisat_Lit minisat_mkLit (minisat_Var x); 53 | minisat_Lit minisat_mkLit_args (minisat_Var x, int sign); 54 | minisat_Lit minisat_negate (minisat_Lit p); 55 | 56 | minisat_Var minisat_var (minisat_Lit p); 57 | minisat_bool minisat_sign (minisat_Lit p); 58 | 59 | minisat_bool minisat_addClause (minisat_solver *s, int len, minisat_Lit *ps); 60 | void minisat_addClause_begin (minisat_solver *s); 61 | void minisat_addClause_addLit(minisat_solver *s, minisat_Lit p); 62 | minisat_bool minisat_addClause_commit(minisat_solver *s); 63 | 64 | minisat_bool minisat_simplify (minisat_solver *s); 65 | 66 | minisat_bool minisat_solve (minisat_solver *s, int len, minisat_Lit *ps); 67 | minisat_lbool minisat_limited_solve (minisat_solver *s, int len, minisat_Lit *ps); 68 | void minisat_solve_begin (minisat_solver *s); 69 | void minisat_solve_addLit (minisat_solver *s, minisat_Lit p); 70 | minisat_bool minisat_solve_commit (minisat_solver *s); 71 | minisat_lbool minisat_limited_solve_commit 72 | (minisat_solver *s); 73 | 74 | minisat_bool minisat_okay (minisat_solver *s); 75 | 76 | void minisat_setPolarity (minisat_solver *s, minisat_Var v, int b); 77 | void minisat_setDecisionVar (minisat_solver *s, minisat_Var v, int b); 78 | 79 | minisat_lbool minisat_get_l_True (void); 80 | minisat_lbool minisat_get_l_False (void); 81 | minisat_lbool minisat_get_l_Undef (void); 82 | 83 | minisat_lbool minisat_value_Var (minisat_solver *s, minisat_Var x); 84 | minisat_lbool minisat_value_Lit (minisat_solver *s, minisat_Lit p); 85 | minisat_lbool minisat_modelValue_Var (minisat_solver *s, minisat_Var x); 86 | minisat_lbool minisat_modelValue_Lit (minisat_solver *s, minisat_Lit p); 87 | 88 | int minisat_num_assigns (minisat_solver *s); 89 | int minisat_num_clauses (minisat_solver *s); 90 | int minisat_num_learnts (minisat_solver *s); 91 | int minisat_num_vars (minisat_solver *s); 92 | int minisat_num_freeVars (minisat_solver *s); 93 | 94 | int minisat_conflict_len (minisat_solver *s); 95 | minisat_Lit minisat_conflict_nthLit (minisat_solver *s, int i); 96 | 97 | void minisat_set_conf_budget (minisat_solver* s, int x); 98 | void minisat_set_prop_budget (minisat_solver* s, int x); 99 | void minisat_no_budget (minisat_solver* s); 100 | 101 | // Resource constraints: 102 | void minisat_interrupt(minisat_solver* s); 103 | void minisat_clearInterrupt(minisat_solver* s); 104 | 105 | // SimpSolver methods: 106 | void minisat_setFrozen (minisat_solver* s, minisat_Var v, minisat_bool b); 107 | minisat_bool minisat_isEliminated (minisat_solver* s, minisat_Var v); 108 | minisat_bool minisat_eliminate (minisat_solver* s, minisat_bool turn_off_elim); 109 | 110 | // Setters: 111 | 112 | void minisat_set_verbosity (minisat_solver *s, int v); 113 | 114 | // Getters: 115 | 116 | int minisat_num_conflicts (minisat_solver *s); 117 | int minisat_num_decisions (minisat_solver *s); 118 | int minisat_num_restarts (minisat_solver *s); 119 | int minisat_num_propagations(minisat_solver *s); 120 | 121 | void minisat_set_rnd_init_act(minisat_solver *s, int b); 122 | void minisat_set_random_seed(minisat_solver *s, double x); 123 | 124 | /* TODO 125 | 126 | // Mode of operation: 127 | // 128 | int verbosity; 129 | double var_decay; 130 | double clause_decay; 131 | double random_var_freq; 132 | double random_seed; 133 | double restart_luby_start; // The factor with which the values of the luby sequence is multiplied to get the restart (default 100) 134 | double restart_luby_inc; // The constant that the luby sequence uses powers of (default 2) 135 | bool expensive_ccmin; // FIXME: describe. 136 | bool rnd_pol; // FIXME: describe. 137 | 138 | int restart_first; // The initial restart limit. (default 100) 139 | double restart_inc; // The factor with which the restart limit is multiplied in each restart. (default 1.5) 140 | double learntsize_factor; // The intitial limit for learnt clauses is a factor of the original clauses. (default 1 / 3) 141 | double learntsize_inc; // The limit for learnt clauses is multiplied with this factor each restart. (default 1.1) 142 | 143 | int learntsize_adjust_start_confl; 144 | double learntsize_adjust_inc; 145 | 146 | // Statistics: (read-only member variable) 147 | // 148 | uint64_t starts, decisions, rnd_decisions, propagations, conflicts; 149 | uint64_t dec_vars, clauses_literals, learnts_literals, max_literals, tot_literals; 150 | */ 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! [MiniSat](http://minisat.se) Rust interface. 2 | //! Solves a boolean satisfiability problem given in conjunctive normal form. 3 | //! 4 | //! ```rust 5 | //! extern crate minisat; 6 | //! use std::iter::once; 7 | //! fn main() { 8 | //! let mut sat = minisat::Solver::new(); 9 | //! let a = sat.new_lit(); 10 | //! let b = sat.new_lit(); 11 | //! 12 | //! // Solves ((a OR not b) AND b) 13 | //! sat.add_clause(vec![a, !b]); 14 | //! sat.add_clause(vec![b]); 15 | //! 16 | //! match sat.solve() { 17 | //! Ok(m) => { 18 | //! assert!(m.lit_value(&a)); 19 | //! assert!(m.lit_value(&b)); 20 | //! }, 21 | //! Err(()) => panic!("UNSAT"), 22 | //! } 23 | //! } 24 | //! ``` 25 | //! 26 | //! This crate compiles the MiniSat sources directly and binds through 27 | //! the [minisat-c-bindings](https://github.com/niklasso/minisat-c-bindings) interface. 28 | //! The low-level C bindings are available through the [`sys`](sys/index.html) module. 29 | 30 | #![allow(non_upper_case_globals)] 31 | #![allow(non_camel_case_types)] 32 | #![allow(non_snake_case)] 33 | 34 | /// The FFI interface to MiniSat (imported from 35 | /// [minisat-c-bindings](https://github.com/niklasso/minisat-c-bindings)). 36 | pub mod sys { 37 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 38 | } 39 | 40 | use sys::*; 41 | 42 | pub mod cnf; 43 | pub use cnf::Cnf; 44 | 45 | /// Solver object representing an instance of the boolean satisfiability problem. 46 | pub struct Solver { 47 | ptr: *mut minisat_solver_t, 48 | } 49 | 50 | /// A literal is a boolean variable or its negation. 51 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] 52 | pub struct Lit(minisat_Lit); 53 | 54 | /// A MiniSAT variable. 55 | #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] 56 | pub struct Var(minisat_Var); 57 | 58 | impl Lit { 59 | pub fn var(self) -> (Var, bool) { 60 | ( 61 | Var(unsafe { minisat_var(self.0) }), 62 | unsafe { minisat_sign(self.0) } > 0, 63 | ) 64 | } 65 | 66 | pub fn from_var_sign(var: Var, neg: bool) -> Lit { 67 | let mut l = unsafe { minisat_mkLit(var.0) }; 68 | if neg { 69 | l = unsafe { minisat_negate(l) }; 70 | } 71 | Lit(l) 72 | } 73 | } 74 | 75 | impl std::ops::Not for Lit { 76 | type Output = Lit; 77 | fn not(self) -> Lit { 78 | Lit(unsafe { minisat_negate(self.0) }) 79 | } 80 | } 81 | 82 | impl Solver { 83 | /// Create a new SAT solver instance. 84 | pub fn new() -> Self { 85 | let ptr = unsafe { minisat_new() }; 86 | 87 | // "normal solver"??? (cfr. haskell minisat-0.1.2 newSolver) 88 | unsafe { minisat_eliminate(ptr, 1_i32) }; 89 | 90 | Solver { ptr } 91 | } 92 | 93 | /// Create a fresh boolean variable. 94 | pub fn new_lit(&mut self) -> Lit { 95 | Lit(unsafe { minisat_newLit(self.ptr) }) 96 | } 97 | 98 | /// Set the default polarity of the given literal. 99 | pub fn set_polarity(&mut self, l: Lit, p: bool) { 100 | let (var, pol) = l.var(); 101 | 102 | unsafe { 103 | minisat_setPolarity(self.ptr, var.0, if p ^ pol { 0 } else { 1 }); 104 | } 105 | } 106 | 107 | /// Set whether new variables will be initialized with a small random activity. 108 | pub fn set_rnd_init_act(&mut self, b: bool) { 109 | unsafe { 110 | minisat_set_rnd_init_act(self.ptr, if b { 1 } else { 0 }); 111 | } 112 | } 113 | 114 | /// Set the solver's random seed. 115 | pub fn set_random_seed(&mut self, s: f64) { 116 | unsafe { 117 | minisat_set_random_seed(self.ptr, s); 118 | } 119 | } 120 | 121 | /// Add a clause to the SAT instance (assert the disjunction of the given literals). 122 | pub fn add_clause>(&mut self, lits: I) { 123 | unsafe { minisat_addClause_begin(self.ptr) }; 124 | for lit in lits { 125 | unsafe { 126 | minisat_addClause_addLit(self.ptr, lit.0); 127 | } 128 | } 129 | unsafe { minisat_addClause_commit(self.ptr) }; 130 | } 131 | 132 | /// Add a CNF clause to the SAT Instance. 133 | pub fn add_cnf(&mut self, cnf: Cnf) { 134 | cnf.0.into_iter().for_each(|or| self.add_clause(or)) 135 | } 136 | 137 | /// Solve the SAT instance, returning a solution (`Model`) if the 138 | /// instance is satisfiable, or returning an `Err(())` if the problem 139 | /// is unsatisfiable. 140 | pub fn solve(&mut self) -> Result { 141 | self.solve_under_assumptions(std::iter::empty()) 142 | .map_err(|_| ()) 143 | } 144 | 145 | /// Solve the SAT instance under given assumptions, returning a solution (`Model`) if the 146 | /// instance is satisfiable, or returning an `Err(())` if the problem 147 | /// is unsatisfiable. 148 | /// 149 | /// The conjunction of the given literals are temporarily added to the SAT instance, 150 | /// so the result is the same as if each literal was added as a clause, but 151 | /// the solver object can be re-used afterwards and does then not contain these assumptions. 152 | /// This interface can be used to build SAT instances incrementally. 153 | pub fn solve_under_assumptions>( 154 | &mut self, 155 | lits: I, 156 | ) -> Result { 157 | unsafe { 158 | minisat_solve_begin(self.ptr); 159 | } 160 | for lit in lits { 161 | unsafe { 162 | minisat_solve_addLit(self.ptr, lit.0); 163 | } 164 | } 165 | let sat = unsafe { minisat_solve_commit(self.ptr) } > 0; 166 | if sat { 167 | Ok(Model(self)) 168 | } else { 169 | Err(Conflict(self)) 170 | } 171 | } 172 | 173 | /// Return the number of assignments to variables made in the solver instance. 174 | pub fn num_assigns(&self) -> isize { 175 | unsafe { minisat_num_assigns(self.ptr) as isize } 176 | } 177 | 178 | /// Return the number of clauses in the solver instance. 179 | pub fn num_clauses(&self) -> isize { 180 | unsafe { minisat_num_clauses(self.ptr) as isize } 181 | } 182 | 183 | /// Return the number of learnt clauses in the solver instance. 184 | pub fn num_learnts(&self) -> isize { 185 | unsafe { minisat_num_learnts(self.ptr) as isize } 186 | } 187 | 188 | /// Return the number of variables in the solver instance. 189 | pub fn num_vars(&self) -> isize { 190 | unsafe { minisat_num_vars(self.ptr) as isize } 191 | } 192 | 193 | /// Return the number of free variables in the solver instance. 194 | pub fn num_free_vars(&self) -> isize { 195 | unsafe { minisat_num_freeVars(self.ptr) as isize } 196 | } 197 | 198 | /// Name and version of SAT solver. 199 | pub fn solver_name(&self) -> &'static str { 200 | if cfg!(feature = "glucose") { 201 | "Glucose v4.1" 202 | // https://www.labri.fr/perso/lsimon/glucose/ 203 | } else { 204 | "MiniSAT v2.1.0" 205 | // http://minisat.se/ 206 | } 207 | } 208 | } 209 | 210 | impl Default for Solver { 211 | fn default() -> Self { 212 | Self::new() 213 | } 214 | } 215 | 216 | impl Drop for Solver { 217 | fn drop(&mut self) { 218 | unsafe { 219 | minisat_delete(self.ptr); 220 | } 221 | } 222 | } 223 | 224 | use std::fmt; 225 | impl fmt::Debug for Solver { 226 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 227 | write!( 228 | f, 229 | "SAT instance ({}) {{ variables: {}, clauses: {} }}", 230 | self.solver_name(), 231 | self.num_vars(), 232 | self.num_clauses() 233 | ) 234 | } 235 | } 236 | 237 | /// A model of a satisfiable instance, i.e. assignments to variables in the problem satisfying 238 | /// the asserted constraints. 239 | pub struct Model<'a>(&'a mut Solver); 240 | 241 | impl<'a> Model<'a> { 242 | pub fn lit_value(&self, l: &Lit) -> bool { 243 | let lbool = unsafe { minisat_modelValue_Lit(self.0.ptr, l.0) }; 244 | if unsafe { minisat_get_l_True() } == lbool { 245 | true 246 | } else if unsafe { minisat_get_l_False() } == lbool { 247 | false 248 | } else { 249 | unreachable!() 250 | } 251 | } 252 | } 253 | 254 | /// A model of a satisfiable instance, i.e. assignments to variables in the problem satisfying 255 | /// the asserted constraints. 256 | pub struct Conflict<'a>(&'a mut Solver); 257 | 258 | impl<'a> Conflict<'a> { 259 | pub fn iter(&'a self) -> impl Iterator + 'a { 260 | (0..(self.len())).map(move |i| self.nth(i)) 261 | } 262 | pub fn nth(&self, idx: usize) -> Lit { 263 | Lit(unsafe { minisat_conflict_nthLit(self.0.ptr, idx as i32) }) 264 | } 265 | pub fn is_empty(&self) -> bool { 266 | self.len() == 0 267 | } 268 | pub fn len(&self) -> usize { 269 | (unsafe { minisat_conflict_len(self.0.ptr) }) as usize 270 | } 271 | } 272 | 273 | #[cfg(test)] 274 | mod tests { 275 | use super::*; 276 | use std::iter::once; 277 | 278 | #[test] 279 | fn sat() { 280 | let mut sat = Solver::new(); 281 | let a = sat.new_lit(); 282 | let b = sat.new_lit(); 283 | // sat.add_clause(&[a,b]); 284 | sat.add_clause(once(a).chain(once(b))); 285 | match sat.solve() { 286 | Ok(m) => { 287 | println!("a: {:?}", m.lit_value(&a)); 288 | println!("b: {:?}", m.lit_value(&b)); 289 | } 290 | Err(_) => panic!(), 291 | }; 292 | } 293 | 294 | #[test] 295 | fn unsat() { 296 | let mut sat = Solver::new(); 297 | let a = sat.new_lit(); 298 | let b = sat.new_lit(); 299 | // sat.add_clause(&[a]); 300 | // sat.add_clause(&[b]); 301 | // sat.add_clause(&[!b]); 302 | sat.add_clause(once(a)); 303 | sat.add_clause(once(b)); 304 | sat.add_clause(once(!b)); 305 | let sol = sat.solve(); 306 | assert!(sol.is_err()); 307 | } 308 | 309 | #[test] 310 | fn unsat2() { 311 | use std::iter::empty; 312 | let mut sat = Solver::new(); 313 | sat.add_clause(empty()); 314 | assert!(sat.solve().is_err()); 315 | } 316 | 317 | #[test] 318 | fn sat2() { 319 | let mut sat = Solver::new(); 320 | let a = sat.new_lit(); 321 | assert!(!sat.solve().is_err()); 322 | assert!(!sat.solve_under_assumptions(vec![!a]).is_err()); 323 | sat.add_clause(once(a)); 324 | assert!(!sat.solve().is_err()); 325 | assert!(sat.solve_under_assumptions(vec![!a]).is_err()); 326 | sat.add_clause(vec![!a]); 327 | assert!(sat.solve().is_err()); 328 | } 329 | 330 | #[test] 331 | fn set_polarity() { 332 | for p in [true, false] { 333 | let mut sat = Solver::new(); 334 | let a = sat.new_lit(); 335 | sat.set_polarity(a, p); 336 | let m = sat.solve().unwrap(); 337 | assert!(m.lit_value(&a) == p); 338 | } 339 | } 340 | 341 | #[test] 342 | fn cnf() { 343 | let mut sat = Solver::new(); 344 | let a = sat.new_lit(); 345 | let b = sat.new_lit(); 346 | let c = sat.new_lit(); 347 | let d = sat.new_lit(); 348 | sat.add_cnf((a & b) | (c & d)); 349 | let sol = sat.solve().unwrap(); 350 | assert!((sol.lit_value(&a) & sol.lit_value(&b)) | (sol.lit_value(&c) & sol.lit_value(&d))); 351 | } 352 | } 353 | -------------------------------------------------------------------------------- /wrapper.h: -------------------------------------------------------------------------------- 1 | #include "minisat.h" 2 | --------------------------------------------------------------------------------