Add duration to edges and use it in table plugin

This commit is contained in:
Michael Krasnyk
2017-01-19 22:52:09 +01:00
committed by Patrick Niklaus
parent c059d15cb9
commit 25baf51a2c
24 changed files with 312 additions and 126 deletions
+6
View File
@@ -778,6 +778,7 @@ Contractor::LoadEdgeExpandedGraph(const ContractorConfig &config,
// Find a segment with zero speed and simultaneously compute the new edge weight
EdgeWeight new_weight = 0;
// TODO MKR add new_duration if needed
auto osm_node_id = header->previous_osm_node_id;
bool skip_edge =
std::find_if(first, last, [&](const auto &segment) {
@@ -789,6 +790,9 @@ Contractor::LoadEdgeExpandedGraph(const ContractorConfig &config,
if (value->speed == 0)
return true;
// TODO MKR add new_duration = ConvertToDuration(segment.segment_length,
// value->speed) if needed
segment_weight =
std::isfinite(value->weight)
? std::round(value->weight * config.weight_multiplier)
@@ -798,6 +802,7 @@ Contractor::LoadEdgeExpandedGraph(const ContractorConfig &config,
// Update the edge weight and the next OSM node ID
osm_node_id = segment.this_osm_node_id;
new_weight += segment_weight;
// TODO MKR new_duration += segment_duration;
return false;
}) != last;
@@ -844,6 +849,7 @@ Contractor::LoadEdgeExpandedGraph(const ContractorConfig &config,
// Update edge weight
inbuffer.weight = new_weight + turn_weight_penalty;
// TODO MKR inbuffer.duration = new_duration + turn_duration_penalty;
}
edge_based_edge_list.emplace_back(std::move(inbuffer));
+5
View File
@@ -39,16 +39,21 @@ GraphContractor::GraphContractor(int nodes,
forward_edge.data.id = reverse_edge.data.id = id;
forward_edge.data.originalEdges = reverse_edge.data.originalEdges = 1;
forward_edge.data.weight = reverse_edge.data.weight = INVALID_EDGE_WEIGHT;
forward_edge.data.duration = reverse_edge.data.duration = MAXIMAL_EDGE_DURATION;
// remove parallel edges
while (i < edges.size() && edges[i].source == source && edges[i].target == target)
{
if (edges[i].data.forward)
{
forward_edge.data.weight = std::min(edges[i].data.weight, forward_edge.data.weight);
forward_edge.data.duration =
std::min(edges[i].data.duration, forward_edge.data.duration);
}
if (edges[i].data.backward)
{
reverse_edge.data.weight = std::min(edges[i].data.weight, reverse_edge.data.weight);
reverse_edge.data.duration =
std::min(edges[i].data.duration, reverse_edge.data.duration);
}
++i;
}
+30 -16
View File
@@ -18,11 +18,13 @@ operator()(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
const auto number_of_targets =
target_indices.empty() ? phantom_nodes.size() : target_indices.size();
const auto number_of_entries = number_of_sources * number_of_targets;
std::vector<EdgeWeight> result_table(number_of_entries, std::numeric_limits<EdgeWeight>::max());
engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade->GetNumberOfNodes());
std::vector<EdgeWeight> weights_table(number_of_entries, INVALID_EDGE_WEIGHT);
std::vector<EdgeWeight> durations_table(number_of_entries, MAXIMAL_EDGE_DURATION);
QueryHeap &query_heap = *(engine_working_data.forward_heap_1);
engine_working_data.InitializeOrClearManyToManyThreadLocalStorage(facade->GetNumberOfNodes());
QueryHeap &query_heap = *(engine_working_data.many_to_many_heap);
SearchSpaceWithBuckets search_space_with_buckets;
@@ -35,13 +37,13 @@ operator()(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
{
query_heap.Insert(phantom.forward_segment_id.id,
phantom.GetForwardWeightPlusOffset(),
phantom.forward_segment_id.id);
{phantom.forward_segment_id.id, phantom.GetForwardDuration()});
}
if (phantom.reverse_segment_id.enabled)
{
query_heap.Insert(phantom.reverse_segment_id.id,
phantom.GetReverseWeightPlusOffset(),
phantom.reverse_segment_id.id);
{phantom.reverse_segment_id.id, phantom.GetReverseDuration()});
}
// explore search space
@@ -62,13 +64,13 @@ operator()(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
{
query_heap.Insert(phantom.forward_segment_id.id,
-phantom.GetForwardWeightPlusOffset(),
phantom.forward_segment_id.id);
{phantom.forward_segment_id.id, -phantom.GetForwardDuration()});
}
if (phantom.reverse_segment_id.enabled)
{
query_heap.Insert(phantom.reverse_segment_id.id,
-phantom.GetReverseWeightPlusOffset(),
phantom.reverse_segment_id.id);
{phantom.reverse_segment_id.id, -phantom.GetReverseDuration()});
}
// explore search space
@@ -79,7 +81,8 @@ operator()(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
number_of_targets,
query_heap,
search_space_with_buckets,
result_table);
weights_table,
durations_table);
}
++row_idx;
};
@@ -116,7 +119,7 @@ operator()(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
}
}
return result_table;
return durations_table;
}
void ManyToManyRouting::ForwardRoutingStep(
@@ -125,10 +128,12 @@ void ManyToManyRouting::ForwardRoutingStep(
const unsigned number_of_targets,
QueryHeap &query_heap,
const SearchSpaceWithBuckets &search_space_with_buckets,
std::vector<EdgeWeight> &result_table) const
std::vector<EdgeWeight> &weights_table,
std::vector<EdgeWeight> &durations_table) const
{
const NodeID node = query_heap.DeleteMin();
const EdgeWeight source_weight = query_heap.GetKey(node);
const EdgeWeight source_duration = query_heap.GetData(node).duration;
// check if each encountered node has an entry
const auto bucket_iterator = search_space_with_buckets.find(node);
@@ -141,21 +146,29 @@ void ManyToManyRouting::ForwardRoutingStep(
// get target id from bucket entry
const unsigned column_idx = current_bucket.target_id;
const EdgeWeight target_weight = current_bucket.weight;
auto &current_weight = result_table[row_idx * number_of_targets + column_idx];
const EdgeWeight target_duration = current_bucket.duration;
auto &current_weight = weights_table[row_idx * number_of_targets + column_idx];
auto &current_duration = durations_table[row_idx * number_of_targets + column_idx];
// check if new weight is better
const EdgeWeight new_weight = source_weight + target_weight;
if (new_weight < 0)
{
const EdgeWeight loop_weight = super::GetLoopWeight(facade, node);
const EdgeWeight loop_weight = super::GetLoopWeight<false>(facade, node);
const EdgeWeight new_weight_with_loop = new_weight + loop_weight;
if (loop_weight != INVALID_EDGE_WEIGHT && new_weight_with_loop >= 0)
{
current_weight = std::min(current_weight, new_weight_with_loop);
current_duration = std::min(current_duration,
source_duration + target_duration +
super::GetLoopWeight<true>(facade, node));
}
}
else if (new_weight < current_weight)
{
result_table[row_idx * number_of_targets + column_idx] = new_weight;
current_weight = new_weight;
current_duration = source_duration + target_duration;
}
}
}
@@ -163,7 +176,7 @@ void ManyToManyRouting::ForwardRoutingStep(
{
return;
}
RelaxOutgoingEdges<true>(facade, node, source_weight, query_heap);
RelaxOutgoingEdges<true>(facade, node, source_weight, source_duration, query_heap);
}
void ManyToManyRouting::BackwardRoutingStep(
@@ -174,16 +187,17 @@ void ManyToManyRouting::BackwardRoutingStep(
{
const NodeID node = query_heap.DeleteMin();
const EdgeWeight target_weight = query_heap.GetKey(node);
const EdgeWeight target_duration = query_heap.GetData(node).duration;
// store settled nodes in search space bucket
search_space_with_buckets[node].emplace_back(column_idx, target_weight);
search_space_with_buckets[node].emplace_back(column_idx, target_weight, target_duration);
if (StallAtNode<false>(facade, node, target_weight, query_heap))
{
return;
}
RelaxOutgoingEdges<false>(facade, node, target_weight, query_heap);
RelaxOutgoingEdges<false>(facade, node, target_weight, target_duration, query_heap);
}
} // namespace routing_algorithms
@@ -127,26 +127,6 @@ void BasicRoutingInterface::RoutingStep(
}
}
EdgeWeight
BasicRoutingInterface::GetLoopWeight(const std::shared_ptr<const datafacade::BaseDataFacade> facade,
NodeID node) const
{
EdgeWeight loop_weight = INVALID_EDGE_WEIGHT;
for (auto edge : facade->GetAdjacentEdgeRange(node))
{
const auto &data = facade->GetEdgeData(edge);
if (data.forward)
{
const NodeID to = facade->GetTarget(edge);
if (to == node)
{
loop_weight = std::min(loop_weight, data.weight);
}
}
}
return loop_weight;
}
/**
* Unpacks a single edge (NodeID->NodeID) from the CH graph down to it's original non-shortcut
* route.
+13
View File
@@ -13,6 +13,7 @@ SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3;
SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap;
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes)
{
@@ -76,5 +77,17 @@ void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned n
reverse_heap_3.reset(new QueryHeap(number_of_nodes));
}
}
void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes)
{
if (many_to_many_heap.get())
{
many_to_many_heap->Clear();
}
else
{
many_to_many_heap.reset(new ManyToManyQueryHeap(number_of_nodes));
}
}
}
}
+9 -2
View File
@@ -544,8 +544,15 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
auto turn_id = m_edge_based_edge_list.size();
auto weight =
boost::numeric_cast<EdgeWeight>(edge_data1.weight + weight_penalty);
m_edge_based_edge_list.emplace_back(
edge_data1.edge_id, edge_data2.edge_id, turn_id, weight, true, false);
auto duration =
boost::numeric_cast<EdgeWeight>(edge_data1.duration + duration_penalty);
m_edge_based_edge_list.emplace_back(edge_data1.edge_id,
edge_data2.edge_id,
turn_id,
weight,
duration,
true,
false);
BOOST_ASSERT(original_edges_counter == m_edge_based_edge_list.size());
BOOST_ASSERT(turn_weight_penalties.size() == turn_id);
+3 -2
View File
@@ -324,6 +324,7 @@ void Extractor::FindComponents(unsigned max_edge_id,
{
struct UncontractedEdgeData
{
EdgeWeight duration;
};
struct InputEdge
{
@@ -353,12 +354,12 @@ void Extractor::FindComponents(unsigned max_edge_id,
BOOST_ASSERT(edge.target <= max_edge_id);
if (edge.forward)
{
edges.push_back({edge.source, edge.target, {}});
edges.push_back({edge.source, edge.target, {edge.duration}});
}
if (edge.backward)
{
edges.push_back({edge.target, edge.source, {}});
edges.push_back({edge.target, edge.source, {edge.duration}});
}
}