-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph_Inlines.hh
122 lines (107 loc) · 2.18 KB
/
Graph_Inlines.hh
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
112
113
114
115
116
117
118
119
120
121
122
/*
@file Graph_inlines.hh
@author Ayoub Ouarrak, [email protected]
@version 1.0
*/
#ifndef GRAPH_INLINES_HH
#define GRAPH_INLINES_HH 1
/** eg. <v. u> */
typedef std::pair<std::string, std::string> link;
/**
@return number of nodes
*/
inline unsigned
Graph::nodes() const {
return _node.size();
}
/**
@return vector of nodes
*/
inline std::vector<std::string>
Graph::_Node() const {
return _node;
}
/**
@return vector of edge
*/
inline std::vector<link>
Graph::_Edge() const {
return _edge;
}
/**
@return weight of edges
*/
inline std::map<link, double>
Graph::_EdgeWeight() const {
return _edgeWeight;
}
/**
@return number of edges
*/
inline unsigned
Graph::edges() const {
return _edge.size();
}
/**
@param v node
@return number of nodes adjacent to v
*/
inline unsigned
Graph::rank(std::string v) const {
return adjacent(v).size();
}
/**
@return minRank = maxRank?
*/
inline bool
Graph::isRegular() const {
return minRank() == maxRank() ? true : false;
}
/**
@return graph oriented or not?
*/
inline bool
Graph::isOriented() const {
return direct;
}
/**
@param node to control
@return exist node?
*/
inline bool
Graph::exist(std::string node) const {
return std::find(_node.begin(), _node.end(), node) != _node.end();
}
/**
@param fromNode first node of edge
@param toNode second node of edge
@return exist edge: (fromNode, toNode)?
*/
inline bool
Graph::hasEdge(std::string fromNode, std::string toNode) const {
return std::find(_edge.begin(), _edge.end(),
std::make_pair(fromNode, toNode)) != _edge.end();
}
/**
@param fromNode first node of edge
@param toNode second node of edge
@return weight of edge: (fromNode, toNode)
*/
inline double
Graph::weight(std::string fromNode, std::string toNode) const {
if(_edgeWeight.find(std::make_pair(fromNode, toNode)) != _edgeWeight.end())
return _edgeWeight.at(std::make_pair(fromNode, toNode));
return 0;
}
/**
Overloaded << operator
@param os ostream object
@param g Graph object
@return ostream object
*/
inline std::ostream&
operator<<(std::ostream& os, const Graph& g) {
g.print(os);
return os;
}
#endif