Skip to content

Commit

Permalink
Smarter search radius formula for map matching
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrick-lyft committed Oct 26, 2016
1 parent fead71d commit b19a38b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
19 changes: 18 additions & 1 deletion include/engine/api/match_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ENGINE_API_MATCH_PARAMETERS_HPP
#define ENGINE_API_MATCH_PARAMETERS_HPP

#define SEARCH_RADIUS_BASE_DEFAULT 45
#define SEARCH_RADIUS_BASE_LIMIT 100
#define SEARCH_RADIUS_MULTIPLIER_DEFAULT 3.5
#define SEARCH_RADIUS_MULTIPLIER_LIMIT 10
#define SEARCH_RADIUS_MAX_DEFAULT 200
#define SEARCH_RADIUS_MAX_LIMIT 500

#include "engine/api/route_parameters.hpp"

#include <vector>
Expand Down Expand Up @@ -67,10 +74,20 @@ struct MatchParameters : public RouteParameters
}

std::vector<unsigned> timestamps;

double search_radius_base = SEARCH_RADIUS_BASE_DEFAULT;
double search_radius_multiplier = SEARCH_RADIUS_MULTIPLIER_DEFAULT;
double search_radius_max = SEARCH_RADIUS_MAX_DEFAULT;

bool IsValid() const
{
return RouteParameters::IsValid() &&
(timestamps.empty() || timestamps.size() == coordinates.size());
(timestamps.empty() || timestamps.size() == coordinates.size()) &&
search_radius_base >= 0 && search_radius_multiplier >= 0 && search_radius_max > 0 &&
// limit the search_radius parameters to "sane" values to prevent overloading the server
search_radius_base <= SEARCH_RADIUS_BASE_LIMIT &&
search_radius_multiplier <= SEARCH_RADIUS_MULTIPLIER_LIMIT &&
search_radius_max <= SEARCH_RADIUS_MAX_LIMIT;
}
};
}
Expand Down
22 changes: 21 additions & 1 deletion include/server/api/match_parameter_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,33 @@ struct MatchParametersGrammar final : public RouteParametersGrammar<Iterator, Si
(qi::uint_ %
';')[ph::bind(&engine::api::MatchParameters::timestamps, qi::_r1) = qi::_1];

search_radius_base_rule =
qi::lit("search_radius_base=") > qi::double_[
ph::bind(&engine::api::MatchParameters::search_radius_base, qi::_r1) = qi::_1];

search_radius_multiplier_rule =
qi::lit("search_radius_multiplier=") > qi::double_[
ph::bind(&engine::api::MatchParameters::search_radius_multiplier, qi::_r1) = qi::_1];

search_radius_max_rule =
qi::lit("search_radius_max=") > qi::double_[
ph::bind(&engine::api::MatchParameters::search_radius_max, qi::_r1) = qi::_1];

root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1)) % '&');
-('?' > (timestamps_rule(qi::_r1) |
search_radius_base_rule(qi::_r1) |
search_radius_multiplier_rule(qi::_r1) |
search_radius_max_rule(qi::_r1) |
BaseGrammar::base_rule(qi::_r1))
% '&');
}

private:
qi::rule<Iterator, Signature> root_rule;
qi::rule<Iterator, Signature> timestamps_rule;
qi::rule<Iterator, Signature> search_radius_base_rule;
qi::rule<Iterator, Signature> search_radius_multiplier_rule;
qi::rule<Iterator, Signature> search_radius_max_rule;
};
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/engine/plugins/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,11 @@ Status MatchPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFaca
parameters.radiuses.end(),
search_radiuses.begin(),
[](const boost::optional<double> &maybe_radius) {
if (maybe_radius)
{
return *maybe_radius * RADIUS_MULTIPLIER;
}
else
{
return DEFAULT_GPS_PRECISION * RADIUS_MULTIPLIER;
}
double in_radius = maybe_radius ? *maybe_radius : DEFAULT_GPS_PRECISION;

return std::min(
in_radius * parameters.search_radius_multiplier + parameters.search_radius_base,
parameters.search_radius_max);
});
}

Expand Down

0 comments on commit b19a38b

Please sign in to comment.