forked from smaniu/treewidth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBag.h
More file actions
50 lines (41 loc) · 1.11 KB
/
Bag.h
File metadata and controls
50 lines (41 loc) · 1.11 KB
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
#ifndef Bag_h
#define Bag_h
#include <unordered_set>
#include <vector>
#include <ostream>
//A node in the tree deocomposition
class Bag{
private:
unsigned long id;
std::vector<unsigned long> nodes;
unsigned long parent=0;
std::vector<unsigned long> children;
public:
Bag(unsigned long id, const std::unordered_set<unsigned long> &nodeset){
this->id = id;
nodes.reserve(nodeset.size());
for(unsigned long node:nodeset) nodes.push_back(node);
}
void set_parent(unsigned long parent){
this->parent = parent;
}
void add_to_children(unsigned long node){
children.push_back(node);
}
std::vector<unsigned long>& get_nodes(){
return nodes;
}
friend std::ostream& operator<<(std::ostream& out, Bag& bag);
};
std::ostream& operator<<(std::ostream& out, Bag& bag){
out << bag.id << "\n";
out << bag.nodes.size() << "\n";
for(auto node:bag.nodes) out << node << "\t";
out << "\n";
out << bag.parent << "\n";
out << bag.children.size() << "\n";
for(auto node:bag.children) out << node << "\t";
if(bag.children.size()>0) out << "\n";
return out;
}
#endif /* Bag_h */