-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNetwork.h
45 lines (35 loc) · 924 Bytes
/
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
#ifndef __PSO_NETWORK__
#define __PSO_NETWORK__
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
namespace PSO {
class Network {
public:
Network() {}
Network(int size) : order(size), links(size) {}
virtual ~Network() {}
inline void resize(int new_size) {
clear();
links.resize(new_size);
}
inline void clear() { links.clear(); }
inline set<int>::const_iterator get_link(int i, int j) const {
return links[i].find(j);
}
inline void add_link(int i, int j) {
if (get_link(i,j) != nn_end(i)) links[i].insert(j);
}
inline set<int>::const_iterator nn_begin(int i) const {
return links[i].begin();
}
inline set<int>::const_iterator nn_end(int i) const {
return links[i].end();
}
protected:
int order;
vector< set<int> > links;
};
}
#endif