-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.h
97 lines (80 loc) · 1.76 KB
/
Graph.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
#ifndef GRAPH_H
#define GRAPH_H
#include <vector>
#include <fstream>
#include <string>
#include <boost/dynamic_bitset.hpp>
#include <bits/stdc++.h>
class Graph
{
unsigned int nVertices;
unsigned int nEdges;
unsigned int numActiveVertices;
std::vector<boost::dynamic_bitset<> > adjMat;
std::vector<std::vector<double> > weightedMat;
std::vector<int> degrees;
boost::dynamic_bitset<> active;
std::vector<std::string> labels;
std::vector<std::unordered_set<unsigned int> > adjList;
public:
Graph();
void readGraph(std::ifstream& );
void readWeighted(std::ifstream&);
double density(void);
int maxDegree(void);
int minDegree(void);
boost::dynamic_bitset<> neighbors(int);
boost::dynamic_bitset<> closedNeighbors(int);
std::unordered_set<unsigned int> neighborsList(int);
std::vector<int> wNeighbors(int);
void addEdge(int,int);
void deleteEdge(int,int);
void deleteVertex(int);
void deleteLowerDegreeVertices(int);
void printGraph(void);
void printWeighted(void);
~Graph();
inline int numVertices(void){
return nVertices;
}
inline int numEdges(void){
return nEdges;
}
inline bool edgeExists(int v1,int v2){
return adjMat[v1][v2];
}
inline bool isActive(int i){
return active[i];
}
inline void inactive(int i){
active[i]=false;
}
inline bool hasWeight(int v1, int v2){
if(edgeWeight(v1,v2)!=0)
return true;
else
return false;
}
inline double edgeWeight(int v1, int v2){
return weightedMat[v1][v2];
}
inline bool vertexExists(int v){
return active[v];
}
inline int degree(int v){
return degrees[v];
}
inline std::string label(int v){
return labels[v];
}
inline int indexFromLabel(std::string v){
for (int i = 0; i < labels.size(); ++i)
{
if (labels[i].compare(v)==0)
{
return i;
}
}
}
};
#endif