-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupergraph.h
111 lines (89 loc) · 2.46 KB
/
supergraph.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
#ifndef _SUPERGRAPH_H_
#define _SUPERGRAPH_H_
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include "colors.h"
#include "graphlet.h"
namespace graphlets {
class snode;
class edge {
friend class graph;
public:
edge(snode * A, snode * B, unsigned type)
: src_(A),
trg_(B),
type_(type)
{ }
~edge() {}
snode * src() const { return src_; }
snode * trg() const { return trg_; }
unsigned type() const { return type_; }
private:
snode * src_;
snode * trg_;
unsigned type_;
};
class snode {
friend class graph;
public:
snode()
: color_(NULL)
{ }
void setColor(Color * c) { color_ = c; }
std::vector<edge*> const& ins() const { return in_; }
std::vector<edge*> const& outs() const { return out_; }
std::string name_;
Color * color() const { return color_; }
private:
std::vector<edge*> in_;
std::vector<edge*> out_;
Color * color_;
};
class graph {
public:
graph() { }
~graph()
{
for(unsigned i=0;i<nodes_.size();++i)
delete nodes_[i];
for(unsigned i=0;i<edges_.size();++i)
delete edges_[i];
}
snode * addNode() {
snode * n = new snode();
nodes_.push_back(n);
return n;
}
edge * link(snode * A, snode * B, unsigned t) {
edge * e = new edge(A,B,t);
A->out_.push_back(e);
B->in_.push_back(e);
edges_.push_back(e);
return e;
}
void compact();
void todot(int&) const;
void todot(int&,bool string) const;
std::vector<edge*> const& edges() const { return edges_; }
std::vector<snode*> const& nodes() const { return nodes_; }
void mkgraphlets(unordered_map<std::string,int> & cnts,bool docolor, bool doanon);
void mkgraphlets_new(int size, unordered_map<std::string,int> & cnts,bool docolor, bool doanon);
node edge_sets(snode *A, snode *B, snode *C, bool docolor, bool doanon);
node edge_sets(snode *A, std::set<snode*> &nodes, bool docolor, bool doanon);
private:
void merge(snode const* A, snode const* B, snode * C);
void update_edges(snode const*, snode *, edge*);
std::vector<snode*> nodes_;
std::vector<edge*> edges_;
void enumerate_subgraphs(std::set<snode*> ¬Considered,
std::set<snode*> &neighbors,
std::set<snode*> &cur,
int size,
unordered_map<std::string,int> &counts,
bool docolor, bool doanon);
};
}
#endif