-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartition.h
142 lines (108 loc) · 4.26 KB
/
Partition.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef PARTITION_H
#define PARTITION_H
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <map>
typedef unsigned int nat;
class int_partition : public std::multiset<nat> {
public:
typedef std::vector<int_partition> vector_of;
typedef std::set<int_partition> set_of;
private:
const vector_of* theLayer;
public:
int_partition();
int_partition(const vector_of& layer);
bool lexico_next();
// Is this a covering refinement of mu?
void BuildListOfCoveringCoarsenings(set_of& out) const;
void BuildListOfCoveringDominators(set_of& out) const;
int GetQuadraticSum() const;
nat GetWeight() const;
void Print(nat spaces) const;
void PrintInline(std::ostream& cout) const;
nat GetFirstPart() const;
const_iterator GetFirstPartIterator() const;
bool IsContainedWithin(const int_partition& mu) const;
};
template<class C_ITR>
struct int_partition_properties {
typedef std::vector<C_ITR> vector_of;
vector_of theCoveringCoarsenings;
vector_of theCoveringRefinements;
vector_of theCoveringDominators;
vector_of theCoveringDominees;
int QuadraticSum;
};
template<class C_ITR>
struct int_partition_pair_properties {
std::vector<C_ITR> theLowestCommonCoarsenings, theHighestCommonRefinements;
};
class int_partition_layer : public int_partition::vector_of
{
public:
typedef std::vector<int_partition_layer> vector_of;
typedef int_partition_properties<const_iterator> properties;
typedef int_partition_pair_properties<const_iterator> pair_properties;
typedef std::vector<const_iterator> vector_of_ptr;
typedef std::set<const_iterator> set_of_ptr;
typedef vector_of_ptr ptr_bin;
typedef std::vector<ptr_bin> vector_of_ptr_bin;
typedef std::pair<const_iterator,const_iterator> ptr_pair;
typedef std::set<const_iterator>*(*collect_function)(std::set<const_iterator>*, const_iterator);
private:
const vector_of* theBank;
nat N;
std::vector<properties> theProperties;
std::map<ptr_pair, pair_properties> thePairProperties;
vector_of_ptr_bin ptrByLength;
vector_of_ptr_bin ptrByMaxPart;
vector_of_ptr BeginByFirstPart;
//void build_bound_recursively(const_iterator i, const_iterator j, const int_partition& intersection);
//void build_bound_naively(const_iterator i1, const_iterator i2);
const std::vector<set_of_ptr>& init_collections(std::vector<set_of_ptr>& collection, const vector_of_ptr& ptrs) const;
void build_intersection(set_of_ptr& intersection, const std::vector<set_of_ptr>& collection) const;
void test_sizes_are_equal(const set_of_ptr& intersection) const;
//const_iterator collect_naively(const_iterator i1, const_iterator i2, std::function<collect_function> collect) const;
//const_iterator find_union_partition(const_iterator i, const int_partition& intersection, nat m) const;
public:
int_partition_layer();
int_partition_layer(const vector_of& bank, nat n);
void Build();
void BuildBins();
void BuildProperties();
// Algorithms
ptr_pair BuildPair(const_iterator i, const_iterator j) const;
//void BuildPairBounds();
void BuildHighestCommonRefinements(vector_of_ptr& out, const vector_of_ptr& ptrs) const;
void BuildLowestCommonCoarsenings(vector_of_ptr& out, const vector_of_ptr& ptrs) const;
// Property Getters
const properties& GetProperties(const_iterator i) const;
const std::vector<const_iterator>& GetHighestCommonRefinements(const_iterator i, const_iterator j) const;
const std::vector<const_iterator>& GetLowestCommonCoarsenings(const_iterator i, const_iterator j) const;
// Lattice Getters
const_iterator GetMax() const { return begin(); }
const_iterator GetMin() const { return empty()?end():end() - 1; }
const_iterator FindFromRaw(const int_partition& raw) const;
// Weight Getters
nat GetWeight() const;
operator nat() const;
// Get Other Layers
const int_partition_layer& operator()(nat n) const;
};
class int_partition_bank : public int_partition_layer::vector_of
{
nat max_n;
public:
int_partition_bank(nat n);
void Build();
void BuildProperties();
void BuildPairBounds();
nat GetMaxWeight() const;
void Print() const;
};
#endif