remove scale_factor restrictions

This commit is contained in:
Kajari Ghosh 2018-12-08 10:51:44 -05:00
parent 1421758e60
commit cbda3663ab
7 changed files with 39 additions and 21 deletions

View File

@ -235,10 +235,10 @@ In addition to the [general options](#general-options) the following options are
|------------|--------------------------------------------------|---------------------------------------------|
|sources |`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as source. |
|destinations|`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as destination.|
|annotations |`duration` (default), `distance`, or `duration,distance`|Return the requested table or tables in response. Note that computing the `distances` table is currently only implemented for CH. If `annotations=distance` or `annotations=duration,distance` is requested when running a MLD router, a `NotImplemented` error will be returned. |
|fallback_speed|`double > 0`|If no route found between a source/destination pair, calculate the as-the-crow-flies distance, then use this speed to estimate duration.|
|annotations |`duration` (default), `distance`, or `duration,distance`|Return the requested table or tables in response. |
|fallback_speed|`double > 0`| If no route found between a source/destination pair, calculate the as-the-crow-flies distance, then use this speed to estimate duration.|
|fallback_coordinate|`input` (default), or `snapped`| When using a `fallback_speed`, use the user-supplied coordinate (`input`), or the snapped location (`snapped`) for calculating distances.|
|scale_factor|`double > 0`| Multiply the table `duration` values by this number. Default is 1.0.|
|scale_factor|`double`| Multiplies the table `duration` values by this number.|
Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal**
to number of input locations;

View File

@ -624,4 +624,22 @@ Feature: Basic Duration Matrix
When I request a travel time matrix I should get
| | a | b |
| a | 0 | 20 |
| b | 20 | 0 |
| b | 20 | 0 |
Scenario: Testbot - Travel time matrix of minimal network with overflow factor
Given the query options
| scale_factor | 2147483647 |
Given the node map
"""
a b
"""
And the ways
| nodes |
| ab |
When I request a travel time matrix I should get
| | a | b |
| a | 0 | 20 |
| b | 20 | 0 |

View File

@ -140,9 +140,6 @@ struct TableParameters : public BaseParameters
if (fallback_speed < 0)
return false;
if (scale_factor < 1)
return false;
return true;
}
};

View File

@ -1238,11 +1238,6 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
Nan::ThrowError("scale_factor must be a number");
return table_parameters_ptr();
}
else if (scale_factor->NumberValue() < 1)
{
Nan::ThrowError("scale_factor must be > 1");
return table_parameters_ptr();
}
params->scale_factor = static_cast<double>(scale_factor->NumberValue());
}

View File

@ -96,7 +96,7 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
}
// Scan table for null results - if any exist, replace with distance estimates
if (params.fallback_speed > 0 || params.scale_factor > 1.0)
if (params.fallback_speed > 0 || params.scale_factor != 1.0)
{
for (std::size_t row = 0; row < num_sources; row++)
{
@ -128,11 +128,15 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
result_tables_pair.second[table_index] = distance_estimate;
}
}
if (params.scale_factor > 1.0 &&
if (params.scale_factor != 1.0 &&
result_tables_pair.first[table_index] != MAXIMAL_EDGE_DURATION)
{
result_tables_pair.first[table_index] = std::lround(
result_tables_pair.first[table_index] * (double)params.scale_factor);
double result = std::lround(result_tables_pair.first[table_index] * params.scale_factor);
if (result > MAXIMAL_EDGE_DURATION) {
result_tables_pair.first[table_index] = MAXIMAL_EDGE_DURATION - 1;
} else {
result_tables_pair.first[table_index] = result;
}
}
}
}

View File

@ -61,11 +61,6 @@ std::string getWrongOptionHelp(const engine::api::TableParameters &parameters)
help = "fallback_speed must be > 0";
}
if (parameters.scale_factor < 1)
{
help = "scale_factor must be > 1";
}
return help;
}
} // anon. ns

View File

@ -565,6 +565,15 @@ BOOST_AUTO_TEST_CASE(valid_table_urls)
BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true);
CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources);
CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations);
auto result_8 = parseParameters<TableParameters>("1,2;3,4?sources=all&destinations=all&annotations=duration&fallback_speed=1&fallback_coordinate=snapped&scale_factor=2");
BOOST_CHECK(result_8);
CHECK_EQUAL_RANGE(reference_1.sources, result_3->sources);
CHECK_EQUAL_RANGE(reference_1.destinations, result_3->destinations);
CHECK_EQUAL_RANGE(reference_1.bearings, result_3->bearings);
CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses);
CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches);
CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates);
}
BOOST_AUTO_TEST_CASE(valid_match_urls)