Don't use location cache if not needed

This commit is contained in:
Michael Krasnyk 2017-09-22 17:33:06 +02:00
parent 476bc347b4
commit 545097cf06
8 changed files with 50 additions and 14 deletions

View File

@ -6,7 +6,7 @@ Feature: osrm-extract lua ways:get_nodes()
""" """
functions = require('testbot') functions = require('testbot')
function way_function(profile, way, result) functions.process_way = function(profile, way, result)
for _, node in ipairs(way:get_nodes()) do for _, node in ipairs(way:get_nodes()) do
print('node id ' .. node:id()) print('node id ' .. node:id())
end end
@ -14,7 +14,6 @@ Feature: osrm-extract lua ways:get_nodes()
result.forward_speed = 1 result.forward_speed = 1
end end
functions.process_way = way_function
return functions return functions
""" """
And the node map And the node map
@ -32,12 +31,36 @@ Feature: osrm-extract lua ways:get_nodes()
And stdout should contain "node id 2" And stdout should contain "node id 2"
Scenario: osrm-extract location-dependent data without add-locations-to-ways preprocessing and node locations cache
Given the profile file
"""
functions = require('testbot')
functions.process_way = function(profile, way, result, relations)
print(way:get_location_tag('driving_side'))
end
return functions
"""
And the node map
"""
a b
"""
And the ways
| nodes |
| ab |
And the data has been saved to disk
When I try to run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --use-locations-cache=false"
Then it should exit with an error
And stderr should contain "invalid location"
Scenario: osrm-extract location-dependent data Scenario: osrm-extract location-dependent data
Given the profile file Given the profile file
""" """
functions = require('testbot') functions = require('testbot')
function way_function(profile, way, result, relations) functions.process_way = function(profile, way, result, relations)
for _, key in ipairs({'answer', 'boolean', 'object', 'array'}) do for _, key in ipairs({'answer', 'boolean', 'object', 'array'}) do
print (key .. ' ' .. tostring(way:get_location_tag(key))) print (key .. ' ' .. tostring(way:get_location_tag(key)))
end end
@ -45,7 +68,6 @@ Feature: osrm-extract lua ways:get_nodes()
result.forward_speed = 1 result.forward_speed = 1
end end
functions.process_way = way_function
return functions return functions
""" """
And the node map And the node map
@ -57,7 +79,7 @@ Feature: osrm-extract lua ways:get_nodes()
| ab | | ab |
And the data has been saved to disk And the data has been saved to disk
When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson" When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --use-locations-cache=false"
Then it should exit successfully Then it should exit successfully
And stdout should contain "answer 42" And stdout should contain "answer 42"
And stdout should contain "boolean true" And stdout should contain "boolean true"
@ -70,14 +92,13 @@ Feature: osrm-extract lua ways:get_nodes()
""" """
functions = require('testbot') functions = require('testbot')
function way_function(profile, way, result, relations) functions.process_way = function(profile, way, result, relations)
print('ISO3166-1 ' .. (way:get_location_tag('ISO3166-1') or 'none')) print('ISO3166-1 ' .. (way:get_location_tag('ISO3166-1') or 'none'))
print('answer ' .. (way:get_location_tag('answer') or 'none')) print('answer ' .. (way:get_location_tag('answer') or 'none'))
result.forward_mode = mode.driving result.forward_mode = mode.driving
result.forward_speed = 1 result.forward_speed = 1
end end
functions.process_way = way_function
return functions return functions
""" """
And the node locations And the node locations
@ -95,7 +116,7 @@ Feature: osrm-extract lua ways:get_nodes()
| ef | Null Island | | ef | Null Island |
And the data has been saved to disk And the data has been saved to disk
When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --location-dependent-data test/data/regions/hong-kong.geojson" When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --location-dependent-data test/data/regions/hong-kong.geojson --use-locations-cache=false"
Then it should exit successfully Then it should exit successfully
And stdout should not contain "1 GeoJSON polygon" And stdout should not contain "1 GeoJSON polygon"
And stdout should contain "2 GeoJSON polygons" And stdout should contain "2 GeoJSON polygons"
@ -108,13 +129,12 @@ Feature: osrm-extract lua ways:get_nodes()
""" """
functions = require('testbot') functions = require('testbot')
function way_function(profile, way, result, relations) functions.process_way = function(profile, way, result, relations)
print ('answer ' .. tostring(way:get_location_tag('answer'))) print ('answer ' .. tostring(way:get_location_tag('answer')))
result.forward_mode = mode.driving result.forward_mode = mode.driving
result.forward_speed = 1 result.forward_speed = 1
end end
functions.process_way = way_function
return functions return functions
""" """
And the node map And the node map

