Fix endless loop

This commit is contained in:
Patrick Niklaus 2015-09-03 10:40:16 +02:00
parent 8b8a19c75d
commit 70bb082973
2 changed files with 11 additions and 2 deletions

View File

@ -96,6 +96,7 @@ template <class CandidateLists> struct HiddenMarkovModel
path_lengths.resize(candidates_list.size());
suspicious.resize(candidates_list.size());
pruned.resize(candidates_list.size());
breakage.resize(candidates_list.size());
for (const auto i : osrm::irange<std::size_t>(0u, candidates_list.size()))
{
const auto& num_candidates = candidates_list[i].size();

View File

@ -301,14 +301,17 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
{
osrm::matching::SubMatching matching;
// find real end of trace
// not sure if this is really needed
std::size_t parent_timestamp_index = sub_matching_end - 1;
while (parent_timestamp_index >= sub_matching_begin &&
model.breakage[parent_timestamp_index])
{
--parent_timestamp_index;
}
while (sub_matching_begin < sub_matching_end &&
model.breakage[sub_matching_begin])
{
++sub_matching_begin;
}
// matchings that only consist of one candidate are invalid
if (parent_timestamp_index - sub_matching_begin + 1 < 2)
@ -335,6 +338,11 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
reconstructed_indices.emplace_front(parent_timestamp_index, parent_candidate_index);
const auto &next = model.parents[parent_timestamp_index][parent_candidate_index];
// make sure we can never get stuck in this loop
if (parent_timestamp_index == next.first)
{
break;
}
parent_timestamp_index = next.first;
parent_candidate_index = next.second;
}