Refactor StaticRTree to remove application dependent code

StaticRTree now acts like a container, just returning the input data
(NodeBasedEdge) and not PhantomNodes.
This commit is contained in:
Patrick Niklaus
2015-12-03 20:04:23 +01:00
parent a8e8f04fa3
commit cdb1918973
29 changed files with 742 additions and 1606 deletions
+51 -30
View File
@@ -67,7 +67,7 @@ class ManyToManyRouting final
~ManyToManyRouting() {}
std::shared_ptr<std::vector<EdgeWeight>>
operator()(const PhantomNodeArray &phantom_sources_array, const PhantomNodeArray &phantom_targets_array) const
operator()(const std::vector<PhantomNodePair> &phantom_sources_array, const std::vector<PhantomNodePair> &phantom_targets_array) const
{
const auto number_of_sources = phantom_sources_array.size();
const auto number_of_targets = phantom_targets_array.size();
@@ -83,25 +83,35 @@ class ManyToManyRouting final
SearchSpaceWithBuckets search_space_with_buckets;
unsigned target_id = 0;
for (const std::vector<PhantomNode> &phantom_node_vector : phantom_targets_array)
for (const auto &pair : phantom_targets_array)
{
query_heap.Clear();
// insert target(s) at distance 0
for (const PhantomNode &phantom_node : phantom_node_vector)
if (SPECIAL_NODEID != pair.first.forward_node_id)
{
if (SPECIAL_NODEID != phantom_node.forward_node_id)
{
query_heap.Insert(phantom_node.forward_node_id,
phantom_node.GetForwardWeightPlusOffset(),
phantom_node.forward_node_id);
}
if (SPECIAL_NODEID != phantom_node.reverse_node_id)
{
query_heap.Insert(phantom_node.reverse_node_id,
phantom_node.GetReverseWeightPlusOffset(),
phantom_node.reverse_node_id);
}
query_heap.Insert(pair.first.forward_node_id,
pair.first.GetForwardWeightPlusOffset(),
pair.first.forward_node_id);
}
if (SPECIAL_NODEID != pair.first.reverse_node_id)
{
query_heap.Insert(pair.first.reverse_node_id,
pair.first.GetReverseWeightPlusOffset(),
pair.first.reverse_node_id);
}
if (SPECIAL_NODEID != pair.second.forward_node_id)
{
query_heap.Insert(pair.second.forward_node_id,
pair.second.GetForwardWeightPlusOffset(),
pair.second.forward_node_id);
}
if (SPECIAL_NODEID != pair.second.reverse_node_id)
{
query_heap.Insert(pair.second.reverse_node_id,
pair.second.GetReverseWeightPlusOffset(),
pair.second.reverse_node_id);
}
// explore search space
@@ -114,24 +124,35 @@ class ManyToManyRouting final
// for each source do forward search
unsigned source_id = 0;
for (const std::vector<PhantomNode> &phantom_node_vector : phantom_sources_array)
for (const auto &pair : phantom_sources_array)
{
query_heap.Clear();
for (const PhantomNode &phantom_node : phantom_node_vector)
// insert target(s) at distance 0
if (SPECIAL_NODEID != pair.first.forward_node_id)
{
// insert sources at distance 0
if (SPECIAL_NODEID != phantom_node.forward_node_id)
{
query_heap.Insert(phantom_node.forward_node_id,
-phantom_node.GetForwardWeightPlusOffset(),
phantom_node.forward_node_id);
}
if (SPECIAL_NODEID != phantom_node.reverse_node_id)
{
query_heap.Insert(phantom_node.reverse_node_id,
-phantom_node.GetReverseWeightPlusOffset(),
phantom_node.reverse_node_id);
}
query_heap.Insert(pair.first.forward_node_id,
-pair.first.GetForwardWeightPlusOffset(),
pair.first.forward_node_id);
}
if (SPECIAL_NODEID != pair.first.reverse_node_id)
{
query_heap.Insert(pair.first.reverse_node_id,
-pair.first.GetReverseWeightPlusOffset(),
pair.first.reverse_node_id);
}
if (SPECIAL_NODEID != pair.second.forward_node_id)
{
query_heap.Insert(pair.second.forward_node_id,
-pair.second.GetForwardWeightPlusOffset(),
pair.second.forward_node_id);
}
if (SPECIAL_NODEID != pair.second.reverse_node_id)
{
query_heap.Insert(pair.second.reverse_node_id,
-pair.second.GetReverseWeightPlusOffset(),
pair.second.reverse_node_id);
}
// explore search space
+5 -5
View File
@@ -57,7 +57,7 @@ struct SubMatching
double confidence;
};
using CandidateList = std::vector<std::pair<PhantomNode, double>>;
using CandidateList = std::vector<std::pair<double, PhantomNode>>;
using CandidateLists = std::vector<CandidateList>;
using HMM = HiddenMarkovModel<CandidateLists>;
using SubMatchingList = std::vector<SubMatching>;
@@ -232,7 +232,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
// how likely is candidate s_prime at time t to be emitted?
// FIXME this can be pre-computed
const double emission_pr =
emission_log_probability(candidates_list[t][s_prime].second);
emission_log_probability(candidates_list[t][s_prime].first);
double new_value = prev_viterbi[s] + emission_pr;
if (current_viterbi[s_prime] > new_value)
{
@@ -244,8 +244,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
// get distance diff between loc1/2 and locs/s_prime
const auto network_distance = super::get_network_distance(
forward_heap, reverse_heap, prev_unbroken_timestamps_list[s].first,
current_timestamps_list[s_prime].first);
forward_heap, reverse_heap, prev_unbroken_timestamps_list[s].second,
current_timestamps_list[s_prime].second);
const auto d_t = std::abs(network_distance - haversine_distance);
@@ -365,7 +365,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
const auto location_index = reconstructed_indices[i].second;
matching.indices[i] = timestamp_index;
matching.nodes[i] = candidates_list[timestamp_index][location_index].first;
matching.nodes[i] = candidates_list[timestamp_index][location_index].second;
matching.length += model.path_lengths[timestamp_index][location_index];
matching_debug.add_chosen(timestamp_index, location_index);