├── benchTest ├── littleTest.w ├── one.cnf ├── projected.var ├── littleTest.cnf ├── test1.cnf └── bug.cnf ├── patoh ├── patoh ├── libpatoh.a ├── manual.pdf ├── test.u ├── simple.c └── README ├── patoh_mac ├── patoh ├── libpatoh.a ├── manual.pdf ├── README └── simple.c ├── .gitignore ├── certification-master.tar.gz ├── core ├── Main.hh └── ShareStructures.hh ├── manager ├── ParserProblem.hh ├── formulaManager.hh ├── greedyOccurrenceManager.hh ├── dynamicOccurrenceManager.hh ├── OptionManager.hh ├── ParserProblem.cc ├── formulaManager.cc └── greedyOccurrenceManager.cc ├── preproc ├── Preproc.hh ├── Backbone.hh ├── Backbone.cc ├── OccurrenceLitElimination.hh ├── EquivClauseSimplification.hh ├── Vivification.hh ├── Vivification.cc ├── Preproc.cc ├── Forgetting.hh └── OccurrenceLitElimination.cc ├── DAG ├── ConstantNode.hh ├── True.hh ├── False.hh ├── PCNode.hh ├── ImplicitAnd.hh ├── Root.hh ├── BinaryDeterministicOrNode.hh ├── UnaryNode.hh ├── KromFormula.hh ├── UnaryNodeCertified.hh ├── DecomposableAndNode.hh ├── DeterministicOrNode.hh ├── DecomposableAndNodeCerified.hh ├── BinaryDeterministicOrNodeCertified.hh └── RenamableHornFormula.hh ├── heuristics ├── MinCutPartitioner.hh ├── PhaseHeuristic.hh ├── MinCutPartitioner.cc └── ScoringMethod.hh ├── interfaces ├── PartitionerInterface.hh ├── VariableHeuristicInterface.hh ├── ClauseCheckProperty.hh ├── PartitionerInterface.cc ├── VariableHeuristicInterface.cc ├── OccurrenceManagerInterface.hh └── BucketManagerInterface.hh ├── utils ├── HittingSet.hh ├── InterpretationRefiner.hh ├── ResidualNotPC.cc ├── ResidualNotPC.hh ├── System.hh ├── equiv.hh ├── System.cc ├── HittingSet.cc ├── Dimacs.hh ├── RenamableHorn.hh ├── Options.cc └── ParseUtils.hh ├── hashing └── HashCnf.hh ├── mtl ├── IntTypes.hh ├── XAlloc.hh ├── Queue.hh ├── Alg.hh ├── Sort.hh ├── Alloc.hh └── Heap.hh ├── Makefile └── README.md /benchTest/littleTest.w: -------------------------------------------------------------------------------- 1 | 1 0 2 | -------------------------------------------------------------------------------- /benchTest/one.cnf: -------------------------------------------------------------------------------- 1 | p cnf 2 1 2 | 1 2 0 -------------------------------------------------------------------------------- /benchTest/projected.var: -------------------------------------------------------------------------------- 1 | 14,9,3,8,12 -------------------------------------------------------------------------------- /benchTest/littleTest.cnf: -------------------------------------------------------------------------------- 1 | p cnf 3 1 2 | 1 2 3 0 3 | -------------------------------------------------------------------------------- /benchTest/test1.cnf: -------------------------------------------------------------------------------- 1 | p cnf 6 3 2 | -2 -1 0 3 | 5 4 0 4 | 6 4 0 -------------------------------------------------------------------------------- /patoh/patoh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/patoh/patoh -------------------------------------------------------------------------------- /patoh/libpatoh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/patoh/libpatoh.a -------------------------------------------------------------------------------- /patoh/manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/patoh/manual.pdf -------------------------------------------------------------------------------- /patoh_mac/patoh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/patoh_mac/patoh -------------------------------------------------------------------------------- /patoh_mac/libpatoh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/patoh_mac/libpatoh.a -------------------------------------------------------------------------------- /patoh_mac/manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/patoh_mac/manual.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | objs/ 2 | 3 | d4 4 | d4_debug 5 | d4_profile 6 | d4_release 7 | d4_static 8 | -------------------------------------------------------------------------------- /certification-master.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crillab/d4/HEAD/certification-master.tar.gz -------------------------------------------------------------------------------- /patoh/test.u: -------------------------------------------------------------------------------- 1 | 1 8 9 28 2 | 8 6 3 5 2 3 | 4 5 1 7 4 | 4 2 5 7 5 | 4 7 6 | 3 5 7 | 8 2 4 8 | 6 5 2 9 | 5 7 2 10 | 8 4 -------------------------------------------------------------------------------- /benchTest/bug.cnf: -------------------------------------------------------------------------------- 1 | p cnf 14 13 2 | -2 1 0 3 | 6 -3 0 4 | 5 | 8 2 0 6 | -2 -8 0 7 | 8 | 7 -6 0 9 | 10 -9 0 10 | 11 12 0 11 | 13 -11 0 12 | 13 -10 0 13 | 5 14 0 14 | -14 -5 0 15 | 4 -5 0 16 | -4 5 0 17 | -------------------------------------------------------------------------------- /core/Main.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | -------------------------------------------------------------------------------- /manager/ParserProblem.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef ManagerParserProblem_h 19 | #define ManagerParserProblem_h 20 | 21 | #include "../mtl/Vec.hh" 22 | #include "../utils/SolverTypes.hh" 23 | 24 | class ParserProblem 25 | { 26 | public: 27 | int parseCNF(char *benchName, vec > &clauses, bool verb = true); 28 | void parseWeight(const char *fileWeights, vec &weightLit, int nbVar); 29 | int parseProblem(char *benchName, const char *fileWeights, vec > &clauses, vec &weightLit, bool verb = true); 30 | }; 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /preproc/Preproc.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PREPROC_LAUNCHER 19 | #define PREPROC_LAUNCHER 20 | 21 | #include 22 | 23 | #include "../utils/System.hh" 24 | #include "../mtl/Vec.hh" 25 | #include "../mtl/Heap.hh" 26 | #include "../mtl/Alg.hh" 27 | 28 | #include "PreprocSolver.hh" 29 | 30 | using namespace std; 31 | 32 | class Preproc 33 | { 34 | public: 35 | Preproc(){} 36 | 37 | bool run(vec > &clauses, int nbVar, vec &isProtectedVar, string opt); 38 | 39 | inline void displayStat() 40 | { 41 | }// displayStat 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /DAG/ConstantNode.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef DAG_ConstantNode_h 19 | #define DAG_ConstantNode_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | template class ConstantNode : public DAG 25 | { 26 | public: 27 | T nbModels; 28 | 29 | ConstantNode(T _nbModels) : nbModels(_nbModels) {} 30 | 31 | inline void toNNF(std::ostream& out) 32 | { 33 | assert(false); // This should never get called since is a singleton 34 | out << "A 0" << std::endl; 35 | } 36 | 37 | inline void printNNF(){out << T;}// printNNF 38 | 39 | inline bool isSAT(){ return (nbModels > 0);} 40 | inline T computeNbModels() { return nbModels; } 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /DAG/True.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef DAG_True_h 19 | #define DAG_True_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | template class trueNode : public DAG 25 | { 26 | public: 27 | using DAG::globalStamp; 28 | using DAG::idxOutputStruct; 29 | using DAG::stamp; 30 | 31 | inline void printNNF(std::ostream& out, bool certif) 32 | { 33 | if(stamp >= globalStamp) return; 34 | stamp = globalStamp + idxOutputStruct + 1; 35 | int idxCurrent = ++idxOutputStruct; 36 | 37 | out << "t " << idxCurrent << " 0" << endl; 38 | } 39 | 40 | inline bool isSAT(vec &unitsLitBranches){return true;} 41 | inline T computeNbModels() { return 1; } 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /DAG/False.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef DAG_False_h 19 | #define DAG_False_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | template class falseNode : public DAG 25 | { 26 | public: 27 | using DAG::globalStamp; 28 | using DAG::idxOutputStruct; 29 | using DAG::stamp; 30 | 31 | 32 | inline void printNNF(std::ostream& out, bool certif) 33 | { 34 | if(stamp >= globalStamp) return; 35 | stamp = globalStamp + idxOutputStruct + 1; 36 | int idxCurrent = ++idxOutputStruct; 37 | 38 | out << "f " << idxCurrent << " 0" << endl; 39 | } 40 | 41 | inline bool isSAT(vec &unitsLitBranches) {return false;} 42 | inline T computeNbModels() { return 0; } 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /manager/formulaManager.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef MANAGER_FORMULA_MANAGER 19 | #define MANAGER_FORMULA_MANAGER 20 | 21 | class FormulaManager 22 | { 23 | private: 24 | vec > clauses; 25 | vec nbSat, nbUnsat; 26 | vec > occurrence; 27 | int nbVar; 28 | 29 | public: 30 | FormulaManager(vec > &cls, int nbVar); 31 | void assignValue(vec &lits); 32 | void unassignValue(vec &lits); 33 | void debug(vec ¤tValue); 34 | 35 | inline int getNbVar(){return nbVar;} 36 | inline vec > &getClauses(){return clauses;} 37 | inline int nbLitSatInClause(int idx){return nbSat[idx];} 38 | inline int nbLitUnsatInClause(int idx){return nbUnsat[idx];} 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /manager/greedyOccurrenceManager.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef MANAGER_GREEDY_OCCURRENCE_MANAGER 19 | #define MANAGER_GREEDY_OCCURRENCE_MANAGER 20 | 21 | #include "../manager/CnfOccurrenceManager.hh" 22 | 23 | class GreedyOccurrenceManager : public CnfOccurrenceManager 24 | { 25 | vec > initOccList; 26 | 27 | int counterStampViewClause; 28 | vec stampViewClause; 29 | 30 | void initializeFromLiteral(Lit l); 31 | 32 | public: 33 | GreedyOccurrenceManager(vec > &clauses, int nbVar); 34 | void initialize(vec &setOfVar, vec &units); 35 | 36 | // we cannot use these functions here! 37 | inline void preUpdate(vec &lits){assert(0);} 38 | inline void postUpdate(vec &lits){assert(0);} 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /patoh/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "patoh.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | PaToH_Parameters args; 8 | int _c, _n, _nconst, *cwghts, *nwghts, *xpins, *pins, *partvec, cut, *partweights; 9 | 10 | if (argc<3) { 11 | fprintf(stderr, "usage: %s <#parts>\n", argv[0]); 12 | exit(1); 13 | } 14 | 15 | PaToH_Read_Hypergraph(argv[1], &_c, &_n, &_nconst, &cwghts, &nwghts, &xpins, &pins); 16 | printf("Hypergraph %8s -- #Cells=%6d #Nets=%6d #Pins=%8d #Const=%2d\n", argv[1], _c, _n, xpins[_n], _nconst); 17 | 18 | PaToH_Initialize_Parameters(&args, PATOH_CONPART, PATOH_SUGPARAM_DEFAULT); 19 | 20 | args.seed = 1; 21 | args._k = atoi(argv[2]); 22 | partvec = (int *) malloc(_c*sizeof(int)); 23 | partweights = (int *) malloc(args._k*_nconst*sizeof(int)); 24 | PaToH_Alloc(&args, _c, _n, _nconst, cwghts, nwghts, xpins, pins); 25 | 26 | PaToH_Part(&args, _c, _n, _nconst, 0, cwghts, nwghts, xpins, pins, NULL, partvec, partweights, &cut); 27 | printf("seed %d -- %d-way cutsize is: %d\n", args.seed, args._k, cut); 28 | 29 | printf("partvec: "); 30 | for(int i = 0 ; i<_c ; i++) printf("%d ", partvec[i]); 31 | printf("\n"); 32 | 33 | printf("partweights: "); 34 | for(int i = 0 ; i. 17 | */ 18 | #ifndef HEURISTIC_MINCUT_PARTIONER 19 | #define HEURISTIC_MINCUT_PARTIONER 20 | 21 | struct edge_t 22 | { 23 | int first; 24 | int second; 25 | }; 26 | 27 | /** 28 | Method which consist in computing some shortest path in the 29 | graph. 30 | */ 31 | class MinCutPartition : public PartitionerInterface 32 | { 33 | private: 34 | OccurrenceManagerInterface *om; 35 | vec inCurrentComponent, markedVar; 36 | 37 | public: 38 | MinCutPartition(OccurrenceManagerInterface *_om): om(_om) 39 | { 40 | inCurrentComponent.initialize(om->getNbVariable(), false); 41 | markedVar.initialize(om->getNbVariable(), false); 42 | }// MinCutPartition Constructor 43 | 44 | void minCut(vec &component); 45 | 46 | }; 47 | #endif 48 | -------------------------------------------------------------------------------- /interfaces/PartitionerInterface.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PARTITIONER_INTERFACE 19 | #define PARTITIONER_INTERFACE 20 | 21 | #include "../manager/OptionManager.hh" 22 | #include 23 | 24 | using namespace std; 25 | 26 | class PartitionerInterface 27 | { 28 | public: 29 | virtual ~PartitionerInterface(){} 30 | bool reduceFormula; 31 | bool equivSimp; 32 | 33 | inline void setReduceFormula(bool b){reduceFormula = b;} 34 | inline void setEquivSimp(bool b){equivSimp = b;} 35 | 36 | virtual void computePartition(vec &component, vec &partition, vec &cutVar, ScoringMethod *sm) 37 | { 38 | component.copyTo(partition); 39 | } 40 | 41 | static PartitionerInterface *getPartitioner(Solver &s, OccurrenceManagerInterface *om, OptionManager &optList); 42 | }; 43 | #endif 44 | -------------------------------------------------------------------------------- /utils/HittingSet.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef UTILS_HITTING_SET 19 | #define UTILS_HITTING_SET 20 | 21 | #include "../mtl/Sort.hh" 22 | #include "../mtl/Vec.hh" 23 | #include "../utils/SolverTypes.hh" 24 | #include "../heuristics/ScoringMethod.hh" 25 | 26 | 27 | class HittingSet 28 | { 29 | vec selectedLit; 30 | ScoringMethod *sm; 31 | 32 | vec > occ; 33 | 34 | void debug(vec > &cls, vec &hs); 35 | 36 | public: 37 | struct LitOrderScoringMethod 38 | { 39 | ScoringMethod *sm; 40 | bool operator () (Lit x, Lit y) const {return sm->computeScore(var(x)) > sm->computeScore(var(y)); } 41 | LitOrderScoringMethod(ScoringMethod *_sm) : sm(_sm) { } 42 | }; 43 | 44 | 45 | HittingSet(int nbVar, ScoringMethod *_sm); 46 | void computeHittingSet(vec > &cls, vec &hs); 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /preproc/Backbone.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PREPROC_BACKBONE 19 | #define PREPROC_BACKBONE 20 | 21 | #include 22 | 23 | #include "../utils/System.hh" 24 | #include "../mtl/Vec.hh" 25 | #include "../mtl/Heap.hh" 26 | #include "../mtl/Alg.hh" 27 | #include "PreprocSolver.hh" 28 | 29 | using namespace std; 30 | 31 | class Backbone 32 | { 33 | public: 34 | Backbone(PreprocSolver &_os) : os(_os) 35 | { 36 | timeBackone = 0; 37 | } 38 | 39 | void run(); 40 | vec &getBackbone(){return backbone;} 41 | 42 | inline void displayStat() 43 | { 44 | fprintf(stderr, "c\nc Backbone, total time: %lf\n", timeBackone); 45 | fprintf(stderr, "c Backbone size: %d\n", backbone.size()); 46 | }// displayStat 47 | 48 | private: 49 | PreprocSolver &os; 50 | double timeBackone; 51 | 52 | vec backbone; 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /patoh/README: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------- 2 | PaToH Version 3.2 3 | Copyright (c) 1996- by Umit V. Catalyurek 4 | --------------------------------------------------------------------- 5 | License: PaToH binary distribution is available free of charge for 6 | non-commercial, research use by individuals, academic or research 7 | institutions and corporations. Commercial use of PaToH software 8 | requires commercial license. Please direct commercial-use license 9 | inquiries to umit@gatech.edu. 10 | --------------------------------------------------------------------- 11 | 12 | PaToH (Partitioning Tools for Hypergraphs) is a multilevel hypergraph 13 | partitioning tool. 14 | 15 | Important features of PaToH: 16 | 17 | - Fast, stable multilevel hypergraph partitioner, 18 | - Hypergraph partitioning with fixed cells, 19 | - Multi-constraint hypergraph partitioner. 20 | 21 | You can download latest binary distribution of PaToH 22 | from http://cc.gatech.edu/~umit/software.html. 23 | 24 | 25 | This distribution contains the following files: 26 | 27 | README - This file 28 | patoh - PaToH executable 29 | libpatoh.a - PaToH library file 30 | patoh.h - C header file for the library 31 | manual.pdf - manual 32 | simple.c - sample C code 33 | try.c - another sample C code 34 | ken-11.u - sample hypergraph 35 | 36 | To compile sample codes: 37 | 38 | cc -o try try.c -L. -lpatoh -lm 39 | cc -o simple simple.c -L. -lpatoh -lm 40 | 41 | For questions, comments, suggestions, bugs please send e-mail to: 42 | 43 | Umit V. Catalyurek umit@gatech.edu 44 | Cevdet Aykanat aykanat@cs.bilkent.edu.tr 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /patoh_mac/README: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------- 2 | PaToH Version 3.2 3 | Copyright (c) 1996- by Umit V. Catalyurek 4 | --------------------------------------------------------------------- 5 | License: PaToH binary distribution is available free of charge for 6 | non-commercial, research use by individuals, academic or research 7 | institutions and corporations. Commercial use of PaToH software 8 | requires commercial license. Please direct commercial-use license 9 | inquiries to catalyurek.1@osu.edu. 10 | --------------------------------------------------------------------- 11 | 12 | PaToH (Partitioning Tools for Hypergraphs) is a multilevel hypergraph 13 | partitioning tool. 14 | 15 | Important features of PaToH: 16 | 17 | - Fast, stable multilevel hypergraph partitioner, 18 | - Hypergraph partitioning with fixed cells, 19 | - Multi-constraint hypergraph partitioner. 20 | 21 | You can download latest binary distribution of PaToH 22 | from http://bmi.osu.edu/~umit/software.html. 23 | 24 | 25 | This distribution contains the following files: 26 | 27 | README - This file 28 | patoh - PaToH executable 29 | libpatoh.a - PaToH library file 30 | patoh.h - C header file for the library 31 | manual.pdf - manual 32 | simple.c - sample C code 33 | try.c - another sample C code 34 | ken-11.u - sample hypergraph 35 | 36 | To compile sample codes: 37 | 38 | cc -o try try.c -L. -lpatoh -lm 39 | cc -o simple simple.c -L. -lpatoh -lm 40 | 41 | For questions, comments, suggestions, bugs please send e-mail to: 42 | 43 | Umit V. Catalyurek catalyurek.1@osu.edu 44 | Cevdet Aykanat aykanat@cs.bilkent.edu.tr 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /heuristics/PhaseHeuristic.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | class PhaseSelection 20 | { 21 | public: 22 | virtual ~PhaseSelection(){;} 23 | virtual bool selectPhase(Var v) = 0; 24 | }; 25 | 26 | class PhaseTrue : public PhaseSelection 27 | { 28 | public: 29 | bool selectPhase(Var v){return true;} 30 | }; 31 | 32 | class PhaseFalse : public PhaseSelection 33 | { 34 | public: 35 | bool selectPhase(Var v){return false;} 36 | }; 37 | 38 | class PhasePolarity : public PhaseSelection 39 | { 40 | private: 41 | vec &polarity; 42 | 43 | public: 44 | PhasePolarity(vec &p) : polarity(p){} 45 | bool selectPhase(Var v){return polarity[v];} 46 | }; 47 | 48 | class PhaseOccurrence : public PhaseSelection 49 | { 50 | private: 51 | OccurrenceManagerInterface *om; 52 | 53 | public: 54 | PhaseOccurrence(OccurrenceManagerInterface *_om) : om(_om){} 55 | 56 | inline bool selectPhase(Var v){assert(om); return om->getNbClause(mkLit(v, false)) < om->getNbClause(mkLit(v, true));} 57 | }; 58 | -------------------------------------------------------------------------------- /interfaces/VariableHeuristicInterface.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef HEURISTICS_VARIABLE_HEURISTIC_INTERFACE 19 | #define HEURISTICS_VARIABLE_HEURISTIC_INTERFACE 20 | 21 | #include "../interfaces/OccurrenceManagerInterface.hh" 22 | #include "../utils/SolverTypes.hh" 23 | #include "../utils/Solver.hh" 24 | #include "../heuristics/ScoringMethod.hh" 25 | #include "../heuristics/PhaseHeuristic.hh" 26 | 27 | class VariableHeuristicInterface 28 | { 29 | private: 30 | Solver &s; 31 | OccurrenceManagerInterface *occM; 32 | ScoringMethod *sm; 33 | PhaseSelection *ps; 34 | 35 | public: 36 | vec varProjected; 37 | VariableHeuristicInterface(Solver &_s, OccurrenceManagerInterface *occM, const char *v, const char *p, vec &isProjectedVar); 38 | ~VariableHeuristicInterface(){delete sm; delete ps;} 39 | 40 | Var selectVariable(vec &component); 41 | bool selectPhase(Var v){return ps->selectPhase(v);} 42 | bool isProjected(Var v){return varProjected[v];} 43 | 44 | inline ScoringMethod *getScoringFunction(){return sm;} 45 | }; 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /manager/dynamicOccurrenceManager.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef MODELCOUNTER_DYNAMIC_OCCURRENCE_MANAGER 19 | #define MODELCOUNTER_DYNAMIC_OCCURRENCE_MANAGER 20 | 21 | #include "../utils/System.hh" 22 | #include "../utils/SolverTypes.hh" 23 | #include "../utils/Solver.hh" 24 | #include "../mtl/Sort.hh" 25 | #include "../mtl/Vec.hh" 26 | #include "../mtl/Heap.hh" 27 | #include "../mtl/Alg.hh" 28 | #include "../DAG/DAG.hh" 29 | 30 | #include "../manager/CnfOccurrenceManager.hh" 31 | 32 | class DynamicOccurrenceManager : public CnfOccurrenceManager 33 | { 34 | private: 35 | void initClauses(vec > &clauses); 36 | 37 | public: 38 | DynamicOccurrenceManager(int nbClause, int nbVar, int maxClauseSize); 39 | DynamicOccurrenceManager(vec > &clauses, int nbVar); 40 | 41 | void preUpdate(vec &lits); 42 | void postUpdate(vec &lits); 43 | void debug(Solver &s); 44 | void removeIdxFromOccList(vec &o, int idx); 45 | 46 | // we cannot use this function here 47 | inline void initialize(vec &setOfVar, vec &units){assert(0);} 48 | void initFormula(vec > &_clauses); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /preproc/Backbone.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include 19 | #include "Backbone.hh" 20 | 21 | using namespace std; 22 | 23 | /** 24 | We compute the backbone. 25 | */ 26 | void Backbone::run() 27 | { 28 | double currTime = cpuTime(); 29 | 30 | vec currentModel; 31 | os.setNeedModel(true); 32 | bool ret = os.solve(); 33 | if(!ret) 34 | { 35 | cerr << "c Warning the problem is UNSAT" << endl; 36 | return; 37 | } 38 | (os.model()).copyTo(currentModel); 39 | 40 | for(int v = 0 ; v. 17 | */ 18 | #ifndef UTILS_INTERPRETATION_REFINER 19 | #define UTILS_INTERPRETATION_REFINER 20 | 21 | #include "../utils/SolverTypes.hh" 22 | 23 | class InterpretationRefiner 24 | { 25 | private: 26 | vec > cnf; 27 | vec isProtected; 28 | 29 | vec > occurrences; 30 | 31 | vec marked; 32 | vec isSelector; 33 | vec satisfiedByAssums; 34 | 35 | vec selectorToClauseIdx; 36 | vec nbTrueLit; // nbTrueLit[i]: the number of literal that are existantially quatified and that satisfy the ith clause 37 | vec nbExistVariables; 38 | vec idxClausesWithExist; 39 | 40 | public: 41 | InterpretationRefiner(vec > &formula, vec &pvar); 42 | InterpretationRefiner(vec &pvar); 43 | 44 | void initIdxClausesWithExist(int nbVar, vec &idxVec, vec &selectors); 45 | 46 | void init(vec &assums, vec &model); 47 | void transferPureLiteral(vec &assums, vec &model); 48 | void refine(vec &assums, vec &model); 49 | void shouldBeRelaxed(vec &subsetOfEVar); 50 | void addClause(vec &cl); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /preproc/OccurrenceLitElimination.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PREPROC_OCCURRENCE_LIT_ELIMINATION 19 | #define PREPROC_OCCURRENCE_LIT_ELIMINATION 20 | 21 | #include 22 | 23 | #include "../utils/System.hh" 24 | #include "../mtl/Vec.hh" 25 | #include "../mtl/Heap.hh" 26 | #include "../mtl/Alg.hh" 27 | #include "PreprocSolver.hh" 28 | 29 | using namespace std; 30 | 31 | struct LitOrderOccurrenceLt { 32 | PreprocSolver &os; 33 | bool operator () (Lit x, Lit y) const { return os.getNbOccLit(x) < os.getNbOccLit(y);} 34 | LitOrderOccurrenceLt(PreprocSolver &_os) : os(_os) { } 35 | }; 36 | 37 | 38 | class OccurrenceLitElimination 39 | { 40 | public: 41 | OccurrenceLitElimination(PreprocSolver &_os) : os(_os) 42 | { 43 | timeOccRm = 0; 44 | nbRemovedLitOccRm = 0; 45 | } 46 | 47 | void run(Lit l); 48 | void run(); 49 | 50 | void displayStat() 51 | { 52 | fprintf(stderr, "c\nc Occurrence Elimination, total time: %lf\n", timeOccRm); 53 | fprintf(stderr, "c Occurrence Elimination, number of literals removed: %d\n", nbRemovedLitOccRm); 54 | }// displayStat 55 | 56 | private: 57 | PreprocSolver &os; 58 | double timeOccRm; 59 | int nbRemovedLitOccRm; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /preproc/EquivClauseSimplification.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PREPROC_EQUIVSIMPLI 19 | #define PREPROC_EQUIVSIMPLI 20 | 21 | #include "../utils/SolverTypes.hh" 22 | #include "../utils/Solver.hh" 23 | 24 | #include "../mtl/Sort.hh" 25 | #include "../mtl/Vec.hh" 26 | #include "../mtl/Alg.hh" 27 | 28 | 29 | class EquivClauseSimplification 30 | { 31 | private: 32 | Solver s; 33 | vec< vec > occurrences; 34 | 35 | void loadSolver(vec< vec > &clauses); 36 | void cleanUpSolver(); 37 | void vivification(); 38 | void occurrenceElimination(); 39 | void rebuildOccurrence(); 40 | 41 | int tryToRemoveLiteral(Lit l); 42 | void removeAndUpdateOccurrence(int index, Lit blocked = lit_Undef, bool clauseAttached = false); 43 | 44 | protected: 45 | struct LitOrderOccurrenceLt { 46 | const vec< vec > &occurrences; 47 | bool operator () (Lit x, Lit y) const { return occurrences[toInt(x)].size() < occurrences[toInt(y)].size();} 48 | LitOrderOccurrenceLt(const vec< vec > &occ) : occurrences(occ) { } 49 | }; 50 | 51 | public: 52 | EquivClauseSimplification(int nbVar); 53 | void equivPreproc(vec< vec > &clauses, bool vivification = true, bool occurrenceELim = true); 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /interfaces/ClauseCheckProperty.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef INTERFACES_CLAUSE_CHECK_PROPERTY 19 | #define INTERFACES_CLAUSE_CHECK_PROPERTY 20 | 21 | #include 22 | #include "../utils/SolverTypes.hh" 23 | 24 | using namespace std; 25 | 26 | class ClauseCheckProperty 27 | { 28 | protected: 29 | vec markedComponent; 30 | 31 | public: 32 | ClauseCheckProperty(int nbVar) 33 | { 34 | while(markedComponent.size() < nbVar) markedComponent.push(false); 35 | } 36 | 37 | virtual bool satisfyProperty(vec &cl) = 0; 38 | 39 | inline void setComponent(vec &component) 40 | { 41 | for(int i = 0 ; i &component) 45 | { 46 | for(int i = 0 ; i &cl) 50 | { 51 | for(int i = 0 ; i &retCl, vec &cl) 56 | { 57 | for(int i = 0 ; i. 17 | */ 18 | #include "../interfaces/OccurrenceManagerInterface.hh" 19 | #include "../mtl/Vec.hh" 20 | #include "../utils/SolverTypes.hh" 21 | 22 | #include "../interfaces/PartitionerInterface.hh" 23 | #include "../heuristics/ClauseBipartiteGraphPartitioner.hh" 24 | #include "../heuristics/VarBipartiteGraphPartitioner.hh" 25 | 26 | PartitionerInterface *PartitionerInterface::getPartitioner(Solver &s, OccurrenceManagerInterface *om, OptionManager &optList) 27 | { 28 | PartitionerInterface *pv = NULL; 29 | if(!strcmp(optList.partitionHeuristic, "NO")) pv = NULL; 30 | else if(!strcmp(optList.partitionHeuristic, "CB")) 31 | { 32 | pv = new ClauseBipartiteGraphPartitioner(s, om); 33 | pv->setReduceFormula(optList.reducePrimalGraph); 34 | pv->setEquivSimp(optList.equivSimplification); 35 | } 36 | else if(!strcmp(optList.partitionHeuristic, "VB")) 37 | { 38 | pv = new VarBipartiteGraphPartitioner(s, om); 39 | pv->setReduceFormula(optList.reducePrimalGraph); 40 | pv->setEquivSimp(optList.equivSimplification); 41 | } 42 | else 43 | { 44 | cerr << "Not available partioner" << endl; 45 | exit(12); 46 | } 47 | 48 | return pv; 49 | }// getPartioner 50 | -------------------------------------------------------------------------------- /preproc/Vivification.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PREPROC_VIVIFICATION 19 | #define PREPROC_VIVIFICATION 20 | 21 | #include 22 | 23 | #include "../utils/System.hh" 24 | #include "../mtl/Vec.hh" 25 | #include "../mtl/Heap.hh" 26 | #include "../mtl/Alg.hh" 27 | #include "PreprocSolver.hh" 28 | 29 | using namespace std; 30 | 31 | class Vivification 32 | { 33 | public: 34 | Vivification(PreprocSolver &_os) : os(_os) 35 | { 36 | nbRemovedClauseVivi = 0; 37 | nbRemovedLitVivi = 0; 38 | timeVivi = 0; 39 | } 40 | 41 | void run(); 42 | 43 | inline int getNbClauseRm(){return nbRemovedClauseVivi;} 44 | inline int getNbLitRm(){return nbRemovedLitVivi;} 45 | inline double getTime(){return timeVivi;} 46 | inline int getNbRemovedLit(){return nbRemovedLitVivi;} 47 | inline int getNbRemovedClause(){return nbRemovedClauseVivi;} 48 | 49 | inline void displayStat() 50 | { 51 | fprintf(stderr, "c\nc Vivification, total time: %lf\n", timeVivi); 52 | fprintf(stderr, "c Vivification, number of clauses removed: %d\n", nbRemovedClauseVivi); 53 | fprintf(stderr, "c Vivification, number of literals removed: %d\n", nbRemovedLitVivi); 54 | }// displayStat 55 | 56 | private: 57 | PreprocSolver &os; 58 | double timeVivi; 59 | 60 | int nbRemovedLitVivi; 61 | int nbRemovedClauseVivi; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /hashing/HashCnf.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef HASHING_HASHCNF 19 | #define HASHING_HASHCNF 20 | 21 | 22 | class HashCnf 23 | { 24 | public: 25 | inline unsigned hash(char *key, unsigned len) 26 | { 27 | // 'm' and 'r' are mixing constants generated offline. They're not really 28 | // 'magic', they just happen to work well. 29 | const unsigned int m = 0x5bd1e995; 30 | const int r = 24; 31 | 32 | // Initialize the hash to a 'random' value 33 | unsigned int h = 0x29111983 ^ len; 34 | 35 | // Mix 4 bytes at a time into the hash 36 | const unsigned char * data = (const unsigned char *)key; 37 | 38 | while(len >= 4) 39 | { 40 | unsigned int k = *(unsigned int *)data; 41 | 42 | k *= m; 43 | k ^= k >> r; 44 | k *= m; 45 | 46 | h *= m; 47 | h ^= k; 48 | 49 | data += 4; 50 | len -= 4; 51 | } 52 | 53 | // Handle the last few bytes of the input array 54 | switch(len) 55 | { 56 | case 3: h ^= data[2] << 16; 57 | case 2: h ^= data[1] << 8; 58 | case 1: h ^= data[0]; 59 | h *= m; 60 | }; 61 | 62 | // Do a few final mixes of the hash to ensure the last few bytes are 63 | // well-incorporated. 64 | h ^= h >> 13; 65 | h *= m; 66 | h ^= h >> 15; 67 | 68 | return h; 69 | 70 | }// hash 71 | 72 | 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /utils/ResidualNotPC.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include "../utils/ResidualNotPC.hh" 19 | 20 | 21 | /** 22 | Update the residual formula. 23 | */ 24 | void ResidualNotPC::updateResidualFormula(vec &component) 25 | { 26 | cck->setComponent(component); 27 | 28 | for(int i = currentStart ; i &cl = residue[indexes[i]]; 32 | if(cck->satisfyProperty(cl)) 33 | { 34 | int tmp = indexes[i]; 35 | indexes[i] = indexes[currentStart]; 36 | indexes[currentStart] = tmp; 37 | currentStart++; 38 | } 39 | } 40 | 41 | cck->unsetComponent(component); 42 | }// updateResidualFormula 43 | 44 | 45 | /** 46 | Print the remaining set of clauses that are stored in the residual 47 | part. 48 | */ 49 | void ResidualNotPC::printRemainingClauses() 50 | { 51 | cout << "printRemainingClauses " << currentStart << "/" << indexes.size() << endl; 52 | for(int i = currentStart ; iprintClause(residue[indexes[i]]); 54 | }// printRemainingClause 55 | 56 | 57 | /** 58 | Extract the residual set of clauses. 59 | */ 60 | void ResidualNotPC::extractRemainingClauses(vec > &rcl) 61 | { 62 | for(int i = currentStart ; iextractRemainingClause(rcl.last(), residue[indexes[i]])) 66 | rcl.pop(); 67 | } 68 | }// extractExtractRemainingClauses 69 | -------------------------------------------------------------------------------- /DAG/PCNode.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef DAG_PCNODE_h 19 | #define DAG_PCNODE_h 20 | 21 | #include "DAG.hh" 22 | 23 | #include "../utils/SolverTypes.hh" 24 | #include "../utils/Solver.hh" 25 | 26 | 27 | template class DAG; 28 | template class PcNode : public DAG 29 | { 30 | using DAG::globalStamp; 31 | vec units; 32 | 33 | public: 34 | Solver s; 35 | 36 | PcNode(vec > &cnf, int nbVar) 37 | { 38 | for(int i = 0 ; i &unitsLitBranches) 45 | { 46 | assert(Branch::s); 47 | // cout << "return SAT: "; showListLit(unitsLitBranches); 48 | return true; // we can return SAT because we call unit propagation around the path 49 | 50 | cout << "call the SAT solver oO: "; showListLit(unitsLitBranches); 51 | s.cancelUntil(0); 52 | s.newDecisionLevel(); 53 | for(int i = 0 ; i. 17 | */ 18 | #ifndef UTILS_RESIDUAL_NOT_PC 19 | #define UTILS_RESIDUAL_NOT_PC 20 | 21 | #include 22 | 23 | #include "../interfaces/ClauseCheckProperty.hh" 24 | #include "../utils/SolverTypes.hh" 25 | 26 | using namespace std; 27 | 28 | class ResidualNotPC 29 | { 30 | private: 31 | ClauseCheckProperty *cck; 32 | vec< vec > residue; 33 | vec indexes; 34 | 35 | vec stack; 36 | int currentStart; 37 | 38 | public: 39 | 40 | ResidualNotPC(ClauseCheckProperty *_cck) : cck(_cck) 41 | { 42 | currentStart = 0; 43 | } 44 | 45 | inline vec &getClause(int i){return residue[i];} 46 | inline vec &getRemainingClause(int i){return residue[indexes[currentStart + i]];} 47 | 48 | inline void pushSize(){stack.push(currentStart);} 49 | inline void popSize(){currentStart = stack.last(); stack.pop();} 50 | inline int getCurrentSize(){return residue.size() - currentStart;} 51 | inline void setCurrentSize(int csz){currentStart = csz;} 52 | inline int topSize(){assert(stack.size()); return stack.last();} 53 | 54 | inline void setComponent(vec &component){cck->setComponent(component);} 55 | inline void unsetComponent(vec &component){cck->unsetComponent(component);} 56 | 57 | inline void addClause(vec &cl) 58 | { 59 | residue.push(); 60 | cl.copyTo(residue.last()); 61 | indexes.push(residue.size() - 1); 62 | }// addClause 63 | 64 | void updateResidualFormula(vec &component); 65 | void extractRemainingClauses(vec > &rcl); 66 | void printRemainingClauses(); 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /DAG/ImplicitAnd.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_ImplicitAnd_h 19 | #define Minisat_DAG_ImplicitAnd_h 20 | 21 | #include "../DAG/DAG.hh" 22 | 23 | 24 | template class DAG; 25 | // This is a class used only to generate the d-DNNF file 26 | // It represents implicit "and" nodes. 27 | template class ImplicitAnd: public DAG 28 | { 29 | public: 30 | ImplicitAnd(Branch& b): b{b} 31 | { 32 | DAG::nbImplicitAnd++; 33 | if (DAG::nbImplicitAnd % 1000000 == 0) 34 | printf("%dM ImplicitAnd size: %dMb\n", (int) DAG::nbImplicitAnd/1000000, 35 | (int) sizeof(ImplicitAnd)*DAG::nbImplicitAnd/1000000); 36 | } 37 | 38 | DAG *duplicateSameVarUnderAssumption_(int szAssums){assert(0); return NULL;} 39 | 40 | void toNNF(std::ostream& out) { 41 | const int index = DAG::nodeToIndex[this]; 42 | int nbUnitLit = b.nbUnit(); 43 | for (int i = 0; i < nbUnitLit; i++) { 44 | out << "L " << readableLit((&DAG::unitLits[b.idxUnitLit])[i]) << std::endl; 45 | } 46 | out << "A " << (nbUnitLit + 1) << " "; 47 | for (int i = 0; i < nbUnitLit; i++) { 48 | out << (index - i - 1) << " "; 49 | } 50 | out << DAG::nodeToIndex[b.d] << std::endl; 51 | } 52 | 53 | // TODO: this is plain wrong but we don't really care as this will never be called. 54 | inline void printNNF(std::ostream& out){ assert(0);}// printNNF 55 | 56 | bool isSAT(){assert(false); return false;} 57 | bool isSAT(vec &unitsLit){assert(false); return false;} 58 | T computeNbModels() {assert(false); return 0;} 59 | 60 | private: 61 | Branch& b; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /core/ShareStructures.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef CORE_SHARE_STRUCTURE 19 | #define CORE_SHARE_STRUCTURE 20 | 21 | struct VarOrderPrior 22 | { 23 | ScoringMethod *sm; 24 | bool operator () (Var x, Var y) const { return sm->computeScore(x) > sm->computeScore(y); } 25 | VarOrderPrior(ScoringMethod *_sm) : sm(_sm) { } 26 | }; 27 | 28 | inline void prepareVecClauses(vec > &clauses, Solver &s) 29 | { 30 | vec markedClauseLit; 31 | for(int i = 0 ; i &cl = clauses.last(); 46 | for(int j = 0 ; j. 17 | */ 18 | /**************************************************************************************[IntTypes.h] 19 | Copyright (c) 2009-2010, Niklas Sorensson 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 22 | associated documentation files (the "Software"), to deal in the Software without restriction, 23 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 24 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in all copies or 28 | substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 31 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 32 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 33 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 34 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | **************************************************************************************************/ 36 | 37 | #ifndef IntTypes_h 38 | #define IntTypes_h 39 | 40 | #ifdef __sun 41 | // Not sure if there are newer versions that support C99 headers. The 42 | // needed features are implemented in the headers below though: 43 | 44 | # include 45 | # include 46 | # include 47 | 48 | #else 49 | # define __STDC_FORMAT_MACROS 1 50 | # include 51 | # include 52 | 53 | #endif 54 | 55 | #include 56 | 57 | //================================================================================================= 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /mtl/XAlloc.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /****************************************************************************************[XAlloc.h] 19 | Copyright (c) 2009-2010, Niklas Sorensson 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 22 | associated documentation files (the "Software"), to deal in the Software without restriction, 23 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 24 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in all copies or 28 | substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 31 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 32 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 33 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 34 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | **************************************************************************************************/ 36 | 37 | 38 | #ifndef XAlloc_h 39 | #define XAlloc_h 40 | 41 | #include 42 | #include 43 | 44 | //================================================================================================= 45 | // Simple layer on top of malloc/realloc to catch out-of-memory situtaions and provide some typing: 46 | 47 | class OutOfMemoryException{}; 48 | static inline void* xrealloc(void *ptr, size_t size) 49 | { 50 | void* mem = realloc(ptr, size); 51 | if (mem == NULL && errno == ENOMEM){ 52 | throw OutOfMemoryException(); 53 | }else 54 | return mem; 55 | } 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /preproc/Vivification.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include "Vivification.hh" 19 | 20 | /** 21 | Realized the vivication [Piette2008] procedure on a set of clauses 22 | given in parameter. 23 | 24 | WARNING: this function does not work if the set of clauses is not contiguous. 25 | 26 | [Piette2008] Cédric Piette, Youssef Hamadi, Lakhdar Sais: 27 | Vivifying Propositional Clausal Formulae. ECAI 2008: 525-529 28 | */ 29 | void Vivification::run() 30 | { 31 | os.removeLearnt(); 32 | assert(!(os.getLearnts()).size()); 33 | 34 | double currTime = cpuTime(); 35 | for(int i = 0 ; i 2 | #include 3 | #include "patoh.h" 4 | 5 | 6 | void PrintInfo(int _k, int *partweights, int cut, int _nconst) 7 | { 8 | double *avg, *maxi, maxall=-1.0; 9 | int i, j; 10 | 11 | printf("\n-------------------------------------------------------------------"); 12 | printf("\n Partitioner: %s", (_nconst>1) ? "Multi-Constraint" : "Single-Constraint"); 13 | 14 | printf("\n %d-way cutsize = %d \n", _k, cut); 15 | 16 | printf("\nPartWeights are:\n"); 17 | avg = (double *) malloc(sizeof(double)*_nconst); 18 | maxi = (double *) malloc(sizeof(double)*_nconst); 19 | for (i=0; i<_nconst; ++i) 20 | maxi[i] = avg[i] = 0.0; 21 | for (i=0; i<_k; ++i) 22 | for (j=0; j<_nconst; ++j) 23 | avg[j] += partweights[i*_nconst+j]; 24 | for (i=0; i<_nconst; ++i) 25 | { 26 | maxi[i] = 0.0; 27 | avg[i] /= (double) _k; 28 | } 29 | 30 | for (i=0; i<_k; ++i) 31 | { 32 | printf("\n %3d :", i); 33 | for (j=0; j<_nconst; ++j) 34 | { 35 | double im= (double)((double)partweights[i*_nconst+j] - avg[j]) / avg[j]; 36 | 37 | maxi[j] = (maxi[j] > im) ? maxi[j] : im; 38 | printf("%10d ", partweights[i*_nconst+j]); 39 | } 40 | } 41 | for (j=0; j<_nconst; ++j) 42 | maxall = (maxi[j] > maxall) ? maxi[j] : maxall; 43 | printf("\n MaxImbals are (as %%): %.3lf", 100.0*maxall); 44 | printf("\n "); 45 | for (i=0; i<_nconst; ++i) 46 | printf("%10.1lf ", 100.0*maxi[i]); 47 | printf("\n"); 48 | free(maxi); 49 | free(avg); 50 | } 51 | 52 | 53 | int main(int argc, char *argv[]) 54 | { 55 | PaToH_Parameters args; 56 | int _c, _n, _nconst, *cwghts, *nwghts, 57 | *xpins, *pins, *partvec, cut, *partweights; 58 | 59 | 60 | if (argc<3) { 61 | fprintf(stderr, "usage: %s <#parts>\n", argv[0]); 62 | exit(1); 63 | } 64 | 65 | 66 | PaToH_Read_Hypergraph(argv[1], &_c, &_n, &_nconst, &cwghts, 67 | &nwghts, &xpins, &pins); 68 | 69 | printf("Hypergraph %10s -- #Cells=%6d #Nets=%6d #Pins=%8d #Const=%2d\n", 70 | argv[1], _c, _n, xpins[_n], _nconst); 71 | 72 | PaToH_Initialize_Parameters(&args, PATOH_CONPART, 73 | PATOH_SUGPARAM_DEFAULT); 74 | 75 | args._k = atoi(argv[2]); 76 | partvec = (int *) malloc(_c*sizeof(int)); 77 | partweights = (int *) malloc(args._k*_nconst*sizeof(int)); 78 | PaToH_Alloc(&args, _c, _n, _nconst, cwghts, nwghts, 79 | xpins, pins); 80 | 81 | PaToH_Part(&args, _c, _n, _nconst, 0, cwghts, nwghts, 82 | xpins, pins, NULL, partvec, partweights, &cut); 83 | 84 | printf("%d-way cutsize is: %d\n", args._k, cut); 85 | 86 | 87 | PrintInfo(args._k, partweights, cut, _nconst); 88 | 89 | 90 | free(cwghts); free(nwghts); 91 | free(xpins); free(pins); 92 | free(partweights); free(partvec); 93 | 94 | PaToH_Free(); 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /preproc/Preproc.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | #include 21 | 22 | #include "../utils/System.hh" 23 | #include "../utils/SolverTypes.hh" 24 | #include "../utils/Dimacs.hh" 25 | #include "../utils/Solver.hh" 26 | 27 | #include "OccurrenceLitElimination.hh" 28 | #include "Vivification.hh" 29 | #include "Backbone.hh" 30 | #include "Preproc.hh" 31 | 32 | using namespace std; 33 | using namespace boost; 34 | 35 | 36 | /** 37 | Parse the option given in paremeter and apply the preprocessing on 38 | the set of given clauses. Consequently at the end of the procedure 39 | the input clauses can be changed. 40 | 41 | @param[out] clauses, the set of clauses 42 | @param[in] opt, the option 43 | */ 44 | bool Preproc::run(vec > &clauses, int nbVar, vec &isProtectedVar, string opt) 45 | { 46 | double initTime = cpuTime(); 47 | cout << "c Preproc options: " << opt << endl; 48 | return true; // no preproc. 49 | 50 | // create the preproc solver. 51 | Solver s; 52 | for(int i = 0 ; i sep("+"); 60 | tokenizer> tokens(opt, sep); 61 | for (const auto& t : tokens) 62 | { 63 | if(t == "backbone") 64 | { 65 | cout << "c Run Backbone" << endl; 66 | Backbone b(os); 67 | b.run(); 68 | b.displayStat(); 69 | } 70 | 71 | if(t == "vivification") 72 | { 73 | cout << "c Run Vivification" << endl; 74 | Vivification v(os); 75 | v.run(); 76 | v.displayStat(); 77 | } 78 | 79 | if(t == "occElimination") 80 | { 81 | cout << "c Run Occurrence Elimination" << endl; 82 | OccurrenceLitElimination o(os); 83 | o.run(); 84 | o.displayStat(); 85 | } 86 | } 87 | 88 | // modify the input clauses in order to take into account the preprocessing. 89 | clauses.clear(); 90 | os.collectInitFormula(clauses); 91 | 92 | cout << "c" << endl << "c Preproc time: " << fixed << cpuTime() - initTime << endl; 93 | return true; 94 | }// run 95 | -------------------------------------------------------------------------------- /manager/OptionManager.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef MANAGER_OPTIONMANAGER_h 19 | #define MANAGER_OPTIONMANAGER_h 20 | 21 | #include 22 | #include "../utils/SolverTypes.hh" 23 | #include "../mtl/Vec.hh" 24 | 25 | class OptionManager 26 | { 27 | public: 28 | int optCache; 29 | bool optDecomposableAndNode; 30 | bool reversePolarity; 31 | bool reducePrimalGraph; 32 | bool equivSimplification; 33 | 34 | int freqLimitDyn; 35 | int reduceCache, strategyRedCache; 36 | 37 | const char *cacheStore; 38 | const char *varHeuristic; 39 | const char *phaseHeuristic; 40 | const char *partitionHeuristic; 41 | const char *cacheRepresentation; 42 | 43 | OptionManager(int _optCache, bool _optAnd, bool _reversePolarity, bool _reducePrimalGraph, 44 | bool _equivSimplification, const char *_cacheStore, const char *_varHeuristic, 45 | const char *_phaseHeuristic, const char *_partitionHeuristic, 46 | const char *_cacheRepresentation, int rdCache, int strCache, int frqLimit) 47 | { 48 | freqLimitDyn = frqLimit; 49 | strategyRedCache = strCache; 50 | reduceCache = rdCache; 51 | cacheRepresentation = _cacheRepresentation; 52 | optCache = _optCache; 53 | optDecomposableAndNode = _optAnd; 54 | reversePolarity = _reversePolarity; 55 | reducePrimalGraph = _reducePrimalGraph; 56 | equivSimplification = _equivSimplification; 57 | 58 | varHeuristic = _varHeuristic; 59 | phaseHeuristic = _phaseHeuristic; 60 | partitionHeuristic = _partitionHeuristic; 61 | cacheStore = _cacheStore; 62 | }// constructor 63 | 64 | inline void printOptions() 65 | { 66 | printf("c\nc \033[1m\033[32mOption list \033[0m\n"); 67 | printf("c Caching: %d\n", optCache); 68 | printf("c Reduce cache procedure level: %d\n", reduceCache); 69 | printf("c Strategy for Reducing the cache: %d\n", strategyRedCache); 70 | printf("c Cache representation: %s\n", cacheRepresentation); 71 | printf("c Part of the formula that is cached: %s\n", cacheStore); 72 | printf("c Variable heuristic: %s\n", varHeuristic); 73 | printf("c Phase heuristic: %s%s\n", (reversePolarity) ? "reverse " : "", phaseHeuristic); 74 | printf("c Partitioning heuristic: %s%s%s\n", partitionHeuristic, 75 | (reducePrimalGraph) ? " + graph reduction" : "", 76 | (equivSimplification) ? " + equivalence simplication" : ""); 77 | printf("c\n"); 78 | } 79 | }; 80 | #endif 81 | -------------------------------------------------------------------------------- /preproc/Forgetting.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef PREPROC_FORGETTING 19 | #define PREPROC_FORGETTING 20 | 21 | #include 22 | 23 | #include "../mtl/Sort.hh" 24 | #include "../mtl/Vec.hh" 25 | #include "../mtl/Heap.hh" 26 | #include "../mtl/Alg.hh" 27 | 28 | #include "../utils/System.hh" 29 | #include "../utils/SolverTypes.hh" 30 | #include "../utils/Solver.hh" 31 | 32 | #include "PreprocSolver.hh" 33 | #include "OccurrenceLitElimination.hh" 34 | #include "Vivification.hh" 35 | 36 | 37 | using namespace std; 38 | 39 | class Forgetting 40 | { 41 | private: 42 | PreprocSolver &os; 43 | OccurrenceLitElimination occElim; 44 | Vivification vivifier; 45 | 46 | double timeForget; 47 | int nbForget; 48 | int nbIteration; 49 | 50 | vec hashKeyInit; 51 | vec markedOutputVars; 52 | vec markedAsForget; 53 | vec markedLit; // must be 'always' false 54 | vec stampSubsum; 55 | vec< vec > watchNewCls; 56 | unsigned int stamp; 57 | 58 | // functions 59 | void generateAllResolution(Var v, vec< vec > &cls); 60 | void removeSubsum(vec< vec > &newCls); 61 | 62 | void constructWatchList(vec< vec > &newCls); 63 | 64 | inline Var selectVarAndPop(vec &outputVars) 65 | { 66 | int best = 0, score = os.productOccLit(mkLit(outputVars[0], false)); 67 | 68 | for(int i = 1 ; i &outputVars, vec &forgetVar, int lim_occ); 89 | 90 | void displayStat() 91 | { 92 | printf("c Number of variables forgotten: %d\n", nbForget); 93 | printf("c Number of iterations: %d\n", nbIteration); 94 | vivifier.displayStat(); 95 | occElim.displayStat(); 96 | printf("c Time used for the preprocessing step: %lf\nc\n", timeForget); 97 | }// displayStat 98 | }; 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /manager/ParserProblem.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "../utils/SolverTypes.hh" 26 | #include "../utils/Dimacs.hh" 27 | #include "../utils/Solver.hh" 28 | 29 | #include "../DAG/DAG.hh" 30 | #include "../manager/ParserProblem.hh" 31 | 32 | int ParserProblem::parseCNF(char *benchName, vec > &clauses, bool verb) 33 | { 34 | gzFile in = gzopen(benchName, "rb"); 35 | if (in == NULL) printf("ERROR! Could not open file: %s\n", benchName), exit(1); 36 | 37 | int nbVar = parse_DIMACS(in, clauses); 38 | 39 | gzclose(in); 40 | 41 | if(verb) 42 | { 43 | int nbLit = 0; 44 | for(int i = 0 ; i &weightLit, int nbVar) 57 | { 58 | // transfer the clause 59 | for(int i = 0 ; i < nbVar ; i++){weightLit.push(1); weightLit.push(1);} 60 | if(strcmp(fileWeights, "/dev/null")) 61 | { 62 | printf("c External file to collect weight: %s\n", fileWeights); 63 | std::ifstream fichier(fileWeights); 64 | 65 | if(fichier) 66 | { 67 | double l, w; 68 | while(fichier >> l) // normally is a lit 69 | { 70 | fichier >> w; 71 | 72 | unsigned int tmp = ((l > 0) ? 2 * l : (-2 * l) + 1) - 2; 73 | weightLit[tmp] = w; 74 | } 75 | } 76 | else printf("ERROR: Impossible to open the file of weights %s\n", fileWeights), exit(12); 77 | } 78 | 79 | weightLit.copyTo(DAG::weights); 80 | }// parseWeight 81 | 82 | 83 | 84 | /** 85 | Collect the information to construct the problem. 86 | 87 | @param[in] benchName, the path where we can find the CNF formula 88 | @param[in] fileWeights, the path where the file containng the literal 's weight can be found 89 | */ 90 | int ParserProblem::parseProblem(char *benchName, const char *fileWeights, vec > &clauses, 91 | vec &weightLit, bool verb) 92 | { 93 | int nbVar = parseCNF(benchName, clauses, verb); 94 | parseWeight(fileWeights, weightLit, nbVar); 95 | 96 | return nbVar; 97 | }// parseProblem 98 | -------------------------------------------------------------------------------- /interfaces/VariableHeuristicInterface.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | #include 21 | #include "string.h" 22 | 23 | #include "../utils/System.hh" 24 | #include "../utils/SolverTypes.hh" 25 | #include "../utils/Solver.hh" 26 | #include "../mtl/Sort.hh" 27 | #include "../mtl/Vec.hh" 28 | #include "../mtl/Heap.hh" 29 | #include "../mtl/Alg.hh" 30 | #include "../DAG/DAG.hh" 31 | #include "../interfaces/OccurrenceManagerInterface.hh" 32 | 33 | 34 | #include "../interfaces/VariableHeuristicInterface.hh" 35 | 36 | using namespace std; 37 | 38 | /** 39 | The constructor with a lot of options .... 40 | 41 | @param[in] isProjectedVar, boolean vector used to decide if a variable is projected (true) or not (false) 42 | */ 43 | VariableHeuristicInterface::VariableHeuristicInterface(Solver &_s, OccurrenceManagerInterface *_occM, const char *v, const char *p, vec &isProj) : 44 | s(_s), occM(_occM) 45 | { 46 | if(!strcmp(v, "VSADS")) sm = new Vsads(occM, s.scoreActivity); 47 | else if(!strcmp(v, "VSIDS")) sm = new Vsids(s.scoreActivity); 48 | else if(!strcmp(v, "DLCS")) sm = new Dlcs(s, occM); 49 | else if(!strcmp(v, "JW-TS")) sm = new Jwts(s, occM); 50 | else if(!strcmp(v, "MOM")) sm = new Mom(s, occM); 51 | else {fprintf(stderr, "%s: this variable heuristic is unknow\n", v); exit(32);} 52 | 53 | if(!strcmp(p, "OCCURRENCE")) ps= new PhaseOccurrence(occM); 54 | else if(!strcmp(p, "TRUE")) ps = new PhaseTrue(); 55 | else if(!strcmp(p, "FALSE")) ps = new PhaseFalse(); 56 | else if(!strcmp(p, "POLARITY")) ps = new PhasePolarity(s.getPolarity()); 57 | else {fprintf(stderr, "%s: this phase heuristic is unknow\n", p); exit(31);} 58 | 59 | isProj.copyTo(varProjected); 60 | }// constructor 61 | 62 | 63 | /** 64 | Select a new decision variable w.r.t. the scoring function 65 | initially chosen (see the constructor for more information). 66 | 67 | @param[in] component, the current problem's variables. 68 | \return a variable to be assigned, var_undef if any variable can be assigned 69 | */ 70 | Var VariableHeuristicInterface::selectVariable(vec &component) 71 | { 72 | Var next = var_Undef; 73 | double maxScore = -1; 74 | sm->initStructure(component); 75 | 76 | for(int i = 0 ; icomputeScore(v); 82 | if(next == var_Undef || score > maxScore){next = v; maxScore = score;} 83 | } 84 | 85 | assert(next == var_Undef || varProjected[next]); 86 | return next; 87 | }// selectVariable 88 | -------------------------------------------------------------------------------- /interfaces/OccurrenceManagerInterface.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef INTERFACE_OCC_MANAGER_INTERFACE 19 | #define INTERFACE_OCC_MANAGER_INTERFACE 20 | 21 | #include "../utils/SolverTypes.hh" 22 | #include "../utils/Solver.hh" 23 | 24 | class OccurrenceManagerInterface 25 | { 26 | public: 27 | vec< vec > occList; 28 | virtual ~OccurrenceManagerInterface(){} 29 | 30 | virtual int getNbBinaryClause(Var v) = 0; 31 | virtual int getNbNotBinaryClause(Var v) = 0; 32 | virtual int getNbClause(Var v) = 0; 33 | virtual int getNbBinaryClause(Lit l) = 0; 34 | virtual int getNbNotBinaryClause(Lit l) = 0; 35 | virtual int getNbClause(Lit l) = 0; 36 | virtual int getNbClause() = 0; 37 | 38 | virtual vec &getClause(int idx) = 0; 39 | virtual int getSizeClause(int idx){return getClause(idx).size();} 40 | virtual vec &getVecIdxClause(Lit l) = 0; 41 | virtual int getNbUnsat(int idx) = 0; 42 | virtual int getNbVariable() = 0; 43 | virtual int getSumSizeClauses() = 0; 44 | 45 | virtual bool litIsAssigned(Lit l) = 0; 46 | virtual bool litIsAssignedToTrue(Lit l) = 0; 47 | 48 | virtual bool varIsAssigned(Var v) = 0; 49 | virtual int getMaxSizeClause() = 0; 50 | virtual bool isSatisfiedClause(int idx) = 0; 51 | virtual bool isSatisfiedClause(vec &c) = 0; 52 | virtual bool isNotSatisfiedClauseAndInComponent(int idx, vec &inCurrentComponent) = 0; 53 | 54 | inline const vec< vec > &getOccurrenceList(){return occList;} 55 | 56 | virtual int computeConnectedComponent(vec > &varConnected, vec &setOfVar, 57 | vec &freeVar, vec ¬FreeVar) = 0; 58 | virtual void preUpdate(vec &lits) = 0; 59 | virtual void postUpdate(vec &lits) = 0; 60 | virtual void initialize(vec &setOfVar, vec &units) = 0; 61 | virtual void showOccurenceList() {} 62 | virtual void showFormula(){} 63 | virtual void initFormula(vec > &_clauses) = 0; 64 | virtual void debug(Solver &s){} 65 | 66 | virtual bool byPass(int mode, int idx){return false;} 67 | 68 | virtual void getCurrentClauses(vec &idxClauses, vec &inCurrentComponent ) 69 | { 70 | idxClauses.setSize(0); 71 | for(int i = 0 ; i &idxClauses, vec &inCurrentComponent ) 77 | { 78 | idxClauses.setSize(0); 79 | for(int i = 0 ; i &component){return;} 85 | virtual void popPreviousClauseSet(){return;} 86 | }; 87 | #endif 88 | -------------------------------------------------------------------------------- /DAG/Root.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_Root_h 19 | #define Minisat_DAG_Root_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | 25 | template class rootNode : public DAG 26 | { 27 | public: 28 | using DAG::globalStamp; 29 | using DAG::fixedValue; 30 | using DAG::idxOutputStruct; 31 | using DAG::stamp; 32 | 33 | 34 | Branch b; 35 | int nbVariable; 36 | vec reasonForUnits; 37 | bool fromCache; 38 | 39 | rootNode(int nbVar) 40 | { 41 | nbVariable = nbVar; 42 | this->unitLits = (Lit *) malloc(sizeof(Lit)); 43 | this->szUnitLits = this->capUnitLits = 1; 44 | this->unitLits[0] = lit_Undef; 45 | 46 | this->freeVariables = (Var *) malloc(sizeof(Var)); 47 | this->freeVariables[0] = var_Undef; 48 | this->szFreeVariables = this->capFreeVariables = 1; 49 | 50 | this->nbNodes = this->nbEdges = 0; 51 | this->globalStamp = 1; 52 | this->fixedValue.clear(); 53 | this->newAnd = nullptr; 54 | } 55 | 56 | ~rootNode() { 57 | if (newAnd != nullptr) { 58 | delete newAnd; 59 | } 60 | } 61 | 62 | int getSize_(){return 1 + b.d->getSize_();} 63 | 64 | inline void assignRootNode(vec &units, DAG *d, bool fromCache_, 65 | int nbVar, vec &fVar, vec &idxReason) 66 | { 67 | b.initBranch(units, d, fVar); 68 | idxReason.copyTo(reasonForUnits); 69 | fromCache = fromCache_; 70 | } 71 | 72 | inline void printNNF(std::ostream& out, bool certif) 73 | { 74 | stamp = globalStamp + 1; 75 | int idxCurrent = ++idxOutputStruct; 76 | 77 | if(certif) 78 | { 79 | out << "o " << idxCurrent << " 1 "; 80 | for(int i = 0 ; igetIdx() << " "; 87 | if(certif) out << (fromCache ? "1" : "2") << " "; 88 | 89 | Lit *pUnit = &DAG::unitLits[b.idxUnitLit]; 90 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 91 | out << "0" << endl; 92 | 93 | globalStamp += idxOutputStruct; 94 | }// printNNF 95 | 96 | 97 | inline bool isSAT() 98 | { 99 | globalStamp++; 100 | return b.isSAT(); 101 | } 102 | 103 | inline bool isSAT(vec &units) 104 | { 105 | globalStamp++; 106 | return b.isSAT(units); 107 | } 108 | 109 | 110 | inline T computeNbModels() 111 | { 112 | globalStamp++; 113 | return b.computeNbModels(); 114 | } 115 | 116 | private: 117 | ImplicitAnd* newAnd; 118 | }; 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /preproc/OccurrenceLitElimination.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include "OccurrenceLitElimination.hh" 19 | 20 | 21 | /** 22 | Try to remove a maximum number of the occurrences clauses of the 23 | literal l given in parameter. 24 | 25 | @param[in] l, the literal we want to remove 26 | @param[in] refClauses, the set of clause 27 | */ 28 | void OccurrenceLitElimination::run(Lit l) 29 | { 30 | assert(!(os.getLearnts()).size()); 31 | 32 | // the clause index 33 | vec v; 34 | os.copyOccLitInVec(l, v); 35 | 36 | for(int i = 0 ; i 2) 61 | { 62 | os.searchAndRemoveOccFromLit(c[0], v[i]); 63 | c[0] = c.last(); c.shrink(1); // remove it 64 | os.attachClause(cr); 65 | os.setHashKeyInit(v[i]); 66 | } 67 | else 68 | { 69 | os.cancelUntil(0); 70 | if(os.value(c[1]) == l_Undef) os.uncheckedEnqueue(c[1]); 71 | os.removeClauseOcc(v[i]); 72 | } 73 | } 74 | 75 | os.cancelUntil(0); 76 | } 77 | }// occurrenceElimination 78 | 79 | 80 | /** 81 | Run the occurrence elimination process. 82 | */ 83 | void OccurrenceLitElimination::run() 84 | { 85 | double currTime = cpuTime(); 86 | vec orderedLit; 87 | 88 | for(int i = 0 ; i. 17 | */ 18 | #include "../mtl/Vec.hh" 19 | #include "../utils/SolverTypes.hh" 20 | #include "../manager/formulaManager.hh" 21 | 22 | /** 23 | Constructor. We initialize the structure. 24 | 25 | @param[in] cls, the set of clauses. 26 | */ 27 | FormulaManager::FormulaManager(vec > &cls, int _nbVar) : nbVar(_nbVar) 28 | { 29 | 30 | for(int i = 0 ; i &lits) 56 | { 57 | for(int i = 0 ; i &lits) 73 | { 74 | for(int i = 0 ; i ¤tValue) 88 | { 89 | // verif the number of satisfied and falsified literals in the clauses 90 | for(int i = 0 ; i. 17 | */ 18 | /****************************************************************************************[System.h] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef System_h 39 | #define System_h 40 | 41 | #if defined(__linux__) 42 | #include 43 | #endif 44 | 45 | #include "../mtl/IntTypes.hh" 46 | 47 | //------------------------------------------------------------------------------------------------- 48 | 49 | static inline double cpuTime(void); // CPU-time in seconds. 50 | extern double memUsed(); // Memory in mega bytes (returns 0 for unsupported architectures). 51 | extern double memUsedPeak(); // Peak-memory in mega bytes (returns 0 for unsupported architectures). 52 | 53 | 54 | //------------------------------------------------------------------------------------------------- 55 | // Implementation of inline functions: 56 | 57 | #if defined(_MSC_VER) || defined(__MINGW32__) 58 | #include 59 | static inline double cpuTime(void) { return (double)clock() / CLOCKS_PER_SEC; } 60 | #else 61 | #include 62 | #include 63 | #include 64 | 65 | 66 | static struct timeval initTime; 67 | 68 | static inline double init_wall_time(){ 69 | gettimeofday(&initTime,NULL); 70 | return (double) initTime.tv_sec + (double)initTime.tv_usec * .000001; 71 | } 72 | 73 | 74 | static inline double cpuTime(void) 75 | { 76 | static double start_wall_time = init_wall_time(); 77 | 78 | gettimeofday(&initTime, NULL); 79 | double current_wall_time = (double)initTime.tv_sec + (double)initTime.tv_usec * .000001; 80 | double result = current_wall_time-start_wall_time; 81 | return result; 82 | } 83 | 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /mtl/Queue.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /*****************************************************************************************[Queue.h] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef Queue_h 39 | #define Queue_h 40 | 41 | #include "Vec.h" 42 | 43 | template 44 | class Queue { 45 | vec buf; 46 | int first; 47 | int end; 48 | 49 | public: 50 | typedef T Key; 51 | 52 | Queue() : buf(1), first(0), end(0) {} 53 | 54 | void clear (bool dealloc = false) { buf.clear(dealloc); buf.growTo(1); first = end = 0; } 55 | int size () const { return (end >= first) ? end - first : end - first + buf.size(); } 56 | 57 | const T& operator [] (int index) const { assert(index >= 0); assert(index < size()); return buf[(first + index) % buf.size()]; } 58 | T& operator [] (int index) { assert(index >= 0); assert(index < size()); return buf[(first + index) % buf.size()]; } 59 | 60 | T peek () const { assert(first != end); return buf[first]; } 61 | void pop () { assert(first != end); first++; if (first == buf.size()) first = 0; } 62 | void insert(T elem) { // INVARIANT: buf[end] is always unused 63 | buf[end++] = elem; 64 | if (end == buf.size()) end = 0; 65 | if (first == end){ // Resize: 66 | vec tmp((buf.size()*3 + 1) >> 1); 67 | //**/printf("queue alloc: %d elems (%.1f MB)\n", tmp.size(), tmp.size() * sizeof(T) / 1000000.0); 68 | int i = 0; 69 | for (int j = first; j < buf.size(); j++) tmp[i++] = buf[j]; 70 | for (int j = 0 ; j < end ; j++) tmp[i++] = buf[j]; 71 | first = 0; 72 | end = buf.size(); 73 | tmp.moveTo(buf); 74 | } 75 | } 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /mtl/Alg.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /*******************************************************************************************[Alg.h] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef Alg_h 39 | #define Alg_h 40 | 41 | #include "Vec.hh" 42 | 43 | 44 | //================================================================================================= 45 | // Useful functions on vector-like types: 46 | 47 | //================================================================================================= 48 | // Removing and searching for elements: 49 | // 50 | 51 | template 52 | static inline void remove(V& ts, const T& t) 53 | { 54 | int j = 0; 55 | for (; j < ts.size() && ts[j] != t; j++); 56 | assert(j < ts.size()); 57 | for (; j < ts.size()-1; j++) ts[j] = ts[j+1]; 58 | ts.pop(); 59 | } 60 | 61 | 62 | template 63 | static inline bool find(V& ts, const T& t) 64 | { 65 | int j = 0; 66 | for (; j < ts.size() && ts[j] != t; j++); 67 | return j < ts.size(); 68 | } 69 | 70 | 71 | //================================================================================================= 72 | // Copying vectors with support for nested vector types: 73 | // 74 | 75 | // Base case: 76 | template 77 | static inline void copy(const T& from, T& to) 78 | { 79 | to = from; 80 | } 81 | 82 | // Recursive case: 83 | template 84 | static inline void copy(const vec& from, vec& to, bool append = false) 85 | { 86 | if (!append) 87 | to.clear(); 88 | for (int i = 0; i < from.size(); i++){ 89 | to.push(); 90 | copy(from[i], to.last()); 91 | } 92 | } 93 | 94 | template 95 | static inline void append(const vec& from, vec& to){ copy(from, to, true); } 96 | 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /manager/greedyOccurrenceManager.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include "../manager/greedyOccurrenceManager.hh" 19 | 20 | /** 21 | Constructor. 22 | 23 | @param[in] clauses, the set of clauses. 24 | @param[in] nbVar, the number of variable present in the problem. 25 | */ 26 | GreedyOccurrenceManager::GreedyOccurrenceManager(vec > &_clauses, int _nbVar) : CnfOccurrenceManager(_clauses, _nbVar) 27 | { 28 | for(int i = 0 ; i<(nbVar<<1) ; i++) initOccList.push(); 29 | 30 | counterStampViewClause = 0; 31 | for(int i = 0 ; i &occ = initOccList[toInt(l)]; 51 | 52 | for(int j = 0 ; j &cl = clauses[occ[j]]; 60 | bool isSAT = false; 61 | for(int k = 0 ; k &setOfVar, vec &units) 85 | { 86 | for(int i = 0 ; i. 17 | */ 18 | #ifndef MODELCOUNTER_EQUIV 19 | #define MODELCOUNTER_EQUIV 20 | 21 | #include "../utils/Solver.hh" 22 | 23 | class EquivManager 24 | { 25 | private: 26 | vec markedVar; 27 | 28 | public: 29 | 30 | inline void initEquivManager(int nbVar) 31 | { 32 | markedVar.initialize(nbVar, false); 33 | } 34 | 35 | 36 | /** 37 | Take a conflict reference, compute the last UIP, add a learnt 38 | clause, backtrack and enqueue the unit literal. 39 | */ 40 | inline void resolveUnit(Solver &s, CRef confl, Lit l) 41 | { 42 | int bt; 43 | vec learnt_clause; 44 | s.analyzeLastUIP(confl, learnt_clause, bt); 45 | s.cancelUntil(s.decisionLevel() - 1); 46 | assert(learnt_clause[0] == ~l); 47 | s.insertClauseAndPropagate(learnt_clause); 48 | }// resolveUnit 49 | 50 | 51 | /** 52 | For a given literal, collect the set of literal obtained by 53 | unit propagation. 54 | 55 | @param[in] l, the literal we want to collect the unit list 56 | @param[out] listVarPU, the vector where is strore the result 57 | */ 58 | inline bool interCollectUnit(Solver &s, Lit l, vec &listVarPU) 59 | { 60 | listVarPU.clear(); 61 | int posTrail = (s.trail).size(); 62 | s.newDecisionLevel(); 63 | s.uncheckedEnqueue(l); 64 | CRef confl = s.propagate(); 65 | 66 | if(confl != CRef_Undef) // unit literal 67 | { 68 | resolveUnit(s, confl, l); 69 | return false; 70 | } 71 | 72 | for(int j = posTrail + 1; j &v, vec< vec > &equivVar) 100 | { 101 | vec reinit; 102 | 103 | for(int i = 0 ; i &eql = equivVar.last(); 109 | if(interCollectUnit(s, mkLit(v[i], false), eql)) 110 | { 111 | for(int j = 0 ; j<(equivVar.last()).size() ; j++) 112 | if(!markedVar[eql[j]]) 113 | { 114 | markedVar[eql[j]] = true; 115 | reinit.push(eql[j]); 116 | } 117 | 118 | if(eql.size()) eql.push(v[i]); else equivVar.pop(); 119 | } else equivVar.pop(); 120 | } 121 | for(int i = 0 ; i. 17 | */ 18 | #ifndef Minisat_DAG_BinaryDetermOrNode_h 19 | #define Minisat_DAG_BinaryDetermOrNode_h 20 | 21 | #include "DeterministicOrNode.hh" 22 | #include "DAG.hh" 23 | 24 | template class DAG; 25 | template class BinaryDeterministicOrNode : public DAG 26 | { 27 | using DAG::nbEdges; 28 | using DAG::globalStamp; 29 | using DAG::idxOutputStruct; 30 | using DAG::stamp; 31 | 32 | public: 33 | bool saveDecision; 34 | Branch firstBranch, secondBranch; 35 | T nbModels; 36 | 37 | inline void assignFirstBranch(DAG *d, vec &units, vec &fVar) 38 | { 39 | firstBranch.initBranch(units, d, fVar); 40 | nbEdges++; 41 | } 42 | 43 | inline void assignSecondBranch(DAG *d, vec &units, vec &fVar) 44 | { 45 | secondBranch.initBranch(units, d, fVar); 46 | nbEdges++; 47 | } 48 | 49 | BinaryDeterministicOrNode(){} 50 | 51 | BinaryDeterministicOrNode(DAG *l, DAG *r) 52 | { 53 | firstBranch.initBranch(l); 54 | secondBranch.initBranch(r); 55 | } 56 | 57 | BinaryDeterministicOrNode(DAG *l, vec &unitLitL, vec &freeVarL, DAG *r, vec &unitLitR, 58 | vec &freeVarR) 59 | { 60 | assignFirstBranch(l, unitLitL, freeVarL); 61 | assignSecondBranch(r, unitLitR, freeVarR); 62 | } 63 | 64 | inline int getSize_() 65 | { 66 | if(stamp == globalStamp) return 0; 67 | stamp = globalStamp; 68 | return firstBranch.d->getSize_() + secondBranch.d->getSize_(); 69 | } 70 | 71 | inline void printNNF(std::ostream& out, bool certif) 72 | { 73 | if(stamp >= globalStamp) return; 74 | stamp = globalStamp + idxOutputStruct + 1; 75 | int idxCurrent = ++idxOutputStruct; 76 | 77 | out << "o " << idxCurrent << " 0" << endl; 78 | 79 | firstBranch.printNNF(out, certif); 80 | secondBranch.printNNF(out, certif); 81 | 82 | out << idxCurrent << " " << (firstBranch.d)->getIdx() << " "; 83 | Lit *pUnit = &DAG::unitLits[firstBranch.idxUnitLit]; 84 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 85 | out << "0" << endl; 86 | 87 | out << idxCurrent << " " << (secondBranch.d)->getIdx() << " "; 88 | pUnit = &DAG::unitLits[secondBranch.idxUnitLit]; 89 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 90 | out << "0" << endl; 91 | }// printNNF 92 | 93 | 94 | inline bool isSAT() 95 | { 96 | if(stamp == globalStamp) return saveDecision; 97 | stamp = globalStamp; 98 | saveDecision = firstBranch.isSAT() || secondBranch.isSAT(); 99 | 100 | return saveDecision; 101 | }// isSAT 102 | 103 | inline bool isSAT(vec &unitsLitBranches) 104 | { 105 | if(stamp == globalStamp) return saveDecision; 106 | stamp = globalStamp; 107 | saveDecision = firstBranch.isSAT(unitsLitBranches) || secondBranch.isSAT(unitsLitBranches); 108 | 109 | return saveDecision; 110 | }// isSAT 111 | 112 | 113 | inline T computeNbModels() 114 | { 115 | if(stamp == globalStamp) return nbModels; 116 | nbModels = firstBranch.computeNbModels() + secondBranch.computeNbModels(); 117 | stamp = globalStamp; 118 | return nbModels; 119 | }// computeNbModels 120 | 121 | }; 122 | #endif 123 | -------------------------------------------------------------------------------- /DAG/UnaryNode.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_UnaryNode_h 19 | #define Minisat_DAG_UnaryNode_h 20 | 21 | #include "DeterministicOrNode.hh" 22 | #include "DAG.hh" 23 | 24 | template class DAG; 25 | template class UnaryNode : public DAG 26 | { 27 | using DAG::nbEdges; 28 | using DAG::globalStamp; 29 | using DAG::idxOutputStruct; 30 | using DAG::stamp; 31 | 32 | public: 33 | T nbModels; 34 | bool saveDecision; 35 | Branch branch; 36 | 37 | inline void assignBranch(DAG *d, vec &units, vec &fVar) 38 | { 39 | branch.initBranch(units, d, fVar); 40 | nbEdges++; 41 | } 42 | 43 | UnaryNode(DAG *l) 44 | { 45 | branch.initBranch(l); 46 | } 47 | 48 | UnaryNode(DAG *l, vec &unitLit, vec &freeVar){assignBranch(l, unitLit, freeVar);} 49 | 50 | inline int getSize_() 51 | { 52 | if(stamp == globalStamp) return 0; 53 | stamp = globalStamp; 54 | return branch.d->getSize_(); 55 | } 56 | 57 | 58 | inline void printNNF(std::ostream& out, bool certif) 59 | { 60 | if(stamp >= globalStamp) return; 61 | stamp = globalStamp + idxOutputStruct + 1; 62 | int idxCurrent = ++idxOutputStruct; 63 | 64 | out << "o " << idxCurrent << " 0" << endl; 65 | 66 | branch.printNNF(out, certif); 67 | out << idxCurrent << " " << (branch.d)->getIdx() << " "; 68 | Lit *pUnit = &DAG::unitLits[branch.idxUnitLit]; 69 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 70 | out << "0" << endl; 71 | }// printNNF 72 | 73 | 74 | inline bool isSAT() 75 | { 76 | if(stamp == globalStamp) return saveDecision; 77 | saveDecision = branch.isSAT(); 78 | stamp = globalStamp; 79 | return saveDecision; 80 | }// isSAT 81 | 82 | 83 | inline bool isSAT(vec &unitsLitBranches) 84 | { 85 | if(stamp == globalStamp) return saveDecision; 86 | saveDecision = branch.isSAT(unitsLitBranches); 87 | stamp = globalStamp; 88 | return saveDecision; 89 | }// isSAT 90 | 91 | 92 | inline T computeNbModels() 93 | { 94 | if(stamp == globalStamp) return nbModels; 95 | nbModels = branch.computeNbModels(); 96 | stamp = globalStamp; 97 | return nbModels; 98 | }// computeNbModels 99 | 100 | private: 101 | // Used when generating d-DNNF: branches are translated as ImplicitAnd nodes. 102 | // ImplicitAnd* newAnd0; 103 | // ImplicitAnd* newAnd1; 104 | 105 | // findLitFromBranches finds a var that is common to two branches. 106 | // It must be positive in one branch, negative in the other. 107 | // If it is positive in the first one, negative in the second, a positive value will be returned. 108 | // Else it will be negative. 109 | Lit findLitFromBranches() { 110 | assert(false); 111 | return lit_Undef; 112 | } 113 | 114 | void printBranch(Branch& b, int index, std::ostream& out) { 115 | int nbUnitLit = b.nbUnit(); 116 | for (int i = 0; i < nbUnitLit ; i++) { 117 | out << "L " << readableLit((&DAG::unitLits[b.idxUnitLit])[i]) << std::endl; 118 | } 119 | out << "A " << (nbUnitLit + 1) << " "; 120 | for (int i = 0; i < nbUnitLit; i++) { 121 | out << (index - i - 1) << " "; 122 | } 123 | out << DAG::nodeToIndex[b.d] << std::endl; 124 | } 125 | }; 126 | #endif 127 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Authors: Lagniez Jean-Marie 2 | Date: 2017/07/09 3 | 4 | # How to compile 5 | 6 | To compile and print out the help please use the following command lines: 7 | 8 | ```bash 9 | make -j8 10 | ./d4 --help 11 | ``` 12 | 13 | To compile in debug mode (make possible the use of gdb and valgrind) and print out the help please use: 14 | 15 | ```bash 16 | make -j8 d 17 | ./d4_debug --help 18 | ``` 19 | 20 | To compile in profile mode (make possible to use gprof) and print out the help please use: 21 | 22 | ```bash 23 | make -j8 p 24 | ./d4_profil --help 25 | ``` 26 | 27 | 28 | To compile in static mode and print out the help please use: 29 | 30 | ```bash 31 | make -j8 rs 32 | ./d4_static --help 33 | ``` 34 | 35 | # How to run 36 | 37 | To run the model counter: 38 | 39 | ```bash 40 | ./d4 -mc benchTest/littleTest.cnf 41 | ``` 42 | 43 | To run the dDNNF compiler: 44 | 45 | ```bash 46 | ./d4 -dDNNF benchTest/littleTest.cnf 47 | ``` 48 | 49 | To get the resulting decision-DNNF representation in file /tmp/test.nnf please use: 50 | 51 | ```bash 52 | ./d4 -dDNNF benchTest/littleTest.cnf -out=/tmp/test.nnf 53 | cat /tmp/test.nnf 54 | o 1 0 55 | o 2 0 56 | o 3 0 57 | t 4 0 58 | 3 4 -2 3 0 59 | 3 4 2 0 60 | 2 3 -1 0 61 | 2 4 1 0 62 | 1 2 0 63 | ``` 64 | 65 | 66 | Note that the format used now is an extension of the previous format 67 | (as defined in the archive of c2d available from http://reasoning.cs.ucla.edu/c2d/). 68 | The management of propagated literals has been improved in the new format, where 69 | both nodes and arcs are represented. When a literal becomes true at some node 70 | there is no more need to create an AND node and a literal node to capture it. 71 | Instead the literal is attached to the arc connecting the node with its father. 72 | Each line represents a node or an arc, and is terminated by 0. 73 | When a line represents a node it starts with a node type and is followed by its index. 74 | Here are the node types: 75 | 76 | o, for an OR node 77 | f, for a false leaf 78 | t, for a true leaf 79 | a, for an AND node (not present in this example) 80 | 81 | The second argument just after the type of node is its index. 82 | 83 | In the example above the decision-DNNF representation has 84 | 3 OR nodes (1, 2 and 3) and 1 true node (4). 85 | 86 | As expected arcs are used to connect the nodes. 87 | In the file .nnf, arcs are represented by lines starting with a node index 88 | (a positive integer, the source node), followed by another node index 89 | (a positive integer, the target node), and eventually a sequence of literals 90 | that represents the unit literals that become true at the target node. 91 | 92 | 93 | In the example, 3 4 -2 3 0 means that OR node of index 3 is connected to the 94 | true node of index 4 and the literals -2 and 3 are set to true. 95 | 96 | 97 | To get the resulting certified decision-DNNF representation in file /tmp/test.nnf enhanced 98 | with the drat proof saved in /tmp/test.drat, please use: 99 | 100 | ```bash 101 | ./d4 -dDNNF benchTest/littleTest.cnf -out=/tmp/test.nnf -drat=/tmp/test.drat 102 | cat /tmp/test.nnf 103 | o 1 1 0 104 | o 2 2 0 105 | o 3 2 1 0 106 | t 4 0 107 | 3 4 2 -2 3 0 108 | 3 4 2 2 0 109 | 2 3 2 -1 0 110 | 2 4 2 1 0 111 | 1 2 2 0 112 | cat /tmp/test.drat 113 | 1 2 3 0 114 | d 1 2 3 0 115 | ``` 116 | 117 | The format used for certifying the d-DNNF has been sligthly modified in order to gather the clauses that have been used to propagate the unit literals. 118 | Since literals are always associated to decision nodes, this information has been added on these kind of nodes. 119 | More precisely, just after the index of the node we can now find the number of branches the node has. 120 | Then the indexes of the clauses, following the order in the drat file, are given. 121 | 122 | 123 | In the example, 0 1 1 0 means that we are considering an OR node of index 1 which is connected to 1 node. 0 3 2 1 0 means that we are considering an OR node which is connected with 2 other 124 | nodes and such that the clause with the index 1 has been used to progatate some literals on some branches connected to it. 125 | 126 | -------------------------------------------------------------------------------- /heuristics/MinCutPartitioner.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../interfaces/OccurrenceManagerInterface.hh" 29 | #include "../mtl/Vec.hh" 30 | #include "../utils/SolverTypes.hh" 31 | 32 | #include "../interfaces/PartitionerInterface.hh" 33 | #include "../heuristics/MinCutPartitioner.hh" 34 | 35 | using namespace std; 36 | 37 | /** 38 | This function compute a min cut of the graph. 39 | 40 | */ 41 | void MinCutPartition::minCut(vec &component) 42 | { 43 | for(int i = 0 ; i idxClauses; 46 | for(int i = 0 ; igetNbClause() ; i++) 47 | { 48 | vec &c = om->getClause(i); 49 | if(om->isSatisfiedClause(i)) continue; 50 | if(!inCurrentComponent[var(c[0])]) continue; 51 | idxClauses.push(i); 52 | } 53 | 54 | if(idxClauses.size() <= 1) return; 55 | 56 | vec vecEdges; 57 | for(int i = 0 ; i &c = om->getClause(idxClauses[i]); 60 | for(int j = 0 ; j &d = om->getClause(idxClauses[j]); 65 | bool intersect = false; 66 | for(int k = 0 ; !intersect && k > undirected_graph; 77 | typedef boost::property_map::type weight_map_type; 78 | typedef boost::property_traits::value_type weight_type; 79 | 80 | // construct the graph object 81 | edge_t edges[vecEdges.size()]; 82 | weight_type ws[vecEdges.size()]; 83 | for(int i = 0 ; i. 17 | */ 18 | #ifndef DAG_KromFormula_h 19 | #define DAG_KromFormula_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | template class KromFormula : public DAG 25 | { 26 | using DAG::nbEdges; 27 | using DAG::globalStamp; 28 | using DAG::fixedValue; 29 | 30 | private: 31 | vec< vec > clauses; 32 | int stamp; 33 | bool saveDecision; 34 | vec unit; 35 | 36 | public: 37 | KromFormula() 38 | { 39 | stamp = 0; 40 | } 41 | 42 | KromFormula(vec< vec > _clauses) 43 | { 44 | stamp = 0; 45 | 46 | for(int i = 0 ; i< _clauses.size() ; i++) 47 | { 48 | clauses.push(); 49 | _clauses[i].copyTo(clauses.last()); 50 | } 51 | } 52 | 53 | inline void addClause(vec &cl) 54 | { 55 | clauses.push(); 56 | cl.copyTo(clauses.last()); 57 | nbEdges += 3; 58 | }// addClause 59 | 60 | 61 | inline void addUnitLit(Lit l ){unit.push(l);} 62 | 63 | inline T computeNbModels() { assert(0);} 64 | inline void toNNF(std::ostream& out) 65 | { 66 | assert(false); // This should never get called since trueNode is a singleton 67 | } 68 | 69 | inline void printNNF() 70 | { 71 | printf("("); 72 | for(int i = 0 ; i stackPropagated; 104 | saveDecision = true; 105 | 106 | for(int i = 0 ; i. 17 | */ 18 | /***************************************************************************************[System.cc] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #include "System.hh" 39 | 40 | #if defined(__linux__) 41 | 42 | #include 43 | #include 44 | 45 | 46 | // TODO: split the memory reading functions into two: one for reading high-watermark of RSS, and 47 | // one for reading the current virtual memory size. 48 | 49 | static inline int memReadStat(int field) 50 | { 51 | char name[256]; 52 | pid_t pid = getpid(); 53 | int value; 54 | 55 | sprintf(name, "/proc/%d/statm", pid); 56 | FILE* in = fopen(name, "rb"); 57 | if (in == NULL) return 0; 58 | 59 | for (; field >= 0; field--) 60 | if (fscanf(in, "%d", &value) != 1) 61 | printf("ERROR! Failed to parse memory statistics from \"/proc\".\n"), exit(1); 62 | fclose(in); 63 | return value; 64 | } 65 | 66 | 67 | static inline int memReadPeak(void) 68 | { 69 | char name[256]; 70 | pid_t pid = getpid(); 71 | 72 | sprintf(name, "/proc/%d/status", pid); 73 | FILE* in = fopen(name, "rb"); 74 | if (in == NULL) return 0; 75 | 76 | // Find the correct line, beginning with "VmPeak:": 77 | int peak_kb = 0; 78 | while (!feof(in) && fscanf(in, "VmPeak: %d kB", &peak_kb) != 1) 79 | while (!feof(in) && fgetc(in) != '\n') 80 | ; 81 | fclose(in); 82 | 83 | return peak_kb; 84 | } 85 | 86 | double memUsed() { return (double)memReadStat(0) * (double)getpagesize() / (1024*1024); } 87 | double memUsedPeak() { 88 | double peak = memReadPeak() / 1024; 89 | return peak == 0 ? memUsed() : peak; } 90 | 91 | #elif defined(__FreeBSD__) 92 | 93 | double memUsed(void) { 94 | struct rusage ru; 95 | getrusage(RUSAGE_SELF, &ru); 96 | return (double)ru.ru_maxrss / 1024; } 97 | double memUsedPeak(void) { return memUsed(); } 98 | 99 | 100 | #elif defined(__APPLE__) 101 | #include 102 | 103 | double memUsed(void) { 104 | malloc_statistics_t t; 105 | malloc_zone_statistics(NULL, &t); 106 | return (double)t.max_size_in_use / (1024*1024); } 107 | double memUsedPeak(void) { return memUsed(); } 108 | 109 | #else 110 | double memUsed() { 111 | return 0; } 112 | #endif 113 | -------------------------------------------------------------------------------- /utils/HittingSet.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #include 19 | #include "../utils/HittingSet.hh" 20 | 21 | using namespace std; 22 | 23 | /** 24 | Constructor. 25 | 26 | @param[in] nbVar, the number of variables in the problem 27 | */ 28 | HittingSet::HittingSet(int nbVar, ScoringMethod *_sm) 29 | { 30 | sm = _sm; 31 | 32 | for(int i = 0 ; i > &cls, vec &hs) 50 | { 51 | // construct the occurence list 52 | vec occSet; 53 | for(int i = 0 ; i &cl = cls[i]; 56 | for(int j = 0 ; j &cl = cls[i]; 73 | 74 | // take the best literal w.r.t. vs 75 | Lit best = cl[0]; 76 | double bestScore = sm->computeScore(var(best)); 77 | for(int j = 1 ; jcomputeScore(var(cl[j])) > bestScore) 79 | { 80 | best = cl[j]; 81 | bestScore = sm->computeScore(var(best)); 82 | } 83 | 84 | if(!selectedLit[toInt(best)]) 85 | { 86 | hs.push(best); 87 | selectedLit[toInt(best)] = true; 88 | } 89 | } 90 | 91 | // remove useless literals from the hitting set 92 | sort(hs, LitOrderScoringMethod(sm)); 93 | 94 | vec nbSelected; 95 | for(int i = 0 ; i &cl = cls[i]; 99 | for(int j = 0 ; j= 0 ; i--) 105 | { 106 | bool mustKept = false; 107 | Lit l = hs[i]; 108 | vec &ol = occ[toInt(l)]; 109 | 110 | for(int j = 0 ; !mustKept && j > &cls, vec &hs) 131 | { 132 | for(int i = 0 ; i &cl = cls[i]; 138 | bool inHs = false; 139 | for(int j = 0 ; j. 17 | */ 18 | /******************************************************************************************[Sort.h] 19 | Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef Sort_h 39 | #define Sort_h 40 | 41 | #include "Vec.hh" 42 | 43 | //================================================================================================= 44 | // Some sorting algorithms for vec's 45 | 46 | 47 | template 48 | struct LessThan_default { 49 | bool operator () (T x, T y) { return x < y; } 50 | }; 51 | 52 | 53 | template 54 | void selectionSort(T* array, int size, LessThan lt) 55 | { 56 | int i, j, best_i; 57 | T tmp; 58 | 59 | for (i = 0; i < size-1; i++){ 60 | best_i = i; 61 | for (j = i+1; j < size; j++){ 62 | if (lt(array[j], array[best_i])) 63 | best_i = j; 64 | } 65 | tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp; 66 | } 67 | } 68 | template static inline void selectionSort(T* array, int size) { 69 | selectionSort(array, size, LessThan_default()); } 70 | 71 | template 72 | void sort(T* array, int size, LessThan lt) 73 | { 74 | if (size <= 15) 75 | selectionSort(array, size, lt); 76 | 77 | else{ 78 | T pivot = array[size / 2]; 79 | T tmp; 80 | int i = -1; 81 | int j = size; 82 | 83 | for(;;){ 84 | do i++; while(lt(array[i], pivot)); 85 | do j--; while(lt(pivot, array[j])); 86 | 87 | if (i >= j) break; 88 | 89 | tmp = array[i]; array[i] = array[j]; array[j] = tmp; 90 | } 91 | 92 | sort(array , i , lt); 93 | sort(&array[i], size-i, lt); 94 | } 95 | } 96 | template static inline void sort(T* array, int size) { 97 | sort(array, size, LessThan_default()); } 98 | 99 | 100 | //================================================================================================= 101 | // For 'vec's: 102 | 103 | 104 | template void sort(vec& v, LessThan lt) { 105 | sort((T*)v, v.size(), lt); } 106 | template void sort(vec& v) { 107 | sort(v, LessThan_default()); } 108 | 109 | 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /DAG/UnaryNodeCertified.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_UnaryNodeCertified_h 19 | #define Minisat_DAG_UnaryNodeCertified_h 20 | 21 | #include "DeterministicOrNode.hh" 22 | #include "DAG.hh" 23 | 24 | template class DAG; 25 | template class UnaryNodeCertified : public DAG 26 | { 27 | using DAG::nbEdges; 28 | using DAG::globalStamp; 29 | using DAG::idxOutputStruct; 30 | using DAG::stamp; 31 | 32 | public: 33 | T nbModels; 34 | bool saveDecision; 35 | Branch branch; 36 | vec reasonForUnits; 37 | bool fromCache; 38 | 39 | UnaryNodeCertified(DAG *l) 40 | { 41 | if(!l->creator) l->creator = this; 42 | branch.initBranch(l); 43 | fromCache = false; 44 | } 45 | 46 | UnaryNodeCertified(DAG *l, vec &unitLit, bool fromCache_, vec &idxReason, vec &freeVar) 47 | { 48 | branch.initBranch(unitLit, l, freeVar); 49 | nbEdges++; 50 | idxReason.copyTo(reasonForUnits); 51 | fromCache = fromCache_; 52 | } 53 | 54 | inline int getSize_() 55 | { 56 | if(stamp == globalStamp) return 0; 57 | stamp = globalStamp; 58 | return branch.d->getSize_(); 59 | } 60 | 61 | 62 | inline void printNNF(std::ostream& out, bool certif) 63 | { 64 | if(stamp >= globalStamp) return; 65 | stamp = globalStamp + idxOutputStruct + 1; 66 | int idxCurrent = ++idxOutputStruct; 67 | 68 | out << "o " << idxCurrent << " 1 "; 69 | for(int i = 0 ; igetIdx() << (fromCache ? " 1 " : " 2 "); 74 | Lit *pUnit = &DAG::unitLits[branch.idxUnitLit]; 75 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " " ; 76 | out << "0" << endl; 77 | }// printNNF 78 | 79 | 80 | inline bool isSAT() 81 | { 82 | if(stamp == globalStamp) return saveDecision; 83 | saveDecision = branch.isSAT(); 84 | stamp = globalStamp; 85 | return saveDecision; 86 | }// isSAT 87 | 88 | 89 | inline bool isSAT(vec &unitsLitBranches) 90 | { 91 | if(stamp == globalStamp) return saveDecision; 92 | saveDecision = branch.isSAT(unitsLitBranches); 93 | stamp = globalStamp; 94 | return saveDecision; 95 | }// isSAT 96 | 97 | 98 | inline T computeNbModels() 99 | { 100 | if(stamp == globalStamp) return nbModels; 101 | nbModels = branch.computeNbModels(); 102 | stamp = globalStamp; 103 | return nbModels; 104 | }// computeNbModels 105 | 106 | private: 107 | // Used when generating d-DNNF: branches are translated as ImplicitAnd nodes. 108 | // ImplicitAnd* newAnd0; 109 | // ImplicitAnd* newAnd1; 110 | 111 | // findLitFromBranches finds a var that is common to two branches. 112 | // It must be positive in one branch, negative in the other. 113 | // If it is positive in the first one, negative in the second, a positive value will be returned. 114 | // Else it will be negative. 115 | Lit findLitFromBranches() { 116 | assert(false); 117 | return lit_Undef; 118 | } 119 | 120 | void printBranch(Branch& b, int index, std::ostream& out) { 121 | int nbUnitLit = b.nbUnit(); 122 | for (int i = 0; i < nbUnitLit ; i++) { 123 | out << "L " << readableLit((&DAG::unitLits[b.idxUnitLit])[i]) << std::endl; 124 | } 125 | out << "A " << (nbUnitLit + 1) << " "; 126 | for (int i = 0; i < nbUnitLit; i++) { 127 | out << (index - i - 1) << " "; 128 | } 129 | out << DAG::nodeToIndex[b.d] << std::endl; 130 | } 131 | }; 132 | #endif 133 | -------------------------------------------------------------------------------- /DAG/DecomposableAndNode.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_DecompAndNode_h 19 | #define Minisat_DAG_DecompAndNode_h 20 | 21 | #include 22 | #include "DAG.hh" 23 | 24 | #define BLOCK_ALLOC_ALL_CHILDREN 1<<20 25 | 26 | template class DAG; 27 | template class DecomposableAndNode : public DAG 28 | { 29 | public: 30 | using DAG::nbEdges; 31 | using DAG::saveFreeVar; 32 | using DAG::globalStamp; 33 | using DAG::idxOutputStruct; 34 | using DAG::stamp; 35 | 36 | static DAG **allChildren; 37 | static int capSzAllChildren, szAllChildren; 38 | 39 | struct 40 | { 41 | unsigned szChildren:22; 42 | unsigned posInAllChildren:32; 43 | } header; 44 | 45 | DecomposableAndNode(vec *> &sons) 46 | { 47 | header.szChildren = sons.size(); 48 | header.posInAllChildren = giveMeEmplacementChildren(sons.size()); 49 | 50 | DAG **children = &allChildren[header.posInAllChildren]; 51 | for(int i = 0 ; i **) realloc(allChildren, capSzAllChildren * sizeof(DAG*)); 73 | if(!allChildren) 74 | { 75 | printf("Memory out bufferInfo %d\n",(int) (capSzAllChildren * sizeof(DAG))); 76 | exit(30); 77 | } 78 | } 79 | return szAllChildren; 80 | }// giveMeEmplacementChildren 81 | 82 | 83 | inline int getSize_() 84 | { 85 | int cpt = 0; 86 | DAG **children = &allChildren[header.posInAllChildren]; 87 | for(int i = 0 ; igetSize_(); 88 | return 1 + cpt; 89 | } 90 | 91 | 92 | inline void printNNF(std::ostream& out, bool certif) 93 | { 94 | if(stamp >= globalStamp) return; 95 | stamp = globalStamp + idxOutputStruct + 1; 96 | int idxCurrent = ++idxOutputStruct; 97 | 98 | // out << "a " << idxCurrent << " " << header.szChildren << " 0" << endl; 99 | out << "a " << idxCurrent << " 0" << endl; 100 | 101 | DAG **children = &allChildren[header.posInAllChildren]; 102 | for(int i = 0 ; iprintNNF(out, certif); 105 | out << idxCurrent << " " << children[i]->getIdx() << " 0" << endl; 106 | } 107 | }// printNNF 108 | 109 | 110 | inline bool isSAT(vec &unitsLitBranches) 111 | { 112 | DAG **children = &allChildren[header.posInAllChildren]; 113 | for(int i = 0 ; i < header.szChildren ; i++) if(!children[i]->isSAT(unitsLitBranches)) return false; 114 | return true; 115 | } 116 | 117 | 118 | inline T computeNbModels() 119 | { 120 | T nbModels = 1; 121 | DAG **children = &allChildren[header.posInAllChildren]; 122 | for(int i = 0 ; i < header.szChildren ; i++) nbModels *= children[i]->computeNbModels(); 123 | return nbModels; 124 | }// computeNbModels 125 | }; 126 | 127 | // initialize the static attributs 128 | template int DecomposableAndNode::capSzAllChildren{0}; 129 | template int DecomposableAndNode::szAllChildren{0}; 130 | template DAG **DecomposableAndNode::allChildren{NULL}; 131 | #endif 132 | -------------------------------------------------------------------------------- /utils/Dimacs.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /****************************************************************************************[Dimacs.h] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef Dimacs_h 39 | #define Dimacs_h 40 | 41 | #include 42 | 43 | #include "../utils/ParseUtils.hh" 44 | #include "../utils/SolverTypes.hh" 45 | 46 | //================================================================================================= 47 | // DIMACS Parser: 48 | 49 | template static void readClause(B& in, vec& lits) 50 | { 51 | int parsed_lit, var; 52 | lits.clear(); 53 | for (;;) 54 | { 55 | parsed_lit = parseInt(in); 56 | if (parsed_lit == 0) break; 57 | var = abs(parsed_lit)-1; 58 | lits.push( (parsed_lit > 0) ? mkLit(var) : ~mkLit(var) ); 59 | } 60 | }// readClause 61 | 62 | 63 | template static void collectLit(B& in, vec& lits) 64 | { 65 | int parsed_lit, var; 66 | lits.clear(); 67 | for (;;) 68 | { 69 | parsed_lit = parseInt(in); 70 | if(parsed_lit == 0) break; 71 | var = abs(parsed_lit) - 1; 72 | lits.push( (parsed_lit > 0) ? mkLit(var) : ~mkLit(var) ); 73 | } 74 | }// readClause 75 | 76 | template static int parse_DIMACS_main(B& in, vec > &clauses) 77 | { 78 | vec lits; 79 | int vars = 0; 80 | int nbclauses = 0; 81 | int cnt = 0; 82 | for (;;) 83 | { 84 | skipWhitespace(in); 85 | if (*in == EOF) break; 86 | else if (*in == 'p') 87 | { 88 | if(eagerMatch(in, "p cnf")) 89 | { 90 | vars = parseInt(in); 91 | nbclauses = parseInt(in); 92 | }else printf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3); 93 | } 94 | else if (*in == 'c' || *in == 'p' || *in == 'w') skipLine(in); 95 | else 96 | { 97 | cnt++; 98 | readClause(in, lits); 99 | clauses.push(); 100 | lits.copyTo(clauses.last()); 101 | } 102 | } 103 | 104 | if (cnt != clauses.size()) fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of clauses.\n"); 105 | return vars; 106 | } 107 | 108 | // Inserts problem into solver. 109 | static int parse_DIMACS(gzFile input_stream, vec > &clauses) 110 | { 111 | StreamBuffer in(input_stream); 112 | return parse_DIMACS_main(in, clauses); 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /DAG/DeterministicOrNode.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_DetermOrNode_h 19 | #define Minisat_DAG_DetermOrNode_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | template class DeterministicOrNode : public DAG 25 | { 26 | using DAG::nbEdges; 27 | using DAG::globalStamp; 28 | using DAG::idxOutputStruct; 29 | using DAG::stamp; 30 | 31 | public: 32 | T nbModels; 33 | bool saveDecision; 34 | DAG *alreadyCompute; 35 | vec< Branch > sons; 36 | 37 | vec unitSaveLit; 38 | 39 | inline void setUnitSaveLit(vec &u) 40 | { 41 | u.copyTo(unitSaveLit); 42 | } 43 | 44 | DeterministicOrNode(){stamp = 0;} 45 | 46 | inline void addBranch(vec &units, DAG *d, vec &fVar) 47 | { 48 | sons.push(); 49 | (sons.last()).initBranch(units, d, fVar); 50 | nbEdges++; 51 | }// addBranch 52 | 53 | inline void addBranch(vec &units, DAG *d) 54 | { 55 | sons.push(); 56 | vec fVar; 57 | (sons.last()).initBranch(units, d, fVar); 58 | nbEdges++; 59 | }// addBranch 60 | 61 | inline void addBranch(DAG *d) 62 | { 63 | sons.push(); 64 | (sons.last()).initBranch(d); 65 | nbEdges++; 66 | }// addBranch 67 | 68 | inline int getSize_() 69 | { 70 | if(stamp == globalStamp) return 0; 71 | stamp = globalStamp; 72 | int cpt = 0; 73 | for(int i = 0 ; igetSize_(); 74 | return 1 + cpt; 75 | } 76 | 77 | 78 | inline void printNNF(std::ostream& out, bool certif) 79 | { 80 | if(stamp >= globalStamp) return; 81 | stamp = globalStamp + idxOutputStruct + 1; 82 | int idxCurrent = ++idxOutputStruct; 83 | 84 | //out << "o " << idxCurrent << " " << sons.size() << " 0" << endl; 85 | out << "o " << idxCurrent << endl; 86 | 87 | for(int i = 0 ; igetIdx() << " "; 92 | Lit *pUnit = &DAG::unitLits[sons[i].idxUnitLit]; 93 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 94 | out << "0" << endl; 95 | } 96 | }// printNNF 97 | 98 | inline bool isSAT(vec &unitsLitBranches) 99 | { 100 | static int cpt = 0; 101 | int curr = cpt++; 102 | 103 | // printNNF(); 104 | // cout << "call " << curr << " -> " << this << endl; 105 | // cout << "curr: " << curr << " -> " ; showListLit(unitsLitBranches); 106 | 107 | bool stampOK = stamp == globalStamp; 108 | bool sava = saveDecision; 109 | if(0 && stamp == globalStamp) 110 | { 111 | // cout << "caching" << endl; 112 | return saveDecision; 113 | } 114 | 115 | saveDecision = false; 116 | for(int i = 0 ; !saveDecision && i test: " << i << "/" << sons.size() << endl; 119 | saveDecision = sons[i].isSAT(unitsLitBranches); 120 | // cout << curr << " = " << i << " => ret: " << " = " << saveDecision << endl; 121 | } 122 | stamp = globalStamp; 123 | 124 | if(stampOK) assert(saveDecision == sava); 125 | 126 | return saveDecision; 127 | }// computeNbModels 128 | 129 | 130 | inline T computeNbModels() 131 | { 132 | if(stamp == globalStamp) return nbModels; 133 | 134 | nbModels = 0; 135 | for(int i = 0 ; i &trail) 142 | { 143 | cout << "Hello: " << this << endl; 144 | cout << "trail: "; showListLit(trail); 145 | cout << "save: "; showListLit(unitSaveLit); 146 | } 147 | }; 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /DAG/DecomposableAndNodeCerified.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_DecompAndNodeCertified_h 19 | #define Minisat_DAG_DecompAndNodeCertified_h 20 | 21 | #include 22 | #include "DAG.hh" 23 | 24 | #define BLOCK_ALLOC_ALL_CHILDREN 1<<20 25 | 26 | template class DAG; 27 | template class DecomposableAndNodeCertified : public DAG 28 | { 29 | public: 30 | using DAG::nbEdges; 31 | using DAG::saveFreeVar; 32 | using DAG::globalStamp; 33 | using DAG::idxOutputStruct; 34 | using DAG::stamp; 35 | 36 | static DAG **allChildren; 37 | static int capSzAllChildren, szAllChildren; 38 | vec comeFromCache; 39 | 40 | struct 41 | { 42 | unsigned szChildren:22; 43 | unsigned posInAllChildren:32; 44 | } header; 45 | 46 | DecomposableAndNodeCertified(vec *> &sons, vec &comeFromCache_) 47 | { 48 | comeFromCache_.copyTo(comeFromCache); 49 | header.szChildren = sons.size(); 50 | header.posInAllChildren = giveMeEmplacementChildren(sons.size()); 51 | 52 | DAG **children = &allChildren[header.posInAllChildren]; 53 | for(int i = 0 ; i **) realloc(allChildren, capSzAllChildren * sizeof(DAG*)); 75 | if(!allChildren) 76 | { 77 | printf("Memory out bufferInfo %d\n",(int) (capSzAllChildren * sizeof(DAG))); 78 | exit(30); 79 | } 80 | } 81 | return szAllChildren; 82 | }// giveMeEmplacementChildren 83 | 84 | 85 | inline int getSize_() 86 | { 87 | int cpt = 0; 88 | DAG **children = &allChildren[header.posInAllChildren]; 89 | for(int i = 0 ; igetSize_(); 90 | return 1 + cpt; 91 | } 92 | 93 | 94 | inline void printNNF(std::ostream& out, bool certif) 95 | { 96 | if(stamp >= globalStamp) return; 97 | stamp = globalStamp + idxOutputStruct + 1; 98 | int idxCurrent = ++idxOutputStruct; 99 | 100 | out << "a " << idxCurrent << " " << header.szChildren << " 0" << endl; 101 | DAG **children = &allChildren[header.posInAllChildren]; 102 | for(int i = 0 ; iprintNNF(out, certif); 105 | out << idxCurrent << " " << children[i]->getIdx() << (comeFromCache[i] ? " 1" : " 2") << " 0\n"; 106 | } 107 | }// printNNF 108 | 109 | 110 | inline bool isSAT(vec &unitsLitBranches) 111 | { 112 | DAG **children = &allChildren[header.posInAllChildren]; 113 | for(int i = 0 ; i < header.szChildren ; i++) if(!children[i]->isSAT(unitsLitBranches)) return false; 114 | return true; 115 | } 116 | 117 | 118 | inline T computeNbModels() 119 | { 120 | T nbModels = 1; 121 | DAG **children = &allChildren[header.posInAllChildren]; 122 | for(int i = 0 ; i < header.szChildren ; i++) nbModels *= children[i]->computeNbModels(); 123 | return nbModels; 124 | }// computeNbModels 125 | }; 126 | 127 | // initialize the static attributs 128 | template int DecomposableAndNodeCertified::capSzAllChildren{0}; 129 | template int DecomposableAndNodeCertified::szAllChildren{0}; 130 | template DAG **DecomposableAndNodeCertified::allChildren{NULL}; 131 | #endif 132 | -------------------------------------------------------------------------------- /DAG/BinaryDeterministicOrNodeCertified.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef Minisat_DAG_BinaryDetermOrNodeCertified_h 19 | #define Minisat_DAG_BinaryDetermOrNodeCertified_h 20 | 21 | #include "DeterministicOrNode.hh" 22 | #include "DAG.hh" 23 | 24 | template class DAG; 25 | template class BinaryDeterministicOrNodeCertified : public DAG 26 | { 27 | using DAG::nbEdges; 28 | using DAG::globalStamp; 29 | using DAG::idxOutputStruct; 30 | using DAG::stamp; 31 | 32 | public: 33 | bool saveDecision; 34 | Branch firstBranch, secondBranch; 35 | T nbModels; 36 | vec reasonForUnits; 37 | bool fromCacheL, fromCacheR; 38 | 39 | inline void assignFirstBranch(DAG *d, vec &units, vec &fVar) 40 | { 41 | firstBranch.initBranch(units, d, fVar); 42 | nbEdges++; 43 | } 44 | 45 | inline void assignSecondBranch(DAG *d, vec &units, vec &fVar) 46 | { 47 | secondBranch.initBranch(units, d, fVar); 48 | nbEdges++; 49 | } 50 | 51 | BinaryDeterministicOrNodeCertified(){} 52 | 53 | BinaryDeterministicOrNodeCertified(DAG *l, DAG *r) 54 | { 55 | firstBranch.initBranch(l); 56 | secondBranch.initBranch(r); 57 | fromCacheR = false; 58 | fromCacheL = false; 59 | } 60 | 61 | BinaryDeterministicOrNodeCertified(DAG *l, vec &unitLitL, vec &freeVarL, bool fromCacheL_, 62 | DAG *r, vec &unitLitR, vec &freeVarR, bool fromCacheR_, vec &idxReason) 63 | { 64 | assignFirstBranch(l, unitLitL, freeVarL); 65 | assignSecondBranch(r, unitLitR, freeVarR); 66 | idxReason.copyTo(reasonForUnits); 67 | fromCacheR = fromCacheR_; 68 | fromCacheL = fromCacheL_; 69 | } 70 | 71 | inline int getSize_() 72 | { 73 | if(stamp == globalStamp) return 0; 74 | stamp = globalStamp; 75 | return firstBranch.d->getSize_() + secondBranch.d->getSize_(); 76 | } 77 | 78 | 79 | inline void printNNF(std::ostream& out, bool certif) 80 | { 81 | if(stamp >= globalStamp) return; 82 | stamp = globalStamp + idxOutputStruct + 1; 83 | int idxCurrent = ++idxOutputStruct; 84 | 85 | out << "o " << idxCurrent << " 2 "; 86 | for(int i = 0 ; igetIdx() << (fromCacheL ? " 1 " : " 2 "); 93 | Lit *pUnit = &DAG::unitLits[firstBranch.idxUnitLit]; 94 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 95 | out << "0" << endl; 96 | 97 | out << idxCurrent << " " << (secondBranch.d)->getIdx() << (fromCacheR ? " 1 " : " 2 "); 98 | pUnit = &DAG::unitLits[secondBranch.idxUnitLit]; 99 | for( ; *pUnit != lit_Undef ; pUnit++) out << readableLit(*pUnit) << " "; 100 | out << "0" << endl; 101 | }// printNNF 102 | 103 | 104 | inline bool isSAT() 105 | { 106 | if(stamp == globalStamp) return saveDecision; 107 | stamp = globalStamp; 108 | saveDecision = firstBranch.isSAT() || secondBranch.isSAT(); 109 | 110 | return saveDecision; 111 | }// isSAT 112 | 113 | inline bool isSAT(vec &unitsLitBranches) 114 | { 115 | if(stamp == globalStamp) return saveDecision; 116 | stamp = globalStamp; 117 | saveDecision = firstBranch.isSAT(unitsLitBranches) || secondBranch.isSAT(unitsLitBranches); 118 | 119 | return saveDecision; 120 | }// isSAT 121 | 122 | 123 | inline T computeNbModels() 124 | { 125 | if(stamp == globalStamp) return nbModels; 126 | nbModels = firstBranch.computeNbModels() + secondBranch.computeNbModels(); 127 | stamp = globalStamp; 128 | return nbModels; 129 | }// computeNbModels 130 | 131 | }; 132 | #endif 133 | -------------------------------------------------------------------------------- /utils/RenamableHorn.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef UTILS_RENAMABLE_HORN 19 | #define UTILS_RENAMABLE_HORN 20 | 21 | #include 22 | 23 | #include "../utils/SolverTypes.hh" 24 | 25 | using namespace std; 26 | 27 | class RenamableHorn 28 | { 29 | private: 30 | vec > cnf; 31 | vec > occurrences; 32 | vec renamed; 33 | vec countPositive; 34 | vec whereFalse; 35 | vec notHornClauses; 36 | vec makeCount; 37 | vec breakCount; 38 | vec changed; 39 | 40 | vec bestRenaming; 41 | vec bestNotHornClauses; 42 | 43 | void debug(); 44 | public: 45 | RenamableHorn(int nbVar) 46 | { 47 | for(int i = 0 ; i &cl); 64 | int run(int nbRuns, int nbFlips); 65 | 66 | inline vec &getBestRenaming(){return bestRenaming;} 67 | inline vec &getBestNotHornClauses(){return bestNotHornClauses;} 68 | inline vec &getClauseFromIndex(int i){return cnf[i];} 69 | 70 | inline void heuristicInterpretation() 71 | { 72 | for(int i = 0 ; i>5 ; i++) 73 | { 74 | int idxCl = rand() % cnf.size(); 75 | vec &cl = cnf[idxCl]; 76 | 77 | for(int j = 0 ; j &cl) 106 | { 107 | int pos = rand() % cl.size(); 108 | 109 | for(int i = pos ; i. 17 | */ 18 | /**************************************************************************************[Options.cc] 19 | Copyright (c) 2008-2010, Niklas Sorensson 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 22 | associated documentation files (the "Software"), to deal in the Software without restriction, 23 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 24 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in all copies or 28 | substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 31 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 32 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 33 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 34 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | **************************************************************************************************/ 36 | 37 | #include "../mtl/Sort.hh" 38 | #include "Options.hh" 39 | #include "ParseUtils.hh" 40 | 41 | void parseOptions(int& argc, char** argv, bool strict) 42 | { 43 | int i, j; 44 | for (i = j = 1; i < argc; i++){ 45 | const char* str = argv[i]; 46 | if (match(str, "--") && match(str, Option::getHelpPrefixString()) && match(str, "help")){ 47 | if (*str == '\0') 48 | printUsageAndExit(argc, argv); 49 | else if (match(str, "-verb")) 50 | printUsageAndExit(argc, argv, true); 51 | } else { 52 | bool parsed_ok = false; 53 | 54 | for (int k = 0; !parsed_ok && k < Option::getOptionList().size(); k++){ 55 | parsed_ok = Option::getOptionList()[k]->parse(argv[i]); 56 | 57 | // fprintf(stderr, "checking %d: %s against flag <%s> (%s)\n", i, argv[i], Option::getOptionList()[k]->name, parsed_ok ? "ok" : "skip"); 58 | } 59 | 60 | if (!parsed_ok) 61 | { 62 | if (strict && match(argv[i], "-")) 63 | fprintf(stderr, "ERROR! Unknown flag \"%s\". Use '--%shelp' for help.\n", argv[i], Option::getHelpPrefixString()), exit(1); 64 | else argv[j++] = argv[i]; 65 | } 66 | } 67 | } 68 | 69 | argc -= (i - j); 70 | } 71 | 72 | 73 | void setUsageHelp (const char* str){ Option::getUsageString() = str; } 74 | void setHelpPrefixStr (const char* str){ Option::getHelpPrefixString() = str; } 75 | void printUsageAndExit (int argc, char** argv, bool verbose) 76 | { 77 | const char* usage = Option::getUsageString(); 78 | if (usage != NULL) 79 | fprintf(stderr, usage, argv[0]); 80 | 81 | sort(Option::getOptionList(), Option::OptionLt()); 82 | 83 | const char* prev_cat = NULL; 84 | const char* prev_type = NULL; 85 | 86 | 87 | for (int i = 0; i < Option::getOptionList().size(); i++){ 88 | 89 | const char* cat = Option::getOptionList()[i]->category; 90 | const char* type = Option::getOptionList()[i]->type_name; 91 | 92 | if (cat != prev_cat) 93 | fprintf(stderr, "\n%s OPTIONS:\n\n", cat); 94 | else if (type != prev_type) 95 | fprintf(stderr, "\n"); 96 | Option::getOptionList()[i]->help(verbose); 97 | prev_cat = Option::getOptionList()[i]->category; 98 | prev_type = Option::getOptionList()[i]->type_name; 99 | } 100 | 101 | fprintf(stderr, "\nHELP OPTIONS:\n\n"); 102 | fprintf(stderr, " --%shelp Print help message.\n", Option::getHelpPrefixString()); 103 | fprintf(stderr, " --%shelp-verb Print verbose help message.\n", Option::getHelpPrefixString()); 104 | fprintf(stderr, "\n"); 105 | exit(0); 106 | } 107 | 108 | -------------------------------------------------------------------------------- /utils/ParseUtils.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /************************************************************************************[ParseUtils.h] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef ParseUtils_h 39 | #define ParseUtils_h 40 | 41 | #include 42 | #include 43 | 44 | #include 45 | 46 | //------------------------------------------------------------------------------------------------- 47 | // A simple buffered character stream class: 48 | 49 | static const int buffer_size = 1048576; 50 | 51 | 52 | class StreamBuffer { 53 | gzFile in; 54 | unsigned char buf[buffer_size]; 55 | int pos; 56 | int size; 57 | 58 | void assureLookahead() { 59 | if (pos >= size) { 60 | pos = 0; 61 | size = gzread(in, buf, sizeof(buf)); } } 62 | 63 | public: 64 | explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); } 65 | 66 | int operator * () const { return (pos >= size) ? EOF : buf[pos]; } 67 | void operator ++ () { pos++; assureLookahead(); } 68 | int position () const { return pos; } 69 | }; 70 | 71 | 72 | //------------------------------------------------------------------------------------------------- 73 | // End-of-file detection functions for StreamBuffer and char*: 74 | 75 | 76 | static inline bool isEof(StreamBuffer& in) { return *in == EOF; } 77 | static inline bool isEof(const char* in) { return *in == '\0'; } 78 | 79 | //------------------------------------------------------------------------------------------------- 80 | // Generic parse functions parametrized over the input-stream type. 81 | 82 | 83 | template static void skipWhitespace(B& in) { 84 | while ((*in >= 9 && *in <= 13) || *in == 32) 85 | ++in; } 86 | 87 | 88 | template 89 | static void skipLine(B& in) { 90 | for (;;) 91 | { 92 | if (isEof(in)) return; 93 | if (*in == '\n') { ++in; return; } 94 | ++in; } 95 | } 96 | 97 | 98 | template 99 | static int parseInt(B& in) 100 | { 101 | int val = 0; 102 | bool neg = false; 103 | skipWhitespace(in); 104 | if (*in == '-') neg = true, ++in; 105 | else if (*in == '+') ++in; 106 | if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3); 107 | while (*in >= '0' && *in <= '9') 108 | val = val*10 + (*in - '0'), 109 | ++in; 110 | return neg ? -val : val; 111 | } 112 | 113 | 114 | // String matching: in case of a match the input iterator will be advanced the corresponding 115 | // number of characters. 116 | template 117 | static bool match(B& in, const char* str) { 118 | int i; 119 | for (i = 0; str[i] != '\0'; i++) 120 | if (in[i] != str[i]) 121 | return false; 122 | 123 | in += i; 124 | 125 | return true; 126 | } 127 | 128 | // String matching: consumes characters eagerly, but does not require random access iterator. 129 | template 130 | static bool eagerMatch(B& in, const char* str) { 131 | for (; *str != '\0'; ++str, ++in) 132 | if (*str != *in) 133 | return false; 134 | return true; } 135 | 136 | #endif 137 | 138 | 139 | -------------------------------------------------------------------------------- /heuristics/ScoringMethod.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef MODELCOUNTER_VARIABLE_SELECTION 19 | #define MODELCOUNTER_VARIABLE_SELECTION 20 | 21 | #include "../interfaces/OccurrenceManagerInterface.hh" 22 | #include "../utils/SolverTypes.hh" 23 | #include "../utils/Solver.hh" 24 | 25 | class ScoringMethod 26 | { 27 | public: 28 | virtual ~ScoringMethod(){;} 29 | virtual double computeScore(Var v) = 0; 30 | virtual void initStructure(vec &component){} 31 | }; 32 | 33 | /** 34 | The well-known MOM heuristic. 35 | 36 | D. Pretolani. Efficiency and stability of hypergraph sat 37 | algorithms. In D. S. Johnson and M. A. Trick, editors, Second 38 | DIMACS Implementation Challenge. American Mathematical Society, 39 | 1993. 40 | */ 41 | class Mom : public ScoringMethod 42 | { 43 | private: 44 | Solver &s; 45 | OccurrenceManagerInterface *om; 46 | 47 | public: 48 | Mom(Solver &_s, OccurrenceManagerInterface *_om): s(_s), om(_om){} 49 | 50 | inline double computeScore(Var v) 51 | { 52 | assert(om); 53 | int nbBin = om->getNbBinaryClause(v); 54 | Lit lp = mkLit(v, false); 55 | 56 | for(int sign = 0 ; sign<2 ; sign++) 57 | { 58 | vec &occ = om->getVecIdxClause(sign ? lp : ~lp); 59 | 60 | for(int i = 0 ; i 2) continue; 67 | nbBin++; 68 | } 69 | } 70 | 71 | return nbBin * 0.25; 72 | }// computeScore 73 | }; 74 | 75 | /** 76 | The classical VSIDS heuristic. 77 | 78 | Matthew W. Moskewicz, Conor F. Madigan, Ying Zhao, Lintao Zhang, 79 | and Sharad Malik. Chaff: Engineering an Efficient SAT Solver. In 80 | Proceedings of the 38th Design Automation Conference (DAC’01), 2001 81 | */ 82 | class Vsids : public ScoringMethod 83 | { 84 | private: 85 | vec &activity; 86 | 87 | public: 88 | Vsids(vec &ac) : activity(ac){} 89 | inline double computeScore(Var v){return activity[v];} 90 | }; 91 | 92 | 93 | /** 94 | This scoring function favorises the variables which appear in 95 | most clauses. 96 | */ 97 | class Dlcs : public ScoringMethod 98 | { 99 | private: 100 | Solver &s; 101 | OccurrenceManagerInterface *om; 102 | 103 | public: 104 | Dlcs(Solver &_s, OccurrenceManagerInterface *_om): s(_s), om(_om){} 105 | inline double computeScore(Var v){assert(om); return om->getNbClause(v);} 106 | }; 107 | 108 | 109 | /** 110 | This scoring function favorises the varaibles which appear in 111 | most clauses. 112 | 113 | R. G. Jeroslow and J. Wang. Solving propositional satisfiability 114 | problems. Annals of Mathematics and Artificial Intelligence, 115 | 1:167–187, 1990. 116 | */ 117 | class Jwts : public ScoringMethod 118 | { 119 | private: 120 | Solver &s; 121 | OccurrenceManagerInterface *om; 122 | 123 | public: 124 | Jwts(Solver &_s, OccurrenceManagerInterface *_om): s(_s), om(_om){} 125 | 126 | inline double computeScore(Var v) 127 | { 128 | assert(om); 129 | int nbBin = om->getNbBinaryClause(v); 130 | Lit lp = mkLit(v, false); 131 | 132 | double res = nbBin * 0.25; 133 | for(int sign = 0 ; sign<2 ; sign++) 134 | { 135 | vec &occ = om->getVecIdxClause(sign ? lp : ~lp); 136 | 137 | for(int i = 0 ; i 5) continue; 141 | 142 | int nbUnAssigned = 0; 143 | for(int j = 0 ; j &score; 164 | 165 | public: 166 | Vsads(OccurrenceManagerInterface *_om, vec &ac) : om(_om), score(ac){} 167 | inline double computeScore(Var v){assert(om);return score[v] + om->getNbClause(v);} 168 | }; 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /mtl/Alloc.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /*****************************************************************************************[Alloc.h] 19 | Copyright (c) 2008-2010, Niklas Sorensson 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 22 | associated documentation files (the "Software"), to deal in the Software without restriction, 23 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 24 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in all copies or 28 | substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 31 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 32 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 33 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 34 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | **************************************************************************************************/ 36 | 37 | 38 | #ifndef Alloc_h 39 | #define Alloc_h 40 | 41 | #include "XAlloc.hh" 42 | #include "Vec.hh" 43 | 44 | //================================================================================================= 45 | // Simple Region-based memory allocator: 46 | 47 | template 48 | class RegionAllocator 49 | { 50 | T* memory; 51 | uint32_t sz; 52 | uint32_t cap; 53 | uint32_t wasted_; 54 | 55 | void capacity(uint32_t min_cap); 56 | 57 | public: 58 | // TODO: make this a class for better type-checking? 59 | typedef uint32_t Ref; 60 | enum { Ref_Undef = UINT32_MAX }; 61 | enum { Unit_Size = sizeof(uint32_t) }; 62 | 63 | explicit RegionAllocator(uint32_t start_cap = 1024*1024) : memory(NULL), sz(0), cap(0), wasted_(0){ capacity(start_cap); } 64 | ~RegionAllocator() 65 | { 66 | if (memory != NULL) 67 | ::free(memory); 68 | } 69 | 70 | 71 | uint32_t size () const { return sz; } 72 | uint32_t wasted () const { return wasted_; } 73 | 74 | Ref alloc (int size); 75 | void free (int size) { wasted_ += size; } 76 | 77 | // Deref, Load Effective Address (LEA), Inverse of LEA (AEL): 78 | T& operator[](Ref r) { assert(r >= 0 && r < sz); return memory[r]; } 79 | const T& operator[](Ref r) const { assert(r >= 0 && r < sz); return memory[r]; } 80 | 81 | T* lea (Ref r) { assert(r >= 0 && r < sz); return &memory[r]; } 82 | const T* lea (Ref r) const { assert(r >= 0 && r < sz); return &memory[r]; } 83 | Ref ael (const T* t) { assert((void*)t >= (void*)&memory[0] && (void*)t < (void*)&memory[sz-1]); 84 | return (Ref)(t - &memory[0]); } 85 | 86 | void moveTo(RegionAllocator& to) { 87 | if (to.memory != NULL) ::free(to.memory); 88 | to.memory = memory; 89 | to.sz = sz; 90 | to.cap = cap; 91 | to.wasted_ = wasted_; 92 | 93 | memory = NULL; 94 | sz = cap = wasted_ = 0; 95 | } 96 | 97 | 98 | }; 99 | 100 | template 101 | void RegionAllocator::capacity(uint32_t min_cap) 102 | { 103 | if (cap >= min_cap) return; 104 | 105 | uint32_t prev_cap = cap; 106 | while (cap < min_cap){ 107 | // NOTE: Multiply by a factor (13/8) without causing overflow, then add 2 and make the 108 | // result even by clearing the least significant bit. The resulting sequence of capacities 109 | // is carefully chosen to hit a maximum capacity that is close to the '2^32-1' limit when 110 | // using 'uint32_t' as indices so that as much as possible of this space can be used. 111 | uint32_t delta = ((cap >> 1) + (cap >> 3) + 2) & ~1; 112 | cap += delta; 113 | 114 | if (cap <= prev_cap) 115 | throw OutOfMemoryException(); 116 | } 117 | // printf(" .. (%p) cap = %u\n", this, cap); 118 | 119 | assert(cap > 0); 120 | memory = (T*)xrealloc(memory, sizeof(T)*cap); 121 | } 122 | 123 | 124 | template 125 | typename RegionAllocator::Ref 126 | RegionAllocator::alloc(int size) 127 | { 128 | // printf("ALLOC called (this = %p, size = %d)\n", this, size); fflush(stdout); 129 | assert(size > 0); 130 | capacity(sz + size); 131 | 132 | uint32_t prev_sz = sz; 133 | sz += size; 134 | 135 | // Handle overflow: 136 | if (sz < prev_sz) 137 | throw OutOfMemoryException(); 138 | 139 | return prev_sz; 140 | } 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /mtl/Heap.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | /******************************************************************************************[Heap.h] 19 | Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson 20 | Copyright (c) 2007-2010, Niklas Sorensson 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 23 | associated documentation files (the "Software"), to deal in the Software without restriction, 24 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 25 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all copies or 29 | substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 32 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 34 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 35 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | **************************************************************************************************/ 37 | 38 | #ifndef Heap_h 39 | #define Heap_h 40 | 41 | #include "Vec.hh" 42 | 43 | //================================================================================================= 44 | // A heap implementation with support for decrease/increase key. 45 | 46 | 47 | template 48 | class Heap { 49 | Comp lt; // The heap is a minimum-heap with respect to this comparator 50 | vec heap; // Heap of integers 51 | vec indices; // Each integers position (index) in the Heap 52 | 53 | // Index "traversal" functions 54 | static inline int left (int i) { return i*2+1; } 55 | static inline int right (int i) { return (i+1)*2; } 56 | static inline int parent(int i) { return (i-1) >> 1; } 57 | 58 | 59 | void percolateUp(int i) 60 | { 61 | int x = heap[i]; 62 | int p = parent(i); 63 | 64 | while (i != 0 && lt(x, heap[p])){ 65 | heap[i] = heap[p]; 66 | indices[heap[p]] = i; 67 | i = p; 68 | p = parent(p); 69 | } 70 | heap [i] = x; 71 | indices[x] = i; 72 | } 73 | 74 | 75 | void percolateDown(int i) 76 | { 77 | int x = heap[i]; 78 | while (left(i) < heap.size()){ 79 | int child = right(i) < heap.size() && lt(heap[right(i)], heap[left(i)]) ? right(i) : left(i); 80 | if (!lt(heap[child], x)) break; 81 | heap[i] = heap[child]; 82 | indices[heap[i]] = i; 83 | i = child; 84 | } 85 | heap [i] = x; 86 | indices[x] = i; 87 | } 88 | 89 | 90 | public: 91 | Heap(const Comp& c) : lt(c) { } 92 | 93 | int size () const { return heap.size(); } 94 | bool empty () const { return heap.size() == 0; } 95 | bool inHeap (int n) const { return n < indices.size() && indices[n] >= 0; } 96 | int operator[](int index) const { assert(index < heap.size()); return heap[index]; } 97 | 98 | 99 | void decrease (int n) { assert(inHeap(n)); percolateUp (indices[n]); } 100 | void increase (int n) { assert(inHeap(n)); percolateDown(indices[n]); } 101 | 102 | 103 | // Safe variant of insert/decrease/increase: 104 | void update(int n) 105 | { 106 | if (!inHeap(n)) 107 | insert(n); 108 | else { 109 | percolateUp(indices[n]); 110 | percolateDown(indices[n]); } 111 | } 112 | 113 | 114 | void insert(int n) 115 | { 116 | indices.growTo(n+1, -1); 117 | assert(!inHeap(n)); 118 | 119 | indices[n] = heap.size(); 120 | heap.push(n); 121 | percolateUp(indices[n]); 122 | } 123 | 124 | 125 | int removeMin() 126 | { 127 | int x = heap[0]; 128 | heap[0] = heap.last(); 129 | indices[heap[0]] = 0; 130 | indices[x] = -1; 131 | heap.pop(); 132 | if (heap.size() > 1) percolateDown(0); 133 | return x; 134 | } 135 | 136 | 137 | // Rebuild the heap from scratch, using the elements in 'ns': 138 | void build(vec& ns) { 139 | for (int i = 0; i < heap.size(); i++) 140 | indices[heap[i]] = -1; 141 | heap.clear(); 142 | 143 | for (int i = 0; i < ns.size(); i++){ 144 | indices[ns[i]] = i; 145 | heap.push(ns[i]); } 146 | 147 | for (int i = heap.size() / 2 - 1; i >= 0; i--) 148 | percolateDown(i); 149 | } 150 | 151 | void clear(bool dealloc = false) 152 | { 153 | for (int i = 0; i < heap.size(); i++) 154 | indices[heap[i]] = -1; 155 | heap.clear(dealloc); 156 | } 157 | }; 158 | 159 | #endif 160 | -------------------------------------------------------------------------------- /interfaces/BucketManagerInterface.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef INTERFACE_BUCKET_MANAGER 19 | #define INTERFACE_BUCKET_MANAGER 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "../utils/SolverTypes.hh" 26 | #include "../manager/CacheBucket.hh" 27 | 28 | #define ALL 0 29 | #define NB 1 30 | #define NT 2 31 | 32 | #define ONE_OCTET 2 33 | #define TWO_OCTET 3 34 | #define FOUR_OCTET 4 35 | #define EIGHT_OCTET 5 36 | 37 | #define PAGE (1<<29) 38 | 39 | template class BucketManagerInterface 40 | { 41 | protected: 42 | int modeStore; 43 | vec allocateData; 44 | char *data; 45 | unsigned long int sizeData, posInData; 46 | CacheBucket bucket; 47 | 48 | public: 49 | vec> freeSpace; // freespace[i][j] points to a free memory space of size i 50 | unsigned long int allMemory; 51 | unsigned long int freeMemory; 52 | unsigned long int pageData; 53 | 54 | virtual void storeFormula(vec &component, CacheBucket &b) = 0; 55 | inline void setFixeFormula(const char *cacheStore) 56 | { 57 | if(!strcmp(cacheStore, "ALL")) modeStore = ALL; 58 | if(!strcmp(cacheStore, "NB")) modeStore = NB; 59 | if(!strcmp(cacheStore,"NT")) modeStore = NT; 60 | std::cout << "c Strategy: " << modeStore << std::endl; 61 | } 62 | 63 | virtual ~BucketManagerInterface() 64 | { 65 | for(int i = 0 ; i sizeData) 141 | { 142 | int rSz = sizeData - posInData; 143 | while(freeSpace.size() <= rSz) freeSpace.push(); 144 | freeSpace[rSz].push(&data[posInData]); 145 | freeMemory += rSz; 146 | 147 | printf("c Allocate a new page for the cache %lu\n", freeMemory); 148 | posInData = 0; 149 | data = new char[sizeData]; 150 | allocateData.push(data); 151 | 152 | allMemory += sizeData; 153 | } 154 | 155 | ret = &data[posInData]; 156 | posInData += size; 157 | return ret; 158 | } // getArray 159 | 160 | 161 | /** 162 | Release some memory of a given size and store this information in 163 | freespace. 164 | 165 | @param[in] m, the memory we want to release 166 | @param[in] size, the size of the memory block 167 | */ 168 | inline void releaseMemory(char *m, int size) 169 | { 170 | while(freeSpace.size() <= size) freeSpace.push(); 171 | freeSpace[size].push(m); 172 | freeMemory += size; 173 | }// reverseLastBucket 174 | 175 | 176 | /** 177 | Collect the bucket associtated to the set of variable given in 178 | parameter. 179 | @param[in] component, the variable belonging to the connected component 180 | \return a formula put in a bucket 181 | */ 182 | CacheBucket *collectBuckect(vec &component) 183 | { 184 | storeFormula(component, bucket); 185 | return &bucket; 186 | }// collectBuckect 187 | }; 188 | 189 | #endif 190 | -------------------------------------------------------------------------------- /DAG/RenamableHornFormula.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * d4 3 | * Copyright (C) 2020 Univ. Artois & CNRS 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #ifndef DAG_RenambleHornFormula_h 19 | #define DAG_RenambleHornFormula_h 20 | 21 | #include "DAG.hh" 22 | 23 | template class DAG; 24 | template class RenamableHornFormula : public DAG 25 | { 26 | using DAG::nbEdges; 27 | using DAG::globalStamp; 28 | using DAG::fixedValue; 29 | 30 | private: 31 | vec< vec > clauses; 32 | int stamp; 33 | bool saveDecision; 34 | vec unit; 35 | 36 | vec< vec > occurrence; 37 | 38 | public: 39 | RenamableHornFormula() 40 | { 41 | stamp = 0; 42 | } 43 | 44 | RenamableHornFormula(vec< vec > _clauses) 45 | { 46 | stamp = 0; 47 | for(int i = 0 ; i< _clauses.size() ; i++) addClause(_clauses[i]); 48 | } 49 | 50 | inline void addClause(vec &cl) 51 | { 52 | clauses.push(); 53 | cl.copyTo(clauses.last()); 54 | nbEdges += 1 + cl.size(); 55 | 56 | for(int i = 0 ; i= occurrence.size()) occurrence.push(); 59 | occurrence[toInt(cl[i])].push(clauses.size() - 1); 60 | } 61 | }// addClause 62 | 63 | 64 | inline void addUnitLit(Lit l ){unit.push(l);} 65 | 66 | inline T computeNbModels() { assert(0);} 67 | inline void toNNF(std::ostream& out) 68 | { 69 | assert(false); // This should never get called since trueNode is a singleton 70 | } 71 | 72 | inline void printNNF() 73 | { 74 | printf("("); 75 | for(int i = 0 ; i stackPropagated; 107 | saveDecision = true; 108 | 109 | for(int i = 0 ; i isSAT; 113 | vec nbFalse; 114 | for(int i = 0 ; i &cl = clauses[i]; 124 | for(int j = 0 ; !isSAT[i] && j