Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero Distance Match Leg Causes Nan Duration #2229

Merged
merged 3 commits into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/thor/trace_route_action.cc
Expand Up @@ -613,8 +613,10 @@ thor_worker_t::map_match(Api& request) {
// we need to scale the elapsed time of the current edge to undo what FormPath did
double begin_pct = begin_trimmed ? std::get<2>(edge_group)->distance_along : 0;
double end_pct = end_trimmed ? std::get<3>(edge_group)->distance_along : 1;
double begin_edge_scale = 1.0 / ((trivial_group ? end_pct : 1) - begin_pct);
double end_edge_scale = 1.0 / (end_pct - (trivial_group ? begin_pct : 0));
double dist_from_begin = (trivial_group ? end_pct : 1) - begin_pct;
double dist_to_end = end_pct - (trivial_group ? begin_pct : 0);
double begin_edge_scale = dist_from_begin > 0 ? 1 / dist_from_begin : 0;
double end_edge_scale = dist_to_end > 0 ? 1 / dist_to_end : 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero-out the multiplier if its a degenerate leg


// we get the time up to the last edge before this begin edge if any. we also remove
// the turn cost at the begging of this edge if there is any
Expand Down
22 changes: 22 additions & 0 deletions test/mapmatch.cc
Expand Up @@ -1045,6 +1045,28 @@ TEST(Mapmatch, test_intersection_matching) {
}
}

TEST(Mapmatch, test_degenerate_match) {
std::vector<std::string> test_cases = {
R"({"costing":"auto","format":"osrm","shape_match":"map_snap","shape":[
{"lat": 52.0981280, "lon": 5.1297250, "type": "break", "time":10},
{"lat": 52.0981280, "lon": 5.1297250, "type": "break", "time":169}],
"trace_options": {"interpolation_distance": 0}})",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is important, we never saw much of this before because people generally dont want to skip interpolation. i would argue they still dont 😄

};
tyr::actor_t actor(conf, true);

for (size_t i = 0; i < test_cases.size(); ++i) {
auto matched = json_to_pt(actor.trace_route(test_cases[i]));
const auto& routes = matched.get_child("matchings");
for (const auto& route : routes) {
const auto& legs = route.second.get_child("legs");
for (const auto& leg : legs) {
double duration = leg.second.get<double>("duration");
ASSERT_TRUE(duration >= 0);
}
}
}
}

} // namespace

int main(int argc, char* argv[]) {
Expand Down