View File

@ -68,7 +68,8 @@ struct ExtractorConfig final : storage::IOConfig
".osrm.icd", ".osrm.icd",
".osrm.cnbg", ".osrm.cnbg",
".osrm.cnbg_to_ebg"}), ".osrm.cnbg_to_ebg"}),
requested_num_threads(0) requested_num_threads(0),
use_locations_cache(true)
{ {
} }
@ -88,6 +89,7 @@ struct ExtractorConfig final : storage::IOConfig
bool use_metadata; bool use_metadata;
bool parse_conditionals; bool parse_conditionals;
bool use_locations_cache;
}; };
} }
} }

View File

@ -70,6 +70,8 @@ class ScriptingEnvironment
std::vector<std::pair<const osmium::Way &, ExtractionWay>> &resulting_ways, std::vector<std::pair<const osmium::Way &, ExtractionWay>> &resulting_ways,
std::vector<std::pair<const osmium::Relation &, ExtractionRelation>> &resulting_relations, std::vector<std::pair<const osmium::Relation &, ExtractionRelation>> &resulting_relations,
std::vector<InputConditionalTurnRestriction> &resulting_restrictions) = 0; std::vector<InputConditionalTurnRestriction> &resulting_restrictions) = 0;
virtual bool HasLocationDependentData() const = 0;
}; };
} }
} }

View File

@ -91,6 +91,8 @@ class Sol2ScriptingEnvironment final : public ScriptingEnvironment
std::vector<std::pair<const osmium::Relation &, ExtractionRelation>> &resulting_relations, std::vector<std::pair<const osmium::Relation &, ExtractionRelation>> &resulting_relations,
std::vector<InputConditionalTurnRestriction> &resulting_restrictions) override; std::vector<InputConditionalTurnRestriction> &resulting_restrictions) override;
bool HasLocationDependentData() const { return !location_dependent_data.empty(); }
private: private:
LuaScriptingContext &GetSol2Context(); LuaScriptingContext &GetSol2Context();

View File

@ -453,9 +453,10 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
osmium::io::Reader reader( osmium::io::Reader reader(
input_file, osmium::osm_entity_bits::node | osmium::osm_entity_bits::way, read_meta); input_file, osmium::osm_entity_bits::node | osmium::osm_entity_bits::way, read_meta);
// TODO: make location_cacher conditional
const auto pipeline = const auto pipeline =
buffer_reader(reader) & location_cacher & buffer_transformer & buffer_storage; scripting_environment.HasLocationDependentData() && config.use_locations_cache
? buffer_reader(reader) & location_cacher & buffer_transformer & buffer_storage
: buffer_reader(reader) & buffer_transformer & buffer_storage;
tbb::parallel_pipeline(num_threads, pipeline); tbb::parallel_pipeline(num_threads, pipeline);
} }

View File

@ -302,6 +302,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
[](const osmium::Way &way) { return sol::as_table(way.nodes()); }, [](const osmium::Way &way) { return sol::as_table(way.nodes()); },
"get_location_tag", "get_location_tag",
[&context](const osmium::Way &way, const char *key) { [&context](const osmium::Way &way, const char *key) {
if (context.location_dependent_data.empty())
return sol::object(sol::nil);
// HEURISTIC: use a single node (last) of the way to localize the way // HEURISTIC: use a single node (last) of the way to localize the way
// For more complicated scenarios a proper merging of multiple tags // For more complicated scenarios a proper merging of multiple tags
// at one or many locations must be provided // at one or many locations must be provided

View File

@ -66,7 +66,12 @@ return_code parseArguments(int argc,
boost::program_options::value<std::vector<boost::filesystem::path>>( boost::program_options::value<std::vector<boost::filesystem::path>>(
&extractor_config.location_dependent_data_paths) &extractor_config.location_dependent_data_paths)
->composing(), ->composing(),
"GeoJSON files with location-dependent data"); "GeoJSON files with location-dependent data")(
"use-locations-cache",
boost::program_options::value<bool>(&extractor_config.use_locations_cache)
->implicit_value(true)
->default_value(extractor_config.use_locations_cache),
"Use internal nodes locations cache for location-dependent data lookups");
bool dummy; bool dummy;
// hidden options, will be allowed on command line, but will not be // hidden options, will be allowed on command line, but will not be

View File

@ -44,6 +44,8 @@ class MockScriptingEnvironment : public extractor::ScriptingEnvironment
std::vector<extractor::InputConditionalTurnRestriction> &) override final std::vector<extractor::InputConditionalTurnRestriction> &) override final
{ {
} }
bool HasLocationDependentData() const { return false; };
}; };
} // namespace test } // namespace test