-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNetwork.h
108 lines (88 loc) · 1.88 KB
/
Network.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
#pragma once
#include <unordered_set>
#include <vector>
#include <string>
#include <unordered_map>
#include <random>
using namespace std;
typedef mt19937 RandGenT; //note: minstd_rand0 may be somewhat faster
typedef int node;
//for giving parse errors
class LineReadException: public exception
{
public:
LineReadException(string msg){
wt = msg;
}
virtual const char* what() const throw()
{
return wt.c_str();
}
string wt;
};
//for keeping track of what we are optimizing
enum fitnessName {ICSFit, ECFit, BitscoreSumFit, EvalsSumFit, SizeFit,
GOCFit, S3Fit, S3DenomFit, ICSTimesEC, S3Variant};
string fitnessNameToStr(fitnessName x);
//Edges are undirected, so they are always normalized such that
//the first node is a smaller int than the second.
class Edge{
public:
Edge(node u, node v){
if(u <= v){
n1 = u;
n2 = v;
}
else{
n1 = v;
n2 = u;
}
}
node u(){
return n1;
}
node v(){
return n2;
}
bool operator==(const Edge& other) const{
return n1 == other.n1 && n2 == other.n2;
}
bool operator!=(const Edge& other) const{
return !(*this == other);
}
bool operator<(const Edge& other) const{
/*if(n1 < other.n1){
return true;
}
else if(n1 == other.n1){
return n2 < other.n2;
}
else{
return false;
}*/
return (n1 < other.n1) || (n1 == other.n1 && n2 < other.n2);
}
friend class EdgeHash;
private:
node n1;
node n2;
};
class EdgeHash{
public:
size_t operator()(const Edge& e) const {
return e.n1 ^ e.n2;
}
};
//A network is, for now, just a set of edges. If we
//end up needing real network functionality, I'll add a
//real network library.
class Network{
public:
int degree(node x) const;
Network(string filename);
unordered_set<Edge, EdgeHash> edges;
unordered_map<node,string> nodeToNodeName;
unordered_map<string,node> nodeNameToNode;
vector<vector<node> > adjList;
vector<vector<bool>> adjMatrix;
};