Skip to content

Commit

Permalink
Add flag to allow skipping calling node function for nodes with no tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat committed Jun 13, 2017
1 parent 9e6a226 commit aaaab78
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Features
- Added conditional restriction support with `parse-conditional-restrictions=true|false` to osrm-extract. This option saves conditional turn restrictions to the .restrictions file for parsing by contract later. Added `parse-conditionals-from-now=utc time stamp` and `--time-zone-file=/path/to/file` to osrm-contract
- Command-line tools (osrm-extract, osrm-contract, osrm-routed, etc) now return error codes and legible error messages for common problem scenarios, rather than ugly C++ crashes
- Speed up pre-processing by only running the Lua `node_function` for nodes that have tags. Cuts OSM file parsing time in half.
- Files
- .osrm.nodes file was renamed to .nbg_nodes and .ebg_nodes was added
- Guidance
Expand Down
4 changes: 3 additions & 1 deletion include/extractor/profile_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ProfileProperties
: traffic_signal_penalty(0), u_turn_penalty(0),
max_speed_for_map_matching(DEFAULT_MAX_SPEED), continue_straight_at_waypoint(true),
use_turn_restrictions(false), left_hand_driving(false), fallback_to_duration(true),
weight_name{"duration"}
weight_name{"duration"}, call_tagless_node_function(true)
{
BOOST_ASSERT(weight_name[MAX_WEIGHT_NAME_LENGTH] == '\0');
}
Expand Down Expand Up @@ -88,6 +88,8 @@ struct ProfileProperties
char weight_name[MAX_WEIGHT_NAME_LENGTH + 1];
unsigned weight_precision = 1;
bool force_split_edges = false;

bool call_tagless_node_function = true;
};
}
}
Expand Down
5 changes: 5 additions & 0 deletions profiles/bicycle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ properties.continue_straight_at_waypoint = false
properties.weight_name = 'duration'
--properties.weight_name = 'cyclability'

-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false


local default_speed = 15
local walking_speed = 6
Expand Down
6 changes: 6 additions & 0 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ properties.weight_name = 'routability'
-- For shortest distance without penalties for accessibility
--properties.weight_name = 'distance'

-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false


local profile = {
default_mode = mode.driving,
default_speed = 10,
Expand Down
5 changes: 5 additions & 0 deletions profiles/foot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ properties.continue_straight_at_waypoint = false
properties.weight_name = 'duration'
--properties.weight_name = 'routability'

-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false

local walking_speed = 5

local profile = {
Expand Down
5 changes: 5 additions & 0 deletions profiles/rasterbot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ api_version = 1

properties.force_split_edges = true

-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false

-- Minimalist node_ and way_functions in order to test source_ and segment_functions

function node_function (node, result)
Expand Down
5 changes: 5 additions & 0 deletions profiles/rasterbotinterp.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
api_version = 1
-- Rasterbot profile

-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false

-- Minimalist node_ and way_functions in order to test source_ and segment_functions

function node_function (node, result)
Expand Down
5 changes: 5 additions & 0 deletions profiles/testbot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ properties.use_turn_restrictions = true
properties.max_speed_for_map_matching = 30/3.6 --km -> m/s
properties.weight_name = 'duration'

-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false

local uturn_penalty = 20
local traffic_light_penalty = 7 -- seconds

Expand Down
8 changes: 6 additions & 2 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
"max_turn_weight",
sol::property(&ProfileProperties::GetMaxTurnWeight),
"force_split_edges",
&ProfileProperties::force_split_edges);
&ProfileProperties::force_split_edges,
"call_tagless_node_function",
&ProfileProperties::call_tagless_node_function);

context.state.new_usertype<std::vector<std::string>>(
"vector",
Expand Down Expand Up @@ -510,7 +512,9 @@ void Sol2ScriptingEnvironment::ProcessElements(
{
case osmium::item_type::node:
result_node.clear();
if (local_context.has_node_function)
if (local_context.has_node_function &&
(!static_cast<const osmium::Node &>(*entity).tags().empty() ||
local_context.properties.call_tagless_node_function))
{
local_context.ProcessNode(static_cast<const osmium::Node &>(*entity),
result_node);
Expand Down

0 comments on commit aaaab78

Please sign in to comment.