| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#include "cvc4_private.h" |
| 43 |
|
| 44 |
#ifndef CVC4__THEORY__UF__SYMMETRY_BREAKER_H |
| 45 |
#define CVC4__THEORY__UF__SYMMETRY_BREAKER_H |
| 46 |
|
| 47 |
#include <iostream> |
| 48 |
#include <list> |
| 49 |
#include <unordered_map> |
| 50 |
#include <vector> |
| 51 |
|
| 52 |
#include "context/cdlist.h" |
| 53 |
#include "context/context.h" |
| 54 |
#include "expr/node.h" |
| 55 |
#include "expr/node_builder.h" |
| 56 |
#include "smt/smt_statistics_registry.h" |
| 57 |
#include "util/statistics_registry.h" |
| 58 |
|
| 59 |
namespace CVC4 { |
| 60 |
namespace theory { |
| 61 |
namespace uf { |
| 62 |
|
| 63 |
class SymmetryBreaker : public context::ContextNotifyObj { |
| 64 |
|
| 65 |
class Template { |
| 66 |
Node d_template; |
| 67 |
NodeBuilder<> d_assertions; |
| 68 |
std::unordered_map<TNode, std::set<TNode>, TNodeHashFunction> d_sets; |
| 69 |
std::unordered_map<TNode, TNode, TNodeHashFunction> d_reps; |
| 70 |
|
| 71 |
TNode find(TNode n); |
| 72 |
bool matchRecursive(TNode t, TNode n); |
| 73 |
|
| 74 |
public: |
| 75 |
Template(); |
| 76 |
bool match(TNode n); |
| 77 |
std::unordered_map<TNode, std::set<TNode>, TNodeHashFunction>& partitions() { return d_sets; } |
| 78 |
Node assertions() { |
| 79 |
switch(d_assertions.getNumChildren()) { |
| 80 |
case 0: return Node::null(); |
| 81 |
case 1: return d_assertions[0]; |
| 82 |
default: return Node(d_assertions); |
| 83 |
} |
| 84 |
} |
| 85 |
void reset(); |
| 86 |
}; |
| 87 |
|
| 88 |
public: |
| 89 |
|
| 90 |
typedef std::set<TNode> Permutation; |
| 91 |
typedef std::set<Permutation> Permutations; |
| 92 |
typedef TNode Term; |
| 93 |
typedef std::list<Term> Terms; |
| 94 |
typedef std::set<Term> TermEq; |
| 95 |
typedef std::unordered_map<Term, TermEq, TNodeHashFunction> TermEqs; |
| 96 |
|
| 97 |
private: |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
context::CDList<Node> d_assertionsToRerun; |
| 110 |
bool d_rerunningAssertions; |
| 111 |
|
| 112 |
std::vector<Node> d_phi; |
| 113 |
std::set<TNode> d_phiSet; |
| 114 |
Permutations d_permutations; |
| 115 |
Terms d_terms; |
| 116 |
Template d_template; |
| 117 |
std::unordered_map<Node, Node, NodeHashFunction> d_normalizationCache; |
| 118 |
TermEqs d_termEqs; |
| 119 |
TermEqs d_termEqsOnly; |
| 120 |
|
| 121 |
void clear(); |
| 122 |
void rerunAssertionsIfNecessary(); |
| 123 |
|
| 124 |
void guessPermutations(); |
| 125 |
bool invariantByPermutations(const Permutation& p); |
| 126 |
void selectTerms(const Permutation& p); |
| 127 |
Terms::iterator selectMostPromisingTerm(Terms& terms); |
| 128 |
void insertUsedIn(Term term, const Permutation& p, std::set<Node>& cts); |
| 129 |
Node normInternal(TNode phi, size_t level); |
| 130 |
Node norm(TNode n); |
| 131 |
|
| 132 |
std::string d_name; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
struct Statistics { |
| 137 |
|
| 138 |
IntStat d_clauses; |
| 139 |
IntStat d_units; |
| 140 |
|
| 141 |
IntStat d_permutationSetsConsidered; |
| 142 |
|
| 143 |
IntStat d_permutationSetsInvariant; |
| 144 |
|
| 145 |
TimerStat d_invariantByPermutationsTimer; |
| 146 |
|
| 147 |
TimerStat d_selectTermsTimer; |
| 148 |
|
| 149 |
TimerStat d_initNormalizationTimer; |
| 150 |
|
| 151 |
Statistics(std::string name); |
| 152 |
~Statistics(); |
| 153 |
}; |
| 154 |
|
| 155 |
Statistics d_stats; |
| 156 |
|
| 157 |
protected: |
| 158 |
void contextNotifyPop() override |
| 159 |
{ |
| 160 |
Debug("ufsymm") << "UFSYMM: clearing state due to pop" << std::endl; |
| 161 |
clear(); |
| 162 |
} |
| 163 |
|
| 164 |
public: |
| 165 |
SymmetryBreaker(context::Context* context, std::string name = ""); |
| 166 |
|
| 167 |
void assertFormula(TNode phi); |
| 168 |
void apply(std::vector<Node>& newClauses); |
| 169 |
|
| 170 |
}; |
| 171 |
|
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
std::ostream& operator<<(std::ostream& out, const ::CVC4::theory::uf::SymmetryBreaker::Permutation& p); |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
#endif |