-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.hpp
84 lines (61 loc) · 1.12 KB
/
graph.hpp
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
#include <vector>
#include <iostream>
#include <string>
using namespace std;
#ifndef NODE_HPP
#define NODE_HPP
class Node {
public:
int idx;
vector<int> neighbors;
vector<float> weights;
string specie;
Node();
Node(int);
void print ();
bool operator==(const Node & other) const;
};
class Component {
public:
int idx;
vector<int> nodes;
string specie;
vector<int> neighbors;
vector<float> weights;
Component();
Component(int);
void print ();
int size();
};
template <typename N>
class Graph {
public:
vector<N> nodes;
vector<int> components;
vector<int> componentSize;
Graph();
N & getNodeFromIdx(int idx);
long getEdgesNb();
void print ();
};
template <typename N>
Graph<N>::Graph() {}
template <typename N>
void Graph<N>::print() {
for (N node : nodes)
node.print();
}
template <typename N>
N & Graph<N>::getNodeFromIdx (int idx) {
if (nodes[idx].idx == idx)
return nodes[idx];
return *(find(nodes.begin(), nodes.end(), Node(idx)));
}
template <typename N>
long Graph<N>::getEdgesNb() {
long edgesNb = 0;
for (N node: nodes)
edgesNb += node.neighbors.size();
return edgesNb / 2;
}
#endif