2 #ifndef OPENGM_PARTITIONS_HXX
3 #define OPENGM_PARTITIONS_HXX
11 template<
class I=
size_t,
class L=
size_t>
17 void resize(
size_t N) { buildPartitions(N);}
24 const size_t N = l.size();
27 for(
size_t v1=1; v1<N; ++v1){
29 for(
size_t v2=0; v2<v1; ++v2){
30 if( (el & base) == base){
39 typename std::vector<EdgeLabelType>::iterator it;
40 it = find(partitions.begin(), partitions.end(), el);
42 if(it == partitions.end() )
46 return std::distance(partitions.begin(),it);
50 buildPartitions(l.size());
57 buildPartitions(order);
63 EdgeLabelType indicator = 0;
64 EdgeLabelType base = 1;
66 for(
size_t v1=1; v1<l.size(); ++v1){
67 for(
size_t v2=0; v2<v1; ++v2){
68 indicator += base * (l[v1] == l[v2]);
77 EdgeLabelType indicator = 0;
78 EdgeLabelType base = 1;
80 for(
size_t v1=1; v1<order; ++v1){
81 for(
size_t v2=0; v2<v1; ++v2){
82 indicator += base * (*(begin+v1) == *(begin+v2) );
90 static const size_t Bell[16];
91 static std::vector<EdgeLabelType> partitions;
93 bool increment( std::vector<NodeLabelType>& l){
96 std::vector<NodeLabelType> maxV(N+1,0);
97 for(
size_t i=N; i>0 ; --i)
98 maxV[i-1] = std::max(maxV[i],l[i-1]);
102 if(p==N)
return false;
103 if(l[p]<N-1-p && ( (p==N-1) || (l[p]<=maxV[p+1] )))
108 maxV[p] = std::max(maxV[p+1], l[p]);
110 for(
size_t q=p; q>0;--q){
118 void buildPartitions(
size_t N){
119 if(partitions.size() >= Bell[N])
121 if(N*(N-1)/2>
sizeof(I)*8){
122 throw std::runtime_error(
"Error: EdgeIndexType is to small!");
126 partitions.reserve(Bell[N]);
128 std::vector<NodeLabelType> l(N,0);
130 while( increment(l) ){
135 std::sort(partitions.begin(), partitions.end());
140 template<
class I,
class L>
141 const size_t Partitions<I, L>::Bell[16] = {1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597, 27644437, 190899322, 1382958545};
143 template<
class I,
class L>
144 std::vector<I> Partitions<I, L>::partitions;
size_t label2Index(const IT begin, const size_t order)
EdgeLabelType getPartition(size_t n)
EdgeLabelType label2Number(const std::vector< NodeLabelType > &l)
size_t BellNumber(size_t N)
size_t number2Index(const EdgeLabelType el)
size_t label2Index(const std::vector< NodeLabelType > &l)
void getPartition(const size_t n, std::vector< T > &l)
EdgeLabelType label2Number(IT begin, size_t order)
Enumaration of partitions of a set of N nodes.