Skip to content

Commit 9695fa7

Browse files
oxidasePatrick Niklaus
authored andcommitted
Remove weight and duration from customizer::EdgeBasedGraphEdgeData
1 parent fd9bebb commit 9695fa7

File tree

9 files changed

+69
-57
lines changed

9 files changed

+69
-57
lines changed

include/customizer/edge_based_graph.hpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ namespace osrm
1616
namespace customizer
1717
{
1818

19-
// TODO: Change to turn_id only
20-
using EdgeBasedGraphEdgeData = partitioner::EdgeBasedGraphEdgeData;
19+
struct EdgeBasedGraphEdgeData
20+
{
21+
NodeID turn_id; // ID of the edge based node (node based edge)
22+
};
2123

2224
template <typename EdgeDataT, storage::Ownership Ownership> class MultiLevelGraph;
2325

@@ -39,8 +41,8 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
3941
{
4042
private:
4143
using SuperT = partitioner::MultiLevelGraph<EdgeDataT, Ownership>;
42-
using SuperC = partitioner::MultiLevelGraph<partitioner::EdgeBasedGraphEdgeData,
43-
storage::Ownership::Container>;
44+
using PartitionerGraphT = partitioner::MultiLevelGraph<partitioner::EdgeBasedGraphEdgeData,
45+
storage::Ownership::Container>;
4446
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
4547

4648
public:
@@ -50,34 +52,49 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
5052
MultiLevelGraph &operator=(MultiLevelGraph &&) = default;
5153
MultiLevelGraph &operator=(const MultiLevelGraph &) = default;
5254

53-
// TODO: add constructor for EdgeBasedGraphEdgeData
54-
MultiLevelGraph(SuperC &&graph,
55+
MultiLevelGraph(PartitionerGraphT &&graph,
5556
Vector<EdgeWeight> node_weights_,
5657
Vector<EdgeDuration> node_durations_)
5758
: node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_))
5859
{
60+
util::ViewOrVector<PartitionerGraphT::EdgeArrayEntry, storage::Ownership::Container>
61+
original_edge_array;
62+
5963
std::tie(SuperT::node_array,
60-
SuperT::edge_array,
64+
original_edge_array,
6165
SuperT::node_to_edge_offset,
6266
SuperT::connectivity_checksum) = std::move(graph).data();
63-
// TODO: add EdgeArrayEntry shaving
67+
68+
SuperT::edge_array.reserve(original_edge_array.size());
69+
for (const auto &edge : original_edge_array)
70+
{
71+
SuperT::edge_array.push_back({edge.target, {edge.data.turn_id}});
72+
is_forward_edge.push_back(edge.data.forward);
73+
is_backward_edge.push_back(edge.data.backward);
74+
}
6475
}
6576

6677
MultiLevelGraph(Vector<typename SuperT::NodeArrayEntry> node_array_,
6778
Vector<typename SuperT::EdgeArrayEntry> edge_array_,
6879
Vector<typename SuperT::EdgeOffset> node_to_edge_offset_,
6980
Vector<EdgeWeight> node_weights_,
70-
Vector<EdgeDuration> node_durations_)
81+
Vector<EdgeDuration> node_durations_,
82+
Vector<bool> is_forward_edge_,
83+
Vector<bool> is_backward_edge_)
7184
: SuperT(std::move(node_array_), std::move(edge_array_), std::move(node_to_edge_offset_)),
72-
node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_))
85+
node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_)),
86+
is_forward_edge(is_forward_edge_), is_backward_edge(is_backward_edge_)
7387
{
74-
// TODO: add EdgeArrayEntry shaving
7588
}
7689

7790
EdgeWeight GetNodeWeight(NodeID node) const { return node_weights[node]; }
7891

7992
EdgeWeight GetNodeDuration(NodeID node) const { return node_durations[node]; }
8093

94+
bool IsForwardEdge(EdgeID edge) const { return is_forward_edge[edge]; }
95+
96+
bool IsBackwardEdge(EdgeID edge) const { return is_backward_edge[edge]; }
97+
8198
friend void
8299
serialization::read<EdgeDataT, Ownership>(storage::tar::FileReader &reader,
83100
const std::string &name,
@@ -90,6 +107,8 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
90107
protected:
91108
Vector<EdgeWeight> node_weights;
92109
Vector<EdgeDuration> node_durations;
110+
Vector<bool> is_forward_edge;
111+
Vector<bool> is_backward_edge;
93112
};
94113

