Add feature to fill null matrix entries with straight-line estimates.

This commit is contained in:
Daniel Patterson 2018-10-31 22:02:54 -07:00
parent cb1db646f2
commit 71bdfd2c6e
No known key found for this signature in database
GPG Key ID: 19C12BE1725A028B
6 changed files with 103 additions and 4 deletions

View File

@ -595,3 +595,27 @@ Feature: Basic Distance Matrix
| d | 1478.9 | 1579 | 1779.1 | 0 | 1280.1 | 882.5 |
| e | 198.8 | 298.9 | 499 | 710.3 | 0 | 1592.8 |
| f | 596.4 | 696.5 | 896.6 | 1107.9 | 397.6 | 0 |
Scenario: Testbot - Filling in noroutes with estimates
Given a grid size of 300 meters
Given the extract extra arguments "--small-component-size 4"
Given the query options
| noroute_estimate | 5 |
Given the node map
"""
a b f h
d e g i
"""
And the ways
| nodes |
| abeda |
| fhigf |
When I request a travel distance matrix I should get
| | a | b | f | h |
| a | 0 | 300.2 | 900.7 | 1200.9 |
| b | 300.2 | 0 | 600.5 | 900.7 |
| f | 900.7 | 600.5 | 0 | 302.2 |
| h | 1200.9 | 900.7 | 300.2 | 0 |

View File

@ -510,3 +510,26 @@ Feature: Basic Duration Matrix
| | a |
| a | 0 |
| b | 24.1 |
Scenario: Testbot - Filling in noroutes with estimates
Given a grid size of 300 meters
Given the extract extra arguments "--small-component-size 4"
Given the query options
| noroute_estimate | 5 |
Given the node map
"""
a b f h
d e g i
"""
And the ways
| nodes |
| abeda |
| fhigf |
When I request a travel time matrix I should get
| | a | b | f | h |
| a | 0 | 30 | 18 | 24 |
| b | 30 | 0 | 12 | 18 |
| f | 18 | 12 | 0 | 30 |
| h | 24 | 18 | 30 | 0 |

View File

@ -59,6 +59,7 @@ struct TableParameters : public BaseParameters
{
std::vector<std::size_t> sources;
std::vector<std::size_t> destinations;
std::size_t noroute_estimate = 0;
enum class AnnotationsType
{
@ -74,19 +75,22 @@ struct TableParameters : public BaseParameters
template <typename... Args>
TableParameters(std::vector<std::size_t> sources_,
std::vector<std::size_t> destinations_,
std::size_t noroute_estimate_,
Args... args_)
: BaseParameters{std::forward<Args>(args_)...}, sources{std::move(sources_)},
destinations{std::move(destinations_)}
destinations{std::move(destinations_)}, noroute_estimate{noroute_estimate_}
{
}
template <typename... Args>
TableParameters(std::vector<std::size_t> sources_,
std::vector<std::size_t> destinations_,
std::size_t noroute_estimate_,
const AnnotationsType annotations_,
Args... args_)
: BaseParameters{std::forward<Args>(args_)...}, sources{std::move(sources_)},
destinations{std::move(destinations_)}, annotations{annotations_}
destinations{std::move(destinations_)}, noroute_estimate{noroute_estimate_},
annotations{annotations_}
{
}

View File

@ -1183,6 +1183,19 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
}
}
if (obj->Has(Nan::New("noroute_estimate").ToLocalChecked()))
{
auto noroute_estimate = obj->Get(Nan::New("noroute_estimate").ToLocalChecked());
if (!noroute_estimate->IsNumber() && !noroute_estimate->IsUint32())
{
Nan::ThrowError("noroute_estimate must be an integral number");
return table_parameters_ptr();
}
params->noroute_estimate = static_cast<size_t>(noroute_estimate->NumberValue());
}
return params;
}

View File

@ -48,10 +48,16 @@ struct TableParametersGrammar : public BaseParametersGrammar<Iterator, Signature
(qi::lit("all") |
(size_t_ % ';')[ph::bind(&engine::api::TableParameters::sources, qi::_r1) = qi::_1]);
noroute_estimate_rule =
qi::lit("noroute_estimate=") >
(size_t_)[ph::bind(&engine::api::TableParameters::noroute_estimate, qi::_r1) = qi::_1];
table_rule = destinations_rule(qi::_r1) | sources_rule(qi::_r1);
root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' > (table_rule(qi::_r1) | base_rule(qi::_r1)) % '&');
root_rule =
BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' >
(table_rule(qi::_r1) | base_rule(qi::_r1) | noroute_estimate_rule(qi::_r1)) % '&');
}
TableParametersGrammar(qi::rule<Iterator, Signature> &root_rule_) : BaseGrammar(root_rule_)
@ -77,6 +83,7 @@ struct TableParametersGrammar : public BaseParametersGrammar<Iterator, Signature
qi::rule<Iterator, Signature> table_rule;
qi::rule<Iterator, Signature> sources_rule;
qi::rule<Iterator, Signature> destinations_rule;
qi::rule<Iterator, Signature> noroute_estimate_rule;
qi::rule<Iterator, std::size_t()> size_t_;
qi::symbols<char, engine::api::TableParameters::AnnotationsType> annotations;
qi::rule<Iterator, engine::api::TableParameters::AnnotationsType()> annotations_list;

View File

@ -4,6 +4,7 @@
#include "engine/api/table_parameters.hpp"
#include "engine/routing_algorithms/many_to_many.hpp"
#include "engine/search_engine_data.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/json_container.hpp"
#include "util/string_util.hpp"
@ -94,6 +95,33 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Error("NoTable", "No table found", result);
}
// Scan table for null results - if any exist, replace with distance estimates
if (params.noroute_estimate > 0)
{
for (std::size_t row = 0; row < num_sources; row++)
{
for (std::size_t column = 0; column < num_destinations; column++)
{
if (result_tables_pair.first[row * num_sources + column] == MAXIMAL_EDGE_DURATION)
{
auto distance_estimate = util::coordinate_calculation::fccApproximateDistance(
snapped_phantoms[params.sources.empty() ? row : params.sources[row]]
.location,
snapped_phantoms[params.destinations.empty() ? column
: params.destinations[column]]
.location);
result_tables_pair.first[row * num_sources + column] =
distance_estimate / (double)params.noroute_estimate;
if (!result_tables_pair.second.empty())
{
result_tables_pair.second[row * num_sources + column] = distance_estimate;
}
}
}
}
}
api::TableAPI table_api{facade, params};
table_api.MakeResponse(result_tables_pair, snapped_phantoms, result);