-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDetKDecomp.h
89 lines (65 loc) · 3.15 KB
/
DetKDecomp.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
// Models the algorithm det-k-decomp.
//
//////////////////////////////////////////////////////////////////////
#if !defined(CLS_DetKDecomp)
#define CLS_DetKDecomp
#include "Globals.h"
#include "Decomp.h"
#include "Separator.h"
class Hypergraph;
class Hyperedge;
class Hypertree;
class Vertex;
class Subedges;
struct CompCache {
// Separator component already successfully decomposed
list<HyperedgeSharedPtr> succ;
// fractional width for succ components
unordered_map<HyperedgeSharedPtr,double> succFW;
// Separator component not decomposable
list<HyperedgeSharedPtr> failed;
};
class DetKDecomp : public Decomp
{
protected:
mutable unordered_map<SeparatorSharedPtr,CompCache> MyTriedSeps;
// Run BIP algorithm
bool MyBIP;
std::unique_ptr<Subedges> MySubedges;
// Initializes a Boolean array representing a subset selection
virtual int setInitSubset(const VertexSet &Vertices, HyperedgeVector &Edges, vector<int> &Set, vector<bool> &InComp, vector<int> &CovWeights) const;
// Selects the next subset in a Boolean array representing a subset selection
virtual int setNextSubset(const VertexSet &Vertices, HyperedgeVector &Edges, vector<int> &Set, vector<bool> &InComp, vector<int> &CovWeights) const;
// Covers a set of nodes by a set of edges
int coverNodes(HyperedgeVector &Edges, vector<int> &Set, vector<bool> &InComp, vector<int> &CovWeights, size_t Uncovered, bool Reconstr) const;
// Orders hyperedges according to maximum cardinality search
//void orderMCS(Hyperedge **HEdges, int iNbrOfEdges);
// Divides a set of hyperedges into inner hyperedges and those containing given vertices
size_t divideCompEdges(const HyperedgeVector &HEdges, const VertexSet &Vertices, HyperedgeVector &Inner, HyperedgeVector &Bound) const;
// Returns the partitions to a given separator that are known to be decomposable or undecomposable
CompCache &getSepParts(SeparatorSharedPtr &sep) const;
// Checks whether HEdges contains an edge labeled with iLabel
bool containsLabel(list<Hyperedge *> *HEdges, int iLabel);
// Checks whether the parent connector nodes are distributed to different components
//bool isSplitSep(Node **Connector, Node ***ChildConnectors);
// Checks whether a set of edges or a separator covers a set of vertices
bool covers(const HyperedgeVector &Edges, const VertexSet &Vertices) const;
bool covers(const SeparatorSharedPtr &Edges, const VertexSet &Vertices) const {
return covers(Edges->edges(),Vertices);
}
// Builds a hypertree decomposition according to k-decomp by covering connector nodes
virtual HypertreeSharedPtr decomp(const HyperedgeVector &HEdges, const VertexSet &Connector=VertexSet(), int RecLevel = 0) const;
virtual HypertreeSharedPtr decomp(const DecompComponent &comp, int recLevel) const {
return decomp(comp.component(), comp.connector(), recLevel);
}
// Expands cut hypertree nodes
void expandHTree(HypertreeSharedPtr &HTree);
public:
// Constructor
DetKDecomp(const HypergraphSharedPtr &HGraph, int k, bool bip = false);
// Destructor
virtual ~DetKDecomp();
// Constructs a hypertree decomposition of width at most MyK (if it exists)
virtual HypertreeSharedPtr buildHypertree();
};
#endif // !defined(CLS_DetKDecomp)