-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorientedgraph.hpp
More file actions
73 lines (62 loc) · 1.59 KB
/
Copy pathcorientedgraph.hpp
File metadata and controls
73 lines (62 loc) · 1.59 KB
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
#ifndef ORIENTED_GRAPH
#define ORIENTED_GRAPH
#include <iostream>
#include "cpathfinder.hpp"
/*
*the example of the oriented graph implementation
*/
namespace OrientedGraph
{
class CPath;
class CEdge;
class COrientedGraph;
class CEdge : public CAbstractEdge<CPath>
{
private:
CEdge();
size_t e_weight;
public:
CEdge(size_t source_id, size_t destination_id, size_t weight) : CAbstractEdge(source_id, destination_id), e_weight(weight) {}
friend class CPath;
};
class CPath
{
private:
size_t p_length;
public:
CPath(const size_t length = 0) : p_length(length) {}
CPath add(CEdge* edge);
bool operator <(const CPath& path);
size_t get_path_length() const;
};
class COrientedGraph
{
private:
std::vector<std::vector<CEdge*> > g_edges;
public:
COrientedGraph(const int vertice_amount) : g_edges(vertice_amount) {}
std::vector<CEdge*> get(const int vertice_id) const;
void add(CEdge* edge);
};
size_t CPath::get_path_length() const
{
return p_length;
}
CPath CPath::add(CEdge* edge)
{
return CPath(p_length + edge->e_weight);
}
bool CPath::operator <(const CPath& path)
{
return p_length < path.p_length;
}
std::vector<CEdge*> COrientedGraph::get(const int vertice_id) const
{
return g_edges.at(vertice_id);
}
void COrientedGraph::add(CEdge* edge)
{
g_edges[edge->get_source_id()].push_back(edge);
}
} //OrientedGraph
#endif //ORIENTED_GRAPH