Add namespace around all files
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace benchmarks
|
||||
{
|
||||
|
||||
// Choosen by a fair W20 dice roll (this value is completely arbitrary)
|
||||
constexpr unsigned RANDOM_SEED = 13;
|
||||
constexpr int32_t WORLD_MIN_LAT = -90 * COORDINATE_PRECISION;
|
||||
@@ -16,22 +21,22 @@ constexpr int32_t WORLD_MAX_LAT = 90 * COORDINATE_PRECISION;
|
||||
constexpr int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
|
||||
constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
|
||||
|
||||
using RTreeLeaf = EdgeBasedNode;
|
||||
using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<FixedPointCoordinate>>;
|
||||
using BenchStaticRTree = StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, false>::vector, false>;
|
||||
using BenchQuery = GeospatialQuery<BenchStaticRTree>;
|
||||
using RTreeLeaf = extractor::EdgeBasedNode;
|
||||
using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<util::FixedPointCoordinate>>;
|
||||
using BenchStaticRTree = util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, false>::vector, false>;
|
||||
using BenchQuery = engine::GeospatialQuery<BenchStaticRTree>;
|
||||
|
||||
FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file)
|
||||
{
|
||||
boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
|
||||
|
||||
QueryNode current_node;
|
||||
extractor::QueryNode current_node;
|
||||
unsigned coordinate_count = 0;
|
||||
nodes_input_stream.read((char *)&coordinate_count, sizeof(unsigned));
|
||||
auto coords = std::make_shared<std::vector<FixedPointCoordinate>>(coordinate_count);
|
||||
for (unsigned i = 0; i < coordinate_count; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode));
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode));
|
||||
coords->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon);
|
||||
BOOST_ASSERT((std::abs(coords->at(i).lat) >> 30) == 0);
|
||||
BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0);
|
||||
@@ -51,6 +56,7 @@ void benchmarkQuery(const std::vector<FixedPointCoordinate> &queries,
|
||||
for (const auto &q : queries)
|
||||
{
|
||||
auto result = query(q);
|
||||
(void) result;
|
||||
}
|
||||
TIMER_STOP(query);
|
||||
|
||||
@@ -102,6 +108,8 @@ void benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer
|
||||
return geo_query.NearestPhantomNodes(q, 10);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -116,12 +124,12 @@ int main(int argc, char **argv)
|
||||
const char *file_path = argv[2];
|
||||
const char *nodes_path = argv[3];
|
||||
|
||||
auto coords = loadCoordinates(nodes_path);
|
||||
auto coords = osrm::benchmarks::loadCoordinates(nodes_path);
|
||||
|
||||
BenchStaticRTree rtree(ram_path, file_path, coords);
|
||||
BenchQuery query(rtree, coords);
|
||||
osrm::benchmarks::BenchStaticRTree rtree(ram_path, file_path, coords);
|
||||
osrm::benchmarks::BenchQuery query(rtree, coords);
|
||||
|
||||
benchmark(rtree, query, 10000);
|
||||
osrm::benchmarks::benchmark(rtree, query, 10000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace contractor
|
||||
{
|
||||
|
||||
return_code
|
||||
ContractorOptions::ParseArguments(int argc, char *argv[], ContractorConfig &contractor_config)
|
||||
{
|
||||
@@ -87,13 +92,13 @@ ContractorOptions::ParseArguments(int argc, char *argv[], ContractorConfig &cont
|
||||
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
SimpleLogger().Write() << OSRM_VERSION;
|
||||
util::SimpleLogger().Write() << OSRM_VERSION;
|
||||
return return_code::exit;
|
||||
}
|
||||
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
SimpleLogger().Write() << "\n" << visible_options;
|
||||
util::SimpleLogger().Write() << "\n" << visible_options;
|
||||
return return_code::exit;
|
||||
}
|
||||
|
||||
@@ -101,7 +106,7 @@ ContractorOptions::ParseArguments(int argc, char *argv[], ContractorConfig &cont
|
||||
|
||||
if (!option_variables.count("input"))
|
||||
{
|
||||
SimpleLogger().Write() << "\n" << visible_options;
|
||||
util::SimpleLogger().Write() << "\n" << visible_options;
|
||||
return return_code::fail;
|
||||
}
|
||||
|
||||
@@ -119,3 +124,5 @@ void ContractorOptions::GenerateOutputFilesNames(ContractorConfig &contractor_co
|
||||
contractor_config.edge_penalty_path =
|
||||
contractor_config.osrm_input_path.string() + ".edge_penalties";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,24 @@
|
||||
|
||||
#include "util/debug_geometry.hpp"
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <> struct hash<std::pair<OSMNodeID, OSMNodeID>>
|
||||
{
|
||||
std::size_t operator()(const std::pair<OSMNodeID, OSMNodeID> &k) const
|
||||
{
|
||||
return OSMNodeID_to_uint64_t(k.first) ^ (OSMNodeID_to_uint64_t(k.second) << 12);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace contractor
|
||||
{
|
||||
|
||||
Prepare::~Prepare() {}
|
||||
|
||||
int Prepare::Run()
|
||||
@@ -37,24 +55,24 @@ int Prepare::Run()
|
||||
#ifdef WIN32
|
||||
#pragma message("Memory consumption on Windows can be higher due to different bit packing")
|
||||
#else
|
||||
static_assert(sizeof(NodeBasedEdge) == 20,
|
||||
"changing NodeBasedEdge type has influence on memory consumption!");
|
||||
static_assert(sizeof(EdgeBasedEdge) == 16,
|
||||
static_assert(sizeof(extractor::NodeBasedEdge) == 20,
|
||||
"changing extractor::NodeBasedEdge type has influence on memory consumption!");
|
||||
static_assert(sizeof(extractor::EdgeBasedEdge) == 16,
|
||||
"changing EdgeBasedEdge type has influence on memory consumption!");
|
||||
#endif
|
||||
|
||||
if (config.core_factor > 1.0 || config.core_factor < 0)
|
||||
{
|
||||
throw osrm::exception("Core factor must be between 0.0 to 1.0 (inclusive)");
|
||||
throw util::exception("Core factor must be between 0.0 to 1.0 (inclusive)");
|
||||
}
|
||||
|
||||
TIMER_START(preparing);
|
||||
|
||||
// Create a new lua state
|
||||
|
||||
SimpleLogger().Write() << "Loading edge-expanded graph representation";
|
||||
util::SimpleLogger().Write() << "Loading edge-expanded graph representation";
|
||||
|
||||
DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
|
||||
util::DeallocatingVector<extractor::EdgeBasedEdge> edge_based_edge_list;
|
||||
|
||||
size_t max_edge_id = LoadEdgeExpandedGraph(
|
||||
config.edge_based_graph_path, edge_based_edge_list, config.edge_segment_lookup_path,
|
||||
@@ -69,12 +87,12 @@ int Prepare::Run()
|
||||
{
|
||||
ReadNodeLevels(node_levels);
|
||||
}
|
||||
DeallocatingVector<QueryEdge> contracted_edge_list;
|
||||
util::DeallocatingVector<QueryEdge> contracted_edge_list;
|
||||
ContractGraph(max_edge_id, edge_based_edge_list, contracted_edge_list, is_core_node,
|
||||
node_levels);
|
||||
TIMER_STOP(contraction);
|
||||
|
||||
SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec";
|
||||
util::SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec";
|
||||
|
||||
std::size_t number_of_used_edges = WriteContractedGraph(max_edge_id, contracted_edge_list);
|
||||
WriteCoreNodeMarker(std::move(is_core_node));
|
||||
@@ -85,35 +103,23 @@ int Prepare::Run()
|
||||
|
||||
TIMER_STOP(preparing);
|
||||
|
||||
SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
|
||||
SimpleLogger().Write() << "Contraction: " << ((max_edge_id + 1) / TIMER_SEC(contraction))
|
||||
util::SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
|
||||
util::SimpleLogger().Write() << "Contraction: " << ((max_edge_id + 1) / TIMER_SEC(contraction))
|
||||
<< " nodes/sec and " << number_of_used_edges / TIMER_SEC(contraction)
|
||||
<< " edges/sec";
|
||||
|
||||
SimpleLogger().Write() << "finished preprocessing";
|
||||
util::SimpleLogger().Write() << "finished preprocessing";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <> struct hash<std::pair<OSMNodeID, OSMNodeID>>
|
||||
{
|
||||
std::size_t operator()(const std::pair<OSMNodeID, OSMNodeID> &k) const
|
||||
{
|
||||
return OSMNodeID_to_uint64_t(k.first) ^ (OSMNodeID_to_uint64_t(k.second) << 12);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_filename,
|
||||
DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
|
||||
util::DeallocatingVector<extractor::EdgeBasedEdge> &edge_based_edge_list,
|
||||
const std::string &edge_segment_lookup_filename,
|
||||
const std::string &edge_penalty_filename,
|
||||
const std::string &segment_speed_filename)
|
||||
{
|
||||
SimpleLogger().Write() << "Opening " << edge_based_graph_filename;
|
||||
util::SimpleLogger().Write() << "Opening " << edge_based_graph_filename;
|
||||
boost::filesystem::ifstream input_stream(edge_based_graph_filename, std::ios::binary);
|
||||
|
||||
const bool update_edge_weights = segment_speed_filename != "";
|
||||
@@ -127,14 +133,14 @@ std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_f
|
||||
edge_fixed_penalties_input_stream.open(edge_penalty_filename, std::ios::binary);
|
||||
if (!edge_segment_input_stream || !edge_fixed_penalties_input_stream)
|
||||
{
|
||||
throw osrm::exception("Could not load .edge_segment_lookup or .edge_penalties, did you "
|
||||
throw util::exception("Could not load .edge_segment_lookup or .edge_penalties, did you "
|
||||
"run osrm-extract with '--generate-edge-lookup'?");
|
||||
}
|
||||
}
|
||||
|
||||
const FingerPrint fingerprint_valid = FingerPrint::GetValid();
|
||||
FingerPrint fingerprint_loaded;
|
||||
input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
|
||||
const util::FingerPrint fingerprint_valid = util::FingerPrint::GetValid();
|
||||
util::FingerPrint fingerprint_loaded;
|
||||
input_stream.read((char *)&fingerprint_loaded, sizeof(util::FingerPrint));
|
||||
fingerprint_loaded.TestPrepare(fingerprint_valid);
|
||||
|
||||
size_t number_of_edges = 0;
|
||||
@@ -143,13 +149,13 @@ std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_f
|
||||
input_stream.read((char *)&max_edge_id, sizeof(size_t));
|
||||
|
||||
edge_based_edge_list.resize(number_of_edges);
|
||||
SimpleLogger().Write() << "Reading " << number_of_edges << " edges from the edge based graph";
|
||||
util::SimpleLogger().Write() << "Reading " << number_of_edges << " edges from the edge based graph";
|
||||
|
||||
std::unordered_map<std::pair<OSMNodeID, OSMNodeID>, unsigned> segment_speed_lookup;
|
||||
|
||||
if (update_edge_weights)
|
||||
{
|
||||
SimpleLogger().Write() << "Segment speed data supplied, will update edge weights from "
|
||||
util::SimpleLogger().Write() << "Segment speed data supplied, will update edge weights from "
|
||||
<< segment_speed_filename;
|
||||
io::CSVReader<3> csv_in(segment_speed_filename);
|
||||
csv_in.set_header("from_node", "to_node", "speed");
|
||||
@@ -163,14 +169,14 @@ std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_f
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_GEOMETRY_START(config);
|
||||
util::DEBUG_GEOMETRY_START(config);
|
||||
|
||||
// TODO: can we read this in bulk? DeallocatingVector isn't necessarily
|
||||
// TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily
|
||||
// all stored contiguously
|
||||
for (; number_of_edges > 0; --number_of_edges)
|
||||
{
|
||||
EdgeBasedEdge inbuffer;
|
||||
input_stream.read((char *)&inbuffer, sizeof(EdgeBasedEdge));
|
||||
extractor::EdgeBasedEdge inbuffer;
|
||||
input_stream.read((char *)&inbuffer, sizeof(extractor::EdgeBasedEdge));
|
||||
|
||||
if (update_edge_weights)
|
||||
{
|
||||
@@ -212,7 +218,7 @@ std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_f
|
||||
(segment_length * 10.) / (speed_iter->second / 3.6) + .5)));
|
||||
new_weight += new_segment_weight;
|
||||
|
||||
DEBUG_GEOMETRY_EDGE(new_segment_weight, segment_length, previous_osm_node_id,
|
||||
util::DEBUG_GEOMETRY_EDGE(new_segment_weight, segment_length, previous_osm_node_id,
|
||||
this_osm_node_id);
|
||||
}
|
||||
else
|
||||
@@ -220,7 +226,7 @@ std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_f
|
||||
// If no lookup found, use the original weight value for this segment
|
||||
new_weight += segment_weight;
|
||||
|
||||
DEBUG_GEOMETRY_EDGE(segment_weight, segment_length, previous_osm_node_id,
|
||||
util::DEBUG_GEOMETRY_EDGE(segment_weight, segment_length, previous_osm_node_id,
|
||||
this_osm_node_id);
|
||||
}
|
||||
|
||||
@@ -233,8 +239,8 @@ std::size_t Prepare::LoadEdgeExpandedGraph(std::string const &edge_based_graph_f
|
||||
edge_based_edge_list.emplace_back(std::move(inbuffer));
|
||||
}
|
||||
|
||||
DEBUG_GEOMETRY_STOP();
|
||||
SimpleLogger().Write() << "Done reading edges";
|
||||
util::DEBUG_GEOMETRY_STOP();
|
||||
util::SimpleLogger().Write() << "Done reading edges";
|
||||
return max_edge_id;
|
||||
}
|
||||
|
||||
@@ -277,17 +283,17 @@ void Prepare::WriteCoreNodeMarker(std::vector<bool> &&in_is_core_node) const
|
||||
}
|
||||
|
||||
std::size_t Prepare::WriteContractedGraph(unsigned max_node_id,
|
||||
const DeallocatingVector<QueryEdge> &contracted_edge_list)
|
||||
const util::DeallocatingVector<QueryEdge> &contracted_edge_list)
|
||||
{
|
||||
// Sorting contracted edges in a way that the static query graph can read some in in-place.
|
||||
tbb::parallel_sort(contracted_edge_list.begin(), contracted_edge_list.end());
|
||||
const unsigned contracted_edge_count = contracted_edge_list.size();
|
||||
SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
|
||||
util::SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
|
||||
<< " edges";
|
||||
|
||||
const FingerPrint fingerprint = FingerPrint::GetValid();
|
||||
const util::FingerPrint fingerprint = util::FingerPrint::GetValid();
|
||||
boost::filesystem::ofstream hsgr_output_stream(config.graph_output_path, std::ios::binary);
|
||||
hsgr_output_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
||||
hsgr_output_stream.write((char *)&fingerprint, sizeof(util::FingerPrint));
|
||||
const unsigned max_used_node_id = [&contracted_edge_list]
|
||||
{
|
||||
unsigned tmp_max = 0;
|
||||
@@ -301,20 +307,20 @@ std::size_t Prepare::WriteContractedGraph(unsigned max_node_id,
|
||||
return tmp_max;
|
||||
}();
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "input graph has " << (max_node_id + 1) << " nodes";
|
||||
SimpleLogger().Write(logDEBUG) << "contracted graph has " << (max_used_node_id + 1) << " nodes";
|
||||
util::SimpleLogger().Write(logDEBUG) << "input graph has " << (max_node_id + 1) << " nodes";
|
||||
util::SimpleLogger().Write(logDEBUG) << "contracted graph has " << (max_used_node_id + 1) << " nodes";
|
||||
|
||||
std::vector<StaticGraph<EdgeData>::NodeArrayEntry> node_array;
|
||||
std::vector<util::StaticGraph<EdgeData>::NodeArrayEntry> node_array;
|
||||
// make sure we have at least one sentinel
|
||||
node_array.resize(max_node_id + 2);
|
||||
|
||||
SimpleLogger().Write() << "Building node array";
|
||||
StaticGraph<EdgeData>::EdgeIterator edge = 0;
|
||||
StaticGraph<EdgeData>::EdgeIterator position = 0;
|
||||
StaticGraph<EdgeData>::EdgeIterator last_edge;
|
||||
util::SimpleLogger().Write() << "Building node array";
|
||||
util::StaticGraph<EdgeData>::EdgeIterator edge = 0;
|
||||
util::StaticGraph<EdgeData>::EdgeIterator position = 0;
|
||||
util::StaticGraph<EdgeData>::EdgeIterator last_edge;
|
||||
|
||||
// initializing 'first_edge'-field of nodes:
|
||||
for (const auto node : osrm::irange(0u, max_used_node_id + 1))
|
||||
for (const auto node : util::irange(0u, max_used_node_id + 1))
|
||||
{
|
||||
last_edge = edge;
|
||||
while ((edge < contracted_edge_count) && (contracted_edge_list[edge].source == node))
|
||||
@@ -326,17 +332,17 @@ std::size_t Prepare::WriteContractedGraph(unsigned max_node_id,
|
||||
}
|
||||
|
||||
for (const auto sentinel_counter :
|
||||
osrm::irange<unsigned>(max_used_node_id + 1, node_array.size()))
|
||||
util::irange<unsigned>(max_used_node_id + 1, node_array.size()))
|
||||
{
|
||||
// sentinel element, guarded against underflow
|
||||
node_array[sentinel_counter].first_edge = contracted_edge_count;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Serializing node array";
|
||||
util::SimpleLogger().Write() << "Serializing node array";
|
||||
|
||||
RangebasedCRC32 crc32_calculator;
|
||||
const unsigned edges_crc32 = crc32_calculator(contracted_edge_list);
|
||||
SimpleLogger().Write() << "Writing CRC32: " << edges_crc32;
|
||||
util::SimpleLogger().Write() << "Writing CRC32: " << edges_crc32;
|
||||
|
||||
const unsigned node_array_size = node_array.size();
|
||||
// serialize crc32, aka checksum
|
||||
@@ -349,15 +355,15 @@ std::size_t Prepare::WriteContractedGraph(unsigned max_node_id,
|
||||
if (node_array_size > 0)
|
||||
{
|
||||
hsgr_output_stream.write((char *)&node_array[0],
|
||||
sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
|
||||
sizeof(util::StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
|
||||
}
|
||||
|
||||
// serialize all edges
|
||||
SimpleLogger().Write() << "Building edge array";
|
||||
util::SimpleLogger().Write() << "Building edge array";
|
||||
int number_of_used_edges = 0;
|
||||
|
||||
StaticGraph<EdgeData>::EdgeArrayEntry current_edge;
|
||||
for (const auto edge : osrm::irange<std::size_t>(0, contracted_edge_list.size()))
|
||||
util::StaticGraph<EdgeData>::EdgeArrayEntry current_edge;
|
||||
for (const auto edge : util::irange<std::size_t>(0, contracted_edge_list.size()))
|
||||
{
|
||||
// no eigen loops
|
||||
BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target);
|
||||
@@ -369,19 +375,19 @@ std::size_t Prepare::WriteContractedGraph(unsigned max_node_id,
|
||||
#ifndef NDEBUG
|
||||
if (current_edge.data.distance <= 0)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Edge: " << edge
|
||||
util::SimpleLogger().Write(logWARNING) << "Edge: " << edge
|
||||
<< ",source: " << contracted_edge_list[edge].source
|
||||
<< ", target: " << contracted_edge_list[edge].target
|
||||
<< ", dist: " << current_edge.data.distance;
|
||||
|
||||
SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node "
|
||||
util::SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node "
|
||||
<< contracted_edge_list[edge].source << "/"
|
||||
<< node_array.size() - 1;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
hsgr_output_stream.write((char *)¤t_edge,
|
||||
sizeof(StaticGraph<EdgeData>::EdgeArrayEntry));
|
||||
sizeof(util::StaticGraph<EdgeData>::EdgeArrayEntry));
|
||||
|
||||
++number_of_used_edges;
|
||||
}
|
||||
@@ -393,8 +399,8 @@ std::size_t Prepare::WriteContractedGraph(unsigned max_node_id,
|
||||
\brief Build contracted graph.
|
||||
*/
|
||||
void Prepare::ContractGraph(const unsigned max_edge_id,
|
||||
DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
|
||||
DeallocatingVector<QueryEdge> &contracted_edge_list,
|
||||
util::DeallocatingVector<extractor::EdgeBasedEdge> &edge_based_edge_list,
|
||||
util::DeallocatingVector<QueryEdge> &contracted_edge_list,
|
||||
std::vector<bool> &is_core_node,
|
||||
std::vector<float> &inout_node_levels) const
|
||||
{
|
||||
@@ -407,3 +413,5 @@ void Prepare::ContractGraph(const unsigned max_edge_id,
|
||||
contractor.GetCoreMarker(is_core_node);
|
||||
contractor.GetNodeLevels(inout_node_levels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,18 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
struct CoordinatePairCalculator
|
||||
{
|
||||
CoordinatePairCalculator() = delete;
|
||||
CoordinatePairCalculator(const FixedPointCoordinate &coordinate_a,
|
||||
const FixedPointCoordinate &coordinate_b)
|
||||
CoordinatePairCalculator(const util::FixedPointCoordinate &coordinate_a,
|
||||
const util::FixedPointCoordinate &coordinate_b)
|
||||
{
|
||||
// initialize distance calculator with two fixed coordinates a, b
|
||||
const float RAD = 0.017453292519943295769236907684886f;
|
||||
@@ -25,7 +30,7 @@ struct CoordinatePairCalculator
|
||||
second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * RAD;
|
||||
}
|
||||
|
||||
int operator()(FixedPointCoordinate &other) const
|
||||
int operator()(util::FixedPointCoordinate &other) const
|
||||
{
|
||||
// set third coordinate c
|
||||
const float RAD = 0.017453292519943295769236907684886f;
|
||||
@@ -135,3 +140,5 @@ void DouglasPeucker::Run(RandomAccessIt begin, RandomAccessIt end, const unsigne
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-20
@@ -28,43 +28,51 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
OSRM::OSRM_impl::OSRM_impl(LibOSRMConfig &lib_config)
|
||||
{
|
||||
if (lib_config.use_shared_memory)
|
||||
{
|
||||
barrier = osrm::make_unique<SharedBarriers>();
|
||||
query_data_facade = new SharedDataFacade<QueryEdge::EdgeData>();
|
||||
barrier = util::make_unique<datafacade::SharedBarriers>();
|
||||
query_data_facade = new datafacade::SharedDataFacade<contractor::QueryEdge::EdgeData>();
|
||||
}
|
||||
else
|
||||
{
|
||||
// populate base path
|
||||
populate_base_path(lib_config.server_paths);
|
||||
query_data_facade = new InternalDataFacade<QueryEdge::EdgeData>(lib_config.server_paths);
|
||||
util::populate_base_path(lib_config.server_paths);
|
||||
query_data_facade = new datafacade::InternalDataFacade<contractor::QueryEdge::EdgeData>(
|
||||
lib_config.server_paths);
|
||||
}
|
||||
|
||||
using DataFacade = datafacade::BaseDataFacade<contractor::QueryEdge::EdgeData>;
|
||||
|
||||
// The following plugins handle all requests.
|
||||
RegisterPlugin(new DistanceTablePlugin<BaseDataFacade<QueryEdge::EdgeData>>(
|
||||
RegisterPlugin(new plugins::DistanceTablePlugin<DataFacade>(
|
||||
query_data_facade, lib_config.max_locations_distance_table));
|
||||
RegisterPlugin(new HelloWorldPlugin());
|
||||
RegisterPlugin(new NearestPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
RegisterPlugin(new MapMatchingPlugin<BaseDataFacade<QueryEdge::EdgeData>>(
|
||||
RegisterPlugin(new plugins::HelloWorldPlugin());
|
||||
RegisterPlugin(new plugins::NearestPlugin<DataFacade>(query_data_facade));
|
||||
RegisterPlugin(new plugins::MapMatchingPlugin<DataFacade>(
|
||||
query_data_facade, lib_config.max_locations_map_matching));
|
||||
RegisterPlugin(new TimestampPlugin<BaseDataFacade<QueryEdge::EdgeData>>(query_data_facade));
|
||||
RegisterPlugin(new ViaRoutePlugin<BaseDataFacade<QueryEdge::EdgeData>>(
|
||||
query_data_facade, lib_config.max_locations_viaroute));
|
||||
RegisterPlugin(new RoundTripPlugin<BaseDataFacade<QueryEdge::EdgeData>>(
|
||||
query_data_facade, lib_config.max_locations_trip));
|
||||
RegisterPlugin(new plugins::TimestampPlugin<DataFacade>(query_data_facade));
|
||||
RegisterPlugin(new plugins::ViaRoutePlugin<DataFacade>(query_data_facade,
|
||||
lib_config.max_locations_viaroute));
|
||||
RegisterPlugin(
|
||||
new plugins::RoundTripPlugin<DataFacade>(query_data_facade, lib_config.max_locations_trip));
|
||||
}
|
||||
|
||||
void OSRM::OSRM_impl::RegisterPlugin(BasePlugin *raw_plugin_ptr)
|
||||
void OSRM::OSRM_impl::RegisterPlugin(plugins::BasePlugin *raw_plugin_ptr)
|
||||
{
|
||||
std::unique_ptr<BasePlugin> plugin_ptr(raw_plugin_ptr);
|
||||
SimpleLogger().Write() << "loaded plugin: " << plugin_ptr->GetDescriptor();
|
||||
std::unique_ptr<plugins::BasePlugin> plugin_ptr(raw_plugin_ptr);
|
||||
util::SimpleLogger().Write() << "loaded plugin: " << plugin_ptr->GetDescriptor();
|
||||
plugin_map[plugin_ptr->GetDescriptor()] = std::move(plugin_ptr);
|
||||
}
|
||||
|
||||
int OSRM::OSRM_impl::RunQuery(const RouteParameters &route_parameters,
|
||||
osrm::json::Object &json_result)
|
||||
util::json::Object &json_result)
|
||||
{
|
||||
const auto &plugin_iterator = plugin_map.find(route_parameters.service);
|
||||
|
||||
@@ -124,17 +132,20 @@ void OSRM::OSRM_impl::increase_concurrent_query_count()
|
||||
// increment query count
|
||||
++(barrier->number_of_queries);
|
||||
|
||||
(static_cast<SharedDataFacade<QueryEdge::EdgeData> *>(query_data_facade))
|
||||
(static_cast<datafacade::SharedDataFacade<contractor::QueryEdge::EdgeData> *>(
|
||||
query_data_facade))
|
||||
->CheckAndReloadFacade();
|
||||
}
|
||||
|
||||
// proxy code for compilation firewall
|
||||
OSRM::OSRM(LibOSRMConfig &lib_config) : OSRM_pimpl_(osrm::make_unique<OSRM_impl>(lib_config)) {}
|
||||
OSRM::OSRM(LibOSRMConfig &lib_config) : OSRM_pimpl_(util::make_unique<OSRM_impl>(lib_config)) {}
|
||||
|
||||
// needed because unique_ptr needs the size of OSRM_impl for delete
|
||||
OSRM::~OSRM() {}
|
||||
|
||||
int OSRM::RunQuery(const RouteParameters &route_parameters, osrm::json::Object &json_result)
|
||||
int OSRM::RunQuery(const RouteParameters &route_parameters, util::json::Object &json_result)
|
||||
{
|
||||
return OSRM_pimpl_->RunQuery(route_parameters, json_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
PhantomNode::PhantomNode(NodeID forward_node_id,
|
||||
NodeID reverse_node_id,
|
||||
unsigned name_id,
|
||||
@@ -15,10 +20,10 @@ PhantomNode::PhantomNode(NodeID forward_node_id,
|
||||
unsigned packed_geometry_id,
|
||||
bool is_tiny_component,
|
||||
unsigned component_id,
|
||||
FixedPointCoordinate &location,
|
||||
util::FixedPointCoordinate &location,
|
||||
unsigned short fwd_segment_position,
|
||||
TravelMode forward_travel_mode,
|
||||
TravelMode backward_travel_mode)
|
||||
extractor::TravelMode forward_travel_mode,
|
||||
extractor::TravelMode backward_travel_mode)
|
||||
: forward_node_id(forward_node_id), reverse_node_id(reverse_node_id), name_id(name_id),
|
||||
forward_weight(forward_weight), reverse_weight(reverse_weight),
|
||||
forward_offset(forward_offset), reverse_offset(reverse_offset),
|
||||
@@ -74,3 +79,5 @@ bool PhantomNode::is_valid(const unsigned number_of_nodes) const
|
||||
bool PhantomNode::IsValid() const { return location.IsValid() && (name_id != INVALID_NAMEID); }
|
||||
|
||||
bool PhantomNode::operator==(const PhantomNode &other) const { return location == other.location; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
std::string PolylineCompressor::encode_vector(std::vector<int> &numbers) const
|
||||
{
|
||||
std::string output;
|
||||
@@ -47,7 +52,7 @@ PolylineCompressor::get_encoded_string(const std::vector<SegmentInformation> &po
|
||||
|
||||
std::vector<int> delta_numbers;
|
||||
delta_numbers.reserve((polyline.size() - 1) * 2);
|
||||
FixedPointCoordinate previous_coordinate = {0, 0};
|
||||
util::FixedPointCoordinate previous_coordinate = {0, 0};
|
||||
for (const auto &segment : polyline)
|
||||
{
|
||||
if (segment.necessary)
|
||||
@@ -62,10 +67,10 @@ PolylineCompressor::get_encoded_string(const std::vector<SegmentInformation> &po
|
||||
return encode_vector(delta_numbers);
|
||||
}
|
||||
|
||||
std::vector<FixedPointCoordinate>
|
||||
std::vector<util::FixedPointCoordinate>
|
||||
PolylineCompressor::decode_string(const std::string &geometry_string) const
|
||||
{
|
||||
std::vector<FixedPointCoordinate> new_coordinates;
|
||||
std::vector<util::FixedPointCoordinate> new_coordinates;
|
||||
int index = 0, len = geometry_string.size();
|
||||
int lat = 0, lng = 0;
|
||||
|
||||
@@ -92,7 +97,7 @@ PolylineCompressor::decode_string(const std::string &geometry_string) const
|
||||
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
||||
lng += dlng;
|
||||
|
||||
FixedPointCoordinate p;
|
||||
util::FixedPointCoordinate p;
|
||||
p.lat = COORDINATE_PRECISION * (((double)lat / 1E6));
|
||||
p.lon = COORDINATE_PRECISION * (((double)lng / 1E6));
|
||||
new_coordinates.push_back(p);
|
||||
@@ -100,3 +105,5 @@ PolylineCompressor::decode_string(const std::string &geometry_string) const
|
||||
|
||||
return new_coordinates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,26 @@
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
osrm::json::String
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
util::json::String
|
||||
PolylineFormatter::printEncodedString(const std::vector<SegmentInformation> &polyline) const
|
||||
{
|
||||
return osrm::json::String(PolylineCompressor().get_encoded_string(polyline));
|
||||
return util::json::String(PolylineCompressor().get_encoded_string(polyline));
|
||||
}
|
||||
|
||||
osrm::json::Array
|
||||
util::json::Array
|
||||
PolylineFormatter::printUnencodedString(const std::vector<SegmentInformation> &polyline) const
|
||||
{
|
||||
osrm::json::Array json_geometry_array;
|
||||
util::json::Array json_geometry_array;
|
||||
for (const auto &segment : polyline)
|
||||
{
|
||||
if (segment.necessary)
|
||||
{
|
||||
osrm::json::Array json_coordinate;
|
||||
util::json::Array json_coordinate;
|
||||
json_coordinate.values.push_back(segment.location.lat / COORDINATE_PRECISION);
|
||||
json_coordinate.values.push_back(segment.location.lon / COORDINATE_PRECISION);
|
||||
json_geometry_array.values.push_back(json_coordinate);
|
||||
@@ -27,3 +32,5 @@ PolylineFormatter::printUnencodedString(const std::vector<SegmentInformation> &p
|
||||
}
|
||||
return json_geometry_array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
#include "engine/polyline_compressor.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
RouteParameters::RouteParameters()
|
||||
: zoom_level(18), print_instructions(false), alternate_route(true), geometry(true),
|
||||
compression(true), deprecatedAPI(false), uturn_default(false), classify(false),
|
||||
@@ -151,3 +156,5 @@ void RouteParameters::SetCoordinatesFromGeometry(const std::string &geometry_str
|
||||
PolylineCompressor pc;
|
||||
coordinates = pc.decode_string(geometry_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
#include "util/binary_heap.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes)
|
||||
{
|
||||
if (forward_heap_1.get())
|
||||
@@ -64,3 +69,5 @@ void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned n
|
||||
reverse_heap_3.reset(new QueryHeap(number_of_nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
CompressedEdgeContainer::CompressedEdgeContainer()
|
||||
{
|
||||
m_free_list.reserve(100);
|
||||
@@ -181,7 +186,7 @@ void CompressedEdgeContainer::PrintStatistics() const
|
||||
longest_chain_length = std::max(longest_chain_length, (uint64_t)current_vector.size());
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Geometry successfully removed:"
|
||||
util::SimpleLogger().Write() << "Geometry successfully removed:"
|
||||
"\n compressed edges: "
|
||||
<< compressed_edges
|
||||
<< "\n compressed geometries: " << compressed_geometries
|
||||
@@ -212,3 +217,5 @@ NodeID CompressedEdgeContainer::GetLastEdgeSourceID(const EdgeID edge_id) const
|
||||
BOOST_ASSERT(bucket.size() >= 2);
|
||||
return bucket[bucket.size() - 2].first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,13 @@
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
||||
std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
|
||||
std::shared_ptr<util::NodeBasedDynamicGraph> node_based_graph,
|
||||
const CompressedEdgeContainer &compressed_edge_container,
|
||||
const std::unordered_set<NodeID> &barrier_nodes,
|
||||
const std::unordered_set<NodeID> &traffic_lights,
|
||||
@@ -32,7 +37,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
||||
{
|
||||
}
|
||||
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector<EdgeBasedEdge> &output_edge_list)
|
||||
void EdgeBasedGraphFactory::GetEdgeBasedEdges(util::DeallocatingVector<EdgeBasedEdge> &output_edge_list)
|
||||
{
|
||||
BOOST_ASSERT_MSG(0 == output_edge_list.size(), "Vector is not empty");
|
||||
using std::swap; // Koenig swap
|
||||
@@ -108,7 +113,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
|
||||
// TODO: move to lambda function with C++11
|
||||
int temp_sum = 0;
|
||||
|
||||
for (const auto i : osrm::irange(0u, geometry_size))
|
||||
for (const auto i : util::irange(0u, geometry_size))
|
||||
{
|
||||
forward_dist_prefix_sum[i] = temp_sum;
|
||||
temp_sum += forward_geometry[i].second;
|
||||
@@ -117,7 +122,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
|
||||
}
|
||||
|
||||
temp_sum = 0;
|
||||
for (const auto i : osrm::irange(0u, geometry_size))
|
||||
for (const auto i : util::irange(0u, geometry_size))
|
||||
{
|
||||
temp_sum += reverse_geometry[reverse_geometry.size() - 1 - i].second;
|
||||
reverse_dist_prefix_sum[i] = reverse_data.distance - temp_sum;
|
||||
@@ -127,7 +132,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
|
||||
NodeID current_edge_source_coordinate_id = node_u;
|
||||
|
||||
// traverse arrays from start and end respectively
|
||||
for (const auto i : osrm::irange(0u, geometry_size))
|
||||
for (const auto i : util::irange(0u, geometry_size))
|
||||
{
|
||||
BOOST_ASSERT(current_edge_source_coordinate_id ==
|
||||
reverse_geometry[geometry_size - 1 - i].first);
|
||||
@@ -238,10 +243,10 @@ void EdgeBasedGraphFactory::Run(const std::string &original_edge_data_filename,
|
||||
|
||||
TIMER_STOP(generate_edges);
|
||||
|
||||
SimpleLogger().Write() << "Timing statistics for edge-expanded graph:";
|
||||
SimpleLogger().Write() << "Renumbering edges: " << TIMER_SEC(renumber) << "s";
|
||||
SimpleLogger().Write() << "Generating nodes: " << TIMER_SEC(generate_nodes) << "s";
|
||||
SimpleLogger().Write() << "Generating edges: " << TIMER_SEC(generate_edges) << "s";
|
||||
util::SimpleLogger().Write() << "Timing statistics for edge-expanded graph:";
|
||||
util::SimpleLogger().Write() << "Renumbering edges: " << TIMER_SEC(renumber) << "s";
|
||||
util::SimpleLogger().Write() << "Generating nodes: " << TIMER_SEC(generate_nodes) << "s";
|
||||
util::SimpleLogger().Write() << "Generating edges: " << TIMER_SEC(generate_edges) << "s";
|
||||
}
|
||||
|
||||
/// Renumbers all _forward_ edges and sets the edge_id.
|
||||
@@ -251,7 +256,7 @@ unsigned EdgeBasedGraphFactory::RenumberEdges()
|
||||
{
|
||||
// renumber edge based node of outgoing edges
|
||||
unsigned numbered_edges_count = 0;
|
||||
for (const auto current_node : osrm::irange(0u, m_node_based_graph->GetNumberOfNodes()))
|
||||
for (const auto current_node : util::irange(0u, m_node_based_graph->GetNumberOfNodes()))
|
||||
{
|
||||
for (const auto current_edge : m_node_based_graph->GetAdjacentEdgeRange(current_node))
|
||||
{
|
||||
@@ -277,10 +282,10 @@ unsigned EdgeBasedGraphFactory::RenumberEdges()
|
||||
/// Creates the nodes in the edge expanded graph from edges in the node-based graph.
|
||||
void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
|
||||
{
|
||||
Percent progress(m_node_based_graph->GetNumberOfNodes());
|
||||
util::Percent progress(m_node_based_graph->GetNumberOfNodes());
|
||||
|
||||
// loop over all edges and generate new set of nodes
|
||||
for (const auto node_u : osrm::irange(0u, m_node_based_graph->GetNumberOfNodes()))
|
||||
for (const auto node_u : util::irange(0u, m_node_based_graph->GetNumberOfNodes()))
|
||||
{
|
||||
BOOST_ASSERT(node_u != SPECIAL_NODEID);
|
||||
BOOST_ASSERT(node_u < m_node_based_graph->GetNumberOfNodes());
|
||||
@@ -315,7 +320,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
|
||||
|
||||
BOOST_ASSERT(m_edge_based_node_list.size() == m_edge_based_node_is_startpoint.size());
|
||||
|
||||
SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size()
|
||||
util::SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size()
|
||||
<< " nodes in edge-expanded graph";
|
||||
}
|
||||
|
||||
@@ -337,7 +342,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
const bool generate_edge_lookup)
|
||||
#endif
|
||||
{
|
||||
SimpleLogger().Write() << "generating edge-expanded edges";
|
||||
util::SimpleLogger().Write() << "generating edge-expanded edges";
|
||||
|
||||
unsigned node_based_edge_counter = 0;
|
||||
unsigned original_edges_counter = 0;
|
||||
@@ -366,13 +371,13 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
unsigned skipped_barrier_turns_counter = 0;
|
||||
unsigned compressed = 0;
|
||||
|
||||
Percent progress(m_node_based_graph->GetNumberOfNodes());
|
||||
util::Percent progress(m_node_based_graph->GetNumberOfNodes());
|
||||
|
||||
#ifdef DEBUG_GEOMETRY
|
||||
DEBUG_TURNS_START(debug_turns_path);
|
||||
util::DEBUG_TURNS_START(debug_turns_path);
|
||||
#endif
|
||||
|
||||
for (const auto node_u : osrm::irange(0u, m_node_based_graph->GetNumberOfNodes()))
|
||||
for (const auto node_u : util::irange(0u, m_node_based_graph->GetNumberOfNodes()))
|
||||
{
|
||||
// progress.printStatus(node_u);
|
||||
for (const EdgeID e1 : m_node_based_graph->GetAdjacentEdgeRange(node_u))
|
||||
@@ -446,7 +451,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
{
|
||||
distance += speed_profile.traffic_signal_penalty;
|
||||
|
||||
DEBUG_SIGNAL(node_v, m_node_info_list, speed_profile.traffic_signal_penalty);
|
||||
util::DEBUG_SIGNAL(node_v, m_node_info_list, speed_profile.traffic_signal_penalty);
|
||||
}
|
||||
|
||||
// unpack last node of first segment if packed
|
||||
@@ -461,7 +466,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
? m_compressed_edge_container.GetFirstEdgeTargetID(e2)
|
||||
: node_w)];
|
||||
|
||||
const double turn_angle = ComputeAngle::OfThreeFixedPointCoordinates(
|
||||
const double turn_angle = util::ComputeAngle::OfThreeFixedPointCoordinates(
|
||||
first_coordinate, m_node_info_list[node_v], third_coordinate);
|
||||
|
||||
const int turn_penalty = GetTurnPenalty(turn_angle, lua_state);
|
||||
@@ -470,10 +475,10 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
{
|
||||
distance += speed_profile.u_turn_penalty;
|
||||
|
||||
DEBUG_UTURN(node_v, m_node_info_list, speed_profile.u_turn_penalty);
|
||||
util::DEBUG_UTURN(node_v, m_node_info_list, speed_profile.u_turn_penalty);
|
||||
}
|
||||
|
||||
DEBUG_TURN(node_v, m_node_info_list, first_coordinate, turn_angle, turn_penalty);
|
||||
util::DEBUG_TURN(node_v, m_node_info_list, first_coordinate, turn_angle, turn_penalty);
|
||||
|
||||
distance += turn_penalty;
|
||||
|
||||
@@ -541,7 +546,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
const QueryNode &from = m_node_info_list[previous];
|
||||
const QueryNode &to = m_node_info_list[target_node.first];
|
||||
const double segment_length =
|
||||
coordinate_calculation::greatCircleDistance(from.lat, from.lon,
|
||||
util::coordinate_calculation::greatCircleDistance(from.lat, from.lon,
|
||||
to.lat, to.lon);
|
||||
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&to.node_id),
|
||||
@@ -559,7 +564,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
static const unsigned node_count = 2;
|
||||
const QueryNode from = m_node_info_list[node_u];
|
||||
const QueryNode to = m_node_info_list[node_v];
|
||||
const double segment_length = coordinate_calculation::greatCircleDistance(
|
||||
const double segment_length = util::coordinate_calculation::greatCircleDistance(
|
||||
from.lat, from.lon, to.lat, to.lon);
|
||||
edge_segment_file.write(reinterpret_cast<const char *>(&node_count),
|
||||
sizeof(node_count));
|
||||
@@ -578,7 +583,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_TURNS_STOP();
|
||||
util::DEBUG_TURNS_STOP();
|
||||
|
||||
FlushVectorToStream(edge_data_file, original_edge_data_vector);
|
||||
|
||||
@@ -586,15 +591,15 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
||||
edge_data_file.write((char *)&original_edges_counter, sizeof(unsigned));
|
||||
edge_data_file.close();
|
||||
|
||||
SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " edge based nodes";
|
||||
SimpleLogger().Write() << "Node-based graph contains " << node_based_edge_counter << " edges";
|
||||
SimpleLogger().Write() << "Edge-expanded graph ...";
|
||||
SimpleLogger().Write() << " contains " << m_edge_based_edge_list.size() << " edges";
|
||||
SimpleLogger().Write() << " skips " << restricted_turns_counter << " turns, "
|
||||
util::SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " edge based nodes";
|
||||
util::SimpleLogger().Write() << "Node-based graph contains " << node_based_edge_counter << " edges";
|
||||
util::SimpleLogger().Write() << "Edge-expanded graph ...";
|
||||
util::SimpleLogger().Write() << " contains " << m_edge_based_edge_list.size() << " edges";
|
||||
util::SimpleLogger().Write() << " skips " << restricted_turns_counter << " turns, "
|
||||
"defined by "
|
||||
<< m_restriction_map->size() << " restrictions";
|
||||
SimpleLogger().Write() << " skips " << skipped_uturns_counter << " U turns";
|
||||
SimpleLogger().Write() << " skips " << skipped_barrier_turns_counter << " turns over barriers";
|
||||
util::SimpleLogger().Write() << " skips " << skipped_uturns_counter << " U turns";
|
||||
util::SimpleLogger().Write() << " skips " << skipped_barrier_turns_counter << " turns over barriers";
|
||||
}
|
||||
|
||||
int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) const
|
||||
@@ -611,7 +616,7 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co
|
||||
}
|
||||
catch (const luabind::error &er)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << er.what();
|
||||
util::SimpleLogger().Write(logWARNING) << er.what();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -673,3 +678,5 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID node_u,
|
||||
|
||||
return TurnInstructionsClass::GetTurnDirectionOfInstruction(angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
ExternalMemoryNode::ExternalMemoryNode(
|
||||
int lat, int lon, OSMNodeID node_id, bool barrier, bool traffic_lights)
|
||||
: QueryNode(lat, lon, node_id), barrier(barrier), traffic_lights(traffic_lights)
|
||||
@@ -37,3 +42,5 @@ ExternalMemoryNodeSTXXLCompare::value_type ExternalMemoryNodeSTXXLCompare::min_v
|
||||
{
|
||||
return ExternalMemoryNode::min_value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
static const int WRITE_BLOCK_BUFFER_SIZE = 8000;
|
||||
|
||||
ExtractionContainers::ExtractionContainers()
|
||||
@@ -65,8 +70,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
|
||||
{
|
||||
std::ofstream file_out_stream;
|
||||
file_out_stream.open(output_file_name.c_str(), std::ios::binary);
|
||||
const FingerPrint fingerprint = FingerPrint::GetValid();
|
||||
file_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
||||
const util::FingerPrint fingerprint = util::FingerPrint::GetValid();
|
||||
file_out_stream.write((char *)&fingerprint, sizeof(util::FingerPrint));
|
||||
|
||||
PrepareNodes();
|
||||
WriteNodes(file_out_stream);
|
||||
@@ -100,7 +105,7 @@ void ExtractionContainers::WriteNames(const std::string &names_file_name) const
|
||||
}
|
||||
|
||||
// builds and writes the index
|
||||
RangeTable<> name_index_range(name_lengths);
|
||||
util::RangeTable<> name_index_range(name_lengths);
|
||||
name_file_stream << name_index_range;
|
||||
|
||||
name_file_stream.write((char *)&total_length, sizeof(unsigned));
|
||||
@@ -182,7 +187,7 @@ void ExtractionContainers::PrepareNodes()
|
||||
}
|
||||
if (internal_id > std::numeric_limits<NodeID>::max())
|
||||
{
|
||||
throw osrm::exception("There are too many nodes remaining after filtering, OSRM only "
|
||||
throw util::exception("There are too many nodes remaining after filtering, OSRM only "
|
||||
"supports 2^32 unique nodes");
|
||||
}
|
||||
max_internal_node_id = boost::numeric_cast<NodeID>(internal_id);
|
||||
@@ -212,7 +217,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
{
|
||||
if (edge_iterator->result.osm_source_id < node_iterator->node_id)
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference "
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference "
|
||||
<< edge_iterator->result.source;
|
||||
edge_iterator->result.source = SPECIAL_NODEID;
|
||||
++edge_iterator;
|
||||
@@ -249,7 +254,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
// them. This happens when using osmosis with bbox or polygon to extract smaller areas.
|
||||
auto markSourcesInvalid = [](InternalExtractorEdge &edge)
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference "
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference "
|
||||
<< edge.result.source;
|
||||
edge.result.source = SPECIAL_NODEID;
|
||||
edge.result.osm_source_id = SPECIAL_OSM_NODEID;
|
||||
@@ -284,7 +289,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
|
||||
if (edge_iterator->result.osm_target_id < node_iterator->node_id)
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logWARNING)
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING)
|
||||
<< "Found invalid node reference "
|
||||
<< OSMNodeID_to_uint64_t(edge_iterator->result.osm_target_id);
|
||||
edge_iterator->result.target = SPECIAL_NODEID;
|
||||
@@ -302,11 +307,11 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
BOOST_ASSERT(edge_iterator->source_coordinate.lat != std::numeric_limits<int>::min());
|
||||
BOOST_ASSERT(edge_iterator->source_coordinate.lon != std::numeric_limits<int>::min());
|
||||
|
||||
const double distance = coordinate_calculation::greatCircleDistance(
|
||||
const double distance = util::coordinate_calculation::greatCircleDistance(
|
||||
edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon,
|
||||
node_iterator->lat, node_iterator->lon);
|
||||
|
||||
if (lua_function_exists(segment_state, "segment_function"))
|
||||
if (util::lua_function_exists(segment_state, "segment_function"))
|
||||
{
|
||||
luabind::call_function<void>(
|
||||
segment_state, "segment_function", boost::cref(edge_iterator->source_coordinate),
|
||||
@@ -325,7 +330,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
return (distance * 10.) / (data.speed / 3.6);
|
||||
break;
|
||||
case InternalExtractorEdge::WeightType::INVALID:
|
||||
osrm::exception("invalid weight type");
|
||||
util::exception("invalid weight type");
|
||||
}
|
||||
return -1.0;
|
||||
}(edge_iterator->weight_data);
|
||||
@@ -356,7 +361,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
|
||||
// them. This happens when using osmosis with bbox or polygon to extract smaller areas.
|
||||
auto markTargetsInvalid = [](InternalExtractorEdge &edge)
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference "
|
||||
util::SimpleLogger().Write(LogLevel::logWARNING) << "Found invalid node reference "
|
||||
<< edge.result.target;
|
||||
edge.result.target = SPECIAL_NODEID;
|
||||
};
|
||||
@@ -488,7 +493,7 @@ void ExtractionContainers::WriteEdges(std::ofstream &file_out_stream) const
|
||||
|
||||
if (used_edges_counter > std::numeric_limits<unsigned>::max())
|
||||
{
|
||||
throw osrm::exception("There are too many edges, OSRM only supports 2^32");
|
||||
throw util::exception("There are too many edges, OSRM only supports 2^32");
|
||||
}
|
||||
TIMER_STOP(write_edges);
|
||||
std::cout << "ok, after " << TIMER_SEC(write_edges) << "s" << std::endl;
|
||||
@@ -501,7 +506,7 @@ void ExtractionContainers::WriteEdges(std::ofstream &file_out_stream) const
|
||||
file_out_stream.write((char *)&used_edges_counter_buffer, sizeof(unsigned));
|
||||
std::cout << "ok" << std::endl;
|
||||
|
||||
SimpleLogger().Write() << "Processed " << used_edges_counter << " edges";
|
||||
util::SimpleLogger().Write() << "Processed " << used_edges_counter << " edges";
|
||||
}
|
||||
|
||||
void ExtractionContainers::WriteNodes(std::ofstream &file_out_stream) const
|
||||
@@ -541,7 +546,7 @@ void ExtractionContainers::WriteNodes(std::ofstream &file_out_stream) const
|
||||
TIMER_STOP(write_nodes);
|
||||
std::cout << "ok, after " << TIMER_SEC(write_nodes) << "s" << std::endl;
|
||||
|
||||
SimpleLogger().Write() << "Processed " << max_internal_node_id << " nodes";
|
||||
util::SimpleLogger().Write() << "Processed " << max_internal_node_id << " nodes";
|
||||
}
|
||||
|
||||
void ExtractionContainers::WriteRestrictions(const std::string &path) const
|
||||
@@ -550,8 +555,8 @@ void ExtractionContainers::WriteRestrictions(const std::string &path) const
|
||||
std::ofstream restrictions_out_stream;
|
||||
unsigned written_restriction_count = 0;
|
||||
restrictions_out_stream.open(path.c_str(), std::ios::binary);
|
||||
const FingerPrint fingerprint = FingerPrint::GetValid();
|
||||
restrictions_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
||||
const util::FingerPrint fingerprint = util::FingerPrint::GetValid();
|
||||
restrictions_out_stream.write((char *)&fingerprint, sizeof(util::FingerPrint));
|
||||
const auto count_position = restrictions_out_stream.tellp();
|
||||
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));
|
||||
|
||||
@@ -569,7 +574,7 @@ void ExtractionContainers::WriteRestrictions(const std::string &path) const
|
||||
restrictions_out_stream.seekp(count_position);
|
||||
restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned));
|
||||
restrictions_out_stream.close();
|
||||
SimpleLogger().Write() << "usable restrictions: " << written_restriction_count;
|
||||
util::SimpleLogger().Write() << "usable restrictions: " << written_restriction_count;
|
||||
}
|
||||
|
||||
void ExtractionContainers::PrepareRestrictions()
|
||||
@@ -609,7 +614,7 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
if (way_start_and_end_iterator->way_id >
|
||||
OSMWayID(restrictions_iterator->restriction.from.way))
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logDEBUG) << "Restriction references invalid way: "
|
||||
util::SimpleLogger().Write(LogLevel::logDEBUG) << "Restriction references invalid way: "
|
||||
<< restrictions_iterator->restriction.from.way;
|
||||
restrictions_iterator->restriction.from.node = SPECIAL_NODEID;
|
||||
++restrictions_iterator;
|
||||
@@ -625,7 +630,7 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
auto via_id_iter = external_to_internal_node_id_map.find(via_node_id);
|
||||
if (via_id_iter == external_to_internal_node_id_map.end())
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logDEBUG) << "Restriction references invalid node: "
|
||||
util::SimpleLogger().Write(LogLevel::logDEBUG) << "Restriction references invalid node: "
|
||||
<< restrictions_iterator->restriction.via.node;
|
||||
restrictions_iterator->restriction.via.node = SPECIAL_NODEID;
|
||||
++restrictions_iterator;
|
||||
@@ -686,7 +691,7 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
if (way_start_and_end_iterator->way_id >
|
||||
OSMWayID(restrictions_iterator->restriction.to.way))
|
||||
{
|
||||
SimpleLogger().Write(LogLevel::logDEBUG) << "Restriction references invalid way: "
|
||||
util::SimpleLogger().Write(LogLevel::logDEBUG) << "Restriction references invalid way: "
|
||||
<< restrictions_iterator->restriction.to.way;
|
||||
restrictions_iterator->restriction.to.way = SPECIAL_NODEID;
|
||||
++restrictions_iterator;
|
||||
@@ -720,3 +725,5 @@ void ExtractionContainers::PrepareRestrictions()
|
||||
TIMER_STOP(fix_restriction_ends);
|
||||
std::cout << "ok, after " << TIMER_SEC(fix_restriction_ends) << "s" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+54
-47
@@ -46,6 +46,11 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO: Refactor this function into smaller functions for better readability.
|
||||
*
|
||||
@@ -69,7 +74,7 @@ int extractor::run()
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
TIMER_START(extracting);
|
||||
|
||||
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
|
||||
@@ -77,15 +82,15 @@ int extractor::run()
|
||||
std::min(recommended_num_threads, config.requested_num_threads);
|
||||
tbb::task_scheduler_init init(number_of_threads);
|
||||
|
||||
SimpleLogger().Write() << "Input file: " << config.input_path.filename().string();
|
||||
SimpleLogger().Write() << "Profile: " << config.profile_path.filename().string();
|
||||
SimpleLogger().Write() << "Threads: " << number_of_threads;
|
||||
util::SimpleLogger().Write() << "Input file: " << config.input_path.filename().string();
|
||||
util::SimpleLogger().Write() << "Profile: " << config.profile_path.filename().string();
|
||||
util::SimpleLogger().Write() << "Threads: " << number_of_threads;
|
||||
|
||||
// setup scripting environment
|
||||
ScriptingEnvironment scripting_environment(config.profile_path.string().c_str());
|
||||
|
||||
ExtractionContainers extraction_containers;
|
||||
auto extractor_callbacks = osrm::make_unique<ExtractorCallbacks>(extraction_containers);
|
||||
auto extractor_callbacks = util::make_unique<ExtractorCallbacks>(extraction_containers);
|
||||
|
||||
const osmium::io::File input_file(config.input_path.string());
|
||||
osmium::io::Reader reader(input_file);
|
||||
@@ -96,12 +101,12 @@ int extractor::run()
|
||||
std::atomic<unsigned> number_of_relations{0};
|
||||
std::atomic<unsigned> number_of_others{0};
|
||||
|
||||
SimpleLogger().Write() << "Parsing in progress..";
|
||||
util::SimpleLogger().Write() << "Parsing in progress..";
|
||||
TIMER_START(parsing);
|
||||
|
||||
lua_State *segment_state = scripting_environment.GetLuaState();
|
||||
|
||||
if (lua_function_exists(segment_state, "source_function"))
|
||||
if (util::lua_function_exists(segment_state, "source_function"))
|
||||
{
|
||||
// bind a single instance of SourceContainer class to relevant lua state
|
||||
SourceContainer sources;
|
||||
@@ -115,7 +120,7 @@ int extractor::run()
|
||||
{
|
||||
generator = "unknown tool";
|
||||
}
|
||||
SimpleLogger().Write() << "input file generated by " << generator;
|
||||
util::SimpleLogger().Write() << "input file generated by " << generator;
|
||||
|
||||
// write .timestamp data file
|
||||
std::string timestamp = header.get("osmosis_replication_timestamp");
|
||||
@@ -123,7 +128,7 @@ int extractor::run()
|
||||
{
|
||||
timestamp = "n/a";
|
||||
}
|
||||
SimpleLogger().Write() << "timestamp: " << timestamp;
|
||||
util::SimpleLogger().Write() << "timestamp: " << timestamp;
|
||||
|
||||
boost::filesystem::ofstream timestamp_out(config.timestamp_file_name);
|
||||
timestamp_out.write(timestamp.c_str(), timestamp.length());
|
||||
@@ -214,9 +219,9 @@ int extractor::run()
|
||||
}
|
||||
}
|
||||
TIMER_STOP(parsing);
|
||||
SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
|
||||
util::SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
|
||||
|
||||
SimpleLogger().Write() << "Raw input contains " << number_of_nodes.load() << " nodes, "
|
||||
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";
|
||||
@@ -225,7 +230,7 @@ int extractor::run()
|
||||
|
||||
if (extraction_containers.all_edges_list.empty())
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
||||
util::SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -233,11 +238,11 @@ int extractor::run()
|
||||
config.names_file_name, segment_state);
|
||||
|
||||
TIMER_STOP(extracting);
|
||||
SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting) << "s";
|
||||
util::SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting) << "s";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -250,12 +255,12 @@ int extractor::run()
|
||||
//
|
||||
// // Create a new lua state
|
||||
|
||||
SimpleLogger().Write() << "Generating edge-expanded graph representation";
|
||||
util::SimpleLogger().Write() << "Generating edge-expanded graph representation";
|
||||
|
||||
TIMER_START(expansion);
|
||||
|
||||
std::vector<EdgeBasedNode> node_based_edge_list;
|
||||
DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
|
||||
util::DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
|
||||
std::vector<bool> node_is_startpoint;
|
||||
std::vector<QueryNode> internal_to_external_node_map;
|
||||
auto graph_size =
|
||||
@@ -267,7 +272,7 @@ int extractor::run()
|
||||
|
||||
TIMER_STOP(expansion);
|
||||
|
||||
SimpleLogger().Write() << "building r-tree ...";
|
||||
util::SimpleLogger().Write() << "building r-tree ...";
|
||||
TIMER_START(rtree);
|
||||
|
||||
FindComponents(max_edge_id, edge_based_edge_list, node_based_edge_list);
|
||||
@@ -277,21 +282,21 @@ int extractor::run()
|
||||
|
||||
TIMER_STOP(rtree);
|
||||
|
||||
SimpleLogger().Write() << "writing node map ...";
|
||||
util::SimpleLogger().Write() << "writing node map ...";
|
||||
WriteNodeMapping(internal_to_external_node_map);
|
||||
|
||||
WriteEdgeBasedGraph(config.edge_graph_output_path, max_edge_id, edge_based_edge_list);
|
||||
|
||||
SimpleLogger().Write() << "Expansion : "
|
||||
util::SimpleLogger().Write() << "Expansion : "
|
||||
<< (number_of_node_based_nodes / TIMER_SEC(expansion))
|
||||
<< " nodes/sec and " << ((max_edge_id + 1) / TIMER_SEC(expansion))
|
||||
<< " edges/sec";
|
||||
SimpleLogger().Write() << "To prepare the data for routing, run: "
|
||||
util::SimpleLogger().Write() << "To prepare the data for routing, run: "
|
||||
<< "./osrm-prepare " << config.output_file_name << std::endl;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -309,39 +314,39 @@ void extractor::SetupScriptingEnvironment(lua_State *lua_state,
|
||||
luaL_openlibs(lua_state);
|
||||
|
||||
// adjust lua load path
|
||||
luaAddScriptFolderToLoadPath(lua_state, config.profile_path.string().c_str());
|
||||
util::luaAddScriptFolderToLoadPath(lua_state, config.profile_path.string().c_str());
|
||||
|
||||
// Now call our function in a lua script
|
||||
if (0 != luaL_dofile(lua_state, config.profile_path.string().c_str()))
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << lua_tostring(lua_state, -1) << " occurred in scripting block";
|
||||
throw osrm::exception(msg.str());
|
||||
throw util::exception(msg.str());
|
||||
}
|
||||
|
||||
if (0 != luaL_dostring(lua_state, "return traffic_signal_penalty\n"))
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << lua_tostring(lua_state, -1) << " occurred in scripting block";
|
||||
throw osrm::exception(msg.str());
|
||||
throw util::exception(msg.str());
|
||||
}
|
||||
speed_profile.traffic_signal_penalty = 10 * lua_tointeger(lua_state, -1);
|
||||
SimpleLogger().Write(logDEBUG) << "traffic_signal_penalty: "
|
||||
util::SimpleLogger().Write(logDEBUG) << "traffic_signal_penalty: "
|
||||
<< speed_profile.traffic_signal_penalty;
|
||||
|
||||
if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n"))
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << lua_tostring(lua_state, -1) << " occurred in scripting block";
|
||||
throw osrm::exception(msg.str());
|
||||
throw util::exception(msg.str());
|
||||
}
|
||||
|
||||
speed_profile.u_turn_penalty = 10 * lua_tointeger(lua_state, -1);
|
||||
speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function");
|
||||
speed_profile.has_turn_penalty_function = util::lua_function_exists(lua_state, "turn_function");
|
||||
}
|
||||
|
||||
void extractor::FindComponents(unsigned max_edge_id,
|
||||
const DeallocatingVector<EdgeBasedEdge> &input_edge_list,
|
||||
const util::DeallocatingVector<EdgeBasedEdge> &input_edge_list,
|
||||
std::vector<EdgeBasedNode> &input_nodes) const
|
||||
{
|
||||
struct UncontractedEdgeData
|
||||
@@ -363,7 +368,7 @@ void extractor::FindComponents(unsigned max_edge_id,
|
||||
return source == rhs.source && target == rhs.target;
|
||||
}
|
||||
};
|
||||
using UncontractedGraph = StaticGraph<UncontractedEdgeData>;
|
||||
using UncontractedGraph = util::StaticGraph<UncontractedEdgeData>;
|
||||
std::vector<InputEdge> edges;
|
||||
edges.reserve(input_edge_list.size() * 2);
|
||||
|
||||
@@ -424,9 +429,9 @@ std::shared_ptr<RestrictionMap> extractor::LoadRestrictionMap()
|
||||
std::ios::in | std::ios::binary);
|
||||
|
||||
std::vector<TurnRestriction> restriction_list;
|
||||
loadRestrictionsFromFile(input_stream, restriction_list);
|
||||
util::loadRestrictionsFromFile(input_stream, restriction_list);
|
||||
|
||||
SimpleLogger().Write() << " - " << restriction_list.size() << " restrictions.";
|
||||
util::SimpleLogger().Write() << " - " << restriction_list.size() << " restrictions.";
|
||||
|
||||
return std::make_shared<RestrictionMap>(restriction_list);
|
||||
}
|
||||
@@ -434,7 +439,7 @@ std::shared_ptr<RestrictionMap> extractor::LoadRestrictionMap()
|
||||
/**
|
||||
\brief Load node based graph from .osrm file
|
||||
*/
|
||||
std::shared_ptr<NodeBasedDynamicGraph>
|
||||
std::shared_ptr<util::NodeBasedDynamicGraph>
|
||||
extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barrier_nodes,
|
||||
std::unordered_set<NodeID> &traffic_lights,
|
||||
std::vector<QueryNode> &internal_to_external_node_map)
|
||||
@@ -446,10 +451,10 @@ extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barrier_nodes,
|
||||
|
||||
std::vector<NodeID> barrier_list;
|
||||
std::vector<NodeID> traffic_light_list;
|
||||
NodeID number_of_node_based_nodes = loadNodesFromFile(
|
||||
NodeID number_of_node_based_nodes = util::loadNodesFromFile(
|
||||
input_stream, barrier_list, traffic_light_list, internal_to_external_node_map);
|
||||
|
||||
SimpleLogger().Write() << " - " << barrier_list.size() << " bollard nodes, "
|
||||
util::SimpleLogger().Write() << " - " << barrier_list.size() << " bollard nodes, "
|
||||
<< traffic_light_list.size() << " traffic lights";
|
||||
|
||||
// insert into unordered sets for fast lookup
|
||||
@@ -461,15 +466,15 @@ extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barrier_nodes,
|
||||
traffic_light_list.clear();
|
||||
traffic_light_list.shrink_to_fit();
|
||||
|
||||
loadEdgesFromFile(input_stream, edge_list);
|
||||
util::loadEdgesFromFile(input_stream, edge_list);
|
||||
|
||||
if (edge_list.empty())
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
||||
return std::shared_ptr<NodeBasedDynamicGraph>();
|
||||
util::SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
|
||||
return std::shared_ptr<util::NodeBasedDynamicGraph>();
|
||||
}
|
||||
|
||||
return NodeBasedDynamicGraphFromEdges(number_of_node_based_nodes, edge_list);
|
||||
return util::NodeBasedDynamicGraphFromEdges(number_of_node_based_nodes, edge_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +484,7 @@ std::pair<std::size_t, std::size_t>
|
||||
extractor::BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_node_map,
|
||||
std::vector<EdgeBasedNode> &node_based_edge_list,
|
||||
std::vector<bool> &node_is_startpoint,
|
||||
DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list)
|
||||
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list)
|
||||
{
|
||||
lua_State *lua_state = luaL_newstate();
|
||||
luabind::open(lua_state);
|
||||
@@ -550,7 +555,7 @@ void extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
|
||||
std::vector<bool> node_is_startpoint,
|
||||
const std::vector<QueryNode> &internal_to_external_node_map)
|
||||
{
|
||||
SimpleLogger().Write() << "constructing r-tree of " << node_based_edge_list.size()
|
||||
util::SimpleLogger().Write() << "constructing r-tree of " << node_based_edge_list.size()
|
||||
<< " edge elements build on-top of "
|
||||
<< internal_to_external_node_map.size() << " coordinates";
|
||||
|
||||
@@ -559,7 +564,7 @@ void extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
|
||||
// Filter node based edges based on startpoint
|
||||
auto out_iter = node_based_edge_list.begin();
|
||||
auto in_iter = node_based_edge_list.begin();
|
||||
for (auto index : osrm::irange<std::size_t>(0, node_is_startpoint.size()))
|
||||
for (auto index : util::irange<std::size_t>(0, node_is_startpoint.size()))
|
||||
{
|
||||
BOOST_ASSERT(in_iter != node_based_edge_list.end());
|
||||
if (node_is_startpoint[index])
|
||||
@@ -573,23 +578,23 @@ void extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
|
||||
node_based_edge_list.resize(new_size);
|
||||
|
||||
TIMER_START(construction);
|
||||
StaticRTree<EdgeBasedNode> rtree(node_based_edge_list, config.rtree_nodes_output_path,
|
||||
util::StaticRTree<EdgeBasedNode> rtree(node_based_edge_list, config.rtree_nodes_output_path,
|
||||
config.rtree_leafs_output_path, internal_to_external_node_map);
|
||||
|
||||
TIMER_STOP(construction);
|
||||
SimpleLogger().Write() << "finished r-tree construction in " << TIMER_SEC(construction)
|
||||
util::SimpleLogger().Write() << "finished r-tree construction in " << TIMER_SEC(construction)
|
||||
<< " seconds";
|
||||
}
|
||||
|
||||
void extractor::WriteEdgeBasedGraph(std::string const &output_file_filename,
|
||||
size_t const max_edge_id,
|
||||
DeallocatingVector<EdgeBasedEdge> const &edge_based_edge_list)
|
||||
util::DeallocatingVector<EdgeBasedEdge> const &edge_based_edge_list)
|
||||
{
|
||||
|
||||
std::ofstream file_out_stream;
|
||||
file_out_stream.open(output_file_filename.c_str(), std::ios::binary);
|
||||
const FingerPrint fingerprint = FingerPrint::GetValid();
|
||||
file_out_stream.write((char *)&fingerprint, sizeof(FingerPrint));
|
||||
const util::FingerPrint fingerprint = util::FingerPrint::GetValid();
|
||||
file_out_stream.write((char *)&fingerprint, sizeof(util::FingerPrint));
|
||||
|
||||
std::cout << "[extractor] Writing edge-based-graph egdes ... " << std::flush;
|
||||
TIMER_START(write_edges);
|
||||
@@ -606,6 +611,8 @@ void extractor::WriteEdgeBasedGraph(std::string const &output_file_filename,
|
||||
TIMER_STOP(write_edges);
|
||||
std::cout << "ok, after " << TIMER_SEC(write_edges) << "s" << std::endl;
|
||||
|
||||
SimpleLogger().Write() << "Processed " << number_of_used_edges << " edges";
|
||||
util::SimpleLogger().Write() << "Processed " << number_of_used_edges << " edges";
|
||||
file_out_stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containers)
|
||||
: external_memory(extraction_containers)
|
||||
{
|
||||
@@ -45,7 +50,7 @@ void ExtractorCallbacks::ProcessRestriction(
|
||||
if (restriction)
|
||||
{
|
||||
external_memory.restrictions_list.push_back(restriction.get());
|
||||
// SimpleLogger().Write() << "from: " << restriction.get().restriction.from.node <<
|
||||
// util::SimpleLogger().Write() << "from: " << restriction.get().restriction.from.node <<
|
||||
// ",via: " << restriction.get().restriction.via.node <<
|
||||
// ", to: " << restriction.get().restriction.to.node <<
|
||||
// ", only: " << (restriction.get().restriction.flags.is_only ?
|
||||
@@ -79,7 +84,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
|
||||
if (std::numeric_limits<decltype(input_way.id())>::max() == input_way.id())
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "found bogus way with id: " << input_way.id()
|
||||
util::SimpleLogger().Write(logDEBUG) << "found bogus way with id: " << input_way.id()
|
||||
<< " of size " << input_way.nodes().size();
|
||||
return;
|
||||
}
|
||||
@@ -118,7 +123,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
if (forward_weight_data.type == InternalExtractorEdge::WeightType::INVALID &&
|
||||
backward_weight_data.type == InternalExtractorEdge::WeightType::INVALID)
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "found way with bogus speed, id: " << input_way.id();
|
||||
util::SimpleLogger().Write(logDEBUG) << "found way with bogus speed, id: " << input_way.id();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -159,7 +164,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
{
|
||||
BOOST_ASSERT(split_edge == false);
|
||||
BOOST_ASSERT(parsed_way.backward_travel_mode != TRAVEL_MODE_INACCESSIBLE);
|
||||
osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(),
|
||||
util::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(),
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
|
||||
{
|
||||
external_memory.all_edges_list.push_back(InternalExtractorEdge(
|
||||
@@ -179,7 +184,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
{
|
||||
const bool forward_only =
|
||||
split_edge || TRAVEL_MODE_INACCESSIBLE == parsed_way.backward_travel_mode;
|
||||
osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(),
|
||||
util::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(),
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
|
||||
{
|
||||
external_memory.all_edges_list.push_back(InternalExtractorEdge(
|
||||
@@ -192,7 +197,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
if (split_edge)
|
||||
{
|
||||
BOOST_ASSERT(parsed_way.backward_travel_mode != TRAVEL_MODE_INACCESSIBLE);
|
||||
osrm::for_each_pair(
|
||||
util::for_each_pair(
|
||||
input_way.nodes().cbegin(), input_way.nodes().cend(),
|
||||
[&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
|
||||
{
|
||||
@@ -210,3 +215,5 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
|
||||
OSMNodeID(input_way.nodes()[1].ref()), OSMNodeID(input_way.nodes()[0].ref())});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
#include <tbb/task_scheduler_init.h>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
return_code
|
||||
ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config)
|
||||
{
|
||||
@@ -87,13 +92,13 @@ ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extrac
|
||||
option_variables);
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
SimpleLogger().Write() << OSRM_VERSION;
|
||||
util::SimpleLogger().Write() << OSRM_VERSION;
|
||||
return return_code::exit;
|
||||
}
|
||||
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
SimpleLogger().Write() << visible_options;
|
||||
util::SimpleLogger().Write() << visible_options;
|
||||
return return_code::exit;
|
||||
}
|
||||
|
||||
@@ -102,10 +107,10 @@ ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extrac
|
||||
// parse config file
|
||||
if (boost::filesystem::is_regular_file(extractor_config.config_file_path))
|
||||
{
|
||||
SimpleLogger().Write() << "Reading options from: "
|
||||
util::SimpleLogger().Write() << "Reading options from: "
|
||||
<< extractor_config.config_file_path.string();
|
||||
std::string ini_file_contents =
|
||||
read_file_lower_content(extractor_config.config_file_path);
|
||||
util::read_file_lower_content(extractor_config.config_file_path);
|
||||
std::stringstream config_stream(ini_file_contents);
|
||||
boost::program_options::store(parse_config_file(config_stream, config_file_options),
|
||||
option_variables);
|
||||
@@ -114,13 +119,13 @@ ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extrac
|
||||
|
||||
if (!option_variables.count("input"))
|
||||
{
|
||||
SimpleLogger().Write() << visible_options;
|
||||
util::SimpleLogger().Write() << visible_options;
|
||||
return return_code::exit;
|
||||
}
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << e.what();
|
||||
return return_code::fail;
|
||||
}
|
||||
|
||||
@@ -205,3 +210,5 @@ void ExtractorOptions::GenerateOutputFilesNames(ExtractorConfig &extractor_confi
|
||||
extractor_config.edge_penalty_path.replace(pos, 8, ".osrm.edge_penalties");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
#include "util/simple_logger.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
GraphCompressor::GraphCompressor(SpeedProfileProperties speed_profile)
|
||||
: speed_profile(std::move(speed_profile))
|
||||
{
|
||||
@@ -16,15 +21,15 @@ GraphCompressor::GraphCompressor(SpeedProfileProperties speed_profile)
|
||||
void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
|
||||
const std::unordered_set<NodeID> &traffic_lights,
|
||||
RestrictionMap &restriction_map,
|
||||
NodeBasedDynamicGraph &graph,
|
||||
util::NodeBasedDynamicGraph &graph,
|
||||
CompressedEdgeContainer &geometry_compressor)
|
||||
{
|
||||
const unsigned original_number_of_nodes = graph.GetNumberOfNodes();
|
||||
const unsigned original_number_of_edges = graph.GetNumberOfEdges();
|
||||
|
||||
Percent progress(original_number_of_nodes);
|
||||
util::Percent progress(original_number_of_nodes);
|
||||
|
||||
for (const NodeID node_v : osrm::irange(0u, original_number_of_nodes))
|
||||
for (const NodeID node_v : util::irange(0u, original_number_of_nodes))
|
||||
{
|
||||
progress.printStatus(node_v);
|
||||
|
||||
@@ -163,13 +168,13 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
|
||||
|
||||
void GraphCompressor::PrintStatistics(unsigned original_number_of_nodes,
|
||||
unsigned original_number_of_edges,
|
||||
const NodeBasedDynamicGraph &graph) const
|
||||
const util::NodeBasedDynamicGraph &graph) const
|
||||
{
|
||||
|
||||
unsigned new_node_count = 0;
|
||||
unsigned new_edge_count = 0;
|
||||
|
||||
for (const auto i : osrm::irange(0u, graph.GetNumberOfNodes()))
|
||||
for (const auto i : util::irange(0u, graph.GetNumberOfNodes()))
|
||||
{
|
||||
if (graph.GetOutDegree(i) > 0)
|
||||
{
|
||||
@@ -177,8 +182,10 @@ void GraphCompressor::PrintStatistics(unsigned original_number_of_nodes,
|
||||
new_edge_count += (graph.EndEdges(i) - graph.BeginEdges(i));
|
||||
}
|
||||
}
|
||||
SimpleLogger().Write() << "Node compression ratio: "
|
||||
util::SimpleLogger().Write() << "Node compression ratio: "
|
||||
<< new_node_count / (double)original_number_of_nodes;
|
||||
SimpleLogger().Write() << "Edge compression ratio: "
|
||||
util::SimpleLogger().Write() << "Edge compression ratio: "
|
||||
<< new_edge_count / (double)original_number_of_edges;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
#include "extractor/travel_mode.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
bool NodeBasedEdge::operator<(const NodeBasedEdge &other) const
|
||||
{
|
||||
if (source == other.source)
|
||||
@@ -84,3 +89,5 @@ EdgeBasedEdge::EdgeBasedEdge(const NodeID source,
|
||||
backward(backward)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
RasterSource::RasterSource(RasterGrid _raster_data,
|
||||
std::size_t _width,
|
||||
std::size_t _height,
|
||||
@@ -87,20 +92,20 @@ int SourceContainer::loadRasterSource(const std::string &path_string,
|
||||
const auto itr = LoadedSourcePaths.find(path_string);
|
||||
if (itr != LoadedSourcePaths.end())
|
||||
{
|
||||
SimpleLogger().Write() << "[source loader] Already loaded source '" << path_string
|
||||
util::SimpleLogger().Write() << "[source loader] Already loaded source '" << path_string
|
||||
<< "' at source_id " << itr->second;
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
int source_id = static_cast<int>(LoadedSources.size());
|
||||
|
||||
SimpleLogger().Write() << "[source loader] Loading from " << path_string << " ... ";
|
||||
util::SimpleLogger().Write() << "[source loader] Loading from " << path_string << " ... ";
|
||||
TIMER_START(loading_source);
|
||||
|
||||
boost::filesystem::path filepath(path_string);
|
||||
if (!boost::filesystem::exists(filepath))
|
||||
{
|
||||
throw osrm::exception("error reading: no such path");
|
||||
throw util::exception("error reading: no such path");
|
||||
}
|
||||
|
||||
RasterGrid rasterData{filepath, ncols, nrows};
|
||||
@@ -110,7 +115,7 @@ int SourceContainer::loadRasterSource(const std::string &path_string,
|
||||
LoadedSourcePaths.emplace(path_string, source_id);
|
||||
LoadedSources.push_back(std::move(source));
|
||||
|
||||
SimpleLogger().Write() << "[source loader] ok, after " << TIMER_SEC(loading_source) << "s";
|
||||
util::SimpleLogger().Write() << "[source loader] ok, after " << TIMER_SEC(loading_source) << "s";
|
||||
|
||||
return source_id;
|
||||
}
|
||||
@@ -120,7 +125,7 @@ RasterDatum SourceContainer::getRasterDataFromSource(unsigned int source_id, int
|
||||
{
|
||||
if (LoadedSources.size() < source_id + 1)
|
||||
{
|
||||
throw osrm::exception("error reading: no such loaded source");
|
||||
throw util::exception("error reading: no such loaded source");
|
||||
}
|
||||
|
||||
BOOST_ASSERT(lat < (90 * COORDINATE_PRECISION));
|
||||
@@ -138,7 +143,7 @@ SourceContainer::getRasterInterpolateFromSource(unsigned int source_id, int lon,
|
||||
{
|
||||
if (LoadedSources.size() < source_id + 1)
|
||||
{
|
||||
throw osrm::exception("error reading: no such loaded source");
|
||||
throw util::exception("error reading: no such loaded source");
|
||||
}
|
||||
|
||||
BOOST_ASSERT(lat < (90 * COORDINATE_PRECISION));
|
||||
@@ -149,3 +154,5 @@ SourceContainer::getRasterInterpolateFromSource(unsigned int source_id, int lon,
|
||||
const auto &found = LoadedSources[source_id];
|
||||
return found.getRasterInterpolate(lon, lat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#include "extractor/restriction_map.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
RestrictionMap::RestrictionMap(const std::vector<TurnRestriction> &restriction_list) : m_count(0)
|
||||
{
|
||||
// decompose restriction consisting of a start, via and end node into a
|
||||
@@ -152,3 +157,5 @@ bool RestrictionMap::IsSourceNode(const NodeID node) const
|
||||
{
|
||||
return m_restriction_start_nodes.find(node) != m_restriction_start_nodes.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,16 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
namespace {
|
||||
int luaErrorCallback(lua_State *lua_state)
|
||||
{
|
||||
std::string error_msg = lua_tostring(lua_state, -1);
|
||||
throw osrm::exception("ERROR occurred in profile script:\n" + error_msg);
|
||||
throw util::exception("ERROR occurred in profile script:\n" + error_msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,33 +52,33 @@ void RestrictionParser::ReadUseRestrictionsSetting(lua_State *lua_state)
|
||||
|
||||
if (use_turn_restrictions)
|
||||
{
|
||||
SimpleLogger().Write() << "Using turn restrictions";
|
||||
util::SimpleLogger().Write() << "Using turn restrictions";
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write() << "Ignoring turn restrictions";
|
||||
util::SimpleLogger().Write() << "Ignoring turn restrictions";
|
||||
}
|
||||
}
|
||||
|
||||
void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
|
||||
{
|
||||
if (lua_function_exists(lua_state, "get_exceptions"))
|
||||
if (util::lua_function_exists(lua_state, "get_exceptions"))
|
||||
{
|
||||
luabind::set_pcall_callback(&luaErrorCallback);
|
||||
// get list of turn restriction exceptions
|
||||
luabind::call_function<void>(lua_state, "get_exceptions",
|
||||
boost::ref(restriction_exceptions));
|
||||
const unsigned exception_count = restriction_exceptions.size();
|
||||
SimpleLogger().Write() << "Found " << exception_count
|
||||
util::SimpleLogger().Write() << "Found " << exception_count
|
||||
<< " exceptions to turn restrictions:";
|
||||
for (const std::string &str : restriction_exceptions)
|
||||
{
|
||||
SimpleLogger().Write() << " " << str;
|
||||
util::SimpleLogger().Write() << " " << str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write() << "Found no exceptions to turn restrictions";
|
||||
util::SimpleLogger().Write() << "Found no exceptions to turn restrictions";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,3 +227,5 @@ bool RestrictionParser::ShouldIgnoreRestriction(const std::string &except_tag_st
|
||||
std::end(restriction_exceptions), current_string);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// wrapper method as luabind doesn't automatically overload funcs w/ default parameters
|
||||
@@ -32,13 +37,13 @@ int luaErrorCallback(lua_State *state)
|
||||
std::string error_msg = lua_tostring(state, -1);
|
||||
std::ostringstream error_stream;
|
||||
error_stream << error_msg;
|
||||
throw osrm::exception("ERROR occurred in profile script:\n" + error_stream.str());
|
||||
throw util::exception("ERROR occurred in profile script:\n" + error_stream.str());
|
||||
}
|
||||
}
|
||||
|
||||
ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_name(file_name)
|
||||
{
|
||||
SimpleLogger().Write() << "Using script " << file_name;
|
||||
util::SimpleLogger().Write() << "Using script " << file_name;
|
||||
}
|
||||
|
||||
void ScriptingEnvironment::InitLuaState(lua_State *lua_state)
|
||||
@@ -49,11 +54,11 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state)
|
||||
// open utility libraries string library;
|
||||
luaL_openlibs(lua_state);
|
||||
|
||||
luaAddScriptFolderToLoadPath(lua_state, file_name.c_str());
|
||||
util::luaAddScriptFolderToLoadPath(lua_state, file_name.c_str());
|
||||
|
||||
// Add our function to the state's global scope
|
||||
luabind::module(lua_state)
|
||||
[luabind::def("print", LUA_print<std::string>),
|
||||
[luabind::def("print", util::LUA_print<std::string>),
|
||||
luabind::def("durationIsValid", durationIsValid),
|
||||
luabind::def("parseDuration", parseDuration),
|
||||
luabind::class_<SourceContainer>("sources")
|
||||
@@ -110,9 +115,9 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state)
|
||||
luabind::class_<ExternalMemoryNode>("EdgeTarget")
|
||||
.property("lat", &ExternalMemoryNode::lat)
|
||||
.property("lon", &ExternalMemoryNode::lon),
|
||||
luabind::class_<FixedPointCoordinate>("Coordinate")
|
||||
.property("lat", &FixedPointCoordinate::lat)
|
||||
.property("lon", &FixedPointCoordinate::lon),
|
||||
luabind::class_<util::FixedPointCoordinate>("Coordinate")
|
||||
.property("lat", &util::FixedPointCoordinate::lat)
|
||||
.property("lon", &util::FixedPointCoordinate::lon),
|
||||
luabind::class_<RasterDatum>("RasterDatum")
|
||||
.property("datum", &RasterDatum::datum)
|
||||
.def("invalid_data", &RasterDatum::get_invalid)];
|
||||
@@ -122,7 +127,7 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state)
|
||||
luabind::object error_msg(luabind::from_stack(lua_state, -1));
|
||||
std::ostringstream error_stream;
|
||||
error_stream << error_msg;
|
||||
throw osrm::exception("ERROR occurred in profile script:\n" + error_stream.str());
|
||||
throw util::exception("ERROR occurred in profile script:\n" + error_stream.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,3 +146,5 @@ lua_State *ScriptingEnvironment::GetLuaState()
|
||||
|
||||
return ref.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-11
@@ -10,7 +10,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace http
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
Connection::Connection(boost::asio::io_service &io_service, RequestHandler &handler)
|
||||
@@ -38,14 +40,14 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
}
|
||||
|
||||
// no error detected, let's parse the request
|
||||
compression_type compression_type(no_compression);
|
||||
osrm::tribool result;
|
||||
http::compression_type compression_type(http::no_compression);
|
||||
util::tribool result;
|
||||
std::tie(result, compression_type) =
|
||||
request_parser.parse(current_request, incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred);
|
||||
|
||||
// the request has been parsed
|
||||
if (result == osrm::tribool::yes)
|
||||
if (result == util::tribool::yes)
|
||||
{
|
||||
current_request.endpoint = TCP_socket.remote_endpoint().address();
|
||||
request_handler.handle_request(current_request, current_reply);
|
||||
@@ -56,7 +58,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
// compress the result w/ gzip/deflate if requested
|
||||
switch (compression_type)
|
||||
{
|
||||
case deflate_rfc1951:
|
||||
case http::deflate_rfc1951:
|
||||
// use deflate for compression
|
||||
current_reply.headers.insert(current_reply.headers.begin(),
|
||||
{"Content-Encoding", "deflate"});
|
||||
@@ -65,7 +67,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
output_buffer = current_reply.headers_to_buffers();
|
||||
output_buffer.push_back(boost::asio::buffer(compressed_output));
|
||||
break;
|
||||
case gzip_rfc1952:
|
||||
case http::gzip_rfc1952:
|
||||
// use gzip for compression
|
||||
current_reply.headers.insert(current_reply.headers.begin(),
|
||||
{"Content-Encoding", "gzip"});
|
||||
@@ -74,7 +76,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
output_buffer = current_reply.headers_to_buffers();
|
||||
output_buffer.push_back(boost::asio::buffer(compressed_output));
|
||||
break;
|
||||
case no_compression:
|
||||
case http::no_compression:
|
||||
// don't use any compression
|
||||
current_reply.set_uncompressed_size();
|
||||
output_buffer = current_reply.to_buffers();
|
||||
@@ -86,9 +88,9 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
strand.wrap(boost::bind(&Connection::handle_write, this->shared_from_this(),
|
||||
boost::asio::placeholders::error)));
|
||||
}
|
||||
else if (result == osrm::tribool::no)
|
||||
else if (result == util::tribool::no)
|
||||
{ // request is not parseable
|
||||
current_reply = reply::stock_reply(reply::bad_request);
|
||||
current_reply = http::reply::stock_reply(http::reply::bad_request);
|
||||
|
||||
boost::asio::async_write(
|
||||
TCP_socket, current_reply.to_buffers(),
|
||||
@@ -118,14 +120,14 @@ void Connection::handle_write(const boost::system::error_code &error)
|
||||
}
|
||||
|
||||
std::vector<char> Connection::compress_buffers(const std::vector<char> &uncompressed_data,
|
||||
const compression_type compression_type)
|
||||
const http::compression_type compression_type)
|
||||
{
|
||||
boost::iostreams::gzip_params compression_parameters;
|
||||
|
||||
// there's a trade-off between speed and size. speed wins
|
||||
compression_parameters.level = boost::iostreams::zlib::best_speed;
|
||||
// check which compression flavor is used
|
||||
if (deflate_rfc1951 == compression_type)
|
||||
if (http::deflate_rfc1951 == compression_type)
|
||||
{
|
||||
compression_parameters.noheader = true;
|
||||
}
|
||||
@@ -141,3 +143,4 @@ std::vector<char> Connection::compress_buffers(const std::vector<char> &uncompre
|
||||
return compressed_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
|
||||
@@ -101,3 +105,5 @@ boost::asio::const_buffer reply::status_to_buffer(const reply::status_type statu
|
||||
|
||||
reply::reply() : status(ok) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,22 +20,27 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
RequestHandler::RequestHandler() : routing_machine(nullptr) {}
|
||||
|
||||
void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
http::reply ¤t_reply)
|
||||
{
|
||||
osrm::json::Object json_result;
|
||||
util::json::Object json_result;
|
||||
|
||||
// parse command
|
||||
try
|
||||
{
|
||||
std::string request_string;
|
||||
URIDecode(current_request.uri, request_string);
|
||||
util::URIDecode(current_request.uri, request_string);
|
||||
|
||||
// deactivated as GCC apparently does not implement that, not even in 4.9
|
||||
// std::time_t t = std::time(nullptr);
|
||||
// SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
|
||||
// util::SimpleLogger().Write() << std::put_time(std::localtime(&t), "%m-%d-%Y %H:%M:%S") <<
|
||||
// " " << current_request.endpoint.to_string() << " " <<
|
||||
// current_request.referrer << ( 0 == current_request.referrer.length() ? "- " :" ") <<
|
||||
// current_request.agent << ( 0 == current_request.agent.length() ? "- " :" ") <<
|
||||
@@ -48,7 +53,7 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
time_stamp = localtime(<ime);
|
||||
|
||||
// log timestamp
|
||||
SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday
|
||||
util::SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday
|
||||
<< "-" << (time_stamp->tm_mon + 1 < 10 ? "0" : "")
|
||||
<< (time_stamp->tm_mon + 1) << "-" << 1900 + time_stamp->tm_year
|
||||
<< " " << (time_stamp->tm_hour < 10 ? "0" : "")
|
||||
@@ -61,7 +66,7 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
<< (0 == current_request.agent.length() ? "- " : " ")
|
||||
<< request_string;
|
||||
|
||||
RouteParameters route_parameters;
|
||||
engine::RouteParameters route_parameters;
|
||||
APIGrammarParser api_parser(&route_parameters);
|
||||
|
||||
auto api_iterator = request_string.begin();
|
||||
@@ -116,7 +121,7 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
std::to_string(current_reply.content.size()));
|
||||
if ("gpx" == route_parameters.output_format)
|
||||
{ // gpx file
|
||||
osrm::json::gpx_render(current_reply.content, json_result.values["route"]);
|
||||
util::json::gpx_render(current_reply.content, json_result.values["route"]);
|
||||
current_reply.headers.emplace_back("Content-Type",
|
||||
"application/gpx+xml; charset=UTF-8");
|
||||
current_reply.headers.emplace_back("Content-Disposition",
|
||||
@@ -124,14 +129,14 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
}
|
||||
else if (route_parameters.jsonp_parameter.empty())
|
||||
{ // json file
|
||||
osrm::json::render(current_reply.content, json_result);
|
||||
util::json::render(current_reply.content, json_result);
|
||||
current_reply.headers.emplace_back("Content-Type", "application/json; charset=UTF-8");
|
||||
current_reply.headers.emplace_back("Content-Disposition",
|
||||
"inline; filename=\"response.json\"");
|
||||
}
|
||||
else
|
||||
{ // jsonp
|
||||
osrm::json::render(current_reply.content, json_result);
|
||||
util::json::render(current_reply.content, json_result);
|
||||
current_reply.headers.emplace_back("Content-Type", "text/javascript; charset=UTF-8");
|
||||
current_reply.headers.emplace_back("Content-Disposition",
|
||||
"inline; filename=\"response.js\"");
|
||||
@@ -145,9 +150,11 @@ void RequestHandler::handle_request(const http::request ¤t_request,
|
||||
{
|
||||
current_reply = http::reply::stock_reply(http::reply::internal_server_error);
|
||||
;
|
||||
SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
|
||||
util::SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
|
||||
<< ", uri: " << current_request.uri;
|
||||
}
|
||||
}
|
||||
|
||||
void RequestHandler::RegisterRoutingMachine(OSRM *osrm) { routing_machine = osrm; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,197 +10,199 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace http
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
RequestParser::RequestParser()
|
||||
: state(internal_state::method_start), current_header({"", ""}),
|
||||
selected_compression(no_compression), is_post_header(false), content_length(0)
|
||||
selected_compression(http::no_compression), is_post_header(false), content_length(0)
|
||||
{
|
||||
}
|
||||
|
||||
std::tuple<osrm::tribool, compression_type>
|
||||
RequestParser::parse(request ¤t_request, char *begin, char *end)
|
||||
std::tuple<util::tribool, http::compression_type>
|
||||
RequestParser::parse(http::request ¤t_request, char *begin, char *end)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
osrm::tribool result = consume(current_request, *begin++);
|
||||
if (result != osrm::tribool::indeterminate)
|
||||
util::tribool result = consume(current_request, *begin++);
|
||||
if (result != util::tribool::indeterminate)
|
||||
{
|
||||
return std::make_tuple(result, selected_compression);
|
||||
}
|
||||
}
|
||||
osrm::tribool result = osrm::tribool::indeterminate;
|
||||
util::tribool result = util::tribool::indeterminate;
|
||||
|
||||
if (state == internal_state::post_request && content_length <= 0)
|
||||
{
|
||||
result = osrm::tribool::yes;
|
||||
result = util::tribool::yes;
|
||||
}
|
||||
return std::make_tuple(result, selected_compression);
|
||||
}
|
||||
|
||||
osrm::tribool RequestParser::consume(request ¤t_request, const char input)
|
||||
util::tribool RequestParser::consume(http::request ¤t_request, const char input)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case internal_state::method_start:
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
if (input == 'P')
|
||||
{
|
||||
state = internal_state::post_O;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
state = internal_state::method;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::post_O:
|
||||
if (input == 'O')
|
||||
{
|
||||
state = internal_state::post_S;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::post_S:
|
||||
if (input == 'S')
|
||||
{
|
||||
state = internal_state::post_T;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::post_T:
|
||||
if (input == 'T')
|
||||
{
|
||||
is_post_header = true;
|
||||
state = internal_state::method;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::post_request:
|
||||
current_request.uri.push_back(input);
|
||||
--content_length;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::method:
|
||||
if (input == ' ')
|
||||
{
|
||||
state = internal_state::uri;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::uri_start:
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
state = internal_state::uri;
|
||||
current_request.uri.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::uri:
|
||||
if (input == ' ')
|
||||
{
|
||||
state = internal_state::http_version_h;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
current_request.uri.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::http_version_h:
|
||||
if (input == 'H')
|
||||
{
|
||||
state = internal_state::http_version_t_1;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_t_1:
|
||||
if (input == 'T')
|
||||
{
|
||||
state = internal_state::http_version_t_2;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_t_2:
|
||||
if (input == 'T')
|
||||
{
|
||||
state = internal_state::http_version_p;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_p:
|
||||
if (input == 'P')
|
||||
{
|
||||
state = internal_state::http_version_slash;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_slash:
|
||||
if (input == '/')
|
||||
{
|
||||
state = internal_state::http_version_major_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_major_start:
|
||||
if (is_digit(input))
|
||||
{
|
||||
state = internal_state::http_version_major;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_major:
|
||||
if (input == '.')
|
||||
{
|
||||
state = internal_state::http_version_minor_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_digit(input))
|
||||
{
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_minor_start:
|
||||
if (is_digit(input))
|
||||
{
|
||||
state = internal_state::http_version_minor;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::http_version_minor:
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_1;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_digit(input))
|
||||
{
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::expecting_newline_1:
|
||||
if (input == '\n')
|
||||
{
|
||||
state = internal_state::header_line_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::header_line_start:
|
||||
if (boost::iequals(current_header.name, "Accept-Encoding"))
|
||||
{
|
||||
/* giving gzip precedence over deflate */
|
||||
if (boost::icontains(current_header.value, "deflate"))
|
||||
{
|
||||
selected_compression = deflate_rfc1951;
|
||||
selected_compression = http::deflate_rfc1951;
|
||||
}
|
||||
if (boost::icontains(current_header.value, "gzip"))
|
||||
{
|
||||
selected_compression = gzip_rfc1952;
|
||||
selected_compression = http::gzip_rfc1952;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,77 +230,77 @@ osrm::tribool RequestParser::consume(request ¤t_request, const char input)
|
||||
{
|
||||
if (!boost::icontains(current_header.value, "application/x-www-form-urlencoded"))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
}
|
||||
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_3;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
state = internal_state::header_name;
|
||||
current_header.clear();
|
||||
current_header.name.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::header_lws:
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_2;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (input == ' ' || input == '\t')
|
||||
{
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
state = internal_state::header_value;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::header_name:
|
||||
if (input == ':')
|
||||
{
|
||||
state = internal_state::space_before_header_value;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (!is_char(input) || is_CTL(input) || is_special(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
current_header.name.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::space_before_header_value:
|
||||
if (input == ' ')
|
||||
{
|
||||
state = internal_state::header_value;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::header_value:
|
||||
if (input == '\r')
|
||||
{
|
||||
state = internal_state::expecting_newline_2;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
if (is_CTL(input))
|
||||
{
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
}
|
||||
current_header.value.push_back(input);
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
case internal_state::expecting_newline_2:
|
||||
if (input == '\n')
|
||||
{
|
||||
state = internal_state::header_line_start;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
case internal_state::expecting_newline_3:
|
||||
if (input == '\n')
|
||||
{
|
||||
@@ -309,13 +311,13 @@ osrm::tribool RequestParser::consume(request ¤t_request, const char input)
|
||||
current_request.uri.push_back('?');
|
||||
}
|
||||
state = internal_state::post_request;
|
||||
return osrm::tribool::indeterminate;
|
||||
return util::tribool::indeterminate;
|
||||
}
|
||||
return osrm::tribool::yes;
|
||||
return util::tribool::yes;
|
||||
}
|
||||
return osrm::tribool::no;
|
||||
return util::tribool::no;
|
||||
default: // should never be reached
|
||||
return input == '\n' ? osrm::tribool::yes : osrm::tribool::no;
|
||||
return input == '\n' ? util::tribool::yes : util::tribool::no;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,3 +365,4 @@ bool RequestParser::is_digit(const int character) const
|
||||
return character >= '0' && character <= '9';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-17
@@ -12,45 +12,53 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using EdgeData = QueryEdge::EdgeData;
|
||||
using QueryGraph = StaticGraph<EdgeData>;
|
||||
namespace osrm
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
using EdgeData = contractor::QueryEdge::EdgeData;
|
||||
using QueryGraph = util::StaticGraph<EdgeData>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " <file.hsgr>";
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " <file.hsgr>";
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::filesystem::path hsgr_path(argv[1]);
|
||||
|
||||
std::vector<QueryGraph::NodeArrayEntry> node_list;
|
||||
std::vector<QueryGraph::EdgeArrayEntry> edge_list;
|
||||
SimpleLogger().Write() << "loading graph from " << hsgr_path.string();
|
||||
std::vector<osrm::tools::QueryGraph::NodeArrayEntry> node_list;
|
||||
std::vector<osrm::tools::QueryGraph::EdgeArrayEntry> edge_list;
|
||||
osrm::util::SimpleLogger().Write() << "loading graph from " << hsgr_path.string();
|
||||
|
||||
unsigned m_check_sum = 0;
|
||||
unsigned m_number_of_nodes =
|
||||
readHSGRFromStream(hsgr_path, node_list, edge_list, &m_check_sum);
|
||||
SimpleLogger().Write() << "expecting " << m_number_of_nodes
|
||||
osrm::util::SimpleLogger().Write() << "expecting " << m_number_of_nodes
|
||||
<< " nodes, checksum: " << m_check_sum;
|
||||
BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty");
|
||||
SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size()
|
||||
osrm::util::SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size()
|
||||
<< " edges";
|
||||
auto m_query_graph = std::make_shared<QueryGraph>(node_list, edge_list);
|
||||
auto m_query_graph = std::make_shared<osrm::tools::QueryGraph>(node_list, edge_list);
|
||||
|
||||
BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed");
|
||||
BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed");
|
||||
|
||||
Percent progress(m_query_graph->GetNumberOfNodes());
|
||||
for (const auto node_u : osrm::irange(0u, m_query_graph->GetNumberOfNodes()))
|
||||
osrm::util::Percent progress(m_query_graph->GetNumberOfNodes());
|
||||
for (const auto node_u : osrm::util::irange(0u, m_query_graph->GetNumberOfNodes()))
|
||||
{
|
||||
for (const auto eid : m_query_graph->GetAdjacentEdgeRange(node_u))
|
||||
{
|
||||
const EdgeData &data = m_query_graph->GetEdgeData(eid);
|
||||
const osrm::tools::EdgeData &data = m_query_graph->GetEdgeData(eid);
|
||||
if (!data.shortcut)
|
||||
{
|
||||
continue;
|
||||
@@ -59,7 +67,7 @@ int main(int argc, char *argv[])
|
||||
const EdgeID edge_id_1 = m_query_graph->FindEdgeInEitherDirection(node_u, data.id);
|
||||
if (SPECIAL_EDGEID == edge_id_1)
|
||||
{
|
||||
throw osrm::exception("cannot find first segment of edge (" +
|
||||
throw osrm::util::exception("cannot find first segment of edge (" +
|
||||
std::to_string(node_u) + "," + std::to_string(data.id) +
|
||||
"," + std::to_string(node_v) + "), eid: " +
|
||||
std::to_string(eid));
|
||||
@@ -67,7 +75,7 @@ int main(int argc, char *argv[])
|
||||
const EdgeID edge_id_2 = m_query_graph->FindEdgeInEitherDirection(data.id, node_v);
|
||||
if (SPECIAL_EDGEID == edge_id_2)
|
||||
{
|
||||
throw osrm::exception("cannot find second segment of edge (" +
|
||||
throw osrm::util::exception("cannot find second segment of edge (" +
|
||||
std::to_string(node_u) + "," + std::to_string(data.id) +
|
||||
"," + std::to_string(node_v) + "), eid: " +
|
||||
std::to_string(eid));
|
||||
@@ -76,11 +84,11 @@ int main(int argc, char *argv[])
|
||||
progress.printStatus(node_u);
|
||||
}
|
||||
m_query_graph.reset();
|
||||
SimpleLogger().Write() << "Data file " << argv[0] << " appears to be OK";
|
||||
osrm::util::SimpleLogger().Write() << "Data file " << argv[0] << " appears to be OK";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+41
-38
@@ -26,7 +26,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
namespace osrm
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
struct TarjanEdgeData
|
||||
@@ -37,7 +39,7 @@ struct TarjanEdgeData
|
||||
unsigned name_id;
|
||||
};
|
||||
|
||||
using TarjanGraph = StaticGraph<TarjanEdgeData>;
|
||||
using TarjanGraph = util::StaticGraph<TarjanEdgeData>;
|
||||
using TarjanEdge = TarjanGraph::InputEdge;
|
||||
|
||||
void deleteFileIfExists(const std::string &file_name)
|
||||
@@ -47,27 +49,26 @@ void deleteFileIfExists(const std::string &file_name)
|
||||
boost::filesystem::remove(file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t loadGraph(const char *path,
|
||||
std::vector<QueryNode> &coordinate_list,
|
||||
std::vector<extractor::QueryNode> &coordinate_list,
|
||||
std::vector<TarjanEdge> &graph_edge_list)
|
||||
{
|
||||
std::ifstream input_stream(path, std::ifstream::in | std::ifstream::binary);
|
||||
if (!input_stream.is_open())
|
||||
{
|
||||
throw osrm::exception("Cannot open osrm file");
|
||||
throw util::exception("Cannot open osrm file");
|
||||
}
|
||||
|
||||
// load graph data
|
||||
std::vector<NodeBasedEdge> edge_list;
|
||||
std::vector<extractor::NodeBasedEdge> edge_list;
|
||||
std::vector<NodeID> traffic_light_node_list;
|
||||
std::vector<NodeID> barrier_node_list;
|
||||
|
||||
auto number_of_nodes = loadNodesFromFile(input_stream, barrier_node_list,
|
||||
auto number_of_nodes = util::loadNodesFromFile(input_stream, barrier_node_list,
|
||||
traffic_light_node_list, coordinate_list);
|
||||
|
||||
loadEdgesFromFile(input_stream, edge_list);
|
||||
util::loadEdgesFromFile(input_stream, edge_list);
|
||||
|
||||
traffic_light_node_list.clear();
|
||||
traffic_light_node_list.shrink_to_fit();
|
||||
@@ -94,46 +95,48 @@ std::size_t loadGraph(const char *path,
|
||||
|
||||
return number_of_nodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::vector<QueryNode> coordinate_list;
|
||||
std::vector<osrm::extractor::QueryNode> coordinate_list;
|
||||
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
// enable logging
|
||||
if (argc < 2)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<TarjanEdge> graph_edge_list;
|
||||
auto number_of_nodes = loadGraph(argv[1], coordinate_list, graph_edge_list);
|
||||
std::vector<osrm::tools::TarjanEdge> graph_edge_list;
|
||||
auto number_of_nodes = osrm::tools::loadGraph(argv[1], coordinate_list, graph_edge_list);
|
||||
|
||||
tbb::parallel_sort(graph_edge_list.begin(), graph_edge_list.end());
|
||||
const auto graph = std::make_shared<TarjanGraph>(number_of_nodes, graph_edge_list);
|
||||
const auto graph = std::make_shared<osrm::tools::TarjanGraph>(number_of_nodes, graph_edge_list);
|
||||
graph_edge_list.clear();
|
||||
graph_edge_list.shrink_to_fit();
|
||||
|
||||
SimpleLogger().Write() << "Starting SCC graph traversal";
|
||||
osrm::util::SimpleLogger().Write() << "Starting SCC graph traversal";
|
||||
|
||||
auto tarjan = osrm::make_unique<TarjanSCC<TarjanGraph>>(graph);
|
||||
auto tarjan = osrm::util::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
|
||||
tarjan->run();
|
||||
SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
|
||||
osrm::util::SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
|
||||
<< " many components";
|
||||
SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs";
|
||||
osrm::util::SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs";
|
||||
|
||||
// output
|
||||
TIMER_START(SCC_RUN_SETUP);
|
||||
|
||||
// remove files from previous run if exist
|
||||
deleteFileIfExists("component.dbf");
|
||||
deleteFileIfExists("component.shx");
|
||||
deleteFileIfExists("component.shp");
|
||||
osrm::tools::deleteFileIfExists("component.dbf");
|
||||
osrm::tools::deleteFileIfExists("component.shx");
|
||||
osrm::tools::deleteFileIfExists("component.shp");
|
||||
|
||||
Percent percentage(graph->GetNumberOfNodes());
|
||||
osrm::util::Percent percentage(graph->GetNumberOfNodes());
|
||||
|
||||
OGRRegisterAll();
|
||||
|
||||
@@ -142,13 +145,13 @@ int main(int argc, char *argv[])
|
||||
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(psz_driver_name);
|
||||
if (nullptr == po_driver)
|
||||
{
|
||||
throw osrm::exception("ESRI Shapefile driver not available");
|
||||
throw osrm::util::exception("ESRI Shapefile driver not available");
|
||||
}
|
||||
auto *po_datasource = po_driver->CreateDataSource("component.shp", nullptr);
|
||||
|
||||
if (nullptr == po_datasource)
|
||||
{
|
||||
throw osrm::exception("Creation of output file failed");
|
||||
throw osrm::util::exception("Creation of output file failed");
|
||||
}
|
||||
|
||||
auto *po_srs = new OGRSpatialReference();
|
||||
@@ -158,26 +161,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (nullptr == po_layer)
|
||||
{
|
||||
throw osrm::exception("Layer creation failed.");
|
||||
throw osrm::util::exception("Layer creation failed.");
|
||||
}
|
||||
TIMER_STOP(SCC_RUN_SETUP);
|
||||
SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000.
|
||||
osrm::util::SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000.
|
||||
<< "s";
|
||||
|
||||
uint64_t total_network_length = 0;
|
||||
percentage.reinit(graph->GetNumberOfNodes());
|
||||
TIMER_START(SCC_OUTPUT);
|
||||
for (const NodeID source : osrm::irange(0u, graph->GetNumberOfNodes()))
|
||||
for (const NodeID source : osrm::util::irange(0u, graph->GetNumberOfNodes()))
|
||||
{
|
||||
percentage.printIncrement();
|
||||
for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
|
||||
{
|
||||
const TarjanGraph::NodeIterator target = graph->GetTarget(current_edge);
|
||||
const auto target = graph->GetTarget(current_edge);
|
||||
|
||||
if (source < target || SPECIAL_EDGEID == graph->FindEdge(target, source))
|
||||
{
|
||||
total_network_length +=
|
||||
100 * coordinate_calculation::greatCircleDistance(
|
||||
100 * osrm::util::coordinate_calculation::greatCircleDistance(
|
||||
coordinate_list[source].lat, coordinate_list[source].lon,
|
||||
coordinate_list[target].lat, coordinate_list[target].lon);
|
||||
|
||||
@@ -193,17 +196,17 @@ int main(int argc, char *argv[])
|
||||
if (size_of_containing_component < 1000)
|
||||
{
|
||||
OGRLineString line_string;
|
||||
line_string.addPoint(coordinate_list[source].lon / COORDINATE_PRECISION,
|
||||
coordinate_list[source].lat / COORDINATE_PRECISION);
|
||||
line_string.addPoint(coordinate_list[target].lon / COORDINATE_PRECISION,
|
||||
coordinate_list[target].lat / COORDINATE_PRECISION);
|
||||
line_string.addPoint(coordinate_list[source].lon / osrm::COORDINATE_PRECISION,
|
||||
coordinate_list[source].lat / osrm::COORDINATE_PRECISION);
|
||||
line_string.addPoint(coordinate_list[target].lon / osrm::COORDINATE_PRECISION,
|
||||
coordinate_list[target].lat / osrm::COORDINATE_PRECISION);
|
||||
|
||||
OGRFeature *po_feature = OGRFeature::CreateFeature(po_layer->GetLayerDefn());
|
||||
|
||||
po_feature->SetGeometry(&line_string);
|
||||
if (OGRERR_NONE != po_layer->CreateFeature(po_feature))
|
||||
{
|
||||
throw osrm::exception("Failed to create feature in shapefile.");
|
||||
throw osrm::util::exception("Failed to create feature in shapefile.");
|
||||
}
|
||||
OGRFeature::DestroyFeature(po_feature);
|
||||
}
|
||||
@@ -213,18 +216,18 @@ int main(int argc, char *argv[])
|
||||
OGRSpatialReference::DestroySpatialReference(po_srs);
|
||||
OGRDataSource::DestroyDataSource(po_datasource);
|
||||
TIMER_STOP(SCC_OUTPUT);
|
||||
SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000.
|
||||
osrm::util::SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000.
|
||||
<< "s";
|
||||
|
||||
SimpleLogger().Write() << "total network distance: "
|
||||
osrm::util::SimpleLogger().Write() << "total network distance: "
|
||||
<< static_cast<uint64_t>(total_network_length / 100 / 1000.)
|
||||
<< " km";
|
||||
|
||||
SimpleLogger().Write() << "finished component analysis";
|
||||
osrm::util::SimpleLogger().Write() << "finished component analysis";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+19
-17
@@ -11,28 +11,30 @@
|
||||
#include <new>
|
||||
#include <ostream>
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
ContractorConfig contractor_config;
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
contractor::ContractorConfig contractor_config;
|
||||
|
||||
const return_code result = ContractorOptions::ParseArguments(argc, argv, contractor_config);
|
||||
const contractor::return_code result = contractor::ContractorOptions::ParseArguments(argc, argv, contractor_config);
|
||||
|
||||
if (return_code::fail == result)
|
||||
if (contractor::return_code::fail == result)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (return_code::exit == result)
|
||||
if (contractor::return_code::exit == result)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
ContractorOptions::GenerateOutputFilesNames(contractor_config);
|
||||
contractor::ContractorOptions::GenerateOutputFilesNames(contractor_config);
|
||||
|
||||
if (1 > contractor_config.requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
util::SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -40,43 +42,43 @@ int main(int argc, char *argv[]) try
|
||||
|
||||
if (recommended_num_threads != contractor_config.requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "The recommended number of threads is "
|
||||
util::SimpleLogger().Write(logWARNING) << "The recommended number of threads is "
|
||||
<< recommended_num_threads
|
||||
<< "! This setting may have performance side-effects.";
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(contractor_config.osrm_input_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING)
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Input file " << contractor_config.osrm_input_path.string() << " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(contractor_config.profile_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << contractor_config.profile_path.string()
|
||||
util::SimpleLogger().Write(logWARNING) << "Profile " << contractor_config.profile_path.string()
|
||||
<< " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Input file: "
|
||||
util::SimpleLogger().Write() << "Input file: "
|
||||
<< contractor_config.osrm_input_path.filename().string();
|
||||
SimpleLogger().Write() << "Profile: " << contractor_config.profile_path.filename().string();
|
||||
SimpleLogger().Write() << "Threads: " << contractor_config.requested_num_threads;
|
||||
util::SimpleLogger().Write() << "Profile: " << contractor_config.profile_path.filename().string();
|
||||
util::SimpleLogger().Write() << "Threads: " << contractor_config.requested_num_threads;
|
||||
|
||||
tbb::task_scheduler_init init(contractor_config.requested_num_threads);
|
||||
|
||||
return Prepare(contractor_config).Run();
|
||||
return contractor::Prepare(contractor_config).Run();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
SimpleLogger().Write(logWARNING)
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+63
-49
@@ -19,10 +19,6 @@
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
using RTreeLeaf = BaseDataFacade<QueryEdge::EdgeData>::RTreeLeaf;
|
||||
using RTreeNode = StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, true>::vector, true>::TreeNode;
|
||||
using QueryGraph = StaticGraph<QueryEdge::EdgeData>;
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
@@ -36,6 +32,20 @@ using QueryGraph = StaticGraph<QueryEdge::EdgeData>;
|
||||
#include <new>
|
||||
#include <string>
|
||||
|
||||
// FIXME remove after move to datastore
|
||||
using namespace osrm::engine::datafacade;
|
||||
using namespace osrm::datastore;
|
||||
using namespace osrm;
|
||||
|
||||
using RTreeLeaf = typename engine::datafacade::BaseDataFacade<contractor::QueryEdge::EdgeData>::RTreeLeaf;
|
||||
using RTreeNode = util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, true>::vector, true>::TreeNode;
|
||||
using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>;
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
// delete a shared memory region. report warning if it could not be deleted
|
||||
void deleteRegion(const SharedDataType region)
|
||||
{
|
||||
@@ -62,13 +72,16 @@ void deleteRegion(const SharedDataType region)
|
||||
}
|
||||
}();
|
||||
|
||||
SimpleLogger().Write(logWARNING) << "could not delete shared memory region " << name;
|
||||
util::SimpleLogger().Write(logWARNING) << "could not delete shared memory region " << name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(const int argc, const char *argv[]) try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
SharedBarriers barrier;
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -76,7 +89,7 @@ int main(const int argc, const char *argv[]) try
|
||||
const bool lock_flags = MCL_CURRENT | MCL_FUTURE;
|
||||
if (-1 == mlockall(lock_flags))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Process " << argv[0] << " could not request RAM lock";
|
||||
util::SimpleLogger().Write(logWARNING) << "Process " << argv[0] << " could not request RAM lock";
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -91,45 +104,45 @@ int main(const int argc, const char *argv[]) try
|
||||
barrier.pending_update_mutex.unlock();
|
||||
}
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "Checking input parameters";
|
||||
util::SimpleLogger().Write(logDEBUG) << "Checking input parameters";
|
||||
|
||||
std::unordered_map<std::string, boost::filesystem::path> server_paths;
|
||||
if (!GenerateDataStoreOptions(argc, argv, server_paths))
|
||||
if (!util::GenerateDataStoreOptions(argc, argv, server_paths))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (server_paths.find("hsgrdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no hsgr file found");
|
||||
throw util::exception("no hsgr file found");
|
||||
}
|
||||
if (server_paths.find("ramindex") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no ram index file found");
|
||||
throw util::exception("no ram index file found");
|
||||
}
|
||||
if (server_paths.find("fileindex") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no leaf index file found");
|
||||
throw util::exception("no leaf index file found");
|
||||
}
|
||||
if (server_paths.find("nodesdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no nodes file found");
|
||||
throw util::exception("no nodes file found");
|
||||
}
|
||||
if (server_paths.find("edgesdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no edges file found");
|
||||
throw util::exception("no edges file found");
|
||||
}
|
||||
if (server_paths.find("namesdata") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no names file found");
|
||||
throw util::exception("no names file found");
|
||||
}
|
||||
if (server_paths.find("geometry") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no geometry file found");
|
||||
throw util::exception("no geometry file found");
|
||||
}
|
||||
if (server_paths.find("core") == server_paths.end())
|
||||
{
|
||||
throw osrm::exception("no core file found");
|
||||
throw util::exception("no core file found");
|
||||
}
|
||||
|
||||
auto paths_iterator = server_paths.find("hsgrdata");
|
||||
@@ -173,19 +186,19 @@ int main(const int argc, const char *argv[]) try
|
||||
|
||||
// determine segment to use
|
||||
bool segment2_in_use = SharedMemory::RegionExists(LAYOUT_2);
|
||||
const SharedDataType layout_region = [&]
|
||||
const engine::datafacade::SharedDataType layout_region = [&]
|
||||
{
|
||||
return segment2_in_use ? LAYOUT_1 : LAYOUT_2;
|
||||
}();
|
||||
const SharedDataType data_region = [&]
|
||||
const engine::datafacade::SharedDataType data_region = [&]
|
||||
{
|
||||
return segment2_in_use ? DATA_1 : DATA_2;
|
||||
}();
|
||||
const SharedDataType previous_layout_region = [&]
|
||||
const engine::datafacade::SharedDataType previous_layout_region = [&]
|
||||
{
|
||||
return segment2_in_use ? LAYOUT_2 : LAYOUT_1;
|
||||
}();
|
||||
const SharedDataType previous_data_region = [&]
|
||||
const engine::datafacade::SharedDataType previous_data_region = [&]
|
||||
{
|
||||
return segment2_in_use ? DATA_2 : DATA_1;
|
||||
}();
|
||||
@@ -198,15 +211,15 @@ int main(const int argc, const char *argv[]) try
|
||||
file_index_path.length() + 1);
|
||||
|
||||
// collect number of elements to store in shared memory object
|
||||
SimpleLogger().Write() << "load names from: " << names_data_path;
|
||||
util::SimpleLogger().Write() << "load names from: " << names_data_path;
|
||||
// number of entries in name index
|
||||
boost::filesystem::ifstream name_stream(names_data_path, std::ios::binary);
|
||||
unsigned name_blocks = 0;
|
||||
name_stream.read((char *)&name_blocks, sizeof(unsigned));
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::NAME_OFFSETS, name_blocks);
|
||||
shared_layout_ptr->SetBlockSize<typename RangeTable<16, true>::BlockT>(
|
||||
shared_layout_ptr->SetBlockSize<typename util::RangeTable<16, true>::BlockT>(
|
||||
SharedDataLayout::NAME_BLOCKS, name_blocks);
|
||||
SimpleLogger().Write() << "name offsets size: " << name_blocks;
|
||||
util::SimpleLogger().Write() << "name offsets size: " << name_blocks;
|
||||
BOOST_ASSERT_MSG(0 != name_blocks, "name file broken");
|
||||
|
||||
unsigned number_of_chars = 0;
|
||||
@@ -223,9 +236,9 @@ int main(const int argc, const char *argv[]) try
|
||||
number_of_original_edges);
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::NAME_ID_LIST,
|
||||
number_of_original_edges);
|
||||
shared_layout_ptr->SetBlockSize<TravelMode>(SharedDataLayout::TRAVEL_MODE,
|
||||
shared_layout_ptr->SetBlockSize<extractor::TravelMode>(SharedDataLayout::TRAVEL_MODE,
|
||||
number_of_original_edges);
|
||||
shared_layout_ptr->SetBlockSize<TurnInstruction>(SharedDataLayout::TURN_INSTRUCTION,
|
||||
shared_layout_ptr->SetBlockSize<extractor::TurnInstruction>(SharedDataLayout::TURN_INSTRUCTION,
|
||||
number_of_original_edges);
|
||||
// note: there are 32 geometry indicators in one unsigned block
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_INDICATORS,
|
||||
@@ -233,16 +246,16 @@ int main(const int argc, const char *argv[]) try
|
||||
|
||||
boost::filesystem::ifstream hsgr_input_stream(hsgr_path, std::ios::binary);
|
||||
|
||||
FingerPrint fingerprint_valid = FingerPrint::GetValid();
|
||||
FingerPrint fingerprint_loaded;
|
||||
hsgr_input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
|
||||
util::FingerPrint fingerprint_valid = util::FingerPrint::GetValid();
|
||||
util::FingerPrint fingerprint_loaded;
|
||||
hsgr_input_stream.read((char *)&fingerprint_loaded, sizeof(util::FingerPrint));
|
||||
if (fingerprint_loaded.TestGraphUtil(fingerprint_valid))
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Fingerprint checked out ok";
|
||||
util::SimpleLogger().Write(logDEBUG) << "Fingerprint checked out ok";
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build. "
|
||||
util::SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build. "
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
@@ -279,7 +292,7 @@ int main(const int argc, const char *argv[]) try
|
||||
boost::filesystem::ifstream timestamp_stream(timestamp_path);
|
||||
if (!timestamp_stream)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << timestamp_path << " not found. setting to default";
|
||||
util::SimpleLogger().Write(logWARNING) << timestamp_path << " not found. setting to default";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -309,7 +322,7 @@ int main(const int argc, const char *argv[]) try
|
||||
boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary);
|
||||
unsigned coordinate_list_size = 0;
|
||||
nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned));
|
||||
shared_layout_ptr->SetBlockSize<FixedPointCoordinate>(SharedDataLayout::COORDINATE_LIST,
|
||||
shared_layout_ptr->SetBlockSize<util::FixedPointCoordinate>(SharedDataLayout::COORDINATE_LIST,
|
||||
coordinate_list_size);
|
||||
|
||||
// load geometries sizes
|
||||
@@ -326,7 +339,7 @@ int main(const int argc, const char *argv[]) try
|
||||
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_LIST,
|
||||
number_of_compressed_geometries);
|
||||
// allocate shared memory block
|
||||
SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout()
|
||||
util::SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout()
|
||||
<< " bytes";
|
||||
SharedMemory *shared_memory =
|
||||
SharedMemoryFactory::Get(data_region, shared_layout_ptr->GetSizeOfLayout());
|
||||
@@ -390,19 +403,19 @@ int main(const int argc, const char *argv[]) try
|
||||
unsigned *name_id_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
|
||||
shared_memory_ptr, SharedDataLayout::NAME_ID_LIST);
|
||||
|
||||
TravelMode *travel_mode_ptr = shared_layout_ptr->GetBlockPtr<TravelMode, true>(
|
||||
extractor::TravelMode *travel_mode_ptr = shared_layout_ptr->GetBlockPtr<extractor::TravelMode, true>(
|
||||
shared_memory_ptr, SharedDataLayout::TRAVEL_MODE);
|
||||
|
||||
TurnInstruction *turn_instructions_ptr = shared_layout_ptr->GetBlockPtr<TurnInstruction, true>(
|
||||
extractor::TurnInstruction *turn_instructions_ptr = shared_layout_ptr->GetBlockPtr<extractor::TurnInstruction, true>(
|
||||
shared_memory_ptr, SharedDataLayout::TURN_INSTRUCTION);
|
||||
|
||||
unsigned *geometries_indicator_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
|
||||
shared_memory_ptr, SharedDataLayout::GEOMETRIES_INDICATORS);
|
||||
|
||||
OriginalEdgeData current_edge_data;
|
||||
extractor::OriginalEdgeData current_edge_data;
|
||||
for (unsigned i = 0; i < number_of_original_edges; ++i)
|
||||
{
|
||||
edges_input_stream.read((char *)&(current_edge_data), sizeof(OriginalEdgeData));
|
||||
edges_input_stream.read((char *)&(current_edge_data), sizeof(extractor::OriginalEdgeData));
|
||||
via_node_ptr[i] = current_edge_data.via_node;
|
||||
name_id_ptr[i] = current_edge_data.name_id;
|
||||
travel_mode_ptr[i] = current_edge_data.travel_mode;
|
||||
@@ -456,15 +469,15 @@ int main(const int argc, const char *argv[]) try
|
||||
}
|
||||
|
||||
// Loading list of coordinates
|
||||
FixedPointCoordinate *coordinates_ptr =
|
||||
shared_layout_ptr->GetBlockPtr<FixedPointCoordinate, true>(
|
||||
util::FixedPointCoordinate *coordinates_ptr =
|
||||
shared_layout_ptr->GetBlockPtr<util::FixedPointCoordinate, true>(
|
||||
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
|
||||
|
||||
QueryNode current_node;
|
||||
extractor::QueryNode current_node;
|
||||
for (unsigned i = 0; i < coordinate_list_size; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(QueryNode));
|
||||
coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon);
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode));
|
||||
coordinates_ptr[i] = util::FixedPointCoordinate(current_node.lat, current_node.lon);
|
||||
}
|
||||
nodes_input_stream.close();
|
||||
|
||||
@@ -552,20 +565,21 @@ int main(const int argc, const char *argv[]) try
|
||||
data_timestamp_ptr->layout = layout_region;
|
||||
data_timestamp_ptr->data = data_region;
|
||||
data_timestamp_ptr->timestamp += 1;
|
||||
deleteRegion(previous_data_region);
|
||||
deleteRegion(previous_layout_region);
|
||||
SimpleLogger().Write() << "all data loaded";
|
||||
tools::deleteRegion(previous_data_region);
|
||||
tools::deleteRegion(previous_layout_region);
|
||||
util::SimpleLogger().Write() << "all data loaded";
|
||||
|
||||
shared_layout_ptr->PrintInformation();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
SimpleLogger().Write(logWARNING) << "Please provide more memory or disable locking the virtual "
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << "Please provide more memory or disable locking the virtual "
|
||||
"address space (note: this makes OSRM swap, i.e. slow)";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
}
|
||||
|
||||
+15
-13
@@ -8,55 +8,57 @@
|
||||
#include <exception>
|
||||
#include <new>
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
int main(int argc, char *argv[]) try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
ExtractorConfig extractor_config;
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
extractor::ExtractorConfig extractor_config;
|
||||
|
||||
const return_code result = ExtractorOptions::ParseArguments(argc, argv, extractor_config);
|
||||
const extractor::return_code result = extractor::ExtractorOptions::ParseArguments(argc, argv, extractor_config);
|
||||
|
||||
if (return_code::fail == result)
|
||||
if (extractor::return_code::fail == result)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (return_code::exit == result)
|
||||
if (extractor::return_code::exit == result)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
ExtractorOptions::GenerateOutputFilesNames(extractor_config);
|
||||
extractor::ExtractorOptions::GenerateOutputFilesNames(extractor_config);
|
||||
|
||||
if (1 > extractor_config.requested_num_threads)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
util::SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(extractor_config.input_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Input file " << extractor_config.input_path.string()
|
||||
util::SimpleLogger().Write(logWARNING) << "Input file " << extractor_config.input_path.string()
|
||||
<< " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(extractor_config.profile_path))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Profile " << extractor_config.profile_path.string()
|
||||
util::SimpleLogger().Write(logWARNING) << "Profile " << extractor_config.profile_path.string()
|
||||
<< " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return extractor(extractor_config).run();
|
||||
return extractor::extractor(extractor_config).run();
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
SimpleLogger().Write(logWARNING)
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+59
-54
@@ -1,4 +1,3 @@
|
||||
#include "util/version.hpp"
|
||||
#include "util/osrm_exception.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
@@ -20,7 +19,12 @@
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
const unsigned number_of_elements = 268435456;
|
||||
namespace osrm
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
const unsigned NUMBER_OF_ELEMENTS = 268435456;
|
||||
|
||||
struct Statistics
|
||||
{
|
||||
@@ -41,33 +45,34 @@ void runStatistics(std::vector<double> &timings_vector, Statistics &stats)
|
||||
stats.dev = std::sqrt(primary_sq_sum / timings_vector.size() - (stats.mean * stats.mean));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
SimpleLogger().Write() << "Not supported on FreeBSD";
|
||||
osrm::util::SimpleLogger().Write() << "Not supported on FreeBSD";
|
||||
return 0;
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
SimpleLogger().Write() << "Not supported on Windows";
|
||||
osrm::util::SimpleLogger().Write() << "Not supported on Windows";
|
||||
return 0;
|
||||
#else
|
||||
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
boost::filesystem::path test_path;
|
||||
try
|
||||
{
|
||||
SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
|
||||
|
||||
if (1 == argc)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " /path/on/device";
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " /path/on/device";
|
||||
return -1;
|
||||
}
|
||||
|
||||
test_path = boost::filesystem::path(argv[1]);
|
||||
test_path /= "osrm.tst";
|
||||
SimpleLogger().Write(logDEBUG) << "temporary file: " << test_path.string();
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "temporary file: " << test_path.string();
|
||||
|
||||
// create files for testing
|
||||
if (2 == argc)
|
||||
@@ -75,17 +80,17 @@ int main(int argc, char *argv[])
|
||||
// create file to test
|
||||
if (boost::filesystem::exists(test_path))
|
||||
{
|
||||
throw osrm::exception("Data file already exists");
|
||||
throw osrm::util::exception("Data file already exists");
|
||||
}
|
||||
|
||||
int *random_array = new int[number_of_elements];
|
||||
std::generate(random_array, random_array + number_of_elements, std::rand);
|
||||
int *random_array = new int[osrm::tools::NUMBER_OF_ELEMENTS];
|
||||
std::generate(random_array, random_array + osrm::tools::NUMBER_OF_ELEMENTS, std::rand);
|
||||
#ifdef __APPLE__
|
||||
FILE *fd = fopen(test_path.string().c_str(), "w");
|
||||
fcntl(fileno(fd), F_NOCACHE, 1);
|
||||
fcntl(fileno(fd), F_RDAHEAD, 0);
|
||||
TIMER_START(write_1gb);
|
||||
write(fileno(fd), (char *)random_array, number_of_elements * sizeof(unsigned));
|
||||
write(fileno(fd), (char *)random_array, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
|
||||
TIMER_STOP(write_1gb);
|
||||
fclose(fd);
|
||||
#endif
|
||||
@@ -94,24 +99,24 @@ int main(int argc, char *argv[])
|
||||
open(test_path.string().c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, S_IRWXU);
|
||||
if (-1 == file_desc)
|
||||
{
|
||||
throw osrm::exception("Could not open random data file");
|
||||
throw osrm::util::exception("Could not open random data file");
|
||||
}
|
||||
TIMER_START(write_1gb);
|
||||
int ret = write(file_desc, random_array, number_of_elements * sizeof(unsigned));
|
||||
int ret = write(file_desc, random_array, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
|
||||
if (0 > ret)
|
||||
{
|
||||
throw osrm::exception("could not write random data file");
|
||||
throw osrm::util::exception("could not write random data file");
|
||||
}
|
||||
TIMER_STOP(write_1gb);
|
||||
close(file_desc);
|
||||
#endif
|
||||
delete[] random_array;
|
||||
SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << TIMER_SEC(write_1gb)
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << TIMER_SEC(write_1gb)
|
||||
<< "s";
|
||||
SimpleLogger().Write() << "raw write performance: " << std::setprecision(5)
|
||||
osrm::util::SimpleLogger().Write() << "raw write performance: " << std::setprecision(5)
|
||||
<< std::fixed << 1024 * 1024 / TIMER_SEC(write_1gb) << "MB/sec";
|
||||
|
||||
SimpleLogger().Write(logDEBUG)
|
||||
osrm::util::SimpleLogger().Write(logDEBUG)
|
||||
<< "finished creation of random data. Flush disk cache now!";
|
||||
}
|
||||
else
|
||||
@@ -119,15 +124,15 @@ int main(int argc, char *argv[])
|
||||
// Run Non-Cached I/O benchmarks
|
||||
if (!boost::filesystem::exists(test_path))
|
||||
{
|
||||
throw osrm::exception("data file does not exist");
|
||||
throw osrm::util::exception("data file does not exist");
|
||||
}
|
||||
|
||||
// volatiles do not get optimized
|
||||
Statistics stats;
|
||||
osrm::tools::Statistics stats;
|
||||
|
||||
#ifdef __APPLE__
|
||||
volatile unsigned single_block[1024];
|
||||
char *raw_array = new char[number_of_elements * sizeof(unsigned)];
|
||||
char *raw_array = new char[osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned)];
|
||||
FILE *fd = fopen(test_path.string().c_str(), "r");
|
||||
fcntl(fileno(fd), F_NOCACHE, 1);
|
||||
fcntl(fileno(fd), F_RDAHEAD, 0);
|
||||
@@ -138,33 +143,33 @@ int main(int argc, char *argv[])
|
||||
int file_desc = open(test_path.string().c_str(), O_RDONLY | O_DIRECT | O_SYNC);
|
||||
if (-1 == file_desc)
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
|
||||
return -1;
|
||||
}
|
||||
char *raw_array = (char *)memalign(512, number_of_elements * sizeof(unsigned));
|
||||
char *raw_array = (char *)memalign(512, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
|
||||
#endif
|
||||
TIMER_START(read_1gb);
|
||||
#ifdef __APPLE__
|
||||
read(fileno(fd), raw_array, number_of_elements * sizeof(unsigned));
|
||||
read(fileno(fd), raw_array, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
|
||||
close(fileno(fd));
|
||||
fd = fopen(test_path.string().c_str(), "r");
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
int ret = read(file_desc, raw_array, number_of_elements * sizeof(unsigned));
|
||||
SimpleLogger().Write(logDEBUG) << "read " << ret
|
||||
int ret = read(file_desc, raw_array, osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned));
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "read " << ret
|
||||
<< " bytes, error: " << strerror(errno);
|
||||
close(file_desc);
|
||||
file_desc = open(test_path.string().c_str(), O_RDONLY | O_DIRECT | O_SYNC);
|
||||
SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "opened, error: " << strerror(errno);
|
||||
#endif
|
||||
TIMER_STOP(read_1gb);
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << TIMER_SEC(read_1gb) << "s";
|
||||
SimpleLogger().Write() << "raw read performance: " << std::setprecision(5) << std::fixed
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << TIMER_SEC(read_1gb) << "s";
|
||||
osrm::util::SimpleLogger().Write() << "raw read performance: " << std::setprecision(5) << std::fixed
|
||||
<< 1024 * 1024 / TIMER_SEC(read_1gb) << "MB/sec";
|
||||
|
||||
std::vector<double> timing_results_raw_random;
|
||||
SimpleLogger().Write(logDEBUG) << "running 1000 random I/Os of 4KB";
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "running 1000 random I/Os of 4KB";
|
||||
|
||||
#ifdef __APPLE__
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
@@ -173,7 +178,7 @@ int main(int argc, char *argv[])
|
||||
lseek(file_desc, 0, SEEK_SET);
|
||||
#endif
|
||||
// make 1000 random access, time each I/O seperately
|
||||
unsigned number_of_blocks = (number_of_elements * sizeof(unsigned) - 1) / 4096;
|
||||
unsigned number_of_blocks = (osrm::tools::NUMBER_OF_ELEMENTS * sizeof(unsigned) - 1) / 4096;
|
||||
std::random_device rd;
|
||||
std::default_random_engine e1(rd());
|
||||
std::uniform_int_distribution<unsigned> uniform_dist(0, number_of_blocks - 1);
|
||||
@@ -199,30 +204,30 @@ int main(int argc, char *argv[])
|
||||
TIMER_STOP(random_access);
|
||||
if (((off_t)-1) == ret1)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
SimpleLogger().Write(logWARNING) << "seek error " << strerror(errno);
|
||||
throw osrm::exception("seek error");
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "seek error " << strerror(errno);
|
||||
throw osrm::util::exception("seek error");
|
||||
}
|
||||
if (-1 == ret2)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
|
||||
throw osrm::exception("read error");
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
|
||||
throw osrm::util::exception("read error");
|
||||
}
|
||||
timing_results_raw_random.push_back(TIMER_SEC(random_access));
|
||||
}
|
||||
|
||||
// Do statistics
|
||||
SimpleLogger().Write(logDEBUG) << "running raw random I/O statistics";
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "running raw random I/O statistics";
|
||||
std::ofstream random_csv("random.csv", std::ios::trunc);
|
||||
for (unsigned i = 0; i < timing_results_raw_random.size(); ++i)
|
||||
{
|
||||
random_csv << i << ", " << timing_results_raw_random[i] << std::endl;
|
||||
}
|
||||
random_csv.close();
|
||||
runStatistics(timing_results_raw_random, stats);
|
||||
osrm::tools::runStatistics(timing_results_raw_random, stats);
|
||||
|
||||
SimpleLogger().Write() << "raw random I/O: " << std::setprecision(5) << std::fixed
|
||||
osrm::util::SimpleLogger().Write() << "raw random I/O: " << std::setprecision(5) << std::fixed
|
||||
<< "min: " << stats.min << "ms, "
|
||||
<< "mean: " << stats.mean << "ms, "
|
||||
<< "med: " << stats.med << "ms, "
|
||||
@@ -260,15 +265,15 @@ int main(int argc, char *argv[])
|
||||
TIMER_STOP(read_every_100);
|
||||
if (((off_t)-1) == ret1)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
SimpleLogger().Write(logWARNING) << "seek error " << strerror(errno);
|
||||
throw osrm::exception("seek error");
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "seek error " << strerror(errno);
|
||||
throw osrm::util::exception("seek error");
|
||||
}
|
||||
if (-1 == ret2)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
|
||||
throw osrm::exception("read error");
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "offset: " << current_offset;
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "read error " << strerror(errno);
|
||||
throw osrm::util::exception("read error");
|
||||
}
|
||||
timing_results_raw_seq.push_back(TIMER_SEC(read_every_100));
|
||||
}
|
||||
@@ -282,7 +287,7 @@ int main(int argc, char *argv[])
|
||||
close(file_desc);
|
||||
#endif
|
||||
// Do statistics
|
||||
SimpleLogger().Write(logDEBUG) << "running sequential I/O statistics";
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "running sequential I/O statistics";
|
||||
// print simple statistics: min, max, median, variance
|
||||
std::ofstream seq_csv("sequential.csv", std::ios::trunc);
|
||||
for (unsigned i = 0; i < timing_results_raw_seq.size(); ++i)
|
||||
@@ -290,8 +295,8 @@ int main(int argc, char *argv[])
|
||||
seq_csv << i << ", " << timing_results_raw_seq[i] << std::endl;
|
||||
}
|
||||
seq_csv.close();
|
||||
runStatistics(timing_results_raw_seq, stats);
|
||||
SimpleLogger().Write() << "raw sequential I/O: " << std::setprecision(5) << std::fixed
|
||||
osrm::tools::runStatistics(timing_results_raw_seq, stats);
|
||||
osrm::util::SimpleLogger().Write() << "raw sequential I/O: " << std::setprecision(5) << std::fixed
|
||||
<< "min: " << stats.min << "ms, "
|
||||
<< "mean: " << stats.mean << "ms, "
|
||||
<< "med: " << stats.med << "ms, "
|
||||
@@ -301,18 +306,18 @@ int main(int argc, char *argv[])
|
||||
if (boost::filesystem::exists(test_path))
|
||||
{
|
||||
boost::filesystem::remove(test_path);
|
||||
SimpleLogger().Write(logDEBUG) << "removing temporary files";
|
||||
osrm::util::SimpleLogger().Write(logDEBUG) << "removing temporary files";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
SimpleLogger().Write(logWARNING) << "cleaning up, and exiting";
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "cleaning up, and exiting";
|
||||
if (boost::filesystem::exists(test_path))
|
||||
{
|
||||
boost::filesystem::remove(test_path);
|
||||
SimpleLogger().Write(logWARNING) << "removing temporary files";
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "removing temporary files";
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
+25
-23
@@ -39,25 +39,27 @@ BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
int main(int argc, const char *argv[]) try
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
util::LogPolicy::GetInstance().Unmute();
|
||||
|
||||
bool trial_run = false;
|
||||
std::string ip_address;
|
||||
int ip_port, requested_thread_num;
|
||||
|
||||
LibOSRMConfig lib_config;
|
||||
const unsigned init_result = GenerateServerProgramOptions(
|
||||
const unsigned init_result = util::GenerateServerProgramOptions(
|
||||
argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
|
||||
lib_config.use_shared_memory, trial_run, lib_config.max_locations_trip,
|
||||
lib_config.max_locations_viaroute, lib_config.max_locations_distance_table,
|
||||
lib_config.max_locations_map_matching);
|
||||
if (init_result == INIT_OK_DO_NOT_START_ENGINE)
|
||||
if (init_result == util::INIT_OK_DO_NOT_START_ENGINE)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (init_result == INIT_FAILED)
|
||||
if (init_result == util::INIT_FAILED)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -70,7 +72,7 @@ int main(int argc, const char *argv[]) try
|
||||
if (should_lock && -1 == mlockall(MCL_CURRENT | MCL_FUTURE))
|
||||
{
|
||||
could_lock = false;
|
||||
SimpleLogger().Write(logWARNING) << "memory could not be locked to RAM";
|
||||
util::SimpleLogger().Write(logWARNING) << "memory could not be locked to RAM";
|
||||
}
|
||||
}
|
||||
~MemoryLocker()
|
||||
@@ -81,16 +83,16 @@ int main(int argc, const char *argv[]) try
|
||||
bool should_lock = false, could_lock = true;
|
||||
} memory_locker(lib_config.use_shared_memory);
|
||||
#endif
|
||||
SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
|
||||
util::SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
|
||||
|
||||
if (lib_config.use_shared_memory)
|
||||
{
|
||||
SimpleLogger().Write(logDEBUG) << "Loading from shared memory";
|
||||
util::SimpleLogger().Write(logDEBUG) << "Loading from shared memory";
|
||||
}
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "Threads:\t" << requested_thread_num;
|
||||
SimpleLogger().Write(logDEBUG) << "IP address:\t" << ip_address;
|
||||
SimpleLogger().Write(logDEBUG) << "IP port:\t" << ip_port;
|
||||
util::SimpleLogger().Write(logDEBUG) << "Threads:\t" << requested_thread_num;
|
||||
util::SimpleLogger().Write(logDEBUG) << "IP address:\t" << ip_address;
|
||||
util::SimpleLogger().Write(logDEBUG) << "IP port:\t" << ip_port;
|
||||
|
||||
#ifndef _WIN32
|
||||
int sig = 0;
|
||||
@@ -101,13 +103,13 @@ int main(int argc, const char *argv[]) try
|
||||
#endif
|
||||
|
||||
OSRM osrm_lib(lib_config);
|
||||
auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num);
|
||||
auto routing_server = server::Server::CreateServer(ip_address, ip_port, requested_thread_num);
|
||||
|
||||
routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib);
|
||||
|
||||
if (trial_run)
|
||||
{
|
||||
SimpleLogger().Write() << "trial run, quitting after successful initialization";
|
||||
util::SimpleLogger().Write() << "trial run, quitting after successful initialization";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,18 +129,18 @@ int main(int argc, const char *argv[]) try
|
||||
sigaddset(&wait_mask, SIGQUIT);
|
||||
sigaddset(&wait_mask, SIGTERM);
|
||||
pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr);
|
||||
SimpleLogger().Write() << "running and waiting for requests";
|
||||
util::SimpleLogger().Write() << "running and waiting for requests";
|
||||
sigwait(&wait_mask, &sig);
|
||||
#else
|
||||
// Set console control handler to allow server to be stopped.
|
||||
console_ctrl_function = std::bind(&Server::Stop, routing_server);
|
||||
console_ctrl_function = std::bind(&server::Server::Stop, routing_server);
|
||||
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
|
||||
SimpleLogger().Write() << "running and waiting for requests";
|
||||
util::SimpleLogger().Write() << "running and waiting for requests";
|
||||
routing_server->Run();
|
||||
#endif
|
||||
SimpleLogger().Write() << "initiating shutdown";
|
||||
util::SimpleLogger().Write() << "initiating shutdown";
|
||||
routing_server->Stop();
|
||||
SimpleLogger().Write() << "stopping threads";
|
||||
util::SimpleLogger().Write() << "stopping threads";
|
||||
|
||||
auto status = future.wait_for(std::chrono::seconds(2));
|
||||
|
||||
@@ -148,24 +150,24 @@ int main(int argc, const char *argv[]) try
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "Didn't exit within 2 seconds. Hard abort!";
|
||||
util::SimpleLogger().Write(logWARNING) << "Didn't exit within 2 seconds. Hard abort!";
|
||||
server_task.reset(); // just kill it
|
||||
}
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "freeing objects";
|
||||
util::SimpleLogger().Write() << "freeing objects";
|
||||
routing_server.reset();
|
||||
SimpleLogger().Write() << "shutdown completed";
|
||||
util::SimpleLogger().Write() << "shutdown completed";
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
SimpleLogger().Write(logWARNING)
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+14
-16
@@ -1,4 +1,3 @@
|
||||
#include "util/version.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
#include "util/routed_options.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
@@ -12,32 +11,31 @@
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
std::string ip_address;
|
||||
int ip_port, requested_thread_num;
|
||||
bool trial_run = false;
|
||||
LibOSRMConfig lib_config;
|
||||
const unsigned init_result = GenerateServerProgramOptions(
|
||||
osrm::LibOSRMConfig lib_config;
|
||||
const unsigned init_result = osrm::util::GenerateServerProgramOptions(
|
||||
argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
|
||||
lib_config.use_shared_memory, trial_run, lib_config.max_locations_trip,
|
||||
lib_config.max_locations_viaroute, lib_config.max_locations_distance_table,
|
||||
lib_config.max_locations_map_matching);
|
||||
|
||||
if (init_result == INIT_OK_DO_NOT_START_ENGINE)
|
||||
if (init_result == osrm::util::INIT_OK_DO_NOT_START_ENGINE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (init_result == INIT_FAILED)
|
||||
if (init_result == osrm::util::INIT_FAILED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
|
||||
|
||||
OSRM routing_machine(lib_config);
|
||||
osrm::OSRM routing_machine(lib_config);
|
||||
|
||||
RouteParameters route_parameters;
|
||||
osrm::RouteParameters route_parameters;
|
||||
route_parameters.zoom_level = 18; // no generalization
|
||||
route_parameters.print_instructions = true; // turn by turn instructions
|
||||
route_parameters.alternate_route = true; // get an alternate route, too
|
||||
@@ -51,19 +49,19 @@ int main(int argc, const char *argv[])
|
||||
// route_parameters.hints.push_back(); // see wiki, saves I/O if done properly
|
||||
|
||||
// start_coordinate
|
||||
route_parameters.coordinates.emplace_back(52.519930 * COORDINATE_PRECISION,
|
||||
13.438640 * COORDINATE_PRECISION);
|
||||
route_parameters.coordinates.emplace_back(52.519930 * osrm::COORDINATE_PRECISION,
|
||||
13.438640 * osrm::COORDINATE_PRECISION);
|
||||
// target_coordinate
|
||||
route_parameters.coordinates.emplace_back(52.513191 * COORDINATE_PRECISION,
|
||||
13.415852 * COORDINATE_PRECISION);
|
||||
route_parameters.coordinates.emplace_back(52.513191 * osrm::COORDINATE_PRECISION,
|
||||
13.415852 * osrm::COORDINATE_PRECISION);
|
||||
osrm::json::Object json_result;
|
||||
const int result_code = routing_machine.RunQuery(route_parameters, json_result);
|
||||
SimpleLogger().Write() << "http code: " << result_code;
|
||||
osrm::json::render(SimpleLogger().Write(), json_result);
|
||||
osrm::util::SimpleLogger().Write() << "http code: " << result_code;
|
||||
osrm::json::render(osrm::util::SimpleLogger().Write(), json_result);
|
||||
}
|
||||
catch (std::exception ¤t_exception)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what();
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what();
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
+23
-14
@@ -2,9 +2,17 @@
|
||||
|
||||
#include "datastore/shared_memory_factory.hpp"
|
||||
#include "engine/datafacade/shared_datatype.hpp"
|
||||
#include "util/version.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
// FIXME remove after folding back into datastore
|
||||
using namespace datastore;
|
||||
using namespace engine::datafacade;
|
||||
|
||||
void deleteRegion(const SharedDataType region)
|
||||
{
|
||||
if (SharedMemory::RegionExists(region) && !SharedMemory::Remove(region))
|
||||
@@ -30,46 +38,47 @@ void deleteRegion(const SharedDataType region)
|
||||
}
|
||||
}();
|
||||
|
||||
SimpleLogger().Write(logWARNING) << "could not delete shared memory region " << name;
|
||||
util::SimpleLogger().Write(logWARNING) << "could not delete shared memory region " << name;
|
||||
}
|
||||
}
|
||||
|
||||
// find all existing shmem regions and remove them.
|
||||
void springclean()
|
||||
{
|
||||
SimpleLogger().Write() << "spring-cleaning all shared memory regions";
|
||||
util::SimpleLogger().Write() << "spring-cleaning all shared memory regions";
|
||||
deleteRegion(DATA_1);
|
||||
deleteRegion(LAYOUT_1);
|
||||
deleteRegion(DATA_2);
|
||||
deleteRegion(LAYOUT_2);
|
||||
deleteRegion(CURRENT_REGIONS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION << "\n\n";
|
||||
SimpleLogger().Write() << "Releasing all locks";
|
||||
SimpleLogger().Write() << "ATTENTION! BE CAREFUL!";
|
||||
SimpleLogger().Write() << "----------------------";
|
||||
SimpleLogger().Write() << "This tool may put osrm-routed into an undefined state!";
|
||||
SimpleLogger().Write() << "Type 'Y' to acknowledge that you know what your are doing.";
|
||||
SimpleLogger().Write() << "\n\nDo you want to purge all shared memory allocated "
|
||||
osrm::util::SimpleLogger().Write() << "Releasing all locks";
|
||||
osrm::util::SimpleLogger().Write() << "ATTENTION! BE CAREFUL!";
|
||||
osrm::util::SimpleLogger().Write() << "----------------------";
|
||||
osrm::util::SimpleLogger().Write() << "This tool may put osrm-routed into an undefined state!";
|
||||
osrm::util::SimpleLogger().Write() << "Type 'Y' to acknowledge that you know what your are doing.";
|
||||
osrm::util::SimpleLogger().Write() << "\n\nDo you want to purge all shared memory allocated "
|
||||
<< "by osrm-datastore? [type 'Y' to confirm]";
|
||||
|
||||
const auto letter = getchar();
|
||||
if (letter != 'Y')
|
||||
{
|
||||
SimpleLogger().Write() << "aborted.";
|
||||
osrm::util::SimpleLogger().Write() << "aborted.";
|
||||
return 0;
|
||||
}
|
||||
springclean();
|
||||
osrm::tools::springclean();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "util/version.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "engine/datafacade/shared_barriers.hpp"
|
||||
|
||||
@@ -6,19 +5,18 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
osrm::util::LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
|
||||
SimpleLogger().Write() << "Releasing all locks";
|
||||
SharedBarriers barrier;
|
||||
osrm::util::SimpleLogger().Write() << "Releasing all locks";
|
||||
osrm::engine::datafacade::SharedBarriers barrier;
|
||||
barrier.pending_update_mutex.unlock();
|
||||
barrier.query_mutex.unlock();
|
||||
barrier.update_mutex.unlock();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
|
||||
osrm::util::SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &first,
|
||||
const FixedPointCoordinate &second,
|
||||
const FixedPointCoordinate &third) noexcept
|
||||
@@ -25,3 +30,5 @@ double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &fi
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
FixedPointCoordinate::FixedPointCoordinate()
|
||||
: lat(std::numeric_limits<int>::min()), lon(std::numeric_limits<int>::min())
|
||||
{
|
||||
@@ -50,3 +55,5 @@ std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate &coordina
|
||||
out << "(" << static_cast<double>(coordinate.lat / COORDINATE_PRECISION) << "," << static_cast<double>(coordinate.lon / COORDINATE_PRECISION) << ")";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr static const double RAD = 0.017453292519943295769236907684886;
|
||||
@@ -223,3 +228,5 @@ double bearing(const FixedPointCoordinate &first_coordinate,
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
uint64_t HilbertCode::operator()(const FixedPointCoordinate ¤t_coordinate) const
|
||||
{
|
||||
unsigned location[2];
|
||||
@@ -71,3 +76,5 @@ void HilbertCode::TransposeCoordinate(uint32_t *X) const
|
||||
X[i] ^= t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
double mercator::y2lat(const double value) noexcept
|
||||
{
|
||||
return 180. * M_1_PI * (2. * std::atan(std::exp(value * M_PI / 180.)) - M_PI_2);
|
||||
@@ -11,3 +16,5 @@ double mercator::lat2y(const double latitude) noexcept
|
||||
{
|
||||
return 180. * M_1_PI * std::log(std::tan(M_PI_4 + latitude * (M_PI / 180.) / 2.));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "util/osrm_exception.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
// This function exists to 'anchor' the class, and stop the compiler from
|
||||
// copying vtable and RTTI info into every object file that includes
|
||||
// this header. (Caught by -Wweak-vtables under Clang.)
|
||||
@@ -12,5 +10,13 @@ namespace osrm
|
||||
// always have at least one out-of-line virtual method in the class. Without
|
||||
// this, the compiler will copy the vtable and RTTI into every .o file that
|
||||
// #includes the header, bloating .o file sizes and increasing link times.
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
void exception::anchor() const {}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
static const char COL_RESET[]{"\x1b[0m"};
|
||||
@@ -92,3 +97,5 @@ SimpleLogger::~SimpleLogger()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user