2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/extractor.hpp"
|
|
|
|
|
2016-01-11 10:55:22 -05:00
|
|
|
#include "extractor/edge_based_edge.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/extraction_containers.hpp"
|
|
|
|
#include "extractor/extraction_node.hpp"
|
|
|
|
#include "extractor/extraction_way.hpp"
|
|
|
|
#include "extractor/extractor_callbacks.hpp"
|
2017-04-01 14:44:49 -04:00
|
|
|
#include "extractor/files.hpp"
|
2017-03-08 19:06:06 -05:00
|
|
|
#include "extractor/raster_source.hpp"
|
2017-07-19 08:21:11 -04:00
|
|
|
#include "extractor/restriction_filter.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/restriction_parser.hpp"
|
|
|
|
#include "extractor/scripting_environment.hpp"
|
|
|
|
|
2016-11-21 20:32:00 -05:00
|
|
|
#include "storage/io.hpp"
|
2017-04-02 13:47:17 -04:00
|
|
|
|
2016-12-06 15:30:46 -05:00
|
|
|
#include "util/exception.hpp"
|
|
|
|
#include "util/exception_utils.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "util/graph_loader.hpp"
|
2017-01-26 11:53:19 -05:00
|
|
|
#include "util/integer_range.hpp"
|
2016-12-06 15:30:46 -05:00
|
|
|
#include "util/log.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "util/name_table.hpp"
|
2016-05-10 02:37:45 -04:00
|
|
|
#include "util/range_table.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/timing_util.hpp"
|
|
|
|
|
|
|
|
#include "extractor/compressed_edge_container.hpp"
|
2017-08-01 11:18:12 -04:00
|
|
|
#include "extractor/restriction_index.hpp"
|
2017-07-11 08:22:28 -04:00
|
|
|
#include "extractor/way_restriction_map.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "util/static_graph.hpp"
|
|
|
|
#include "util/static_rtree.hpp"
|
2016-01-02 11:13:44 -05:00
|
|
|
|
2016-08-02 09:09:09 -04:00
|
|
|
// Keep debug include to make sure the debug header is in sync with types.
|
|
|
|
#include "util/debug.hpp"
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "extractor/tarjan_scc.hpp"
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2015-01-31 15:17:16 -05:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/filesystem/fstream.hpp>
|
2017-06-08 17:04:48 -04:00
|
|
|
#include <boost/iterator/function_input_iterator.hpp>
|
2015-09-18 08:26:32 -04:00
|
|
|
#include <boost/optional/optional.hpp>
|
2017-01-26 11:53:19 -05:00
|
|
|
#include <boost/scope_exit.hpp>
|
2015-01-31 15:17:16 -05:00
|
|
|
|
2014-11-28 09:00:48 -05:00
|
|
|
#include <osmium/io/any_input.hpp>
|
|
|
|
|
2017-06-08 17:04:48 -04:00
|
|
|
#include <tbb/pipeline.h>
|
2014-11-28 09:00:48 -05:00
|
|
|
#include <tbb/task_scheduler_init.h>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <atomic>
|
2016-04-26 07:27:40 -04:00
|
|
|
#include <bitset>
|
|
|
|
#include <chrono>
|
2017-01-26 11:53:19 -05:00
|
|
|
#include <future>
|
2014-11-28 09:00:48 -05:00
|
|
|
#include <iostream>
|
2016-11-14 17:43:24 -05:00
|
|
|
#include <iterator>
|
2016-10-17 14:23:19 -04:00
|
|
|
#include <memory>
|
2014-11-28 09:00:48 -05:00
|
|
|
#include <thread>
|
2016-07-22 03:08:40 -04:00
|
|
|
#include <tuple>
|
2016-05-27 15:05:04 -04:00
|
|
|
#include <type_traits>
|
2014-11-28 09:00:48 -05:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
|
2017-06-27 18:01:05 -04:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
// Converts the class name map into a fixed mapping of index to name
|
2017-08-14 18:18:57 -04:00
|
|
|
void SetClassNames(const std::vector<std::string> &class_names,
|
|
|
|
ExtractorCallbacks::ClassesMap &classes_map,
|
2017-06-27 18:01:05 -04:00
|
|
|
ProfileProperties &profile_properties)
|
|
|
|
{
|
2017-08-14 18:18:57 -04:00
|
|
|
// if we get a list of class names we can validate if we set invalid classes
|
|
|
|
// and add classes that were never reference
|
|
|
|
if (!class_names.empty())
|
|
|
|
{
|
|
|
|
// add class names that were never used explicitly on a way
|
|
|
|
// this makes sure we can correctly validate unkown class names later
|
|
|
|
for (const auto &name : class_names)
|
|
|
|
{
|
|
|
|
auto iter = classes_map.find(name);
|
|
|
|
if (iter == classes_map.end())
|
|
|
|
{
|
|
|
|
auto index = classes_map.size();
|
|
|
|
if (index > MAX_CLASS_INDEX)
|
|
|
|
{
|
|
|
|
throw util::exception("Maximum number of classes if " +
|
|
|
|
std::to_string(MAX_CLASS_INDEX + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
classes_map[name] = getClassData(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if class names are only from the list supplied by the user
|
|
|
|
for (const auto &pair : classes_map)
|
|
|
|
{
|
|
|
|
auto iter = std::find(class_names.begin(), class_names.end(), pair.first);
|
|
|
|
if (iter == class_names.end())
|
|
|
|
{
|
|
|
|
throw util::exception("Profile used unknown class name: " + pair.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 18:01:05 -04:00
|
|
|
for (const auto &pair : classes_map)
|
|
|
|
{
|
|
|
|
auto range = getClassIndexes(pair.second);
|
|
|
|
BOOST_ASSERT(range.size() == 1);
|
|
|
|
profile_properties.SetClassName(range.front(), pair.first);
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 17:05:37 -04:00
|
|
|
|
|
|
|
// Converts the class name list to a mask list
|
|
|
|
void SetAvoidableClasses(const ExtractorCallbacks::ClassesMap &classes_map,
|
|
|
|
const std::vector<std::vector<std::string>> &avoidable_classes,
|
|
|
|
ProfileProperties &profile_properties)
|
|
|
|
{
|
|
|
|
if (avoidable_classes.size() > MAX_AVOIDABLE_CLASSES)
|
|
|
|
{
|
2017-08-14 17:24:33 -04:00
|
|
|
throw util::exception("Only " + std::to_string(MAX_AVOIDABLE_CLASSES) +
|
|
|
|
" avoidable combinations allowed.");
|
2017-07-18 17:05:37 -04:00
|
|
|
}
|
|
|
|
|
2017-07-21 17:55:19 -04:00
|
|
|
// The avoid index 0 is reserve for not avoiding anything
|
|
|
|
profile_properties.SetAvoidableClasses(0, 0);
|
|
|
|
|
|
|
|
std::size_t combination_index = 1;
|
2017-07-18 17:05:37 -04:00
|
|
|
for (const auto &combination : avoidable_classes)
|
|
|
|
{
|
|
|
|
ClassData mask = 0;
|
|
|
|
for (const auto &name : combination)
|
|
|
|
{
|
|
|
|
auto iter = classes_map.find(name);
|
|
|
|
if (iter == classes_map.end())
|
|
|
|
{
|
|
|
|
util::Log(logWARNING)
|
|
|
|
<< "Unknown class name " + name + " in avoidable combination. Ignoring.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mask |= iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask > 0)
|
|
|
|
{
|
|
|
|
profile_properties.SetAvoidableClasses(combination_index++, mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-27 18:01:05 -04:00
|
|
|
}
|
|
|
|
|
2015-04-09 06:26:46 -04:00
|
|
|
/**
|
|
|
|
* TODO: Refactor this function into smaller functions for better readability.
|
|
|
|
*
|
|
|
|
* This function is the entry point for the whole extraction process. The goal of the extraction
|
|
|
|
* step is to filter and convert the OSM geometry to something more fitting for routing.
|
|
|
|
* That includes:
|
|
|
|
* - extracting turn restrictions
|
|
|
|
* - splitting ways into (directional!) edge segments
|
|
|
|
* - checking if nodes are barriers or traffic signal
|
|
|
|
* - discarding all tag information: All relevant type information for nodes/ways
|
|
|
|
* is extracted at this point.
|
|
|
|
*
|
|
|
|
* The result of this process are the following files:
|
|
|
|
* .names : Names of all streets, stored as long consecutive string with prefix sum based index
|
2016-02-15 19:16:49 -05:00
|
|
|
* .osrm : Nodes and edges in a intermediate format that easy to digest for osrm-contract
|
|
|
|
* .restrictions : Turn restrictions that are used by osrm-contract to construct the edge-expanded
|
2015-12-11 17:11:04 -05:00
|
|
|
* graph
|
2015-04-09 06:26:46 -04:00
|
|
|
*
|
|
|
|
*/
|
2016-07-11 11:44:58 -04:00
|
|
|
int Extractor::run(ScriptingEnvironment &scripting_environment)
|
2014-11-28 09:00:48 -05:00
|
|
|
{
|
2016-10-10 12:05:17 -04:00
|
|
|
util::LogPolicy::GetInstance().Unmute();
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2016-10-10 12:05:17 -04:00
|
|
|
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
|
2016-10-21 18:24:55 -04:00
|
|
|
const auto number_of_threads = std::min(recommended_num_threads, config.requested_num_threads);
|
2017-03-08 10:00:56 -05:00
|
|
|
tbb::task_scheduler_init init(number_of_threads ? number_of_threads
|
|
|
|
: tbb::task_scheduler_init::automatic);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-06-16 08:35:04 -04:00
|
|
|
guidance::LaneDescriptionMap turn_lane_map;
|
|
|
|
std::vector<TurnRestriction> turn_restrictions;
|
2017-08-01 11:18:12 -04:00
|
|
|
std::vector<ConditionalTurnRestriction> conditional_turn_restrictions;
|
|
|
|
std::tie(turn_lane_map, turn_restrictions, conditional_turn_restrictions) =
|
2017-06-16 08:35:04 -04:00
|
|
|
ParseOSMData(scripting_environment, number_of_threads);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
// Transform the node-based graph that OSM is based on into an edge-based graph
|
|
|
|
// 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
|
|
|
|
util::Log() << "Generating edge-expanded graph representation";
|
2017-01-04 04:49:34 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
TIMER_START(expansion);
|
2017-01-04 04:49:34 -05:00
|
|
|
|
2017-05-15 16:36:52 -04:00
|
|
|
EdgeBasedNodeDataContainer edge_based_nodes_container;
|
2017-05-16 13:22:41 -04:00
|
|
|
std::vector<EdgeBasedNodeSegment> edge_based_node_segments;
|
2017-05-11 06:13:52 -04:00
|
|
|
util::DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
|
|
|
|
std::vector<bool> node_is_startpoint;
|
|
|
|
std::vector<EdgeWeight> edge_based_node_weights;
|
|
|
|
std::vector<util::Coordinate> coordinates;
|
|
|
|
extractor::PackedOSMIDs osm_node_ids;
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
auto graph_size = BuildEdgeExpandedGraph(scripting_environment,
|
|
|
|
coordinates,
|
|
|
|
osm_node_ids,
|
2017-05-15 06:15:00 -04:00
|
|
|
edge_based_nodes_container,
|
2017-05-16 13:22:41 -04:00
|
|
|
edge_based_node_segments,
|
2017-05-11 06:13:52 -04:00
|
|
|
node_is_startpoint,
|
|
|
|
edge_based_node_weights,
|
|
|
|
edge_based_edge_list,
|
2017-06-16 04:45:24 -04:00
|
|
|
config.GetPath(".osrm.icd").string(),
|
2017-06-16 08:35:04 -04:00
|
|
|
turn_restrictions,
|
2017-08-01 11:18:12 -04:00
|
|
|
conditional_turn_restrictions,
|
2017-06-16 08:35:04 -04:00
|
|
|
turn_lane_map);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
auto number_of_node_based_nodes = graph_size.first;
|
2017-07-11 08:22:28 -04:00
|
|
|
auto max_edge_id = graph_size.second - 1;
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
TIMER_STOP(expansion);
|
2016-05-12 12:50:10 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Saving edge-based node weights to file.";
|
|
|
|
TIMER_START(timer_write_node_weights);
|
|
|
|
{
|
2017-06-16 04:45:24 -04:00
|
|
|
storage::io::FileWriter writer(config.GetPath(".osrm.enw"),
|
2017-05-11 06:13:52 -04:00
|
|
|
storage::io::FileWriter::GenerateFingerprint);
|
|
|
|
storage::serialization::write(writer, edge_based_node_weights);
|
|
|
|
}
|
|
|
|
TIMER_STOP(timer_write_node_weights);
|
|
|
|
util::Log() << "Done writing. (" << TIMER_SEC(timer_write_node_weights) << ")";
|
2015-05-29 20:28:29 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Computing strictly connected components ...";
|
2017-05-17 01:54:23 -04:00
|
|
|
FindComponents(
|
|
|
|
max_edge_id, edge_based_edge_list, edge_based_node_segments, edge_based_nodes_container);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Building r-tree ...";
|
|
|
|
TIMER_START(rtree);
|
2017-05-16 13:22:41 -04:00
|
|
|
BuildRTree(std::move(edge_based_node_segments), std::move(node_is_startpoint), coordinates);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
TIMER_STOP(rtree);
|
2017-03-04 05:52:40 -05:00
|
|
|
|
2017-05-15 06:15:00 -04:00
|
|
|
util::Log() << "Writing nodes for nodes-based and edges-based graphs ...";
|
2017-06-16 04:45:24 -04:00
|
|
|
files::writeNodes(config.GetPath(".osrm.nbg_nodes"), coordinates, osm_node_ids);
|
|
|
|
files::writeNodeData(config.GetPath(".osrm.ebg_nodes"), edge_based_nodes_container);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-19 18:28:01 -04:00
|
|
|
util::Log() << "Writing edge-based-graph edges ... " << std::flush;
|
|
|
|
TIMER_START(write_edges);
|
2017-06-16 04:45:24 -04:00
|
|
|
files::writeEdgeBasedGraph(config.GetPath(".osrm.ebg"), max_edge_id, edge_based_edge_list);
|
2017-05-19 18:28:01 -04:00
|
|
|
TIMER_STOP(write_edges);
|
|
|
|
util::Log() << "ok, after " << TIMER_SEC(write_edges) << "s";
|
|
|
|
|
|
|
|
util::Log() << "Processed " << edge_based_edge_list.size() << " edges";
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
const auto nodes_per_second =
|
|
|
|
static_cast<std::uint64_t>(number_of_node_based_nodes / TIMER_SEC(expansion));
|
|
|
|
const auto edges_per_second =
|
|
|
|
static_cast<std::uint64_t>((max_edge_id + 1) / TIMER_SEC(expansion));
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Expansion: " << nodes_per_second << " nodes/sec and " << edges_per_second
|
|
|
|
<< " edges/sec";
|
|
|
|
util::Log() << "To prepare the data for routing, run: "
|
2017-06-16 04:45:24 -04:00
|
|
|
<< "./osrm-contract " << config.GetPath(".osrm");
|
2017-05-11 06:13:52 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-12 18:16:32 -05:00
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
std::tuple<guidance::LaneDescriptionMap,
|
|
|
|
std::vector<TurnRestriction>,
|
|
|
|
std::vector<ConditionalTurnRestriction>>
|
2017-06-16 08:35:04 -04:00
|
|
|
Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
|
|
|
|
const unsigned number_of_threads)
|
2017-05-11 06:13:52 -04:00
|
|
|
{
|
|
|
|
TIMER_START(extracting);
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Input file: " << config.input_path.filename().string();
|
|
|
|
if (!config.profile_path.empty())
|
|
|
|
{
|
|
|
|
util::Log() << "Profile: " << config.profile_path.filename().string();
|
|
|
|
}
|
|
|
|
util::Log() << "Threads: " << number_of_threads;
|
2016-07-22 03:08:40 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
const osmium::io::File input_file(config.input_path.string());
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
osmium::io::Reader reader(
|
|
|
|
input_file, (config.use_metadata ? osmium::io::read_meta::yes : osmium::io::read_meta::no));
|
2014-11-28 09:00:48 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
const osmium::io::Header header = reader.header();
|
2016-03-21 17:42:47 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
unsigned number_of_nodes = 0;
|
|
|
|
unsigned number_of_ways = 0;
|
|
|
|
unsigned number_of_relations = 0;
|
2015-05-29 20:28:29 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Parsing in progress..";
|
|
|
|
TIMER_START(parsing);
|
|
|
|
|
|
|
|
ExtractionContainers extraction_containers;
|
2017-06-27 18:01:05 -04:00
|
|
|
ExtractorCallbacks::ClassesMap classes_map;
|
|
|
|
guidance::LaneDescriptionMap turn_lane_map;
|
|
|
|
auto extractor_callbacks =
|
|
|
|
std::make_unique<ExtractorCallbacks>(extraction_containers,
|
|
|
|
classes_map,
|
|
|
|
turn_lane_map,
|
|
|
|
scripting_environment.GetProfileProperties());
|
2017-05-11 06:13:52 -04:00
|
|
|
|
|
|
|
std::string generator = header.get("generator");
|
|
|
|
if (generator.empty())
|
|
|
|
{
|
|
|
|
generator = "unknown tool";
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "input file generated by " << generator;
|
2016-07-19 07:13:52 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
// write .timestamp data file
|
|
|
|
std::string timestamp = header.get("osmosis_replication_timestamp");
|
|
|
|
if (timestamp.empty())
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-05-11 06:13:52 -04:00
|
|
|
timestamp = "n/a";
|
|
|
|
}
|
|
|
|
util::Log() << "timestamp: " << timestamp;
|
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
storage::io::FileWriter timestamp_file(config.GetPath(".osrm.timestamp"),
|
2017-05-23 11:37:41 -04:00
|
|
|
storage::io::FileWriter::GenerateFingerprint);
|
2017-05-11 06:13:52 -04:00
|
|
|
|
2017-05-23 11:37:41 -04:00
|
|
|
timestamp_file.WriteFrom(timestamp.c_str(), timestamp.length());
|
2017-05-11 06:13:52 -04:00
|
|
|
|
|
|
|
std::vector<std::string> restrictions = scripting_environment.GetRestrictions();
|
|
|
|
// setup restriction parser
|
|
|
|
const RestrictionParser restriction_parser(
|
|
|
|
scripting_environment.GetProfileProperties().use_turn_restrictions,
|
|
|
|
config.parse_conditionals,
|
|
|
|
restrictions);
|
|
|
|
|
2017-06-08 17:04:48 -04:00
|
|
|
std::mutex process_mutex;
|
|
|
|
|
|
|
|
using SharedBuffer = std::shared_ptr<const osmium::memory::Buffer>;
|
|
|
|
struct ParsedBuffer
|
2017-05-11 06:13:52 -04:00
|
|
|
{
|
2017-06-08 17:04:48 -04:00
|
|
|
SharedBuffer buffer;
|
|
|
|
std::vector<std::pair<const osmium::Node &, ExtractionNode>> resulting_nodes;
|
|
|
|
std::vector<std::pair<const osmium::Way &, ExtractionWay>> resulting_ways;
|
2017-07-06 11:09:24 -04:00
|
|
|
std::vector<InputConditionalTurnRestriction> resulting_restrictions;
|
2017-06-08 17:04:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
tbb::filter_t<void, SharedBuffer> buffer_reader(
|
|
|
|
tbb::filter::serial_in_order, [&](tbb::flow_control &fc) {
|
|
|
|
if (auto buffer = reader.read())
|
|
|
|
{
|
|
|
|
return std::make_shared<const osmium::memory::Buffer>(std::move(buffer));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fc.stop();
|
|
|
|
return SharedBuffer{};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tbb::filter_t<SharedBuffer, std::shared_ptr<ParsedBuffer>> buffer_transform(
|
|
|
|
tbb::filter::parallel, [&](const SharedBuffer buffer) {
|
|
|
|
if (!buffer)
|
|
|
|
return std::shared_ptr<ParsedBuffer>{};
|
|
|
|
|
|
|
|
auto parsed_buffer = std::make_shared<ParsedBuffer>();
|
|
|
|
parsed_buffer->buffer = buffer;
|
|
|
|
scripting_environment.ProcessElements(*buffer,
|
|
|
|
restriction_parser,
|
|
|
|
parsed_buffer->resulting_nodes,
|
|
|
|
parsed_buffer->resulting_ways,
|
|
|
|
parsed_buffer->resulting_restrictions);
|
|
|
|
return parsed_buffer;
|
|
|
|
});
|
|
|
|
tbb::filter_t<std::shared_ptr<ParsedBuffer>, void> buffer_storage(
|
|
|
|
tbb::filter::serial_in_order, [&](const std::shared_ptr<ParsedBuffer> parsed_buffer) {
|
|
|
|
if (!parsed_buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
number_of_nodes += parsed_buffer->resulting_nodes.size();
|
|
|
|
// put parsed objects thru extractor callbacks
|
|
|
|
for (const auto &result : parsed_buffer->resulting_nodes)
|
|
|
|
{
|
|
|
|
extractor_callbacks->ProcessNode(result.first, result.second);
|
|
|
|
}
|
|
|
|
number_of_ways += parsed_buffer->resulting_ways.size();
|
|
|
|
for (const auto &result : parsed_buffer->resulting_ways)
|
|
|
|
{
|
|
|
|
extractor_callbacks->ProcessWay(result.first, result.second);
|
|
|
|
}
|
|
|
|
number_of_relations += parsed_buffer->resulting_restrictions.size();
|
|
|
|
for (const auto &result : parsed_buffer->resulting_restrictions)
|
|
|
|
{
|
|
|
|
extractor_callbacks->ProcessRestriction(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Number of pipeline tokens that yielded the best speedup was about 1.5 * num_cores
|
|
|
|
tbb::parallel_pipeline(tbb::task_scheduler_init::default_num_threads() * 1.5,
|
|
|
|
buffer_reader & buffer_transform & buffer_storage);
|
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
TIMER_STOP(parsing);
|
|
|
|
util::Log() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
util::Log() << "Raw input contains " << number_of_nodes << " nodes, " << number_of_ways
|
|
|
|
<< " ways, and " << number_of_relations << " relations";
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
extractor_callbacks.reset();
|
2016-11-18 06:14:38 -05:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
if (extraction_containers.all_edges_list.empty())
|
|
|
|
{
|
|
|
|
throw util::exception(std::string("There are no edges remaining after parsing.") +
|
|
|
|
SOURCE_REF);
|
2014-11-28 09:00:48 -05:00
|
|
|
}
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
extraction_containers.PrepareData(scripting_environment,
|
2017-06-16 04:45:24 -04:00
|
|
|
config.GetPath(".osrm").string(),
|
|
|
|
config.GetPath(".osrm.names").string());
|
2017-05-11 06:13:52 -04:00
|
|
|
|
2017-06-27 18:01:05 -04:00
|
|
|
auto profile_properties = scripting_environment.GetProfileProperties();
|
2017-08-14 18:18:57 -04:00
|
|
|
SetClassNames(scripting_environment.GetClassNames(), classes_map, profile_properties);
|
2017-07-18 17:05:37 -04:00
|
|
|
auto avoidable_classes = scripting_environment.GetAvoidableClasses();
|
|
|
|
SetAvoidableClasses(classes_map, avoidable_classes, profile_properties);
|
2017-06-16 04:45:24 -04:00
|
|
|
files::writeProfileProperties(config.GetPath(".osrm.properties").string(), profile_properties);
|
2017-05-11 06:13:52 -04:00
|
|
|
|
|
|
|
TIMER_STOP(extracting);
|
|
|
|
util::Log() << "extraction finished after " << TIMER_SEC(extracting) << "s";
|
|
|
|
|
2017-06-16 08:35:04 -04:00
|
|
|
return std::make_tuple(std::move(turn_lane_map),
|
2017-08-01 11:18:12 -04:00
|
|
|
std::move(extraction_containers.unconditional_turn_restrictions),
|
|
|
|
std::move(extraction_containers.conditional_turn_restrictions));
|
2014-11-28 09:00:48 -05:00
|
|
|
}
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2016-01-07 04:33:47 -05:00
|
|
|
void Extractor::FindComponents(unsigned max_edge_id,
|
2016-01-05 10:51:13 -05:00
|
|
|
const util::DeallocatingVector<EdgeBasedEdge> &input_edge_list,
|
2017-05-17 01:54:23 -04:00
|
|
|
const std::vector<EdgeBasedNodeSegment> &input_node_segments,
|
|
|
|
EdgeBasedNodeDataContainer &nodes_container) const
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-02-22 08:15:07 -05:00
|
|
|
using InputEdge = util::static_graph_details::SortableEdgeWithData<void>;
|
|
|
|
using UncontractedGraph = util::StaticGraph<void>;
|
2015-10-01 15:47:29 -04:00
|
|
|
std::vector<InputEdge> edges;
|
|
|
|
edges.reserve(input_edge_list.size() * 2);
|
|
|
|
|
|
|
|
for (const auto &edge : input_edge_list)
|
|
|
|
{
|
2017-03-06 17:00:11 -05:00
|
|
|
BOOST_ASSERT_MSG(static_cast<unsigned int>(std::max(edge.data.weight, 1)) > 0,
|
2015-10-01 15:47:29 -04:00
|
|
|
"edge distance < 1");
|
2016-03-05 14:53:53 -05:00
|
|
|
BOOST_ASSERT(edge.source <= max_edge_id);
|
|
|
|
BOOST_ASSERT(edge.target <= max_edge_id);
|
2017-03-06 17:00:11 -05:00
|
|
|
if (edge.data.forward)
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-02-22 08:15:07 -05:00
|
|
|
edges.push_back({edge.source, edge.target});
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
|
2017-03-06 17:00:11 -05:00
|
|
|
if (edge.data.backward)
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-02-22 08:15:07 -05:00
|
|
|
edges.push_back({edge.target, edge.source});
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 01:54:23 -04:00
|
|
|
// Connect forward and backward nodes of each edge to enforce
|
|
|
|
// forward and backward edge-based nodes be in one strongly-connected component
|
|
|
|
for (const auto &segment : input_node_segments)
|
|
|
|
{
|
|
|
|
if (segment.reverse_segment_id.enabled)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(segment.forward_segment_id.id <= max_edge_id);
|
|
|
|
BOOST_ASSERT(segment.reverse_segment_id.id <= max_edge_id);
|
|
|
|
edges.push_back({segment.forward_segment_id.id, segment.reverse_segment_id.id});
|
|
|
|
edges.push_back({segment.reverse_segment_id.id, segment.forward_segment_id.id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 15:47:29 -04:00
|
|
|
tbb::parallel_sort(edges.begin(), edges.end());
|
2017-02-22 08:15:07 -05:00
|
|
|
edges.erase(std::unique(edges.begin(), edges.end()), edges.end());
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2017-01-26 04:34:01 -05:00
|
|
|
auto uncontracted_graph = UncontractedGraph(max_edge_id + 1, edges);
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2017-01-26 04:34:01 -05:00
|
|
|
TarjanSCC<UncontractedGraph> component_search(uncontracted_graph);
|
2016-04-28 18:39:59 -04:00
|
|
|
component_search.Run();
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2017-05-15 06:15:00 -04:00
|
|
|
for (NodeID node_id = 0; node_id <= max_edge_id; ++node_id)
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-05-15 06:15:00 -04:00
|
|
|
const auto forward_component = component_search.GetComponentID(node_id);
|
|
|
|
const auto component_size = component_search.GetComponentSize(forward_component);
|
|
|
|
const auto is_tiny = component_size < config.small_component_size;
|
2017-05-17 01:54:23 -04:00
|
|
|
nodes_container.SetComponentID(node_id, {1 + forward_component, is_tiny});
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Load node based graph from .osrm file
|
|
|
|
*/
|
2016-01-05 10:51:13 -05:00
|
|
|
std::shared_ptr<util::NodeBasedDynamicGraph>
|
2016-11-14 17:43:24 -05:00
|
|
|
Extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barriers,
|
|
|
|
std::unordered_set<NodeID> &traffic_signals,
|
2017-04-02 19:58:06 -04:00
|
|
|
std::vector<util::Coordinate> &coordiantes,
|
2017-04-10 16:15:25 -04:00
|
|
|
extractor::PackedOSMIDs &osm_node_ids)
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-06-16 04:45:24 -04:00
|
|
|
storage::io::FileReader file_reader(config.GetPath(".osrm"),
|
2016-11-21 20:32:00 -05:00
|
|
|
storage::io::FileReader::VerifyFingerprint);
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2016-11-14 17:43:24 -05:00
|
|
|
auto barriers_iter = inserter(barriers, end(barriers));
|
|
|
|
auto traffic_signals_iter = inserter(traffic_signals, end(traffic_signals));
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2016-11-14 17:43:24 -05:00
|
|
|
NodeID number_of_node_based_nodes = util::loadNodesFromFile(
|
2017-04-02 19:58:06 -04:00
|
|
|
file_reader, barriers_iter, traffic_signals_iter, coordiantes, osm_node_ids);
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2016-12-06 15:30:46 -05:00
|
|
|
util::Log() << " - " << barriers.size() << " bollard nodes, " << traffic_signals.size()
|
|
|
|
<< " traffic lights";
|
2015-10-01 15:47:29 -04:00
|
|
|
|
2016-11-14 17:43:24 -05:00
|
|
|
std::vector<NodeBasedEdge> edge_list;
|
2016-11-21 20:32:00 -05:00
|
|
|
util::loadEdgesFromFile(file_reader, edge_list);
|
2015-10-01 15:47:29 -04:00
|
|
|
|
|
|
|
if (edge_list.empty())
|
|
|
|
{
|
2017-06-16 04:45:24 -04:00
|
|
|
throw util::exception("Node-based-graph (" + config.GetPath(".osrm").string() +
|
2016-12-06 15:30:46 -05:00
|
|
|
") contains no edges." + SOURCE_REF);
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
return util::NodeBasedDynamicGraphFromEdges(number_of_node_based_nodes, edge_list);
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Building an edge-expanded graph from node-based input and turn restrictions
|
|
|
|
*/
|
2017-08-01 11:18:12 -04:00
|
|
|
std::pair<std::size_t, EdgeID> Extractor::BuildEdgeExpandedGraph(
|
|
|
|
ScriptingEnvironment &scripting_environment,
|
|
|
|
std::vector<util::Coordinate> &coordinates,
|
|
|
|
extractor::PackedOSMIDs &osm_node_ids,
|
|
|
|
EdgeBasedNodeDataContainer &edge_based_nodes_container,
|
|
|
|
std::vector<EdgeBasedNodeSegment> &edge_based_node_segments,
|
|
|
|
std::vector<bool> &node_is_startpoint,
|
|
|
|
std::vector<EdgeWeight> &edge_based_node_weights,
|
|
|
|
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
|
|
|
|
const std::string &intersection_class_output_file,
|
|
|
|
std::vector<TurnRestriction> &turn_restrictions,
|
|
|
|
std::vector<ConditionalTurnRestriction> &conditional_turn_restrictions,
|
|
|
|
guidance::LaneDescriptionMap &turn_lane_map)
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
|
|
|
std::unordered_set<NodeID> barrier_nodes;
|
2017-07-20 08:03:39 -04:00
|
|
|
std::unordered_set<NodeID> traffic_signals;
|
2015-10-01 15:47:29 -04:00
|
|
|
|
|
|
|
auto node_based_graph =
|
2017-07-20 08:03:39 -04:00
|
|
|
LoadNodeBasedGraph(barrier_nodes, traffic_signals, coordinates, osm_node_ids);
|
2015-10-01 15:47:29 -04:00
|
|
|
|
|
|
|
CompressedEdgeContainer compressed_edge_container;
|
2016-03-21 17:42:47 -04:00
|
|
|
GraphCompressor graph_compressor;
|
2016-05-27 15:05:04 -04:00
|
|
|
graph_compressor.Compress(barrier_nodes,
|
2017-07-20 08:03:39 -04:00
|
|
|
traffic_signals,
|
|
|
|
scripting_environment,
|
2017-07-06 11:09:24 -04:00
|
|
|
turn_restrictions,
|
2017-08-01 11:18:12 -04:00
|
|
|
conditional_turn_restrictions,
|
2016-05-27 15:05:04 -04:00
|
|
|
*node_based_graph,
|
2015-10-01 15:47:29 -04:00
|
|
|
compressed_edge_container);
|
|
|
|
|
2017-08-01 11:18:12 -04:00
|
|
|
conditional_turn_restrictions =
|
|
|
|
removeInvalidRestrictions(std::move(conditional_turn_restrictions), *node_based_graph);
|
2017-07-19 08:21:11 -04:00
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
util::NameTable name_table(config.GetPath(".osrm.names").string());
|
2016-06-21 04:41:08 -04:00
|
|
|
|
2017-07-11 08:22:28 -04:00
|
|
|
EdgeBasedGraphFactory edge_based_graph_factory(node_based_graph,
|
|
|
|
compressed_edge_container,
|
|
|
|
barrier_nodes,
|
2017-07-20 08:03:39 -04:00
|
|
|
traffic_signals,
|
2017-07-11 08:22:28 -04:00
|
|
|
coordinates,
|
|
|
|
osm_node_ids,
|
|
|
|
scripting_environment.GetProfileProperties(),
|
|
|
|
name_table,
|
|
|
|
turn_lane_map);
|
|
|
|
|
|
|
|
const auto create_edge_based_edges = [&]() {
|
|
|
|
// scoped to relase intermediate datastructures right after the call
|
2017-08-01 11:18:12 -04:00
|
|
|
std::vector<TurnRestriction> node_restrictions;
|
|
|
|
for (auto const &t : turn_restrictions)
|
|
|
|
if (t.Type() == RestrictionType::NODE_RESTRICTION)
|
|
|
|
node_restrictions.push_back(t);
|
|
|
|
|
|
|
|
std::vector<ConditionalTurnRestriction> conditional_node_restrictions;
|
|
|
|
for (auto const &t : conditional_turn_restrictions)
|
|
|
|
if (t.Type() == RestrictionType::NODE_RESTRICTION)
|
|
|
|
conditional_node_restrictions.push_back(t);
|
|
|
|
|
|
|
|
RestrictionMap via_node_restriction_map(node_restrictions, IndexNodeByFromAndVia());
|
|
|
|
WayRestrictionMap via_way_restriction_map(conditional_turn_restrictions);
|
|
|
|
ConditionalRestrictionMap conditional_node_restriction_map(conditional_node_restrictions,
|
|
|
|
IndexNodeByFromAndVia());
|
2017-07-11 08:22:28 -04:00
|
|
|
turn_restrictions.clear();
|
|
|
|
turn_restrictions.shrink_to_fit();
|
|
|
|
|
|
|
|
edge_based_graph_factory.Run(scripting_environment,
|
|
|
|
config.GetPath(".osrm.edges").string(),
|
|
|
|
config.GetPath(".osrm.tld").string(),
|
|
|
|
config.GetPath(".osrm.turn_weight_penalties").string(),
|
|
|
|
config.GetPath(".osrm.turn_duration_penalties").string(),
|
|
|
|
config.GetPath(".osrm.turn_penalties_index").string(),
|
|
|
|
config.GetPath(".osrm.cnbg_to_ebg").string(),
|
2017-08-01 11:18:12 -04:00
|
|
|
config.GetPath(".osrm.restrictions").string(),
|
2017-07-11 08:22:28 -04:00
|
|
|
via_node_restriction_map,
|
2017-08-01 11:18:12 -04:00
|
|
|
conditional_node_restriction_map,
|
2017-07-11 08:22:28 -04:00
|
|
|
via_way_restriction_map);
|
|
|
|
return edge_based_graph_factory.GetNumberOfEdgeBasedNodes();
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto number_of_edge_based_nodes = create_edge_based_edges();
|
2017-05-10 19:04:09 -04:00
|
|
|
compressed_edge_container.PrintStatistics();
|
|
|
|
|
2017-01-26 11:53:19 -05:00
|
|
|
// The osrm-partition tool requires the compressed node based graph with an embedding.
|
|
|
|
//
|
|
|
|
// The `Run` function above re-numbers non-reverse compressed node based graph edges
|
|
|
|
// to a continuous range so that the nodes in the edge based graph are continuous.
|
|
|
|
//
|
|
|
|
// Luckily node based node ids still coincide with the coordinate array.
|
|
|
|
// That's the reason we can only here write out the final compressed node based graph.
|
|
|
|
|
|
|
|
// Dumps to file asynchronously and makes sure we wait for its completion.
|
|
|
|
std::future<void> compressed_node_based_graph_writing;
|
|
|
|
|
|
|
|
BOOST_SCOPE_EXIT_ALL(&)
|
|
|
|
{
|
|
|
|
if (compressed_node_based_graph_writing.valid())
|
|
|
|
compressed_node_based_graph_writing.wait();
|
|
|
|
};
|
|
|
|
|
2017-02-28 20:02:58 -05:00
|
|
|
compressed_node_based_graph_writing = std::async(std::launch::async, [&] {
|
2017-04-04 18:00:17 -04:00
|
|
|
WriteCompressedNodeBasedGraph(
|
2017-06-16 04:45:24 -04:00
|
|
|
config.GetPath(".osrm.cnbg").string(), *node_based_graph, coordinates);
|
2017-02-28 20:02:58 -05:00
|
|
|
});
|
2017-01-26 11:53:19 -05:00
|
|
|
|
2017-06-16 08:35:04 -04:00
|
|
|
{
|
|
|
|
std::vector<std::uint32_t> turn_lane_offsets;
|
|
|
|
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks;
|
|
|
|
std::tie(turn_lane_offsets, turn_lane_masks) =
|
|
|
|
guidance::transformTurnLaneMapIntoArrays(turn_lane_map);
|
|
|
|
files::writeTurnLaneDescriptions(
|
2017-06-16 04:45:24 -04:00
|
|
|
config.GetPath(".osrm.tls"), turn_lane_offsets, turn_lane_masks);
|
2017-06-16 08:35:04 -04:00
|
|
|
}
|
2017-06-16 04:45:24 -04:00
|
|
|
files::writeSegmentData(config.GetPath(".osrm.geometry"),
|
2017-04-01 21:25:55 -04:00
|
|
|
*compressed_edge_container.ToSegmentData());
|
2016-06-30 03:31:08 -04:00
|
|
|
|
2015-10-01 15:47:29 -04:00
|
|
|
edge_based_graph_factory.GetEdgeBasedEdges(edge_based_edge_list);
|
2017-05-16 13:22:41 -04:00
|
|
|
edge_based_graph_factory.GetEdgeBasedNodes(edge_based_nodes_container);
|
|
|
|
edge_based_graph_factory.GetEdgeBasedNodeSegments(edge_based_node_segments);
|
2015-12-11 17:11:04 -05:00
|
|
|
edge_based_graph_factory.GetStartPointMarkers(node_is_startpoint);
|
2016-01-07 04:33:47 -05:00
|
|
|
edge_based_graph_factory.GetEdgeBasedNodeWeights(edge_based_node_weights);
|
2015-10-01 15:47:29 -04:00
|
|
|
|
|
|
|
const std::size_t number_of_node_based_nodes = node_based_graph->GetNumberOfNodes();
|
2016-04-26 07:27:40 -04:00
|
|
|
|
2017-06-19 09:27:46 -04:00
|
|
|
util::Log() << "Writing Intersection Classification Data";
|
|
|
|
TIMER_START(write_intersections);
|
|
|
|
files::writeIntersections(
|
|
|
|
intersection_class_output_file,
|
|
|
|
IntersectionBearingsContainer{edge_based_graph_factory.GetBearingClassIds(),
|
|
|
|
edge_based_graph_factory.GetBearingClasses()},
|
|
|
|
edge_based_graph_factory.GetEntryClasses());
|
|
|
|
TIMER_STOP(write_intersections);
|
|
|
|
util::Log() << "ok, after " << TIMER_SEC(write_intersections) << "s";
|
2016-04-26 07:27:40 -04:00
|
|
|
|
2017-07-11 08:22:28 -04:00
|
|
|
return std::make_pair(number_of_node_based_nodes, number_of_edge_based_nodes);
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Building rtree-based nearest-neighbor data structure
|
|
|
|
|
|
|
|
Saves tree into '.ramIndex' and leaves into '.fileIndex'.
|
|
|
|
*/
|
2017-05-16 13:22:41 -04:00
|
|
|
void Extractor::BuildRTree(std::vector<EdgeBasedNodeSegment> edge_based_node_segments,
|
2015-12-11 17:11:04 -05:00
|
|
|
std::vector<bool> node_is_startpoint,
|
2017-04-02 19:58:06 -04:00
|
|
|
const std::vector<util::Coordinate> &coordinates)
|
2015-10-01 15:47:29 -04:00
|
|
|
{
|
2017-05-16 13:22:41 -04:00
|
|
|
util::Log() << "Constructing r-tree of " << edge_based_node_segments.size()
|
|
|
|
<< " segments build on-top of " << coordinates.size() << " coordinates";
|
2015-12-11 17:11:04 -05:00
|
|
|
|
2017-05-16 13:22:41 -04:00
|
|
|
BOOST_ASSERT(node_is_startpoint.size() == edge_based_node_segments.size());
|
2015-12-11 17:11:04 -05:00
|
|
|
|
|
|
|
// Filter node based edges based on startpoint
|
2017-05-16 13:22:41 -04:00
|
|
|
auto out_iter = edge_based_node_segments.begin();
|
|
|
|
auto in_iter = edge_based_node_segments.begin();
|
2016-04-12 06:42:16 -04:00
|
|
|
for (auto index : util::irange<std::size_t>(0UL, node_is_startpoint.size()))
|
2015-12-11 17:11:04 -05:00
|
|
|
{
|
2017-05-16 13:22:41 -04:00
|
|
|
BOOST_ASSERT(in_iter != edge_based_node_segments.end());
|
2015-12-11 17:11:04 -05:00
|
|
|
if (node_is_startpoint[index])
|
|
|
|
{
|
|
|
|
*out_iter = *in_iter;
|
|
|
|
out_iter++;
|
|
|
|
}
|
|
|
|
in_iter++;
|
|
|
|
}
|
2017-05-16 13:22:41 -04:00
|
|
|
auto new_size = out_iter - edge_based_node_segments.begin();
|
2016-04-14 16:07:23 -04:00
|
|
|
if (new_size == 0)
|
|
|
|
{
|
2016-04-14 17:39:20 -04:00
|
|
|
throw util::exception("There are no snappable edges left after processing. Are you "
|
2016-12-06 15:30:46 -05:00
|
|
|
"setting travel modes correctly in the profile? Cannot continue." +
|
|
|
|
SOURCE_REF);
|
2016-04-14 16:07:23 -04:00
|
|
|
}
|
2017-05-16 13:22:41 -04:00
|
|
|
edge_based_node_segments.resize(new_size);
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
TIMER_START(construction);
|
2017-05-23 11:37:41 -04:00
|
|
|
util::StaticRTree<EdgeBasedNodeSegment> rtree(edge_based_node_segments,
|
2017-06-16 04:45:24 -04:00
|
|
|
config.GetPath(".osrm.ramIndex").string(),
|
|
|
|
config.GetPath(".osrm.fileIndex").string(),
|
2017-05-23 11:37:41 -04:00
|
|
|
coordinates);
|
2015-12-03 14:04:23 -05:00
|
|
|
|
|
|
|
TIMER_STOP(construction);
|
2016-12-06 15:30:46 -05:00
|
|
|
util::Log() << "finished r-tree construction in " << TIMER_SEC(construction) << " seconds";
|
2015-10-01 15:47:29 -04:00
|
|
|
}
|
|
|
|
|
2017-01-26 11:53:19 -05:00
|
|
|
void Extractor::WriteCompressedNodeBasedGraph(const std::string &path,
|
|
|
|
const util::NodeBasedDynamicGraph &graph,
|
2017-04-02 19:58:06 -04:00
|
|
|
const std::vector<util::Coordinate> &coordinates)
|
2017-01-26 11:53:19 -05:00
|
|
|
{
|
|
|
|
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
|
|
|
|
|
|
|
|
storage::io::FileWriter writer{path, fingerprint};
|
|
|
|
|
|
|
|
// Writes: | Fingerprint | #e | #n | edges | coordinates |
|
|
|
|
// - uint64: number of edges (from, to) pairs
|
|
|
|
// - uint64: number of nodes and therefore also coordinates
|
|
|
|
// - (uint32_t, uint32_t): num_edges * edges
|
|
|
|
// - (int32_t, int32_t: num_nodes * coordinates (lon, lat)
|
|
|
|
|
|
|
|
const auto num_edges = graph.GetNumberOfEdges();
|
|
|
|
const auto num_nodes = graph.GetNumberOfNodes();
|
|
|
|
|
2017-04-02 19:58:06 -04:00
|
|
|
BOOST_ASSERT_MSG(num_nodes == coordinates.size(), "graph and embedding out of sync");
|
2017-01-26 11:53:19 -05:00
|
|
|
|
2017-02-01 09:50:06 -05:00
|
|
|
writer.WriteElementCount64(num_edges);
|
|
|
|
writer.WriteElementCount64(num_nodes);
|
2017-01-26 11:53:19 -05:00
|
|
|
|
|
|
|
// For all nodes iterate over its edges and dump (from, to) pairs
|
|
|
|
for (const NodeID from_node : util::irange(0u, num_nodes))
|
|
|
|
{
|
|
|
|
for (const EdgeID edge : graph.GetAdjacentEdgeRange(from_node))
|
|
|
|
{
|
|
|
|
const auto to_node = graph.GetTarget(edge);
|
|
|
|
|
2017-02-01 09:50:06 -05:00
|
|
|
writer.WriteOne(from_node);
|
|
|
|
writer.WriteOne(to_node);
|
2017-01-26 11:53:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-02 19:58:06 -04:00
|
|
|
// FIXME this is unneccesary: We have this data
|
|
|
|
for (const auto &qnode : coordinates)
|
2017-01-26 11:53:19 -05:00
|
|
|
{
|
2017-02-01 09:50:06 -05:00
|
|
|
writer.WriteOne(qnode.lon);
|
|
|
|
writer.WriteOne(qnode.lat);
|
2017-01-26 11:53:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 03:31:08 -04:00
|
|
|
} // namespace extractor
|
|
|
|
} // namespace osrm
|