95114
using MultiLevelEdgeBasedGraph =

include/customizer/serialization.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ inline void read(storage::tar::FileReader &reader,
4343
storage::serialization::read(reader, name + "/node_weights", graph.node_weights);
4444
storage::serialization::read(reader, name + "/node_durations", graph.node_durations);
4545
storage::serialization::read(reader, name + "/edge_array", graph.edge_array);
46+
storage::serialization::read(reader, name + "/is_forward_edge", graph.is_forward_edge);
47+
storage::serialization::read(reader, name + "/is_backward_edge", graph.is_backward_edge);
4648
storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset);
4749
}
4850

@@ -55,6 +57,8 @@ inline void write(storage::tar::FileWriter &writer,
5557
storage::serialization::write(writer, name + "/node_weights", graph.node_weights);
5658
storage::serialization::write(writer, name + "/node_durations", graph.node_durations);
5759
storage::serialization::write(writer, name + "/edge_array", graph.edge_array);
60+
storage::serialization::write(writer, name + "/is_forward_edge", graph.is_forward_edge);
61+
storage::serialization::write(writer, name + "/is_backward_edge", graph.is_backward_edge);
5862
storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset);
5963
}
6064
}

include/engine/datafacade/algorithm_datafacade.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define OSRM_ENGINE_DATAFACADE_ALGORITHM_DATAFACADE_HPP
33

44
#include "contractor/query_edge.hpp"
5+
#include "customizer/edge_based_graph.hpp"
56
#include "extractor/edge_based_edge.hpp"
67
#include "engine/algorithm.hpp"
78

@@ -59,7 +60,7 @@ template <> class AlgorithmDataFacade<CH>
5960
template <> class AlgorithmDataFacade<MLD>
6061
{
6162
public:
62-
using EdgeData = extractor::EdgeBasedEdge::EdgeData;
63+
using EdgeData = customizer::EdgeBasedGraphEdgeData;
6364
using EdgeRange = util::range<EdgeID>;
6465

6566
// search graph access
@@ -77,6 +78,10 @@ template <> class AlgorithmDataFacade<MLD>
7778

7879
virtual EdgeWeight GetNodeDuration(const NodeID node) const = 0; // TODO: to be removed
7980

81+
virtual bool IsForwardEdge(EdgeID edge) const = 0;
82+
83+
virtual bool IsBackwardEdge(EdgeID edge) const = 0;
84+
8085
virtual NodeID GetTarget(const EdgeID e) const = 0;
8186

8287
virtual const EdgeData &GetEdgeData(const EdgeID e) const = 0;

include/engine/datafacade/contiguous_internalmem_datafacade.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,16 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
697697
return query_graph.GetNodeDuration(node);
698698
}
699699

700+
bool IsForwardEdge(const NodeID node) const override final
701+
{
702+
return query_graph.IsForwardEdge(node);
703+
}
704+
705+
bool IsBackwardEdge(const NodeID node) const override final
706+
{
707+
return query_graph.IsBackwardEdge(node);
708+
}
709+
700710
NodeID GetTarget(const EdgeID e) const override final { return query_graph.GetTarget(e); }
701711

702712
const EdgeData &GetEdgeData(const EdgeID e) const override final

include/engine/routing_algorithms/routing_base_mld.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
207207
{
208208
const auto &edge_data = facade.GetEdgeData(edge);
209209

210-
if (DIRECTION == FORWARD_DIRECTION ? edge_data.forward : edge_data.backward)
210+
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
211+
: facade.IsBackwardEdge(edge))
211212
{
212213
const NodeID to = facade.GetTarget(edge);
213214

@@ -218,7 +219,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
218219
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to);
219220
const auto turn_penalty = facade.GetWeightPenaltyForEdgeID(edge_data.turn_id);
220221

221-
BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty);
222+
// TODO: BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty);
222223

223224
const EdgeWeight to_weight = weight + node_weight + turn_penalty;
224225

include/storage/view_factory.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,16 @@ inline auto make_multi_level_graph_view(const SharedDataIndex &index, const std:
332332
index, name + "/node_to_edge_offset");
333333
auto node_weights = make_vector_view<EdgeWeight>(index, name + "/node_weights");
334334
auto node_durations = make_vector_view<EdgeDuration>(index, name + "/node_durations");
335+
auto is_forward_edge = make_vector_view<bool>(index, name + "/is_forward_edge");
336+
auto is_backward_edge = make_vector_view<bool>(index, name + "/is_backward_edge");
335337

