Skip to content

Commit cacb162

Browse files
oxidasePatrick Niklaus
authored andcommitted
Review and rebase updates
1 parent 105709c commit cacb162

File tree

5 files changed

+39
-37
lines changed

5 files changed

+39
-37
lines changed

include/customizer/edge_based_graph.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
4646
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
4747

4848
public:
49+
using NodeArrayEntry = typename SuperT::NodeArrayEntry;
50+
using EdgeArrayEntry = typename SuperT::EdgeArrayEntry;
51+
using EdgeOffset = typename SuperT::EdgeOffset;
52+
4953
MultiLevelGraph() = default;
5054
MultiLevelGraph(MultiLevelGraph &&) = default;
5155
MultiLevelGraph(const MultiLevelGraph &) = default;
@@ -74,9 +78,9 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership
7478
}
7579
}
7680

77-
MultiLevelGraph(Vector<typename SuperT::NodeArrayEntry> node_array_,
78-
Vector<typename SuperT::EdgeArrayEntry> edge_array_,
79-
Vector<typename SuperT::EdgeOffset> node_to_edge_offset_,
81+
MultiLevelGraph(Vector<NodeArrayEntry> node_array_,
82+
Vector<EdgeArrayEntry> edge_array_,
83+
Vector<EdgeOffset> node_to_edge_offset_,
8084
Vector<EdgeWeight> node_weights_,
8185
Vector<EdgeDuration> node_durations_,
8286
Vector<bool> is_forward_edge_,

include/partitioner/multi_level_graph.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
149149
return max_border_node_id;
150150
}
151151

152-
auto data() &&
152+
auto data() && // rvalue ref-qualifier is a safety-belt
153153
{
154154
return std::make_tuple(std::move(SuperT::node_array),
155155
std::move(SuperT::edge_array),

src/engine/routing_algorithms/alternative_path_mld.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ RandIt filterUnpackedPathsBySharing(RandIt first,
470470
if (shortest_path.edges.empty())
471471
return last;
472472

473-
std::unordered_set<EdgeID> edges;
474-
edges.reserve(size * shortest_path.edges.size() * (1.25));
473+
std::unordered_set<NodeID> nodes;
474+
nodes.reserve(size * shortest_path.nodes.size() * (1.25));
475475

476-
edges.insert(begin(shortest_path.edges), end(shortest_path.edges));
476+
nodes.insert(begin(shortest_path.nodes), end(shortest_path.nodes));
477477

478478
const auto over_sharing_limit = [&](auto &unpacked) {
479479
if (unpacked.edges.empty())
@@ -482,20 +482,20 @@ RandIt filterUnpackedPathsBySharing(RandIt first,
482482
}
483483

484484
EdgeWeight total_duration = 0;
485-
const auto add_if_seen = [&](const EdgeWeight duration, const EdgeID edge) {
486-
auto edge_duration = facade.GetEdgeData(edge).duration;
487-
total_duration += edge_duration;
488-
if (edges.count(edge) > 0)
485+
const auto add_if_seen = [&](const EdgeWeight duration, const NodeID node) {
486+
auto node_duration = facade.GetNodeDuration(node);
487+
total_duration += node_duration;
488+
if (nodes.count(node) > 0)
489489
{
490-
return duration + edge_duration;
490+
return duration + node_duration;
491491
}
492492
return duration;
493493
};
494494

495-
const auto shared_weight =
496-
std::accumulate(begin(unpacked.edges), end(unpacked.edges), EdgeWeight{0}, add_if_seen);
495+
const auto shared_duration = std::accumulate(
496+
begin(unpacked.nodes), end(unpacked.nodes), EdgeDuration{0}, add_if_seen);
497497

498-
unpacked.sharing = shared_weight / static_cast<double>(total_duration);
498+
unpacked.sharing = shared_duration / static_cast<double>(total_duration);
499499
BOOST_ASSERT(unpacked.sharing >= 0.);
500500
BOOST_ASSERT(unpacked.sharing <= 1.);
501501

@@ -505,7 +505,7 @@ RandIt filterUnpackedPathsBySharing(RandIt first,
505505
}
506506
else
507507
{
508-
edges.insert(begin(unpacked.edges), end(unpacked.edges));
508+
nodes.insert(begin(unpacked.nodes), end(unpacked.nodes));
509509
return false;
510510
}
511511
};

src/engine/routing_algorithms/many_to_many_mld.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,15 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
182182
}
183183

184184
const auto turn_id = data.turn_id;
185-
const auto node_weight =
186-
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to);
187-
const auto node_duration = facade.GetNodeDuration(
188-
DIRECTION == FORWARD_DIRECTION ? node : to); // TODO: remove later
189-
const auto edge_weight = node_weight + facade.GetWeightPenaltyForEdgeID(turn_id);
190-
const auto edge_duration = node_duration + facade.GetDurationPenaltyForEdgeID(turn_id);
185+
const auto node_id = DIRECTION == FORWARD_DIRECTION ? node : facade.GetTarget(edge);
186+
const auto node_weight = facade.GetNodeWeight(node_id);
187+
const auto node_duration = facade.GetNodeDuration(node_id);
188+
const auto turn_weight = node_weight + facade.GetWeightPenaltyForEdgeID(turn_id);
189+
const auto turn_duration = node_duration + facade.GetDurationPenaltyForEdgeID(turn_id);
191190

192-
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
193-
const auto to_weight = weight + edge_weight;
194-
const auto to_duration = duration + edge_duration;
191+
BOOST_ASSERT_MSG(node_weight + turn_weight > 0, "edge weight is invalid");
192+
const auto to_weight = weight + turn_weight;
193+
const auto to_duration = duration + turn_duration;
195194

196195
// New Node discovered -> Add to Heap + Node Info Storage
197196
if (!query_heap.WasInserted(to))
@@ -315,15 +314,10 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
315314
: facade.IsBackwardEdge(edge))
316315
{
317316
const auto turn_id = data.turn_id;
318-
const auto edge_weight =
319-
initial_weight +
320-
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node
321-
: facade.GetTarget(edge)) +
322-
facade.GetWeightPenaltyForEdgeID(turn_id);
323-
const auto edge_duration = initial_duration +
324-
+facade.GetNodeDuration(DIRECTION == FORWARD_DIRECTION
325-
? node
326-
: facade.GetTarget(edge)) +
317+
const auto node_id = DIRECTION == FORWARD_DIRECTION ? node : facade.GetTarget(edge);
318+
const auto edge_weight = initial_weight + facade.GetNodeWeight(node_id) +
319+
facade.GetWeightPenaltyForEdgeID(turn_id);
320+
const auto edge_duration = initial_duration + facade.GetNodeDuration(node_id) +
327321
facade.GetDurationPenaltyForEdgeID(turn_id);
328322

329323
query_heap.Insert(facade.GetTarget(edge), edge_weight, {node, edge_duration});

src/extractor/edge_based_graph_factory.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,13 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N
145145
BOOST_ASSERT(nbe_to_ebn_mapping[edge_id_1] != SPECIAL_NODEID ||
146146
nbe_to_ebn_mapping[edge_id_2] != SPECIAL_NODEID);
147147

148-
// TODO: use the sign bit to distinguish oneway streets that must
149-
// have INVALID_EDGE_WEIGHT node weight values to enforce loop edges
150-
// in contraction
148+
// ⚠ Use the sign bit of node weights to distinguish oneway streets:
149+
// * MSB is set - a node corresponds to a one-way street
150+
// * MSB is clear - a node corresponds to a bidirectional street
151+
// Before using node weights data values must be adjusted:
152+
// * in contraction if MSB is set the node weight is INVALID_EDGE_WEIGHT.
153+
// This adjustment is needed to enforce loop creation for oneways.
154+
// * in other cases node weights must be masked with 0x7fffffff to clear MSB
151155
if (nbe_to_ebn_mapping[edge_id_1] != SPECIAL_NODEID &&
152156
nbe_to_ebn_mapping[edge_id_2] == SPECIAL_NODEID)
153157
m_edge_based_node_weights[nbe_to_ebn_mapping[edge_id_1]] |= 0x80000000;

0 commit comments

Comments
 (0)