Switch profiles from Lua to library interface
There's now an abstracted interface and no direct calls to Lua anymore. fixes #1974
This commit is contained in:
committed by
Patrick Niklaus
parent
9b737230d6
commit
1309dd2a0f
+31
-82
@@ -11,7 +11,6 @@
|
||||
#include "extractor/raster_source.hpp"
|
||||
#include "util/graph_loader.hpp"
|
||||
#include "util/io.hpp"
|
||||
#include "util/lua_util.hpp"
|
||||
#include "util/make_unique.hpp"
|
||||
#include "util/name_table.hpp"
|
||||
#include "util/range_table.hpp"
|
||||
@@ -29,11 +28,9 @@
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
|
||||
#include <luabind/luabind.hpp>
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
|
||||
#include <tbb/parallel_for.h>
|
||||
#include <tbb/concurrent_vector.h>
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -74,11 +71,8 @@ namespace extractor
|
||||
* graph
|
||||
*
|
||||
*/
|
||||
int Extractor::run()
|
||||
int Extractor::run(ScriptingEnvironment &scripting_environment)
|
||||
{
|
||||
// setup scripting environment
|
||||
ScriptingEnvironment scripting_environment(config.profile_path.string().c_str());
|
||||
|
||||
try
|
||||
{
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
@@ -90,7 +84,9 @@ int Extractor::run()
|
||||
tbb::task_scheduler_init init(number_of_threads);
|
||||
|
||||
util::SimpleLogger().Write() << "Input file: " << config.input_path.filename().string();
|
||||
util::SimpleLogger().Write() << "Profile: " << config.profile_path.filename().string();
|
||||
if (!config.profile_path.empty()) {
|
||||
util::SimpleLogger().Write() << "Profile: " << config.profile_path.filename().string();
|
||||
}
|
||||
util::SimpleLogger().Write() << "Threads: " << number_of_threads;
|
||||
|
||||
ExtractionContainers extraction_containers;
|
||||
@@ -100,21 +96,15 @@ int Extractor::run()
|
||||
osmium::io::Reader reader(input_file);
|
||||
const osmium::io::Header header = reader.header();
|
||||
|
||||
std::atomic<unsigned> number_of_nodes{0};
|
||||
std::atomic<unsigned> number_of_ways{0};
|
||||
std::atomic<unsigned> number_of_relations{0};
|
||||
std::atomic<unsigned> number_of_others{0};
|
||||
unsigned number_of_nodes = 0;
|
||||
unsigned number_of_ways = 0;
|
||||
unsigned number_of_relations = 0;
|
||||
|
||||
util::SimpleLogger().Write() << "Parsing in progress..";
|
||||
TIMER_START(parsing);
|
||||
|
||||
auto &main_context = scripting_environment.GetContex();
|
||||
|
||||
// setup raster sources
|
||||
if (util::luaFunctionExists(main_context.state, "source_function"))
|
||||
{
|
||||
luabind::call_function<void>(main_context.state, "source_function");
|
||||
}
|
||||
scripting_environment.SetupSources();
|
||||
|
||||
std::string generator = header.get("generator");
|
||||
if (generator.empty())
|
||||
@@ -140,7 +130,7 @@ int Extractor::run()
|
||||
tbb::concurrent_vector<boost::optional<InputRestrictionContainer>> resulting_restrictions;
|
||||
|
||||
// setup restriction parser
|
||||
const RestrictionParser restriction_parser(main_context.state, main_context.properties);
|
||||
const RestrictionParser restriction_parser(scripting_environment);
|
||||
|
||||
while (const osmium::memory::Buffer buffer = reader.read())
|
||||
{
|
||||
@@ -156,52 +146,14 @@ int Extractor::run()
|
||||
resulting_ways.clear();
|
||||
resulting_restrictions.clear();
|
||||
|
||||
// parse OSM entities in parallel, store in resulting vectors
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<std::size_t>(0, osm_elements.size()),
|
||||
[&](const tbb::blocked_range<std::size_t> &range) {
|
||||
ExtractionNode result_node;
|
||||
ExtractionWay result_way;
|
||||
auto &local_context = scripting_environment.GetContex();
|
||||
scripting_environment.ProcessElements(osm_elements,
|
||||
restriction_parser,
|
||||
resulting_nodes,
|
||||
resulting_ways,
|
||||
resulting_restrictions);
|
||||
|
||||
for (auto x = range.begin(), end = range.end(); x != end; ++x)
|
||||
{
|
||||
const auto entity = osm_elements[x];
|
||||
|
||||
switch (entity->type())
|
||||
{
|
||||
case osmium::item_type::node:
|
||||
result_node.clear();
|
||||
++number_of_nodes;
|
||||
luabind::call_function<void>(
|
||||
local_context.state,
|
||||
"node_function",
|
||||
boost::cref(static_cast<const osmium::Node &>(*entity)),
|
||||
boost::ref(result_node));
|
||||
resulting_nodes.push_back(std::make_pair(x, std::move(result_node)));
|
||||
break;
|
||||
case osmium::item_type::way:
|
||||
result_way.clear();
|
||||
++number_of_ways;
|
||||
luabind::call_function<void>(
|
||||
local_context.state,
|
||||
"way_function",
|
||||
boost::cref(static_cast<const osmium::Way &>(*entity)),
|
||||
boost::ref(result_way));
|
||||
resulting_ways.push_back(std::make_pair(x, std::move(result_way)));
|
||||
break;
|
||||
case osmium::item_type::relation:
|
||||
++number_of_relations;
|
||||
resulting_restrictions.push_back(restriction_parser.TryParse(
|
||||
static_cast<const osmium::Relation &>(*entity)));
|
||||
break;
|
||||
default:
|
||||
++number_of_others;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
number_of_nodes += resulting_nodes.size();
|
||||
// put parsed objects thru extractor callbacks
|
||||
for (const auto &result : resulting_nodes)
|
||||
{
|
||||
@@ -209,11 +161,13 @@ int Extractor::run()
|
||||
static_cast<const osmium::Node &>(*(osm_elements[result.first])),
|
||||
result.second);
|
||||
}
|
||||
number_of_ways += resulting_ways.size();
|
||||
for (const auto &result : resulting_ways)
|
||||
{
|
||||
extractor_callbacks->ProcessWay(
|
||||
static_cast<const osmium::Way &>(*(osm_elements[result.first])), result.second);
|
||||
}
|
||||
number_of_relations += resulting_restrictions.size();
|
||||
for (const auto &result : resulting_restrictions)
|
||||
{
|
||||
extractor_callbacks->ProcessRestriction(result);
|
||||
@@ -223,10 +177,9 @@ int Extractor::run()
|
||||
util::SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing)
|
||||
<< " seconds";
|
||||
|
||||
util::SimpleLogger().Write() << "Raw input contains " << number_of_nodes.load()
|
||||
<< " nodes, " << number_of_ways.load() << " ways, and "
|
||||
<< number_of_relations.load() << " relations, and "
|
||||
<< number_of_others.load() << " unknown entities";
|
||||
util::SimpleLogger().Write() << "Raw input contains " << number_of_nodes << " nodes, "
|
||||
<< number_of_ways << " ways, and " << number_of_relations
|
||||
<< " relations";
|
||||
|
||||
extractor_callbacks.reset();
|
||||
|
||||
@@ -236,13 +189,14 @@ int Extractor::run()
|
||||
return 1;
|
||||
}
|
||||
|
||||
extraction_containers.PrepareData(config.output_file_name,
|
||||
extraction_containers.PrepareData(scripting_environment,
|
||||
config.output_file_name,
|
||||
config.restriction_file_name,
|
||||
config.names_file_name,
|
||||
config.turn_lane_descriptions_file_name,
|
||||
main_context.state);
|
||||
config.turn_lane_descriptions_file_name);
|
||||
|
||||
WriteProfileProperties(config.profile_properties_output_path, main_context.properties);
|
||||
WriteProfileProperties(config.profile_properties_output_path,
|
||||
scripting_environment.GetProfileProperties());
|
||||
|
||||
TIMER_STOP(extracting);
|
||||
util::SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting)
|
||||
@@ -261,9 +215,6 @@ int Extractor::run()
|
||||
// that is better for routing. Every edge becomes a node, and every valid
|
||||
// movement (e.g. turn from A->B, and B->A) becomes an edge
|
||||
//
|
||||
|
||||
auto &main_context = scripting_environment.GetContex();
|
||||
|
||||
util::SimpleLogger().Write() << "Generating edge-expanded graph representation";
|
||||
|
||||
TIMER_START(expansion);
|
||||
@@ -273,8 +224,7 @@ int Extractor::run()
|
||||
std::vector<bool> node_is_startpoint;
|
||||
std::vector<EdgeWeight> edge_based_node_weights;
|
||||
std::vector<QueryNode> internal_to_external_node_map;
|
||||
auto graph_size = BuildEdgeExpandedGraph(main_context.state,
|
||||
main_context.properties,
|
||||
auto graph_size = BuildEdgeExpandedGraph(scripting_environment,
|
||||
internal_to_external_node_map,
|
||||
edge_based_node_list,
|
||||
node_is_startpoint,
|
||||
@@ -477,8 +427,7 @@ Extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barrier_nodes,
|
||||
\brief Building an edge-expanded graph from node-based input and turn restrictions
|
||||
*/
|
||||
std::pair<std::size_t, EdgeID>
|
||||
Extractor::BuildEdgeExpandedGraph(lua_State *lua_state,
|
||||
const ProfileProperties &profile_properties,
|
||||
Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
|
||||
std::vector<QueryNode> &internal_to_external_node_map,
|
||||
std::vector<EdgeBasedNode> &node_based_edge_list,
|
||||
std::vector<bool> &node_is_startpoint,
|
||||
@@ -520,14 +469,14 @@ Extractor::BuildEdgeExpandedGraph(lua_State *lua_state,
|
||||
traffic_lights,
|
||||
std::const_pointer_cast<RestrictionMap const>(restriction_map),
|
||||
internal_to_external_node_map,
|
||||
profile_properties,
|
||||
scripting_environment.GetProfileProperties(),
|
||||
name_table,
|
||||
turn_lane_offsets,
|
||||
turn_lane_masks);
|
||||
|
||||
edge_based_graph_factory.Run(config.edge_output_path,
|
||||
edge_based_graph_factory.Run(scripting_environment,
|
||||
config.edge_output_path,
|
||||
config.turn_lane_data_file_name,
|
||||
lua_state,
|
||||
config.edge_segment_lookup_path,
|
||||
config.edge_penalty_path,
|
||||
config.generate_edge_lookup);
|
||||
|
||||
Reference in New Issue
Block a user