336338
return customizer::MultiLevelEdgeBasedGraphView(std::move(node_list),
337339
std::move(edge_list),
338340
std::move(node_to_offset),
339341
std::move(node_weights),
340-
std::move(node_durations));
342+
std::move(node_durations),
343+
std::move(is_forward_edge),
344+
std::move(is_backward_edge));
341345
}
342346

343347
inline auto make_maneuver_overrides_views(const SharedDataIndex &index, const std::string &name)

src/engine/routing_algorithms/many_to_many_mld.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
172172
for (const auto edge : facade.GetBorderEdgeRange(level, node))
173173
{
174174
const auto &data = facade.GetEdgeData(edge);
175-
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
175+
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
176+
: facade.IsBackwardEdge(edge))
176177
{
177178
const NodeID to = facade.GetTarget(edge);
178179
if (facade.ExcludeNode(to))
@@ -310,7 +311,8 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
310311
for (auto edge : facade.GetAdjacentEdgeRange(node))
311312
{
312313
const auto &data = facade.GetEdgeData(edge);
313-
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
314+
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
315+
: facade.IsBackwardEdge(edge))
314316
{
315317
const auto turn_id = data.turn_id;
316318
const auto edge_weight =

src/engine/routing_algorithms/tile_turns.cpp

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,42 +145,8 @@ std::vector<TurnData> generateTurns(const datafacade &facade,
145145
const auto &data = facade.GetEdgeData(edge_based_edge_id);
146146

147147
// Now, calculate the sum of the weight of all the segments.
148-
const auto &geometry =
149-
edge_based_node_info.find(approachedge.edge_based_node_id)->second;
150-
EdgeWeight sum_node_weight = 0;
151-
EdgeDuration sum_node_duration = 0;
152-
if (geometry.is_geometry_forward)
153-
{
154-
const auto approach_weight =
155-
facade.GetUncompressedForwardWeights(geometry.packed_geometry_id);
156-
const auto approach_duration =
157-
facade.GetUncompressedForwardDurations(geometry.packed_geometry_id);
158-
sum_node_weight = std::accumulate(
159-
approach_weight.begin(), approach_weight.end(), EdgeWeight{0});
160-
sum_node_duration = std::accumulate(
161-
approach_duration.begin(), approach_duration.end(), EdgeDuration{0});
162-
}
163-
else
164-
{
165-
const auto approach_weight =
166-
facade.GetUncompressedReverseWeights(geometry.packed_geometry_id);
167-
const auto approach_duration =
168-
facade.GetUncompressedReverseDurations(geometry.packed_geometry_id);
169-
sum_node_weight = std::accumulate(
170-
approach_weight.begin(), approach_weight.end(), EdgeWeight{0});
171-
sum_node_duration = std::accumulate(
172-
approach_duration.begin(), approach_duration.end(), EdgeDuration{0});
173-
}
174-
175-
// The edge.weight is the whole edge weight, which includes the turn
176-
// cost.
177-
// The turn cost is the edge.weight minus the sum of the individual road
178-
// segment weights. This might not be 100% accurate, because some
179-
// intersections include stop signs, traffic signals and other
180-
// penalties, but at this stage, we can't divide those out, so we just
181-
// treat the whole lot as the "turn cost" that we'll stick on the map.
182-
const auto turn_weight = data.weight - sum_node_weight;
183-
const auto turn_duration = data.duration - sum_node_duration;
148+
const auto turn_weight = facade.GetWeightPenaltyForEdgeID(data.turn_id);
149+
const auto turn_duration = facade.GetDurationPenaltyForEdgeID(data.turn_id);
184150
const auto turn_instruction = facade.GetTurnInstructionForEdgeID(data.turn_id);
185151

186152
// Find the three nodes that make up the turn movement)

unit_tests/engine/offline_facade.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,11 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
325325
return {};
326326
}
327327

328-
EdgeWeight GetNodeWeight(const NodeID /*node*/) const
329-
{
330-
return 0;
331-
}
328+
EdgeWeight GetNodeWeight(const NodeID /*node*/) const { return 0; }
329+
330+
bool IsForwardEdge(const NodeID /*edge*/) const { return true; }
331+
332+
bool IsBackwardEdge(const NodeID /*edge*/) const { return true; }
332333

333334
bool HasLaneData(const EdgeID /*id*/) const override { return false; }
334335
NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }

0 commit comments

Comments
 (0)