11 #ifndef PERMISSIVE_MATCHING_HPP
12 #define PERMISSIVE_MATCHING_HPP
14 #include <boost/unordered_map.hpp>
18 #define ARRAY_LENGTH MAX_TW
22 class PermissiveMatching;
23 typedef PermissiveMatching BytePermutation;
35 PermissiveMatching(
const unordered_map<byte, byte>* edges = NULL): matched(new byte[ARRAY_LENGTH])
38 for(byte i = 0; i < ARRAY_LENGTH; ++i){
39 const auto edge_iter = edges->find(i);
40 if(edge_iter != edges->end()){
41 const byte edge_target = edge_iter->second;
42 matched[i] = edge_target;
43 assert((edge_target > i) || (matched[edge_target] == i));
44 }
else matched[i] = i;
46 }
else for(byte i = 0; i < ARRAY_LENGTH; ++i) matched[i] = i;
52 memcpy(matched, P.matched, ARRAY_LENGTH);
65 operator size_t()
const
68 for(byte i = 0; i < ARRAY_LENGTH; ++i)
69 result = boost::hash_combine(result, matched[i]);
89 assert(u < ARRAY_LENGTH);
90 assert(v < ARRAY_LENGTH);
92 if((matched[u] != u) || (matched[v] != v))
return false;
100 for(byte i = 0; i < ARRAY_LENGTH; ++i)
101 if(matched[i] != i)
return false;
113 byte* old_matched = matched;
114 DEBUG5(std::cout <<
"permuting "<<*
this<<
" with permutation "<<perm<<std::endl);
115 matched =
new byte[ARRAY_LENGTH];
116 for(byte i = 0; i < ARRAY_LENGTH; ++i) matched[i] = i;
117 for(byte i = 0; i < ARRAY_LENGTH; ++i)
118 matched[perm[i]] = perm[old_matched[i]];
119 delete[] old_matched;
120 DEBUG5(std::cout<<
"-->"<<*
this<<std::endl);
130 byte* old_matched = matched;
131 matched =
new byte[ARRAY_LENGTH];
133 for(byte u = 0; u < ARRAY_LENGTH; ++u){
142 }
while((v != u) && (v != P[v]) && (v != old_matched[v]));
145 if(u > v) result.c++;
150 if(old_matched[u] != u){
155 }
while((w != old_matched[w]) && (w != P[w]));
160 if(old_matched[u] == u){
161 if(deg1_in_both[u]) result.p++;
169 if(deg1_in_both[w] && (u > w)) result.p++;
180 if(old_matched[u] == u){
185 if(deg1_in_both[v] && (u > v)) result.p++;
201 delete[] old_matched;
209 for(byte i = 0; i < ARRAY_LENGTH; ++i) os << (
unsigned)P.matched[i] <<
" ";
217 size_t hash_value(
const PermissiveMatching& P)
bool is_identity() const
return whether everyone matches to itself
Definition: permissive_matching.hpp:98
PermissiveMatching(const PermissiveMatching &P)
copy constructor
Definition: permissive_matching.hpp:50
PathsAndCycles merge_with(const PermissiveMatching &P, const std::bitset< ARRAY_LENGTH > °1_in_both)
TODO: move this out of the permissive matching class as it's unique to the DP code & this should be a...
Definition: permissive_matching.hpp:127
Definition: read_adj_list.hpp:22
size_t hash_value(const boost::unordered_set< T > &S)
a hash computation for an unordered set, XORing its members
Definition: utils.hpp:178
~PermissiveMatching()
destructor
Definition: permissive_matching.hpp:56
bool introduce_edge(const byte u, const byte v)
introduce an edge uv, unless uv is already present OR the insertion would violate the matching constr...
Definition: permissive_matching.hpp:87
byte & operator[](const byte i)
access to the array
Definition: permissive_matching.hpp:81
const byte & operator[](const byte i) const
access to the array
Definition: permissive_matching.hpp:75
PermissiveMatching(const unordered_map< byte, byte > *edges=NULL)
construct from an unordered_map
Definition: permissive_matching.hpp:35
Definition: permissive_matching.hpp:25
void permute(const BytePermutation &perm)
rename the indices according to the given BytePermutation
Definition: permissive_matching.hpp:111
Definition: graph_typedefs.hpp:26