1 #ifndef EDGE_BASED_EDGE_HPP
2 #define EDGE_BASED_EDGE_HPP
3
4 #include "extractor/travel_mode.hpp"
5 #include "util/typedefs.hpp"
6 #include <tuple>
7
8 namespace osrm
9 {
10 namespace extractor
11 {
12
13 struct EdgeBasedEdge
14 {
15 public:
16 struct EdgeData
17 {
EdgeDataosrm::extractor::EdgeBasedEdge::EdgeData18 EdgeData()
19 : turn_id(0), weight(0), distance(0), duration(0), forward(false), backward(false)
20 {
21 }
22
EdgeDataosrm::extractor::EdgeBasedEdge::EdgeData23 EdgeData(const NodeID turn_id,
24 const EdgeWeight weight,
25 const EdgeDistance distance,
26 const EdgeWeight duration,
27 const bool forward,
28 const bool backward)
29 : turn_id(turn_id), weight(weight), distance(distance), duration(duration),
30 forward(forward), backward(backward)
31 {
32 }
33
34 NodeID turn_id; // ID of the edge based node (node based edge)
35 EdgeWeight weight;
36 EdgeDistance distance;
37 EdgeWeight duration : 30;
38 std::uint32_t forward : 1;
39 std::uint32_t backward : 1;
40
is_unidirectionalosrm::extractor::EdgeBasedEdge::EdgeData41 auto is_unidirectional() const { return !forward || !backward; }
42 };
43
44 EdgeBasedEdge();
45 template <class EdgeT> explicit EdgeBasedEdge(const EdgeT &other);
46 EdgeBasedEdge(const NodeID source,
47 const NodeID target,
48 const NodeID edge_id,
49 const EdgeWeight weight,
50 const EdgeWeight duration,
51 const EdgeDistance distance,
52 const bool forward,
53 const bool backward);
54 EdgeBasedEdge(const NodeID source, const NodeID target, const EdgeBasedEdge::EdgeData &data);
55
56 bool operator<(const EdgeBasedEdge &other) const;
57
58 NodeID source;
59 NodeID target;
60 EdgeData data;
61 };
62 static_assert(sizeof(extractor::EdgeBasedEdge) == 24,
63 "Size of extractor::EdgeBasedEdge type is "
64 "bigger than expected. This will influence "
65 "memory consumption.");
66
67 // Impl.
68
EdgeBasedEdge()69 inline EdgeBasedEdge::EdgeBasedEdge() : source(0), target(0) {}
70
EdgeBasedEdge(const NodeID source,const NodeID target,const NodeID turn_id,const EdgeWeight weight,const EdgeWeight duration,const EdgeDistance distance,const bool forward,const bool backward)71 inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source,
72 const NodeID target,
73 const NodeID turn_id,
74 const EdgeWeight weight,
75 const EdgeWeight duration,
76 const EdgeDistance distance,
77 const bool forward,
78 const bool backward)
79 : source(source), target(target), data{turn_id, weight, distance, duration, forward, backward}
80 {
81 }
82
EdgeBasedEdge(const NodeID source,const NodeID target,const EdgeBasedEdge::EdgeData & data)83 inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source,
84 const NodeID target,
85 const EdgeBasedEdge::EdgeData &data)
86 : source(source), target(target), data{data}
87 {
88 }
89
operator <(const EdgeBasedEdge & other) const90 inline bool EdgeBasedEdge::operator<(const EdgeBasedEdge &other) const
91 {
92 const auto unidirectional = data.is_unidirectional();
93 const auto other_is_unidirectional = other.data.is_unidirectional();
94 // if all items are the same, we want to keep bidirectional edges. due to the `<` operator,
95 // preferring 0 (false) over 1 (true), we need to compare the inverse of `bidirectional`
96 return std::tie(source, target, data.weight, unidirectional) <
97 std::tie(other.source, other.target, other.data.weight, other_is_unidirectional);
98 }
99 } // namespace extractor
100 } // namespace osrm
101
102 #endif /* EDGE_BASED_EDGE_HPP */
103