This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edge.cpp
123 lines (85 loc) · 2.56 KB
/
Edge.cpp
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
123
#include "Edge.h"
#include "Vertex.h"
Edge::Edge(const VertexPtr &src, const VertexPtr &dest, u_int32_t weight)
: m_source (src),
m_destination(dest),
m_weight (weight)
{
}
const pair<VertexPtr, VertexPtr> Edge::getVertices() const
{
auto dest = m_destination.lock();
auto src = m_source.lock();
if(src && dest)
return {src, dest};
return pair<VertexPtr,VertexPtr>({nullptr, nullptr});;
}
const VertexPtr Edge::getDestination() const {
VertexPtr dest = m_destination.lock();
if(dest){
return dest;
}
return nullptr;
}
bool Edge::compareNamesUndirected(const Edge &edge) const
{
bool r1 = (getDestination()->getName() == edge.getDestination()->getName());
bool r2 = (getSource()->getName() == edge.getSource()->getName());
bool r3 = (getDestination()->getName() == edge.getSource()->getName());
bool r4 = (getSource()->getName() == edge.getDestination()->getName());
if((r1 && r2) || (r3 && r4)){
return true;
}
return false;
}
bool Edge::compareNamesDirected(const Edge &edge) const
{
bool r1 = (getDestination()->getName() == edge.getDestination()->getName());
bool r2 = (getSource()->getName() == edge.getSource()->getName());
if(r1 && r2) {
return true;
}
return false;
}
bool Edge::comparePtrsUndirected(const Edge &edge) const
{
bool r1 = (getDestination().get() == edge.getDestination().get());
bool r2 = (getSource().get() == edge.getSource().get());
bool r3 = (getDestination().get() == edge.getSource().get());
bool r4 = (getSource().get() == edge.getDestination().get());
if((r1 && r2) || (r3 && r4)){
return true;
}
return false;
}
bool Edge::comparePtrsDirected(const Edge &edge) const
{
bool r1 = (getDestination().get() == edge.getDestination().get());
bool r2 = (getSource().get() == edge.getSource().get());
if(r1 && r2){
return true;
}
return false;
}
const VertexPtr Edge::getSource() const{
VertexPtr src = m_source.lock();
if(src){
return src;
}
return nullptr;
}
void Edge::print(bool withWeights) const
{
VertexPtr src = m_source.lock();
VertexPtr dest = m_destination.lock();
if(withWeights){
cerr << src->getName() << " - " << dest->getName() << ", " << m_weight << endl;
}else{
cerr << src->getName() << " - " << dest->getName() << ", " << endl;
}
}
bool sortEdgesByWeight(const EdgePtr &l, const EdgePtr &r){
u_int32_t el = l->getWeight();
u_int32_t er = r->getWeight();
return ( el< er);
}