├── 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