renamed: Util/* -> util/*

This commit is contained in:
Dennis Luxen 2015-01-27 17:44:46 +01:00
parent 203e3ef077
commit b20b7e65bf
113 changed files with 4533 additions and 971 deletions

View File

@ -34,44 +34,44 @@ include_directories(${CMAKE_SOURCE_DIR}/include/)
include_directories(${CMAKE_SOURCE_DIR}/third_party/) include_directories(${CMAKE_SOURCE_DIR}/third_party/)
include_directories(${CMAKE_SOURCE_DIR}/third_party/libosmium/include/) include_directories(${CMAKE_SOURCE_DIR}/third_party/libosmium/include/)
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/Util/fingerprint.cpp fingerprint.cpp.alwaysbuild add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/util/fingerprint.cpp fingerprint.cpp.alwaysbuild
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR} COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FingerPrint-Config.cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FingerPrint-Config.cmake
DEPENDS DEPENDS
${CMAKE_SOURCE_DIR}/Util/fingerprint.cpp.in ${CMAKE_SOURCE_DIR}/util/fingerprint.cpp.in
COMMENT "Configuring fingerprint.cpp" COMMENT "Configuring fingerprint.cpp"
VERBATIM) VERBATIM)
add_custom_target(FingerPrintConfigure DEPENDS ${CMAKE_SOURCE_DIR}/Util/fingerprint.cpp) add_custom_target(FingerPrintConfigure DEPENDS ${CMAKE_SOURCE_DIR}/util/fingerprint.cpp)
add_custom_target(tests DEPENDS datastructure-tests algorithm-tests) add_custom_target(tests DEPENDS datastructure-tests algorithm-tests)
add_custom_target(benchmarks DEPENDS rtree-bench) add_custom_target(benchmarks DEPENDS rtree-bench)
set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread unit_test_framework) set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread unit_test_framework)
configure_file( configure_file(
${CMAKE_SOURCE_DIR}/Util/git_sha.cpp.in ${CMAKE_SOURCE_DIR}/util/git_sha.cpp.in
${CMAKE_SOURCE_DIR}/Util/git_sha.cpp ${CMAKE_SOURCE_DIR}/util/git_sha.cpp
) )
file(GLOB ExtractorGlob extractor/*.cpp) file(GLOB ExtractorGlob extractor/*.cpp)
file(GLOB ImporterGlob data_structures/import_edge.cpp data_structures/external_memory_node.cpp) file(GLOB ImporterGlob data_structures/import_edge.cpp data_structures/external_memory_node.cpp)
add_library(IMPORT OBJECT ${ImporterGlob}) add_library(IMPORT OBJECT ${ImporterGlob})
add_library(LOGGER OBJECT Util/simple_logger.cpp) add_library(LOGGER OBJECT util/simple_logger.cpp)
add_library(PHANTOMNODE OBJECT data_structures/phantom_node.cpp) add_library(PHANTOMNODE OBJECT data_structures/phantom_node.cpp)
add_library(EXCEPTION OBJECT Util/osrm_exception.cpp) add_library(EXCEPTION OBJECT util/osrm_exception.cpp)
add_library(MERCATOR OBJECT Util/mercator.cpp) add_library(MERCATOR OBJECT util/mercator.cpp)
set(ExtractorSources extract.cpp ${ExtractorGlob}) set(ExtractorSources extract.cpp ${ExtractorGlob})
add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>) add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>)
add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp) add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp)
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp Util/compute_angle.cpp {RestrictionMapGlob}) file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp util/compute_angle.cpp {RestrictionMapGlob})
set(PrepareSources prepare.cpp ${PrepareGlob}) set(PrepareSources prepare.cpp ${PrepareGlob})
add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>) add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>)
file(GLOB ServerGlob server/*.cpp) file(GLOB ServerGlob server/*.cpp)
file(GLOB DescriptorGlob descriptors/*.cpp) file(GLOB DescriptorGlob descriptors/*.cpp)
file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp Util/bearing.cpp) file(GLOB DatastructureGlob data_structures/search_engine_data.cpp data_structures/route_parameters.cpp util/bearing.cpp)
list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp) list(REMOVE_ITEM DatastructureGlob data_structures/Coordinate.cpp)
file(GLOB CoordinateGlob data_structures/coordinate*.cpp) file(GLOB CoordinateGlob data_structures/coordinate*.cpp)
file(GLOB AlgorithmGlob algorithms/*.cpp) file(GLOB AlgorithmGlob algorithms/*.cpp)
@ -91,8 +91,8 @@ set(
) )
add_library(COORDINATE OBJECT ${CoordinateGlob}) add_library(COORDINATE OBJECT ${CoordinateGlob})
add_library(FINGERPRINT OBJECT Util/fingerprint.cpp) add_library(FINGERPRINT OBJECT util/fingerprint.cpp)
add_library(GITDESCRIPTION OBJECT Util/git_sha.cpp) add_library(GITDESCRIPTION OBJECT util/git_sha.cpp)
add_library(OSRM ${OSRMSources} $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>) add_library(OSRM ${OSRMSources} $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:PHANTOMNODE> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>)
add_dependencies(FINGERPRINT FingerPrintConfigure) add_dependencies(FINGERPRINT FingerPrintConfigure)

View File

@ -46,9 +46,9 @@ class named_mutex;
#include "../server/data_structures/internal_datafacade.hpp" #include "../server/data_structures/internal_datafacade.hpp"
#include "../server/data_structures/shared_barriers.hpp" #include "../server/data_structures/shared_barriers.hpp"
#include "../server/data_structures/shared_datafacade.hpp" #include "../server/data_structures/shared_datafacade.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/routed_options.hpp" #include "../util/routed_options.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/interprocess/sync/named_condition.hpp> #include <boost/interprocess/sync/named_condition.hpp>

View File

@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "reply.hpp" #include "reply.hpp"
#include "../../Util/cast.hpp" #include "../../util/cast.hpp"
namespace http namespace http
{ {

View File

@ -34,9 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/external_memory_node.hpp" #include "../../data_structures/external_memory_node.hpp"
#include "../../data_structures/phantom_node.hpp" #include "../../data_structures/phantom_node.hpp"
#include "../../data_structures/turn_instructions.hpp" #include "../../data_structures/turn_instructions.hpp"
#include "../../Util/integer_range.hpp" #include "../../util/integer_range.hpp"
#include "../../Util/osrm_exception.hpp" #include "../../util/osrm_exception.hpp"
#include "../../Util/string_util.hpp" #include "../../util/string_util.hpp"
#include "../../typedefs.h" #include "../../typedefs.h"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -39,9 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/static_graph.hpp" #include "../../data_structures/static_graph.hpp"
#include "../../data_structures/static_rtree.hpp" #include "../../data_structures/static_rtree.hpp"
#include "../../data_structures/range_table.hpp" #include "../../data_structures/range_table.hpp"
#include "../../Util/boost_filesystem_2_fix.hpp" #include "../../util/boost_filesystem_2_fix.hpp"
#include "../../Util/graph_loader.hpp" #include "../../util/graph_loader.hpp"
#include "../../Util/simple_logger.hpp" #include "../../util/simple_logger.hpp"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>
#include <osrm/server_paths.hpp> #include <osrm/server_paths.hpp>

View File

@ -36,9 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/range_table.hpp" #include "../../data_structures/range_table.hpp"
#include "../../data_structures/static_graph.hpp" #include "../../data_structures/static_graph.hpp"
#include "../../data_structures/static_rtree.hpp" #include "../../data_structures/static_rtree.hpp"
#include "../../Util/boost_filesystem_2_fix.hpp" #include "../../util/boost_filesystem_2_fix.hpp"
#include "../../Util/make_unique.hpp" #include "../../util/make_unique.hpp"
#include "../../Util/simple_logger.hpp" #include "../../util/simple_logger.hpp"
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>

View File

@ -28,8 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SHARED_DATA_TYPE_HPP #ifndef SHARED_DATA_TYPE_HPP
#define SHARED_DATA_TYPE_HPP #define SHARED_DATA_TYPE_HPP
#include "../../Util/osrm_exception.hpp" #include "../../util/osrm_exception.hpp"
#include "../../Util/simple_logger.hpp" #include "../../util/simple_logger.hpp"
#include <cstdint> #include <cstdint>

View File

@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "reply.hpp" #include "reply.hpp"
#include "../../Util/cast.hpp" #include "../../util/cast.hpp"
namespace http namespace http
{ {

View File

@ -38,7 +38,8 @@ struct cast
{ {
// convert scoped enums to integers // convert scoped enums to integers
template <typename Enumeration> template <typename Enumeration>
static auto enum_to_underlying(Enumeration const value) -> typename std::underlying_type<Enumeration>::type static auto enum_to_underlying(Enumeration const value) ->
typename std::underlying_type<Enumeration>::type
{ {
return static_cast<typename std::underlying_type<Enumeration>::type>(value); return static_cast<typename std::underlying_type<Enumeration>::type>(value);
} }
@ -145,10 +146,7 @@ struct cast
template <typename T> struct scientific_policy : boost::spirit::karma::real_policies<T> template <typename T> struct scientific_policy : boost::spirit::karma::real_policies<T>
{ {
// we want the numbers always to be in fixed format // we want the numbers always to be in fixed format
static int floatfield(T) static int floatfield(T) { return boost::spirit::karma::real_policies<T>::fmtflags::fixed; }
{
return boost::spirit::karma::real_policies<T>::fmtflags::fixed;
}
static unsigned int precision(T) { return 6; } static unsigned int precision(T) { return 6; }
}; };
typedef boost::spirit::karma::real_generator<double, scientific_policy<double>> science_type; typedef boost::spirit::karma::real_generator<double, scientific_policy<double>> science_type;
@ -174,8 +172,7 @@ struct cast
return output; return output;
} }
static void double_with_two_digits_to_string(const double value, static void double_with_two_digits_to_string(const double value, std::string &output)
std::string &output)
{ {
// The largest 32-bit integer is 4294967295, that is 10 chars // The largest 32-bit integer is 4294967295, that is 10 chars
// On the safe side, add 1 for sign, and 1 for trailing zero // On the safe side, add 1 for sign, and 1 for trailing zero

View File

@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "compute_angle.hpp" #include "compute_angle.hpp"
#include "trigonometry_table.hpp" #include "trigonometry_table.hpp"
#include "../Util/mercator.hpp" #include "../util/mercator.hpp"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -37,7 +37,8 @@ namespace osrm
template <typename T> void sort_unique_resize(std::vector<T> &vector) template <typename T> void sort_unique_resize(std::vector<T> &vector)
{ {
std::sort(vector.begin(), vector.end()); std::sort(vector.begin(), vector.end());
const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin(); const auto number_of_unique_elements =
std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements); vector.resize(number_of_unique_elements);
} }
@ -47,9 +48,11 @@ template <typename T> void sort_unique_resize(std::vector<T> &vector)
// vector.shrink_to_fit(); // vector.shrink_to_fit();
// } // }
// template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T> &vector) // template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T>
// &vector)
// { // {
// const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin(); // const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) -
// vector.begin();
// vector.resize(number_of_unique_elements); // vector.resize(number_of_unique_elements);
// } // }
@ -67,7 +70,8 @@ Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function func
while (next != end) while (next != end)
{ {
function(*begin, *next); function(*begin, *next);
begin = std::next(begin); next = std::next(next); begin = std::next(begin);
next = std::next(next);
} }
return function; return function;
} }
@ -77,6 +81,5 @@ Function for_each_pair(ContainerT &container, Function function)
{ {
return for_each_pair(std::begin(container), std::end(container), function); return for_each_pair(std::begin(container), std::end(container), function);
} }
} }
#endif /* CONTAINER_HPP_ */ #endif /* CONTAINER_HPP_ */

View File

@ -35,7 +35,7 @@ class FingerPrint
{ {
public: public:
FingerPrint(); FingerPrint();
FingerPrint(const FingerPrint&) = delete; FingerPrint(const FingerPrint &) = delete;
~FingerPrint(); ~FingerPrint();
const boost::uuids::uuid &GetFingerPrint() const; const boost::uuids::uuid &GetFingerPrint() const;
bool IsMagicNumberOK() const; bool IsMagicNumberOK() const;

View File

@ -30,4 +30,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern char g_GIT_DESCRIPTION[]; extern char g_GIT_DESCRIPTION[];
#endif //GIT_SHA_HPP #endif // GIT_SHA_HPP

View File

@ -28,13 +28,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GRAPH_LOADER_HPP #ifndef GRAPH_LOADER_HPP
#define GRAPH_LOADER_HPP #define GRAPH_LOADER_HPP
#include "fingerprint.hpp"
#include "osrm_exception.hpp" #include "osrm_exception.hpp"
#include "simple_logger.hpp"
#include "../data_structures/external_memory_node.hpp" #include "../data_structures/external_memory_node.hpp"
#include "../data_structures/import_edge.hpp" #include "../data_structures/import_edge.hpp"
#include "../data_structures/query_node.hpp" #include "../data_structures/query_node.hpp"
#include "../data_structures/restriction.hpp" #include "../data_structures/restriction.hpp"
#include "../Util/fingerprint.hpp"
#include "../Util/simple_logger.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -80,7 +80,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
for (NodeID i = 0; i < n; ++i) for (NodeID i = 0; i < n; ++i)
{ {
input_stream.read((char *)&current_node, sizeof(ExternalMemoryNode)); input_stream.read((char *)&current_node, sizeof(ExternalMemoryNode));
int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon, current_node.node_id); int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon,
current_node.node_id);
ext_to_int_id_map.emplace(current_node.node_id, i); ext_to_int_id_map.emplace(current_node.node_id, i);
if (current_node.barrier) if (current_node.barrier)
{ {
@ -102,7 +103,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
auto internal_id_iter = ext_to_int_id_map.find(current_restriction.from.node); auto internal_id_iter = ext_to_int_id_map.find(current_restriction.from.node);
if (internal_id_iter == ext_to_int_id_map.end()) if (internal_id_iter == ext_to_int_id_map.end())
{ {
SimpleLogger().Write(logDEBUG) << "Unmapped from node " << current_restriction.from.node << " of restriction"; SimpleLogger().Write(logDEBUG) << "Unmapped from node " << current_restriction.from.node
<< " of restriction";
continue; continue;
} }
current_restriction.from.node = internal_id_iter->second; current_restriction.from.node = internal_id_iter->second;
@ -110,7 +112,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
internal_id_iter = ext_to_int_id_map.find(current_restriction.via.node); internal_id_iter = ext_to_int_id_map.find(current_restriction.via.node);
if (internal_id_iter == ext_to_int_id_map.end()) if (internal_id_iter == ext_to_int_id_map.end())
{ {
SimpleLogger().Write(logDEBUG) << "Unmapped via node " << current_restriction.via.node << " of restriction"; SimpleLogger().Write(logDEBUG) << "Unmapped via node " << current_restriction.via.node
<< " of restriction";
continue; continue;
} }
@ -119,7 +122,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
internal_id_iter = ext_to_int_id_map.find(current_restriction.to.node); internal_id_iter = ext_to_int_id_map.find(current_restriction.to.node);
if (internal_id_iter == ext_to_int_id_map.end()) if (internal_id_iter == ext_to_int_id_map.end())
{ {
SimpleLogger().Write(logDEBUG) << "Unmapped to node " << current_restriction.to.node << " of restriction"; SimpleLogger().Write(logDEBUG) << "Unmapped to node " << current_restriction.to.node
<< " of restriction";
continue; continue;
} }
current_restriction.to.node = internal_id_iter->second; current_restriction.to.node = internal_id_iter->second;
@ -195,17 +199,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
std::swap(forward, backward); std::swap(forward, backward);
} }
edge_list.emplace_back(source, edge_list.emplace_back(source, target, nameID, weight, forward, backward, is_roundabout,
target, ignore_in_grid, is_access_restricted, travel_mode, is_split);
nameID,
weight,
forward,
backward,
is_roundabout,
ignore_in_grid,
is_access_restricted,
travel_mode,
is_split);
} }
ext_to_int_id_map.clear(); ext_to_int_id_map.clear();
@ -216,9 +211,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
if ((edge_list[i - 1].target == edge_list[i].target) && if ((edge_list[i - 1].target == edge_list[i].target) &&
(edge_list[i - 1].source == edge_list[i].source)) (edge_list[i - 1].source == edge_list[i].source))
{ {
const bool edge_flags_equivalent = const bool edge_flags_equivalent = (edge_list[i - 1].forward == edge_list[i].forward) &&
(edge_list[i - 1].forward == edge_list[i].forward) && (edge_list[i - 1].backward == edge_list[i].backward);
(edge_list[i - 1].backward == edge_list[i].backward);
const bool edge_flags_are_superset1 = const bool edge_flags_are_superset1 =
(edge_list[i - 1].forward && edge_list[i - 1].backward) && (edge_list[i - 1].forward && edge_list[i - 1].backward) &&
(edge_list[i].forward != edge_list[i].backward); (edge_list[i].forward != edge_list[i].backward);
@ -263,11 +257,11 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
} }
} }
} }
const auto new_end_iter = std::remove_if(edge_list.begin(), edge_list.end(), [] (const EdgeT &edge) const auto new_end_iter =
{ std::remove_if(edge_list.begin(), edge_list.end(), [](const EdgeT &edge)
return edge.source == SPECIAL_NODEID || {
edge.target == SPECIAL_NODEID; return edge.source == SPECIAL_NODEID || edge.target == SPECIAL_NODEID;
}); });
edge_list.erase(new_end_iter, edge_list.end()); // remove excess candidates. edge_list.erase(new_end_iter, edge_list.end()); // remove excess candidates.
edge_list.shrink_to_fit(); edge_list.shrink_to_fit();
SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges"; SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";

View File

@ -35,7 +35,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
namespace JSON { namespace JSON
{
struct Renderer : mapbox::util::static_visitor<> struct Renderer : mapbox::util::static_visitor<>
{ {

View File

@ -54,4 +54,4 @@ template <class T, class... Types>
typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(Types &&...) = delete; typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(Types &&...) = delete;
} }
#endif //MAKE_UNIQUE_H_ #endif // MAKE_UNIQUE_H_

View File

@ -29,15 +29,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace osrm namespace osrm
{ {
// This function exists to 'anchor' the class, and stop the compiler from // This function exists to 'anchor' the class, and stop the compiler from
// copying vtable and RTTI info into every object file that includes // copying vtable and RTTI info into every object file that includes
// this header. (Caught by -Wweak-vtables under Clang.) // this header. (Caught by -Wweak-vtables under Clang.)
// More information from the LLVM Coding Standards: // More information from the LLVM Coding Standards:
// If a class is defined in a header file and has a vtable (either it has // If a class is defined in a header file and has a vtable (either it has
// virtual methods or it derives from classes with virtual methods), it must // virtual methods or it derives from classes with virtual methods), it must
// always have at least one out-of-line virtual method in the class. Without // 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 // 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. // #includes the header, bloating .o file sizes and increasing link times.
void exception::anchor() const { } void exception::anchor() const {}
} }

View File

@ -23,20 +23,20 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <algorithm> #include <algorithm>
namespace osrm { namespace osrm
{
template<class Container> template <class Container>
auto max_element(const Container & c) -> decltype(std::max_element(c.begin(), c.end())) auto max_element(const Container &c) -> decltype(std::max_element(c.begin(), c.end()))
{ {
return std::max_element(c.begin(), c.end()); return std::max_element(c.begin(), c.end());
} }
template<class Container> template <class Container>
auto max_element(const Container & c) -> decltype(std::max_element(c.cbegin(), c.cend())) auto max_element(const Container &c) -> decltype(std::max_element(c.cbegin(), c.cend()))
{ {
return std::max_element(c.cbegin(), c.cend()); return std::max_element(c.cbegin(), c.cend());
} }
} }
#endif // RANGE_ALGORITHMS_HPP #endif // RANGE_ALGORITHMS_HPP

View File

@ -47,10 +47,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace namespace
{ {
static const char COL_RESET[] { "\x1b[0m"}; static const char COL_RESET[]{"\x1b[0m"};
static const char RED[] { "\x1b[31m"}; static const char RED[]{"\x1b[31m"};
#ifndef NDEBUG #ifndef NDEBUG
static const char YELLOW[] { "\x1b[33m"}; static const char YELLOW[]{"\x1b[33m"};
#endif #endif
// static const char GREEN[] { "\x1b[32m"}; // static const char GREEN[] { "\x1b[32m"};
// static const char BLUE[] { "\x1b[34m"}; // static const char BLUE[] { "\x1b[34m"};
@ -95,7 +95,7 @@ std::ostringstream &SimpleLogger::Write(LogLevel lvl)
os << "debug"; os << "debug";
#endif #endif
break; break;
default: //logINFO: default: // logINFO:
os << "info"; os << "info";
break; break;
} }
@ -127,7 +127,7 @@ SimpleLogger::~SimpleLogger()
<< std::endl; << std::endl;
#endif #endif
break; break;
default: //logINFO: default: // logINFO:
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl; std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
break; break;
} }

View File

@ -33,29 +33,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// this is largely inspired by boost's hash combine as can be found in // this is largely inspired by boost's hash combine as can be found in
// "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012. // "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012.
namespace { namespace
{
template<typename T> template <typename T> void hash_combine(std::size_t &seed, const T &val)
void hash_combine(std::size_t &seed, const T& val)
{ {
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
} }
template<typename T> template <typename T> void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); }
void hash_val(std::size_t &seed, const T& val)
template <typename T, typename... Types>
void hash_val(std::size_t &seed, const T &val, const Types &... args)
{ {
hash_combine(seed, val); hash_combine(seed, val);
hash_val(seed, args...);
} }
template<typename T, typename ... Types> template <typename... Types> std::size_t hash_val(const Types &... args)
void hash_val(std::size_t &seed, const T& val, const Types& ... args)
{
hash_combine(seed, val);
hash_val(seed, args ...);
}
template<typename ... Types>
std::size_t hash_val(const Types&... args)
{ {
std::size_t seed = 0; std::size_t seed = 0;
hash_val(seed, args...); hash_val(seed, args...);

View File

@ -42,39 +42,49 @@ struct GlobalTimer
class GlobalTimerFactory class GlobalTimerFactory
{ {
public: public:
static GlobalTimerFactory& get() static GlobalTimerFactory &get()
{ {
static GlobalTimerFactory instance; static GlobalTimerFactory instance;
return instance; return instance;
} }
GlobalTimer& getGlobalTimer(const std::string& name) GlobalTimer &getGlobalTimer(const std::string &name)
{ {
std::lock_guard<std::mutex> lock(map_mutex); std::lock_guard<std::mutex> lock(map_mutex);
return timer_map[name]; return timer_map[name];
} }
private: private:
std::mutex map_mutex; std::mutex map_mutex;
std::unordered_map<std::string, GlobalTimer> timer_map; std::unordered_map<std::string, GlobalTimer> timer_map;
}; };
#define GLOBAL_TIMER_AQUIRE(_X) auto& _X##_global_timer = GlobalTimerFactory::get().getGlobalTimer(#_X) #define GLOBAL_TIMER_AQUIRE(_X) \
auto &_X##_global_timer = GlobalTimerFactory::get().getGlobalTimer(#_X)
#define GLOBAL_TIMER_RESET(_X) _X##_global_timer.time = 0 #define GLOBAL_TIMER_RESET(_X) _X##_global_timer.time = 0
#define GLOBAL_TIMER_START(_X) TIMER_START(_X) #define GLOBAL_TIMER_START(_X) TIMER_START(_X)
#define GLOBAL_TIMER_STOP(_X) TIMER_STOP(_X); _X##_global_timer.time += TIMER_NSEC(_X) #define GLOBAL_TIMER_STOP(_X) \
TIMER_STOP(_X); \
_X##_global_timer.time += TIMER_NSEC(_X)
#define GLOBAL_TIMER_NSEC(_X) static_cast<double>(_X##_global_timer.time) #define GLOBAL_TIMER_NSEC(_X) static_cast<double>(_X##_global_timer.time)
#define GLOBAL_TIMER_USEC(_X) (_X##_global_timer.time / 1000.0) #define GLOBAL_TIMER_USEC(_X) (_X##_global_timer.time / 1000.0)
#define GLOBAL_TIMER_MSEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0) #define GLOBAL_TIMER_MSEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0)
#define GLOBAL_TIMER_SEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0 / 1000.0) #define GLOBAL_TIMER_SEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0 / 1000.0)
#define TIMER_START(_X) auto _X##_start = std::chrono::steady_clock::now(), _X##_stop = _X##_start #define TIMER_START(_X) auto _X##_start = std::chrono::steady_clock::now(), _X##_stop = _X##_start
#define TIMER_STOP(_X) _X##_stop = std::chrono::steady_clock::now() #define TIMER_STOP(_X) _X##_stop = std::chrono::steady_clock::now()
#define TIMER_NSEC(_X) std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count() #define TIMER_NSEC(_X) \
#define TIMER_USEC(_X) std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count() std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count()
#define TIMER_MSEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count()) #define TIMER_USEC(_X) \
#define TIMER_SEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count()) std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count()
#define TIMER_MIN(_X) std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count() #define TIMER_MSEC(_X) \
(0.000001 * \
std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count())
#define TIMER_SEC(_X) \
(0.000001 * \
std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count())
#define TIMER_MIN(_X) \
std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count()
#endif // TIMING_UTIL_HPP #endif // TIMING_UTIL_HPP

View File

@ -32,7 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
namespace JSON { namespace JSON
{
struct XMLToArrayRenderer : mapbox::util::static_visitor<> struct XMLToArrayRenderer : mapbox::util::static_visitor<>
{ {
@ -66,7 +67,6 @@ struct XMLToArrayRenderer : mapbox::util::static_visitor<>
out.push_back(' '); out.push_back(' ');
out.insert(out.end(), ++(*iterator).first.begin(), (*iterator).first.end()); out.insert(out.end(), ++(*iterator).first.begin(), (*iterator).first.end());
out.push_back('='); out.push_back('=');
} }
mapbox::util::apply_visitor(XMLToArrayRenderer(out), (*iterator).second); mapbox::util::apply_visitor(XMLToArrayRenderer(out), (*iterator).second);
if (iterator->first.at(0) != '_') if (iterator->first.at(0) != '_')
@ -111,29 +111,28 @@ struct XMLToArrayRenderer : mapbox::util::static_visitor<>
std::vector<char> &out; std::vector<char> &out;
}; };
template<class JSONObject> template <class JSONObject> inline void xml_render(std::vector<char> &out, const JSONObject &object)
inline void xml_render(std::vector<char> &out, const JSONObject &object)
{ {
Value value = object; Value value = object;
mapbox::util::apply_visitor(XMLToArrayRenderer(out), value); mapbox::util::apply_visitor(XMLToArrayRenderer(out), value);
} }
template<class JSONObject> template <class JSONObject> inline void gpx_render(std::vector<char> &out, const JSONObject &object)
inline void gpx_render(std::vector<char> &out, const JSONObject &object)
{ {
// add header // add header
const std::string header {"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx creator=\"OSRM Routing Engine\"" const std::string header{
" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http:" "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx creator=\"OSRM Routing Engine\""
"//www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topogr" " version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http:"
"afix.com/GPX/1/1 gpx.xsd\"><metadata><copyright author=\"Project OSRM\"><lice" "//www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topogr"
"nse>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadat" "afix.com/GPX/1/1 gpx.xsd\"><metadata><copyright author=\"Project OSRM\"><lice"
"a><rte>"}; "nse>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadat"
"a><rte>"};
out.insert(out.end(), header.begin(), header.end()); out.insert(out.end(), header.begin(), header.end());
xml_render(out, object); xml_render(out, object);
const std::string footer {"</rte></gpx>"}; const std::string footer{"</rte></gpx>"};
out.insert(out.end(), footer.begin(), footer.end()); out.insert(out.end(), footer.begin(), footer.end());
} }
} // namespace JSON } // namespace JSON

View File

@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "douglas_peucker.hpp" #include "douglas_peucker.hpp"
#include "../data_structures/segment_information.hpp" #include "../data_structures/segment_information.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OBJECT_ENCODER_HPP #ifndef OBJECT_ENCODER_HPP
#define OBJECT_ENCODER_HPP #define OBJECT_ENCODER_HPP
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/base64_from_binary.hpp>
@ -49,8 +49,7 @@ struct ObjectEncoder
8, 8,
6>; 6>;
template <class ObjectT> template <class ObjectT> static void EncodeToBase64(const ObjectT &object, std::string &encoded)
static void EncodeToBase64(const ObjectT &object, std::string &encoded)
{ {
const char *char_ptr_to_object = (const char *)&object; const char *char_ptr_to_object = (const char *)&object;
std::vector<unsigned char> data(sizeof(object)); std::vector<unsigned char> data(sizeof(object));
@ -71,8 +70,7 @@ struct ObjectEncoder
replaceAll(encoded, "/", "_"); replaceAll(encoded, "/", "_");
} }
template <class ObjectT> template <class ObjectT> static void DecodeFromBase64(const std::string &input, ObjectT &object)
static void DecodeFromBase64(const std::string &input, ObjectT &object)
{ {
try try
{ {
@ -81,8 +79,7 @@ struct ObjectEncoder
replaceAll(encoded, "-", "+"); replaceAll(encoded, "-", "+");
replaceAll(encoded, "_", "/"); replaceAll(encoded, "_", "/");
std::copy(binary_t(encoded.begin()), std::copy(binary_t(encoded.begin()), binary_t(encoded.begin() + encoded.length() - 1),
binary_t(encoded.begin() + encoded.length() - 1),
(char *)&object); (char *)&object);
} }
catch (...) catch (...)

View File

@ -37,10 +37,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/restriction_map.hpp" #include "../data_structures/restriction_map.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/std_hash.hpp" #include "../util/std_hash.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>
@ -48,7 +48,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <tbb/parallel_sort.h> #include <tbb/parallel_sort.h>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
@ -57,8 +56,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
template <typename GraphT> template <typename GraphT> class TarjanSCC
class TarjanSCC
{ {
struct TarjanStackFrame struct TarjanStackFrame
{ {
@ -83,13 +81,12 @@ class TarjanSCC
std::size_t size_one_counter; std::size_t size_one_counter;
public: public:
template<class ContainerT> template <class ContainerT>
TarjanSCC(std::shared_ptr<GraphT> graph, TarjanSCC(std::shared_ptr<GraphT> graph,
const RestrictionMap &restrictions, const RestrictionMap &restrictions,
const ContainerT &barrier_node_list) const ContainerT &barrier_node_list)
: components_index(graph->GetNumberOfNodes(), SPECIAL_NODEID), : components_index(graph->GetNumberOfNodes(), SPECIAL_NODEID), m_node_based_graph(graph),
m_node_based_graph(graph), m_restriction_map(restrictions), m_restriction_map(restrictions), size_one_counter(0)
size_one_counter(0)
{ {
barrier_node_set.insert(std::begin(barrier_node_list), std::end(barrier_node_list)); barrier_node_set.insert(std::begin(barrier_node_list), std::end(barrier_node_list));
BOOST_ASSERT(m_node_based_graph->GetNumberOfNodes() > 0); BOOST_ASSERT(m_node_based_graph->GetNumberOfNodes() > 0);
@ -107,8 +104,9 @@ class TarjanSCC
unsigned component_index = 0, size_of_current_component = 0; unsigned component_index = 0, size_of_current_component = 0;
int index = 0; int index = 0;
const NodeID last_node = m_node_based_graph->GetNumberOfNodes(); const NodeID last_node = m_node_based_graph->GetNumberOfNodes();
std::vector<bool> processing_node_before_recursion(m_node_based_graph->GetNumberOfNodes(), true); std::vector<bool> processing_node_before_recursion(m_node_based_graph->GetNumberOfNodes(),
for(const NodeID node : osrm::irange(0u, last_node)) true);
for (const NodeID node : osrm::irange(0u, last_node))
{ {
if (SPECIAL_NODEID == components_index[node]) if (SPECIAL_NODEID == components_index[node])
{ {
@ -150,13 +148,11 @@ class TarjanSCC
const auto vprime = m_node_based_graph->GetTarget(current_edge); const auto vprime = m_node_based_graph->GetTarget(current_edge);
// Traverse outgoing edges // Traverse outgoing edges
if (barrier_node_set.find(v) != barrier_node_set.end() && if (barrier_node_set.find(v) != barrier_node_set.end() && u != vprime)
u != vprime)
{ {
// continue; // continue;
} }
if (to_node_of_only_restriction != std::numeric_limits<unsigned>::max() && if (to_node_of_only_restriction != std::numeric_limits<unsigned>::max() &&
vprime == to_node_of_only_restriction) vprime == to_node_of_only_restriction)
{ {
@ -219,35 +215,25 @@ class TarjanSCC
} }
TIMER_STOP(SCC_RUN); TIMER_STOP(SCC_RUN);
SimpleLogger().Write() << "SCC run took: " << TIMER_MSEC(SCC_RUN)/1000. << "s"; SimpleLogger().Write() << "SCC run took: " << TIMER_MSEC(SCC_RUN) / 1000. << "s";
size_one_counter = std::count_if(component_size_vector.begin(), size_one_counter = std::count_if(component_size_vector.begin(), component_size_vector.end(),
component_size_vector.end(),
[](unsigned value) [](unsigned value)
{ {
return 1 == value; return 1 == value;
}); });
} }
std::size_t get_number_of_components() const std::size_t get_number_of_components() const { return component_size_vector.size(); }
{
return component_size_vector.size();
}
unsigned get_size_one_count() const unsigned get_size_one_count() const { return size_one_counter; }
{
return size_one_counter;
}
unsigned get_component_size(const NodeID node) const unsigned get_component_size(const NodeID node) const
{ {
return component_size_vector[components_index[node]]; return component_size_vector[components_index[node]];
} }
unsigned get_component_id(const NodeID node) const unsigned get_component_id(const NodeID node) const { return components_index[node]; }
{
return components_index[node];
}
}; };
#endif /* TINY_COMPONENTS_HPP */ #endif /* TINY_COMPONENTS_HPP */

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/query_node.hpp" #include "../data_structures/query_node.hpp"
#include "../data_structures/shared_memory_vector_wrapper.hpp" #include "../data_structures/shared_memory_vector_wrapper.hpp"
#include "../data_structures/static_rtree.hpp" #include "../data_structures/static_rtree.hpp"
#include "../Util/boost_filesystem_2_fix.hpp" #include "../util/boost_filesystem_2_fix.hpp"
#include "../data_structures/edge_based_node.hpp" #include "../data_structures/edge_based_node.hpp"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -1,10 +1,10 @@
set(OLDFILE ${SOURCE_DIR}/Util/fingerprint.cpp) set(OLDFILE ${SOURCE_DIR}/util/fingerprint.cpp)
if (EXISTS ${OLDFILE}) if (EXISTS ${OLDFILE})
file(REMOVE_RECURSE ${OLDFILE}) file(REMOVE_RECURSE ${OLDFILE})
endif() endif()
file(MD5 ${SOURCE_DIR}/prepare.cpp MD5PREPARE) file(MD5 ${SOURCE_DIR}/prepare.cpp MD5PREPARE)
file(MD5 ${SOURCE_DIR}/data_structures/static_rtree.hpp MD5RTREE) file(MD5 ${SOURCE_DIR}/data_structures/static_rtree.hpp MD5RTREE)
file(MD5 ${SOURCE_DIR}/Util/graph_loader.hpp MD5GRAPH) file(MD5 ${SOURCE_DIR}/util/graph_loader.hpp MD5GRAPH)
file(MD5 ${SOURCE_DIR}/server/data_structures/internal_datafacade.hpp MD5OBJECTS) file(MD5 ${SOURCE_DIR}/server/data_structures/internal_datafacade.hpp MD5OBJECTS)
CONFIGURE_FILE( ${SOURCE_DIR}/Util/fingerprint.cpp.in ${SOURCE_DIR}/Util/fingerprint.cpp ) CONFIGURE_FILE( ${SOURCE_DIR}/util/fingerprint.cpp.in ${SOURCE_DIR}/util/fingerprint.cpp )

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/query_edge.hpp" #include "../data_structures/query_edge.hpp"
#include "../data_structures/xor_fast_hash.hpp" #include "../data_structures/xor_fast_hash.hpp"
#include "../data_structures/xor_fast_hash_storage.hpp" #include "../data_structures/xor_fast_hash_storage.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -92,9 +92,11 @@ class Contractor
}; };
using ContractorGraph = DynamicGraph<ContractorEdgeData>; using ContractorGraph = DynamicGraph<ContractorEdgeData>;
// using ContractorHeap = BinaryHeap<NodeID, NodeID, int, ContractorHeapData, ArrayStorage<NodeID, NodeID> // using ContractorHeap = BinaryHeap<NodeID, NodeID, int, ContractorHeapData,
// ArrayStorage<NodeID, NodeID>
// >; // >;
using ContractorHeap = BinaryHeap<NodeID, NodeID, int, ContractorHeapData, XORFastHashStorage<NodeID, NodeID>>; using ContractorHeap =
BinaryHeap<NodeID, NodeID, int, ContractorHeapData, XORFastHashStorage<NodeID, NodeID>>;
using ContractorEdge = ContractorGraph::InputEdge; using ContractorEdge = ContractorGraph::InputEdge;
struct ContractorThreadData struct ContractorThreadData
@ -131,15 +133,14 @@ class Contractor
bool is_independent : 1; bool is_independent : 1;
}; };
struct ThreadDataContainer struct ThreadDataContainer
{ {
explicit ThreadDataContainer(int number_of_nodes) : number_of_nodes(number_of_nodes) {} explicit ThreadDataContainer(int number_of_nodes) : number_of_nodes(number_of_nodes) {}
inline ContractorThreadData* getThreadData() inline ContractorThreadData *getThreadData()
{ {
bool exists = false; bool exists = false;
auto& ref = data.local(exists); auto &ref = data.local(exists);
if (!exists) if (!exists)
{ {
ref = std::make_shared<ContractorThreadData>(number_of_nodes); ref = std::make_shared<ContractorThreadData>(number_of_nodes);
@ -149,7 +150,8 @@ class Contractor
} }
int number_of_nodes; int number_of_nodes;
using EnumerableThreadData = tbb::enumerable_thread_specific<std::shared_ptr<ContractorThreadData>>; using EnumerableThreadData =
tbb::enumerable_thread_specific<std::shared_ptr<ContractorThreadData>>;
EnumerableThreadData data; EnumerableThreadData data;
}; };
@ -162,29 +164,25 @@ class Contractor
const auto dend = input_edge_list.dend(); const auto dend = input_edge_list.dend();
for (auto diter = input_edge_list.dbegin(); diter != dend; ++diter) for (auto diter = input_edge_list.dbegin(); diter != dend; ++diter)
{ {
BOOST_ASSERT_MSG(static_cast<unsigned int>(std::max(diter->weight, 1)) > 0, "edge distance < 1"); BOOST_ASSERT_MSG(static_cast<unsigned int>(std::max(diter->weight, 1)) > 0,
"edge distance < 1");
#ifndef NDEBUG #ifndef NDEBUG
if (static_cast<unsigned int>(std::max(diter->weight, 1)) > 24 * 60 * 60 * 10) if (static_cast<unsigned int>(std::max(diter->weight, 1)) > 24 * 60 * 60 * 10)
{ {
SimpleLogger().Write(logWARNING) << "Edge weight large -> " SimpleLogger().Write(logWARNING)
<< static_cast<unsigned int>(std::max(diter->weight, 1)); << "Edge weight large -> "
<< static_cast<unsigned int>(std::max(diter->weight, 1));
} }
#endif #endif
edges.emplace_back(diter->source, diter->target, edges.emplace_back(diter->source, diter->target,
static_cast<unsigned int>(std::max(diter->weight, 1)), static_cast<unsigned int>(std::max(diter->weight, 1)), 1,
1, diter->edge_id, false, diter->forward ? true : false,
diter->edge_id, diter->backward ? true : false);
false,
diter->forward ? true : false,
diter->backward ? true : false);
edges.emplace_back(diter->target, diter->source, edges.emplace_back(diter->target, diter->source,
static_cast<unsigned int>(std::max(diter->weight, 1)), static_cast<unsigned int>(std::max(diter->weight, 1)), 1,
1, diter->edge_id, false, diter->backward ? true : false,
diter->edge_id, diter->forward ? true : false);
false,
diter->backward ? true : false,
diter->forward ? true : false);
} }
// clear input vector // clear input vector
input_edge_list.clear(); input_edge_list.clear();
@ -282,20 +280,20 @@ class Contractor
std::cout << "contractor finished initalization" << std::endl; std::cout << "contractor finished initalization" << std::endl;
} }
~Contractor() { } ~Contractor() {}
void Run() void Run()
{ {
// for the preperation we can use a big grain size, which is much faster (probably cache) // for the preperation we can use a big grain size, which is much faster (probably cache)
constexpr size_t InitGrainSize = 100000; constexpr size_t InitGrainSize = 100000;
constexpr size_t PQGrainSize = 100000; constexpr size_t PQGrainSize = 100000;
// auto_partitioner will automatically increase the blocksize if we have // auto_partitioner will automatically increase the blocksize if we have
// a lot of data. It is *important* for the last loop iterations // a lot of data. It is *important* for the last loop iterations
// (which have a very small dataset) that it is devisible. // (which have a very small dataset) that it is devisible.
constexpr size_t IndependentGrainSize = 1; constexpr size_t IndependentGrainSize = 1;
constexpr size_t ContractGrainSize = 1; constexpr size_t ContractGrainSize = 1;
constexpr size_t NeighboursGrainSize = 1; constexpr size_t NeighboursGrainSize = 1;
constexpr size_t DeleteGrainSize = 1; constexpr size_t DeleteGrainSize = 1;
const NodeID number_of_nodes = contractor_graph->GetNumberOfNodes(); const NodeID number_of_nodes = contractor_graph->GetNumberOfNodes();
Percent p(number_of_nodes); Percent p(number_of_nodes);
@ -307,30 +305,28 @@ class Contractor
std::vector<float> node_priorities(number_of_nodes); std::vector<float> node_priorities(number_of_nodes);
std::vector<NodePriorityData> node_data(number_of_nodes); std::vector<NodePriorityData> node_data(number_of_nodes);
// initialize priorities in parallel // initialize priorities in parallel
tbb::parallel_for(tbb::blocked_range<int>(0, number_of_nodes, InitGrainSize), tbb::parallel_for(tbb::blocked_range<int>(0, number_of_nodes, InitGrainSize),
[&remaining_nodes](const tbb::blocked_range<int>& range) [&remaining_nodes](const tbb::blocked_range<int> &range)
{ {
for (int x = range.begin(); x != range.end(); ++x) for (int x = range.begin(); x != range.end(); ++x)
{ {
remaining_nodes[x].id = x; remaining_nodes[x].id = x;
} }
} });
);
std::cout << "initializing elimination PQ ..." << std::flush; std::cout << "initializing elimination PQ ..." << std::flush;
tbb::parallel_for(tbb::blocked_range<int>(0, number_of_nodes, PQGrainSize), tbb::parallel_for(tbb::blocked_range<int>(0, number_of_nodes, PQGrainSize),
[this, &node_priorities, &node_data, &thread_data_list](const tbb::blocked_range<int>& range) [this, &node_priorities, &node_data, &thread_data_list](
{ const tbb::blocked_range<int> &range)
ContractorThreadData *data = thread_data_list.getThreadData(); {
for (int x = range.begin(); x != range.end(); ++x) ContractorThreadData *data = thread_data_list.getThreadData();
{ for (int x = range.begin(); x != range.end(); ++x)
node_priorities[x] = this->EvaluateNodePriority(data, &node_data[x], x); {
} node_priorities[x] =
} this->EvaluateNodePriority(data, &node_data[x], x);
); }
});
std::cout << "ok" << std::endl << "preprocessing " << number_of_nodes << " nodes ..." std::cout << "ok" << std::endl << "preprocessing " << number_of_nodes << " nodes ..."
<< std::flush; << std::flush;
@ -368,7 +364,8 @@ class Contractor
remaining_nodes[new_node_id].id = new_node_id; remaining_nodes[new_node_id].id = new_node_id;
} }
// walk over all nodes // walk over all nodes
for (const auto i : osrm::irange<std::size_t>(0, contractor_graph->GetNumberOfNodes())) for (const auto i :
osrm::irange<std::size_t>(0, contractor_graph->GetNumberOfNodes()))
{ {
const NodeID source = i; const NodeID source = i;
for (auto current_edge : contractor_graph->GetAdjacentEdgeRange(source)) for (auto current_edge : contractor_graph->GetAdjacentEdgeRange(source))
@ -384,11 +381,9 @@ class Contractor
{ {
// node is not yet contracted. // node is not yet contracted.
// add (renumbered) outgoing edges to new DynamicGraph. // add (renumbered) outgoing edges to new DynamicGraph.
ContractorEdge new_edge = { ContractorEdge new_edge = {new_node_id_from_orig_id_map[source],
new_node_id_from_orig_id_map[source], new_node_id_from_orig_id_map[target],
new_node_id_from_orig_id_map[target], data};
data
};
new_edge.data.is_original_via_node_ID = true; new_edge.data.is_original_via_node_ID = true;
BOOST_ASSERT_MSG(UINT_MAX != new_node_id_from_orig_id_map[source], BOOST_ASSERT_MSG(UINT_MAX != new_node_id_from_orig_id_map[source],
@ -427,28 +422,30 @@ class Contractor
const int last = (int)remaining_nodes.size(); const int last = (int)remaining_nodes.size();
tbb::parallel_for(tbb::blocked_range<int>(0, last, IndependentGrainSize), tbb::parallel_for(tbb::blocked_range<int>(0, last, IndependentGrainSize),
[this, &node_priorities, &remaining_nodes, &thread_data_list](const tbb::blocked_range<int>& range) [this, &node_priorities, &remaining_nodes, &thread_data_list](
{ const tbb::blocked_range<int> &range)
ContractorThreadData *data = thread_data_list.getThreadData(); {
// determine independent node set ContractorThreadData *data = thread_data_list.getThreadData();
for (int i = range.begin(); i != range.end(); ++i) // determine independent node set
{ for (int i = range.begin(); i != range.end(); ++i)
const NodeID node = remaining_nodes[i].id; {
remaining_nodes[i].is_independent = const NodeID node = remaining_nodes[i].id;
this->IsNodeIndependent(node_priorities, data, node); remaining_nodes[i].is_independent =
} this->IsNodeIndependent(node_priorities, data, node);
} }
); });
const auto first = stable_partition(remaining_nodes.begin(), const auto first = stable_partition(remaining_nodes.begin(), remaining_nodes.end(),
remaining_nodes.end(),
[](RemainingNodeData node_data) [](RemainingNodeData node_data)
{ return !node_data.is_independent; }); {
return !node_data.is_independent;
});
const int first_independent_node = static_cast<int>(first - remaining_nodes.begin()); const int first_independent_node = static_cast<int>(first - remaining_nodes.begin());
// contract independent nodes // contract independent nodes
tbb::parallel_for(tbb::blocked_range<int>(first_independent_node, last, ContractGrainSize), tbb::parallel_for(
[this, &remaining_nodes, &thread_data_list](const tbb::blocked_range<int>& range) tbb::blocked_range<int>(first_independent_node, last, ContractGrainSize),
[this, &remaining_nodes, &thread_data_list](const tbb::blocked_range<int> &range)
{ {
ContractorThreadData *data = thread_data_list.getThreadData(); ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(); position != range.end(); ++position) for (int position = range.begin(); position != range.end(); ++position)
@ -456,19 +453,18 @@ class Contractor
const NodeID x = remaining_nodes[position].id; const NodeID x = remaining_nodes[position].id;
this->ContractNode<false>(data, x); this->ContractNode<false>(data, x);
} }
} });
);
// make sure we really sort each block // make sure we really sort each block
tbb::parallel_for(thread_data_list.data.range(), tbb::parallel_for(
[&](const ThreadDataContainer::EnumerableThreadData::range_type& range) thread_data_list.data.range(),
[&](const ThreadDataContainer::EnumerableThreadData::range_type &range)
{ {
for (auto& data : range) for (auto &data : range)
std::sort(data->inserted_edges.begin(), std::sort(data->inserted_edges.begin(), data->inserted_edges.end());
data->inserted_edges.end()); });
} tbb::parallel_for(
); tbb::blocked_range<int>(first_independent_node, last, DeleteGrainSize),
tbb::parallel_for(tbb::blocked_range<int>(first_independent_node, last, DeleteGrainSize), [this, &remaining_nodes, &thread_data_list](const tbb::blocked_range<int> &range)
[this, &remaining_nodes, &thread_data_list](const tbb::blocked_range<int>& range)
{ {
ContractorThreadData *data = thread_data_list.getThreadData(); ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(); position != range.end(); ++position) for (int position = range.begin(); position != range.end(); ++position)
@ -476,15 +472,15 @@ class Contractor
const NodeID x = remaining_nodes[position].id; const NodeID x = remaining_nodes[position].id;
this->DeleteIncomingEdges(data, x); this->DeleteIncomingEdges(data, x);
} }
} });
);
// insert new edges // insert new edges
for (auto& data : thread_data_list.data) for (auto &data : thread_data_list.data)
{ {
for (const ContractorEdge &edge : data->inserted_edges) for (const ContractorEdge &edge : data->inserted_edges)
{ {
const EdgeID current_edge_ID = contractor_graph->FindEdge(edge.source, edge.target); const EdgeID current_edge_ID =
contractor_graph->FindEdge(edge.source, edge.target);
if (current_edge_ID < contractor_graph->EndEdges(edge.source)) if (current_edge_ID < contractor_graph->EndEdges(edge.source))
{ {
ContractorGraph::EdgeData &current_data = ContractorGraph::EdgeData &current_data =
@ -503,8 +499,10 @@ class Contractor
data->inserted_edges.clear(); data->inserted_edges.clear();
} }
tbb::parallel_for(tbb::blocked_range<int>(first_independent_node, last, NeighboursGrainSize), tbb::parallel_for(
[this, &remaining_nodes, &node_priorities, &node_data, &thread_data_list](const tbb::blocked_range<int>& range) tbb::blocked_range<int>(first_independent_node, last, NeighboursGrainSize),
[this, &remaining_nodes, &node_priorities, &node_data, &thread_data_list](
const tbb::blocked_range<int> &range)
{ {
ContractorThreadData *data = thread_data_list.getThreadData(); ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(); position != range.end(); ++position) for (int position = range.begin(); position != range.end(); ++position)
@ -512,8 +510,7 @@ class Contractor
NodeID x = remaining_nodes[position].id; NodeID x = remaining_nodes[position].id;
this->UpdateNodeNeighbours(node_priorities, node_data, data, x); this->UpdateNodeNeighbours(node_priorities, node_data, data, x);
} }
} });
);
// remove contracted nodes from the pool // remove contracted nodes from the pool
number_of_contracted_nodes += last - first_independent_node; number_of_contracted_nodes += last - first_independent_node;
@ -774,17 +771,11 @@ class Contractor
{ {
inserted_edges.emplace_back(source, target, path_distance, inserted_edges.emplace_back(source, target, path_distance,
out_data.originalEdges + in_data.originalEdges, out_data.originalEdges + in_data.originalEdges,
node, node, true, true, false);
true,
true,
false);
inserted_edges.emplace_back(target, source, path_distance, inserted_edges.emplace_back(target, source, path_distance,
out_data.originalEdges + in_data.originalEdges, out_data.originalEdges + in_data.originalEdges,
node, node, true, false, true);
true,
false,
true);
} }
} }
} }
@ -883,10 +874,9 @@ class Contractor
return true; return true;
} }
inline bool IsNodeIndependent( inline bool IsNodeIndependent(const std::vector<float> &priorities,
const std::vector<float> &priorities, ContractorThreadData *const data,
ContractorThreadData *const data, NodeID node) const
NodeID node) const
{ {
const float priority = priorities[node]; const float priority = priorities[node];

View File

@ -28,11 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "edge_based_graph_factory.hpp" #include "edge_based_graph_factory.hpp"
#include "../algorithms/tiny_components.hpp" #include "../algorithms/tiny_components.hpp"
#include "../data_structures/percent.hpp" #include "../data_structures/percent.hpp"
#include "../Util/compute_angle.hpp" #include "../util/compute_angle.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/lua_util.hpp" #include "../util/lua_util.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "geometry_compressor.hpp" #include "geometry_compressor.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -174,8 +174,8 @@ void GeometryCompressor::CompressEdge(const EdgeID edge_id_1,
m_compressed_geometries[list_to_remove_index]; m_compressed_geometries[list_to_remove_index];
// found an existing list, append it to the list of edge_id_1 // found an existing list, append it to the list of edge_id_1
edge_bucket_list1.insert( edge_bucket_list1.insert(edge_bucket_list1.end(), edge_bucket_list2.begin(),
edge_bucket_list1.end(), edge_bucket_list2.begin(), edge_bucket_list2.end()); edge_bucket_list2.end());
// remove the list of edge_id_2 // remove the list of edge_id_2
m_edge_id_to_list_index_map.erase(edge_id_2); m_edge_id_to_list_index_map.erase(edge_id_2);
@ -211,9 +211,8 @@ void GeometryCompressor::PrintStatistics() const
"\n compressed edges: " << compressed_edges "\n compressed edges: " << compressed_edges
<< "\n compressed geometries: " << compressed_geometries << "\n compressed geometries: " << compressed_geometries
<< "\n longest chain length: " << longest_chain_length << "\n longest chain length: " << longest_chain_length
<< "\n cmpr ratio: " << "\n cmpr ratio: " << ((float)compressed_edges /
<< ((float)compressed_edges / std::max(compressed_geometries, (uint64_t)1))
std::max(compressed_geometries, (uint64_t)1))
<< "\n avg chain length: " << "\n avg chain length: "
<< (float)compressed_geometries / << (float)compressed_geometries /
std::max((uint64_t)1, compressed_edges); std::max((uint64_t)1, compressed_edges);
@ -226,16 +225,15 @@ GeometryCompressor::GetBucketReference(const EdgeID edge_id) const
return m_compressed_geometries.at(index); return m_compressed_geometries.at(index);
} }
NodeID GeometryCompressor::GetFirstNodeIDOfBucket(const EdgeID edge_id) const NodeID GeometryCompressor::GetFirstNodeIDOfBucket(const EdgeID edge_id) const
{ {
const auto &bucket = GetBucketReference(edge_id); const auto &bucket = GetBucketReference(edge_id);
BOOST_ASSERT(bucket.size() >= 2); BOOST_ASSERT(bucket.size() >= 2);
return bucket[1].first; return bucket[1].first;
} }
NodeID GeometryCompressor::GetLastNodeIDOfBucket(const EdgeID edge_id) const NodeID GeometryCompressor::GetLastNodeIDOfBucket(const EdgeID edge_id) const
{ {
const auto &bucket = GetBucketReference(edge_id); const auto &bucket = GetBucketReference(edge_id);
BOOST_ASSERT(bucket.size() >= 2); BOOST_ASSERT(bucket.size() >= 2);
return bucket[bucket.size()-2].first; return bucket[bucket.size() - 2].first;
} }

View File

@ -34,15 +34,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/static_rtree.hpp" #include "../data_structures/static_rtree.hpp"
#include "../data_structures/restriction_map.hpp" #include "../data_structures/restriction_map.hpp"
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/graph_loader.hpp" #include "../util/graph_loader.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/lua_util.hpp" #include "../util/lua_util.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>

View File

@ -27,9 +27,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "coordinate_calculation.hpp" #include "coordinate_calculation.hpp"
#include "../Util/mercator.hpp" #include "../util/mercator.hpp"
#ifndef NDEBUG #ifndef NDEBUG
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#endif #endif
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -27,8 +27,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "coordinate_calculation.hpp" #include "coordinate_calculation.hpp"
#include "../Util/mercator.hpp" #include "../util/mercator.hpp"
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>

View File

@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef DEALLOCATING_VECTOR_HPP #ifndef DEALLOCATING_VECTOR_HPP
#define DEALLOCATING_VECTOR_HPP #define DEALLOCATING_VECTOR_HPP
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
@ -171,7 +171,10 @@ class DeallocatingVector
// this forward-only iterator deallocates all buckets that have been visited // this forward-only iterator deallocates all buckets that have been visited
using deallocation_iterator = DeallocatingVectorRemoveIterator<ElementT, ELEMENTS_PER_BLOCK>; using deallocation_iterator = DeallocatingVectorRemoveIterator<ElementT, ELEMENTS_PER_BLOCK>;
DeallocatingVector() : current_size(0) { bucket_list.emplace_back(new ElementT[ELEMENTS_PER_BLOCK]); } DeallocatingVector() : current_size(0)
{
bucket_list.emplace_back(new ElementT[ELEMENTS_PER_BLOCK]);
}
~DeallocatingVector() { clear(); } ~DeallocatingVector() { clear(); }
@ -192,7 +195,8 @@ class DeallocatingVector
bucket = nullptr; bucket = nullptr;
} }
} }
bucket_list.clear(); bucket_list.shrink_to_fit(); bucket_list.clear();
bucket_list.shrink_to_fit();
current_size = 0; current_size = 0;
} }
@ -222,7 +226,7 @@ class DeallocatingVector
++current_size; ++current_size;
} }
void reserve(const std::size_t) const { /* don't do anything */ } void reserve(const std::size_t) const { /* don't do anything */}
void resize(const std::size_t new_size) void resize(const std::size_t new_size)
{ {
@ -234,9 +238,10 @@ class DeallocatingVector
} }
} }
else else
{ // down-size { // down-size
const std::size_t number_of_necessary_buckets = 1 + (new_size / ELEMENTS_PER_BLOCK); const std::size_t number_of_necessary_buckets = 1 + (new_size / ELEMENTS_PER_BLOCK);
for (const auto bucket_index : osrm::irange(number_of_necessary_buckets, bucket_list.size())) for (const auto bucket_index :
osrm::irange(number_of_necessary_buckets, bucket_list.size()))
{ {
if (nullptr != bucket_list[bucket_index]) if (nullptr != bucket_list[bucket_index])
{ {
@ -291,8 +296,7 @@ class DeallocatingVector
return (bucket_list[_bucket][_index]); return (bucket_list[_bucket][_index]);
} }
template<class InputIterator> template <class InputIterator> void append(InputIterator first, const InputIterator last)
void append(InputIterator first, const InputIterator last)
{ {
InputIterator position = first; InputIterator position = first;
while (position != last) while (position != last)

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define DYNAMICGRAPH_HPP #define DYNAMICGRAPH_HPP
#include "deallocating_vector.hpp" #include "deallocating_vector.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -55,10 +55,17 @@ template <typename EdgeDataT> class DynamicGraph
NodeIterator target; NodeIterator target;
EdgeDataT data; EdgeDataT data;
InputEdge() : source(std::numeric_limits<NodeIterator>::max()), target(std::numeric_limits<NodeIterator>::max()) { } InputEdge()
: source(std::numeric_limits<NodeIterator>::max()),
target(std::numeric_limits<NodeIterator>::max())
{
}
template<typename... Ts> template <typename... Ts>
InputEdge(NodeIterator source, NodeIterator target, Ts &&...data) : source(source), target(target), data(std::forward<Ts>(data)...) { } InputEdge(NodeIterator source, NodeIterator target, Ts &&... data)
: source(source), target(target), data(std::forward<Ts>(data)...)
{
}
bool operator<(const InputEdge &right) const bool operator<(const InputEdge &right) const
{ {
@ -106,7 +113,7 @@ template <typename EdgeDataT> class DynamicGraph
for (const auto node : osrm::irange(0u, number_of_nodes)) for (const auto node : osrm::irange(0u, number_of_nodes))
{ {
for (const auto i : osrm::irange(node_list[node].firstEdge, for (const auto i : osrm::irange(node_list[node].firstEdge,
node_list[node].firstEdge + node_list[node].edges)) node_list[node].firstEdge + node_list[node].edges))
{ {
edge_list[i].target = graph[edge].target; edge_list[i].target = graph[edge].target;
edge_list[i].data = graph[edge].data; edge_list[i].data = graph[edge].data;

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "dynamic_graph.hpp" #include "dynamic_graph.hpp"
#include "import_edge.hpp" #include "import_edge.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <tbb/parallel_sort.h> #include <tbb/parallel_sort.h>
@ -40,9 +40,9 @@ struct NodeBasedEdgeData
{ {
NodeBasedEdgeData() NodeBasedEdgeData()
: distance(INVALID_EDGE_WEIGHT), edgeBasedNodeID(SPECIAL_NODEID), : distance(INVALID_EDGE_WEIGHT), edgeBasedNodeID(SPECIAL_NODEID),
nameID(std::numeric_limits<unsigned>::max()), nameID(std::numeric_limits<unsigned>::max()), isAccessRestricted(false), shortcut(false),
isAccessRestricted(false), shortcut(false), forward(false), backward(false), forward(false), backward(false), roundabout(false), ignore_in_grid(false),
roundabout(false), ignore_in_grid(false), travel_mode(TRAVEL_MODE_INACCESSIBLE) travel_mode(TRAVEL_MODE_INACCESSIBLE)
{ {
} }
@ -85,7 +85,8 @@ using SimpleNodeBasedDynamicGraph = DynamicGraph<SimpleEdgeData>;
inline std::shared_ptr<NodeBasedDynamicGraph> inline std::shared_ptr<NodeBasedDynamicGraph>
NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge> &input_edge_list) NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge> &input_edge_list)
{ {
static_assert(sizeof(NodeBasedEdgeData) == 16, "changing node based edge data size changes memory consumption"); static_assert(sizeof(NodeBasedEdgeData) == 16,
"changing node based edge data size changes memory consumption");
DeallocatingVector<NodeBasedDynamicGraph::InputEdge> edges_list; DeallocatingVector<NodeBasedDynamicGraph::InputEdge> edges_list;
NodeBasedDynamicGraph::InputEdge edge; NodeBasedDynamicGraph::InputEdge edge;
@ -134,7 +135,7 @@ NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge
// remove duplicate edges // remove duplicate edges
tbb::parallel_sort(edges_list.begin(), edges_list.end()); tbb::parallel_sort(edges_list.begin(), edges_list.end());
NodeID edge_count = 0; NodeID edge_count = 0;
for (NodeID i = 0; i < edges_list.size(); ) for (NodeID i = 0; i < edges_list.size();)
{ {
const NodeID source = edges_list[i].source; const NodeID source = edges_list[i].source;
const NodeID target = edges_list[i].target; const NodeID target = edges_list[i].target;
@ -150,10 +151,10 @@ NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge
forward_edge.data.forward = reverse_edge.data.backward = true; forward_edge.data.forward = reverse_edge.data.backward = true;
forward_edge.data.backward = reverse_edge.data.forward = false; forward_edge.data.backward = reverse_edge.data.forward = false;
forward_edge.data.shortcut = reverse_edge.data.shortcut = false; forward_edge.data.shortcut = reverse_edge.data.shortcut = false;
forward_edge.data.distance = reverse_edge.data.distance = forward_edge.data.distance = reverse_edge.data.distance = std::numeric_limits<int>::max();
std::numeric_limits<int>::max();
// remove parallel edges // remove parallel edges
while (i < edges_list.size() && edges_list[i].source == source && edges_list[i].target == target) while (i < edges_list.size() && edges_list[i].source == source &&
edges_list[i].target == target)
{ {
if (edges_list[i].data.forward) if (edges_list[i].data.forward)
{ {
@ -189,17 +190,20 @@ NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge
} }
} }
edges_list.resize(edge_count); edges_list.resize(edge_count);
SimpleLogger().Write() << "merged " << edges_list.size() - edge_count << " edges out of " << edges_list.size(); SimpleLogger().Write() << "merged " << edges_list.size() - edge_count << " edges out of "
<< edges_list.size();
auto graph = std::make_shared<NodeBasedDynamicGraph>(static_cast<NodeBasedDynamicGraph::NodeIterator>(number_of_nodes), edges_list); auto graph = std::make_shared<NodeBasedDynamicGraph>(
static_cast<NodeBasedDynamicGraph::NodeIterator>(number_of_nodes), edges_list);
return graph; return graph;
} }
template<class SimpleEdgeT> template <class SimpleEdgeT>
inline std::shared_ptr<SimpleNodeBasedDynamicGraph> inline std::shared_ptr<SimpleNodeBasedDynamicGraph>
SimpleNodeBasedDynamicGraphFromEdges(int number_of_nodes, std::vector<SimpleEdgeT> &input_edge_list) SimpleNodeBasedDynamicGraphFromEdges(int number_of_nodes, std::vector<SimpleEdgeT> &input_edge_list)
{ {
static_assert(sizeof(NodeBasedEdgeData) == 16, "changing node based edge data size changes memory consumption"); static_assert(sizeof(NodeBasedEdgeData) == 16,
"changing node based edge data size changes memory consumption");
tbb::parallel_sort(input_edge_list.begin(), input_edge_list.end()); tbb::parallel_sort(input_edge_list.begin(), input_edge_list.end());
DeallocatingVector<SimpleNodeBasedDynamicGraph::InputEdge> edges_list; DeallocatingVector<SimpleNodeBasedDynamicGraph::InputEdge> edges_list;
@ -218,10 +222,10 @@ SimpleNodeBasedDynamicGraphFromEdges(int number_of_nodes, std::vector<SimpleEdge
edges_list.push_back(edge); edges_list.push_back(edge);
} }
// remove duplicate edges // remove duplicate edges
tbb::parallel_sort(edges_list.begin(), edges_list.end()); tbb::parallel_sort(edges_list.begin(), edges_list.end());
NodeID edge_count = 0; NodeID edge_count = 0;
for (NodeID i = 0; i < edges_list.size(); ) for (NodeID i = 0; i < edges_list.size();)
{ {
const NodeID source = edges_list[i].source; const NodeID source = edges_list[i].source;
const NodeID target = edges_list[i].target; const NodeID target = edges_list[i].target;
@ -236,10 +240,13 @@ SimpleNodeBasedDynamicGraphFromEdges(int number_of_nodes, std::vector<SimpleEdge
forward_edge = reverse_edge = edges_list[i]; forward_edge = reverse_edge = edges_list[i];
forward_edge.data.capacity = reverse_edge.data.capacity = INVALID_EDGE_WEIGHT; forward_edge.data.capacity = reverse_edge.data.capacity = INVALID_EDGE_WEIGHT;
// remove parallel edges // remove parallel edges
while (i < edges_list.size() && edges_list[i].source == source && edges_list[i].target == target) while (i < edges_list.size() && edges_list[i].source == source &&
edges_list[i].target == target)
{ {
forward_edge.data.capacity = std::min(edges_list[i].data.capacity, forward_edge.data.capacity); forward_edge.data.capacity =
reverse_edge.data.capacity = std::min(edges_list[i].data.capacity, reverse_edge.data.capacity); std::min(edges_list[i].data.capacity, forward_edge.data.capacity);
reverse_edge.data.capacity =
std::min(edges_list[i].data.capacity, reverse_edge.data.capacity);
++i; ++i;
} }
// merge edges (s,t) and (t,s) into bidirectional edge // merge edges (s,t) and (t,s) into bidirectional edge
@ -262,7 +269,8 @@ SimpleNodeBasedDynamicGraphFromEdges(int number_of_nodes, std::vector<SimpleEdge
} }
} }
} }
SimpleLogger().Write() << "merged " << edges_list.size() - edge_count << " edges out of " << edges_list.size(); SimpleLogger().Write() << "merged " << edges_list.size() - edge_count << " edges out of "
<< edges_list.size();
auto graph = std::make_shared<SimpleNodeBasedDynamicGraph>(number_of_nodes, edges_list); auto graph = std::make_shared<SimpleNodeBasedDynamicGraph>(number_of_nodes, edges_list);
return graph; return graph;

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef RANGE_TABLE_HPP #ifndef RANGE_TABLE_HPP
#define RANGE_TABLE_HPP #define RANGE_TABLE_HPP
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "shared_memory_factory.hpp" #include "shared_memory_factory.hpp"
#include "shared_memory_vector_wrapper.hpp" #include "shared_memory_vector_wrapper.hpp"
@ -41,13 +41,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* and otherwise the compiler gets confused. * and otherwise the compiler gets confused.
*/ */
template<unsigned BLOCK_SIZE=16, bool USE_SHARED_MEMORY = false> class RangeTable; template <unsigned BLOCK_SIZE = 16, bool USE_SHARED_MEMORY = false> class RangeTable;
template<unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::ostream& operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table); std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table);
template<unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::istream& operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table); std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table);
/** /**
* Stores adjacent ranges in a compressed format. * Stores adjacent ranges in a compressed format.
@ -58,33 +58,34 @@ std::istream& operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEM
* But each block consists of an absolute value and BLOCK_SIZE differential values. * But each block consists of an absolute value and BLOCK_SIZE differential values.
* So the effective block size is sizeof(unsigned) + BLOCK_SIZE. * So the effective block size is sizeof(unsigned) + BLOCK_SIZE.
*/ */
template<unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> class RangeTable
class RangeTable
{ {
public: public:
using BlockT = std::array<unsigned char, BLOCK_SIZE>; using BlockT = std::array<unsigned char, BLOCK_SIZE>;
using BlockContainerT = typename ShM<BlockT, USE_SHARED_MEMORY>::vector; using BlockContainerT = typename ShM<BlockT, USE_SHARED_MEMORY>::vector;
using OffsetContainerT = typename ShM<unsigned, USE_SHARED_MEMORY>::vector; using OffsetContainerT = typename ShM<unsigned, USE_SHARED_MEMORY>::vector;
using RangeT = osrm::range<unsigned>; using RangeT = osrm::range<unsigned>;
friend std::ostream& operator<< <>(std::ostream &out, const RangeTable &table); friend std::ostream &operator<<<>(std::ostream &out, const RangeTable &table);
friend std::istream& operator>> <>(std::istream &in, RangeTable &table); friend std::istream &operator>><>(std::istream &in, RangeTable &table);
RangeTable() : sum_lengths(0) {} RangeTable() : sum_lengths(0) {}
// for loading from shared memory // for loading from shared memory
explicit RangeTable(OffsetContainerT& external_offsets, BlockContainerT& external_blocks, const unsigned sum_lengths) explicit RangeTable(OffsetContainerT &external_offsets,
: sum_lengths(sum_lengths) BlockContainerT &external_blocks,
const unsigned sum_lengths)
: sum_lengths(sum_lengths)
{ {
block_offsets.swap(external_offsets); block_offsets.swap(external_offsets);
diff_blocks.swap(external_blocks); diff_blocks.swap(external_blocks);
} }
// construct table from length vector // construct table from length vector
explicit RangeTable(const std::vector<unsigned>& lengths) explicit RangeTable(const std::vector<unsigned> &lengths)
{ {
const unsigned number_of_blocks = [&lengths]() { const unsigned number_of_blocks = [&lengths]()
{
unsigned num = (lengths.size() + 1) / (BLOCK_SIZE + 1); unsigned num = (lengths.size() + 1) / (BLOCK_SIZE + 1);
if ((lengths.size() + 1) % (BLOCK_SIZE + 1) != 0) if ((lengths.size() + 1) % (BLOCK_SIZE + 1) != 0)
{ {
@ -116,8 +117,8 @@ public:
block_sum += last_length; block_sum += last_length;
} }
BOOST_ASSERT((block_idx == 0 && block_offsets[block_counter] == lengths_prefix_sum) BOOST_ASSERT((block_idx == 0 && block_offsets[block_counter] == lengths_prefix_sum) ||
|| lengths_prefix_sum == (block_offsets[block_counter]+block_sum)); lengths_prefix_sum == (block_offsets[block_counter] + block_sum));
// block is full // block is full
if (BLOCK_SIZE == block_idx) if (BLOCK_SIZE == block_idx)
@ -136,7 +137,7 @@ public:
} }
// Last block can't be finished because we didn't add the sentinel // Last block can't be finished because we didn't add the sentinel
BOOST_ASSERT (block_counter == (number_of_blocks - 1)); BOOST_ASSERT(block_counter == (number_of_blocks - 1));
// one block missing: starts with guard value // one block missing: starts with guard value
if (0 == block_idx) if (0 == block_idx)
@ -155,7 +156,8 @@ public:
} }
diff_blocks.push_back(block); diff_blocks.push_back(block);
BOOST_ASSERT(diff_blocks.size() == number_of_blocks && block_offsets.size() == number_of_blocks); BOOST_ASSERT(diff_blocks.size() == number_of_blocks &&
block_offsets.size() == number_of_blocks);
sum_lengths = lengths_prefix_sum; sum_lengths = lengths_prefix_sum;
} }
@ -172,7 +174,7 @@ public:
unsigned begin_idx = 0; unsigned begin_idx = 0;
unsigned end_idx = 0; unsigned end_idx = 0;
begin_idx = block_offsets[block_idx]; begin_idx = block_offsets[block_idx];
const BlockT& block = diff_blocks[block_idx]; const BlockT &block = diff_blocks[block_idx];
if (internal_idx > 0) if (internal_idx > 0)
{ {
begin_idx += PrefixSumAtIndex(internal_idx - 1, block); begin_idx += PrefixSumAtIndex(internal_idx - 1, block);
@ -195,9 +197,9 @@ public:
return osrm::irange(begin_idx, end_idx); return osrm::irange(begin_idx, end_idx);
} }
private:
inline unsigned PrefixSumAtIndex(int index, const BlockT& block) const; private:
inline unsigned PrefixSumAtIndex(int index, const BlockT &block) const;
// contains offset for each differential block // contains offset for each differential block
OffsetContainerT block_offsets; OffsetContainerT block_offsets;
@ -206,8 +208,9 @@ private:
unsigned sum_lengths; unsigned sum_lengths;
}; };
template<unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
unsigned RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY>::PrefixSumAtIndex(int index, const BlockT& block) const unsigned RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY>::PrefixSumAtIndex(int index,
const BlockT &block) const
{ {
// this loop looks inefficent, but a modern compiler // this loop looks inefficent, but a modern compiler
// will emit nice SIMD here, at least for sensible block sizes. (I checked.) // will emit nice SIMD here, at least for sensible block sizes. (I checked.)
@ -220,39 +223,39 @@ unsigned RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY>::PrefixSumAtIndex(int index,
return sum; return sum;
} }
template<unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::ostream& operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table) std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table)
{ {
// write number of block // write number of block
const unsigned number_of_blocks = table.diff_blocks.size(); const unsigned number_of_blocks = table.diff_blocks.size();
out.write((char *) &number_of_blocks, sizeof(unsigned)); out.write((char *)&number_of_blocks, sizeof(unsigned));
// write total length // write total length
out.write((char *) &table.sum_lengths, sizeof(unsigned)); out.write((char *)&table.sum_lengths, sizeof(unsigned));
// write block offsets // write block offsets
out.write((char *) table.block_offsets.data(), sizeof(unsigned) * table.block_offsets.size()); out.write((char *)table.block_offsets.data(), sizeof(unsigned) * table.block_offsets.size());
// write blocks // write blocks
out.write((char *) table.diff_blocks.data(), BLOCK_SIZE * table.diff_blocks.size()); out.write((char *)table.diff_blocks.data(), BLOCK_SIZE * table.diff_blocks.size());
return out; return out;
} }
template<unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::istream& operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table) std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table)
{ {
// read number of block // read number of block
unsigned number_of_blocks; unsigned number_of_blocks;
in.read((char *) &number_of_blocks, sizeof(unsigned)); in.read((char *)&number_of_blocks, sizeof(unsigned));
// read total length // read total length
in.read((char *) &table.sum_lengths, sizeof(unsigned)); in.read((char *)&table.sum_lengths, sizeof(unsigned));
table.block_offsets.resize(number_of_blocks); table.block_offsets.resize(number_of_blocks);
table.diff_blocks.resize(number_of_blocks); table.diff_blocks.resize(number_of_blocks);
// read block offsets // read block offsets
in.read((char *) table.block_offsets.data(), sizeof(unsigned) * number_of_blocks); in.read((char *)table.block_offsets.data(), sizeof(unsigned) * number_of_blocks);
// read blocks // read blocks
in.read((char *) table.diff_blocks.data(), BLOCK_SIZE * number_of_blocks); in.read((char *)table.diff_blocks.data(), BLOCK_SIZE * number_of_blocks);
return in; return in;
} }
#endif //RANGE_TABLE_HPP #endif // RANGE_TABLE_HPP

View File

@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define RESTRICTION_MAP_HPP #define RESTRICTION_MAP_HPP
#include "restriction.hpp" #include "restriction.hpp"
#include "../Util/std_hash.hpp" #include "../util/std_hash.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -44,9 +44,7 @@ struct RestrictionSource
NodeID start_node; NodeID start_node;
NodeID via_node; NodeID via_node;
RestrictionSource(NodeID start, NodeID via) : start_node(start), via_node(via) RestrictionSource(NodeID start, NodeID via) : start_node(start), via_node(via) {}
{
}
friend inline bool operator==(const RestrictionSource &lhs, const RestrictionSource &rhs) friend inline bool operator==(const RestrictionSource &lhs, const RestrictionSource &rhs)
{ {
@ -59,9 +57,7 @@ struct RestrictionTarget
NodeID target_node; NodeID target_node;
bool is_only; bool is_only;
explicit RestrictionTarget(NodeID target, bool only) : target_node(target), is_only(only) explicit RestrictionTarget(NodeID target, bool only) : target_node(target), is_only(only) {}
{
}
friend inline bool operator==(const RestrictionTarget &lhs, const RestrictionTarget &rhs) friend inline bool operator==(const RestrictionTarget &lhs, const RestrictionTarget &rhs)
{ {
@ -98,7 +94,7 @@ class RestrictionMap
RestrictionMap(const std::vector<TurnRestriction> &restriction_list); RestrictionMap(const std::vector<TurnRestriction> &restriction_list);
// Replace end v with w in each turn restriction containing u as via node // Replace end v with w in each turn restriction containing u as via node
template<class GraphT> template <class GraphT>
void FixupArrivingTurnRestriction(const NodeID node_u, void FixupArrivingTurnRestriction(const NodeID node_u,
const NodeID node_v, const NodeID node_v,
const NodeID node_w, const NodeID node_w,
@ -148,24 +144,18 @@ class RestrictionMap
bool IsViaNode(const NodeID node) const; bool IsViaNode(const NodeID node) const;
// Replaces start edge (v, w) with (u, w). Only start node changes. // Replaces start edge (v, w) with (u, w). Only start node changes.
void FixupStartingTurnRestriction(const NodeID node_u, void
const NodeID node_v, FixupStartingTurnRestriction(const NodeID node_u, const NodeID node_v, const NodeID node_w);
const NodeID node_w);
// Check if edge (u, v) is the start of any turn restriction. // Check if edge (u, v) is the start of any turn restriction.
// If so returns id of first target node. // If so returns id of first target node.
NodeID CheckForEmanatingIsOnlyTurn(const NodeID node_u, const NodeID node_v) const; NodeID CheckForEmanatingIsOnlyTurn(const NodeID node_u, const NodeID node_v) const;
// Checks if turn <u,v,w> is actually a turn restriction. // Checks if turn <u,v,w> is actually a turn restriction.
bool CheckIfTurnIsRestricted(const NodeID node_u, bool
const NodeID node_v, CheckIfTurnIsRestricted(const NodeID node_u, const NodeID node_v, const NodeID node_w) const;
const NodeID node_w) const;
std::size_t size() std::size_t size() { return m_count; }
{
return m_count;
}
private: private:
// check of node is the start of any restriction // check of node is the start of any restriction
@ -182,4 +172,4 @@ class RestrictionMap
std::unordered_set<NodeID> m_no_turn_via_node_set; std::unordered_set<NodeID> m_no_turn_via_node_set;
}; };
#endif //RESTRICTION_MAP_HPP #endif // RESTRICTION_MAP_HPP

View File

@ -28,8 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SHARED_MEMORY_FACTORY_HPP #ifndef SHARED_MEMORY_FACTORY_HPP
#define SHARED_MEMORY_FACTORY_HPP #define SHARED_MEMORY_FACTORY_HPP
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -123,8 +123,8 @@ class SharedMemory
{ {
Remove(key); Remove(key);
} }
shm = boost::interprocess::xsi_shared_memory( shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_or_create, key,
boost::interprocess::open_or_create, key, size); size);
#ifdef __linux__ #ifdef __linux__
if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, 0)) if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, 0))
{ {
@ -150,7 +150,10 @@ class SharedMemory
boost::interprocess::xsi_key key(lock_file().string().c_str(), id); boost::interprocess::xsi_key key(lock_file().string().c_str(), id);
result = RegionExists(key); result = RegionExists(key);
} }
catch (...) { result = false; } catch (...)
{
result = false;
}
return result; return result;
} }
@ -165,8 +168,14 @@ class SharedMemory
static bool RegionExists(const boost::interprocess::xsi_key &key) static bool RegionExists(const boost::interprocess::xsi_key &key)
{ {
bool result = true; bool result = true;
try { boost::interprocess::xsi_shared_memory shm(boost::interprocess::open_only, key); } try
catch (...) { result = false; } {
boost::interprocess::xsi_shared_memory shm(boost::interprocess::open_only, key);
}
catch (...)
{
result = false;
}
return result; return result;
} }
@ -198,12 +207,12 @@ class SharedMemory
// Windows - specific code // Windows - specific code
class SharedMemory class SharedMemory
{ {
SharedMemory(const SharedMemory&) = delete; SharedMemory(const SharedMemory &) = delete;
// Remove shared memory on destruction // Remove shared memory on destruction
class shm_remove class shm_remove
{ {
private: private:
shm_remove(const shm_remove&) = delete; shm_remove(const shm_remove &) = delete;
char *m_shmid; char *m_shmid;
bool m_initialized; bool m_initialized;
@ -242,8 +251,7 @@ class SharedMemory
if (0 == size) if (0 == size)
{ // read_only { // read_only
shm = boost::interprocess::shared_memory_object( shm = boost::interprocess::shared_memory_object(
boost::interprocess::open_only, boost::interprocess::open_only, key,
key,
read_write ? boost::interprocess::read_write : boost::interprocess::read_only); read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
region = boost::interprocess::mapped_region( region = boost::interprocess::mapped_region(
shm, read_write ? boost::interprocess::read_write : boost::interprocess::read_only); shm, read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
@ -255,8 +263,8 @@ class SharedMemory
{ {
Remove(key); Remove(key);
} }
shm = boost::interprocess::shared_memory_object( shm = boost::interprocess::shared_memory_object(boost::interprocess::open_or_create,
boost::interprocess::open_or_create, key, boost::interprocess::read_write); key, boost::interprocess::read_write);
shm.truncate(size); shm.truncate(size);
region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write); region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write);
@ -274,7 +282,10 @@ class SharedMemory
build_key(id, k); build_key(id, k);
result = RegionExists(k); result = RegionExists(k);
} }
catch (...) { result = false; } catch (...)
{
result = false;
}
return result; return result;
} }
@ -286,20 +297,20 @@ class SharedMemory
} }
private: private:
static void build_key(int id, char *key) static void build_key(int id, char *key) { sprintf(key, "%s.%d", "osrm.lock", id); }
{
sprintf(key, "%s.%d", "osrm.lock", id);
}
static bool RegionExists(const char *key) static bool RegionExists(const char *key)
{ {
bool result = true; bool result = true;
try try
{ {
boost::interprocess::shared_memory_object shm( boost::interprocess::shared_memory_object shm(boost::interprocess::open_only, key,
boost::interprocess::open_only, key, boost::interprocess::read_write); boost::interprocess::read_write);
}
catch (...)
{
result = false;
} }
catch (...) { result = false; }
return result; return result;
} }

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "percent.hpp" #include "percent.hpp"
#include "shared_memory_vector_wrapper.hpp" #include "shared_memory_vector_wrapper.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -57,8 +57,11 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
NodeIterator target; NodeIterator target;
EdgeDataT data; EdgeDataT data;
template<typename... Ts> template <typename... Ts>
InputEdge(NodeIterator source, NodeIterator target, Ts &&...data) : source(source), target(target), data(std::forward<Ts>(data)...) { } InputEdge(NodeIterator source, NodeIterator target, Ts &&... data)
: source(source), target(target), data(std::forward<Ts>(data)...)
{
}
bool operator<(const InputEdge &right) const bool operator<(const InputEdge &right) const
{ {
if (source != right.source) if (source != right.source)
@ -94,7 +97,7 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
node_array.resize(number_of_nodes + 1); node_array.resize(number_of_nodes + 1);
EdgeIterator edge = 0; EdgeIterator edge = 0;
EdgeIterator position = 0; EdgeIterator position = 0;
for (const auto node : osrm::irange(0u, number_of_nodes+1)) for (const auto node : osrm::irange(0u, number_of_nodes + 1))
{ {
EdgeIterator last_edge = edge; EdgeIterator last_edge = edge;
while (edge < number_of_edges && graph[edge].source == node) while (edge < number_of_edges && graph[edge].source == node)

View File

@ -37,12 +37,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "shared_memory_vector_wrapper.hpp" #include "shared_memory_vector_wrapper.hpp"
#include "upper_bound.hpp" #include "upper_bound.hpp"
#include "../Util/floating_point.hpp" #include "../util/floating_point.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/mercator.hpp" #include "../util/mercator.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>
@ -69,8 +69,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template <class EdgeDataT, template <class EdgeDataT,
class CoordinateListT = std::vector<FixedPointCoordinate>, class CoordinateListT = std::vector<FixedPointCoordinate>,
bool UseSharedMemory = false, bool UseSharedMemory = false,
uint32_t BRANCHING_FACTOR=64, uint32_t BRANCHING_FACTOR = 64,
uint32_t LEAF_NODE_SIZE=1024> uint32_t LEAF_NODE_SIZE = 1024>
class StaticRTree class StaticRTree
{ {
public: public:
@ -87,19 +87,15 @@ class StaticRTree
{ {
for (uint32_t i = 0; i < element_count; ++i) for (uint32_t i = 0; i < element_count; ++i)
{ {
min_lon = std::min(min_lon, min_lon = std::min(min_lon, std::min(coordinate_list.at(objects[i].u).lon,
std::min(coordinate_list.at(objects[i].u).lon, coordinate_list.at(objects[i].v).lon));
coordinate_list.at(objects[i].v).lon)); max_lon = std::max(max_lon, std::max(coordinate_list.at(objects[i].u).lon,
max_lon = std::max(max_lon, coordinate_list.at(objects[i].v).lon));
std::max(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon));
min_lat = std::min(min_lat, min_lat = std::min(min_lat, std::min(coordinate_list.at(objects[i].u).lat,
std::min(coordinate_list.at(objects[i].u).lat, coordinate_list.at(objects[i].v).lat));
coordinate_list.at(objects[i].v).lat)); max_lat = std::max(max_lat, std::max(coordinate_list.at(objects[i].u).lat,
max_lat = std::max(max_lat, coordinate_list.at(objects[i].v).lat));
std::max(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat));
} }
BOOST_ASSERT(min_lat != std::numeric_limits<int>::min()); BOOST_ASSERT(min_lat != std::numeric_limits<int>::min());
BOOST_ASSERT(min_lon != std::numeric_limits<int>::min()); BOOST_ASSERT(min_lon != std::numeric_limits<int>::min());
@ -150,58 +146,66 @@ class StaticRTree
enum Direction enum Direction
{ {
INVALID = 0, INVALID = 0,
NORTH = 1, NORTH = 1,
SOUTH = 2, SOUTH = 2,
EAST = 4, EAST = 4,
NORTH_EAST = 5, NORTH_EAST = 5,
SOUTH_EAST = 6, SOUTH_EAST = 6,
WEST = 8, WEST = 8,
NORTH_WEST = 9, NORTH_WEST = 9,
SOUTH_WEST = 10 SOUTH_WEST = 10
}; };
Direction d = INVALID; Direction d = INVALID;
if (location.lat > max_lat) if (location.lat > max_lat)
d = (Direction) (d | NORTH); d = (Direction)(d | NORTH);
else if (location.lat < min_lat) else if (location.lat < min_lat)
d = (Direction) (d | SOUTH); d = (Direction)(d | SOUTH);
if (location.lon > max_lon) if (location.lon > max_lon)
d = (Direction) (d | EAST); d = (Direction)(d | EAST);
else if (location.lon < min_lon) else if (location.lon < min_lon)
d = (Direction) (d | WEST); d = (Direction)(d | WEST);
BOOST_ASSERT(d != INVALID); BOOST_ASSERT(d != INVALID);
float min_dist = std::numeric_limits<float>::max(); float min_dist = std::numeric_limits<float>::max();
switch (d) switch (d)
{ {
case NORTH: case NORTH:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(max_lat, location.lon)); min_dist = coordinate_calculation::euclidean_distance(
break; location, FixedPointCoordinate(max_lat, location.lon));
case SOUTH: break;
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(min_lat, location.lon)); case SOUTH:
break; min_dist = coordinate_calculation::euclidean_distance(
case WEST: location, FixedPointCoordinate(min_lat, location.lon));
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(location.lat, min_lon)); break;
break; case WEST:
case EAST: min_dist = coordinate_calculation::euclidean_distance(
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(location.lat, max_lon)); location, FixedPointCoordinate(location.lat, min_lon));
break; break;
case NORTH_EAST: case EAST:
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(max_lat, max_lon)); min_dist = coordinate_calculation::euclidean_distance(
break; location, FixedPointCoordinate(location.lat, max_lon));
case NORTH_WEST: break;
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(max_lat, min_lon)); case NORTH_EAST:
break; min_dist = coordinate_calculation::euclidean_distance(
case SOUTH_EAST: location, FixedPointCoordinate(max_lat, max_lon));
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(min_lat, max_lon)); break;
break; case NORTH_WEST:
case SOUTH_WEST: min_dist = coordinate_calculation::euclidean_distance(
min_dist = coordinate_calculation::euclidean_distance(location, FixedPointCoordinate(min_lat, min_lon)); location, FixedPointCoordinate(max_lat, min_lon));
break; break;
default: case SOUTH_EAST:
break; min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(min_lat, max_lon));
break;
case SOUTH_WEST:
min_dist = coordinate_calculation::euclidean_distance(
location, FixedPointCoordinate(min_lat, min_lon));
break;
default:
break;
} }
BOOST_ASSERT(min_dist != std::numeric_limits<float>::max()); BOOST_ASSERT(min_dist != std::numeric_limits<float>::max());
@ -220,15 +224,13 @@ class StaticRTree
min_max_dist = std::min( min_max_dist = std::min(
min_max_dist, min_max_dist,
std::max( std::max(coordinate_calculation::euclidean_distance(location, upper_left),
coordinate_calculation::euclidean_distance(location, upper_left), coordinate_calculation::euclidean_distance(location, upper_right)));
coordinate_calculation::euclidean_distance(location, upper_right)));
min_max_dist = std::min( min_max_dist = std::min(
min_max_dist, min_max_dist,
std::max( std::max(coordinate_calculation::euclidean_distance(location, upper_right),
coordinate_calculation::euclidean_distance(location, upper_right), coordinate_calculation::euclidean_distance(location, lower_right)));
coordinate_calculation::euclidean_distance(location, lower_right)));
min_max_dist = std::min( min_max_dist = std::min(
min_max_dist, min_max_dist,
@ -378,7 +380,8 @@ class StaticRTree
FixedPointCoordinate(coordinate_list.at(current_element.v).lat, FixedPointCoordinate(coordinate_list.at(current_element.v).lat,
coordinate_list.at(current_element.v).lon)); coordinate_list.at(current_element.v).lon));
current_centroid.lat = current_centroid.lat =
COORDINATE_PRECISION * mercator::lat2y(current_centroid.lat / COORDINATE_PRECISION); COORDINATE_PRECISION *
mercator::lat2y(current_centroid.lat / COORDINATE_PRECISION);
current_wrapper.m_hilbert_value = get_hilbert_number(current_centroid); current_wrapper.m_hilbert_value = get_hilbert_number(current_centroid);
} }
@ -416,8 +419,8 @@ class StaticRTree
} }
// generate tree node that resemble the objects in leaf and store it for next level // generate tree node that resemble the objects in leaf and store it for next level
InitializeMBRectangle(current_node.minimum_bounding_rectangle, InitializeMBRectangle(current_node.minimum_bounding_rectangle, current_leaf.objects,
current_leaf.objects, current_leaf.object_count, coordinate_list); current_leaf.object_count, coordinate_list);
current_node.child_is_on_disk = true; current_node.child_is_on_disk = true;
current_node.children[0] = tree_nodes_in_level.size(); current_node.children[0] = tree_nodes_in_level.size();
tree_nodes_in_level.emplace_back(current_node); tree_nodes_in_level.emplace_back(current_node);
@ -440,8 +443,7 @@ class StaticRTree
TreeNode parent_node; TreeNode parent_node;
// pack BRANCHING_FACTOR elements into tree_nodes each // pack BRANCHING_FACTOR elements into tree_nodes each
for (uint32_t current_child_node_index = 0; for (uint32_t current_child_node_index = 0;
BRANCHING_FACTOR > current_child_node_index; BRANCHING_FACTOR > current_child_node_index; ++current_child_node_index)
++current_child_node_index)
{ {
if (processed_tree_nodes_in_level < tree_nodes_in_level.size()) if (processed_tree_nodes_in_level < tree_nodes_in_level.size())
{ {
@ -474,17 +476,17 @@ class StaticRTree
tbb::parallel_for(tbb::blocked_range<uint32_t>(0, search_tree_size), tbb::parallel_for(tbb::blocked_range<uint32_t>(0, search_tree_size),
[this, &search_tree_size](const tbb::blocked_range<uint32_t> &range) [this, &search_tree_size](const tbb::blocked_range<uint32_t> &range)
{ {
for (uint32_t i = range.begin(); i != range.end(); ++i) for (uint32_t i = range.begin(); i != range.end(); ++i)
{ {
TreeNode &current_tree_node = this->m_search_tree[i]; TreeNode &current_tree_node = this->m_search_tree[i];
for (uint32_t j = 0; j < current_tree_node.child_count; ++j) for (uint32_t j = 0; j < current_tree_node.child_count; ++j)
{ {
const uint32_t old_id = current_tree_node.children[j]; const uint32_t old_id = current_tree_node.children[j];
const uint32_t new_id = search_tree_size - old_id - 1; const uint32_t new_id = search_tree_size - old_id - 1;
current_tree_node.children[j] = new_id; current_tree_node.children[j] = new_id;
} }
} }
}); });
// open tree file // open tree file
boost::filesystem::ofstream tree_node_file(tree_node_filename, std::ios::binary); boost::filesystem::ofstream tree_node_file(tree_node_filename, std::ios::binary);
@ -606,12 +608,10 @@ class StaticRTree
continue; continue;
} }
float current_minimum_distance = float current_minimum_distance = coordinate_calculation::euclidean_distance(
coordinate_calculation::euclidean_distance( input_coordinate.lat, input_coordinate.lon,
input_coordinate.lat, m_coordinate_list->at(current_edge.u).lat,
input_coordinate.lon, m_coordinate_list->at(current_edge.u).lon);
m_coordinate_list->at(current_edge.u).lat,
m_coordinate_list->at(current_edge.u).lon);
if (current_minimum_distance < min_dist) if (current_minimum_distance < min_dist)
{ {
// found a new minimum // found a new minimum
@ -619,12 +619,10 @@ class StaticRTree
result_coordinate = m_coordinate_list->at(current_edge.u); result_coordinate = m_coordinate_list->at(current_edge.u);
} }
current_minimum_distance = current_minimum_distance = coordinate_calculation::euclidean_distance(
coordinate_calculation::euclidean_distance( input_coordinate.lat, input_coordinate.lon,
input_coordinate.lat, m_coordinate_list->at(current_edge.v).lat,
input_coordinate.lon, m_coordinate_list->at(current_edge.v).lon);
m_coordinate_list->at(current_edge.v).lat,
m_coordinate_list->at(current_edge.v).lon);
if (current_minimum_distance < min_dist) if (current_minimum_distance < min_dist)
{ {
@ -636,27 +634,23 @@ class StaticRTree
} }
else else
{ {
min_max_dist = ExploreTreeNode(current_tree_node, min_max_dist = ExploreTreeNode(current_tree_node, input_coordinate, min_dist,
input_coordinate, min_max_dist, traversal_queue);
min_dist,
min_max_dist,
traversal_queue);
} }
} }
} }
return result_coordinate.is_valid(); return result_coordinate.is_valid();
} }
// implementation of the Hjaltason/Samet query [3], a BFS traversal of the tree // implementation of the Hjaltason/Samet query [3], a BFS traversal of the tree
// - searches for k elements nearest elements // - searches for k elements nearest elements
// - continues to find the k+1st element from a big component if k elements // - continues to find the k+1st element from a big component if k elements
// come from tiny components // come from tiny components
bool bool IncrementalFindPhantomNodeForCoordinate(
IncrementalFindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, const FixedPointCoordinate &input_coordinate,
std::vector<PhantomNode> &result_phantom_node_vector, std::vector<PhantomNode> &result_phantom_node_vector,
const unsigned max_number_of_phantom_nodes, const unsigned max_number_of_phantom_nodes,
const unsigned max_checked_elements = 4*LEAF_NODE_SIZE) const unsigned max_checked_elements = 4 * LEAF_NODE_SIZE)
{ {
unsigned inspected_elements = 0; unsigned inspected_elements = 0;
unsigned number_of_elements_from_big_cc = 0; unsigned number_of_elements_from_big_cc = 0;
@ -664,9 +658,9 @@ class StaticRTree
unsigned pruned_elements = 0; unsigned pruned_elements = 0;
std::pair<double, double> projected_coordinate = std::pair<double, double> projected_coordinate = {
{ mercator::lat2y(input_coordinate.lat / COORDINATE_PRECISION), mercator::lat2y(input_coordinate.lat / COORDINATE_PRECISION),
input_coordinate.lon / COORDINATE_PRECISION }; input_coordinate.lon / COORDINATE_PRECISION};
// upper bound pruning technique // upper bound pruning technique
upper_bound<float> pruning_bound(max_number_of_phantom_nodes); upper_bound<float> pruning_bound(max_number_of_phantom_nodes);
@ -682,7 +676,8 @@ class StaticRTree
if (current_query_node.node.template is<TreeNode>()) if (current_query_node.node.template is<TreeNode>())
{ // current object is a tree node { // current object is a tree node
const TreeNode & current_tree_node = current_query_node.node.template get<TreeNode>(); const TreeNode &current_tree_node =
current_query_node.node.template get<TreeNode>();
if (current_tree_node.child_is_on_disk) if (current_tree_node.child_is_on_disk)
{ {
LeafNode current_leaf_node; LeafNode current_leaf_node;
@ -692,11 +687,10 @@ class StaticRTree
for (const auto i : osrm::irange(0u, current_leaf_node.object_count)) for (const auto i : osrm::irange(0u, current_leaf_node.object_count))
{ {
const auto &current_edge = current_leaf_node.objects[i]; const auto &current_edge = current_leaf_node.objects[i];
const float current_perpendicular_distance = const float current_perpendicular_distance = coordinate_calculation::
coordinate_calculation::perpendicular_distance_from_projected_coordinate( perpendicular_distance_from_projected_coordinate(
m_coordinate_list->at(current_edge.u), m_coordinate_list->at(current_edge.u),
m_coordinate_list->at(current_edge.v), m_coordinate_list->at(current_edge.v), input_coordinate,
input_coordinate,
projected_coordinate); projected_coordinate);
// distance must be non-negative // distance must be non-negative
BOOST_ASSERT(0.f <= current_perpendicular_distance); BOOST_ASSERT(0.f <= current_perpendicular_distance);
@ -706,7 +700,9 @@ class StaticRTree
{ {
pruning_bound.insert(current_perpendicular_distance); pruning_bound.insert(current_perpendicular_distance);
traversal_queue.emplace(current_perpendicular_distance, current_edge); traversal_queue.emplace(current_perpendicular_distance, current_edge);
} else { }
else
{
++pruned_elements; ++pruned_elements;
} }
} }
@ -718,8 +714,10 @@ class StaticRTree
{ {
const int32_t child_id = current_tree_node.children[i]; const int32_t child_id = current_tree_node.children[i];
const TreeNode &child_tree_node = m_search_tree[child_id]; const TreeNode &child_tree_node = m_search_tree[child_id];
const RectangleT &child_rectangle = child_tree_node.minimum_bounding_rectangle; const RectangleT &child_rectangle =
const float lower_bound_to_element = child_rectangle.GetMinDist(input_coordinate); child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element =
child_rectangle.GetMinDist(input_coordinate);
BOOST_ASSERT(0.f <= lower_bound_to_element); BOOST_ASSERT(0.f <= lower_bound_to_element);
traversal_queue.emplace(lower_bound_to_element, child_tree_node); traversal_queue.emplace(lower_bound_to_element, child_tree_node);
@ -730,7 +728,8 @@ class StaticRTree
{ // current object is a leaf node { // current object is a leaf node
++inspected_elements; ++inspected_elements;
// inspecting an actual road segment // inspecting an actual road segment
const EdgeDataT & current_segment = current_query_node.node.template get<EdgeDataT>(); const EdgeDataT &current_segment =
current_query_node.node.template get<EdgeDataT>();
// continue searching for the first segment from a big component // continue searching for the first segment from a big component
if (number_of_elements_from_big_cc == 0 && if (number_of_elements_from_big_cc == 0 &&
@ -744,29 +743,20 @@ class StaticRTree
float current_ratio = 0.f; float current_ratio = 0.f;
FixedPointCoordinate foot_point_coordinate_on_segment; FixedPointCoordinate foot_point_coordinate_on_segment;
// const float current_perpendicular_distance = // const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance_from_projected_coordinate( coordinate_calculation::perpendicular_distance_from_projected_coordinate(
m_coordinate_list->at(current_segment.u), m_coordinate_list->at(current_segment.u),
m_coordinate_list->at(current_segment.v), m_coordinate_list->at(current_segment.v), input_coordinate,
input_coordinate, projected_coordinate, foot_point_coordinate_on_segment, current_ratio);
projected_coordinate,
foot_point_coordinate_on_segment,
current_ratio);
// store phantom node in result vector // store phantom node in result vector
result_phantom_node_vector.emplace_back( result_phantom_node_vector.emplace_back(
current_segment.forward_edge_based_node_id, current_segment.forward_edge_based_node_id,
current_segment.reverse_edge_based_node_id, current_segment.reverse_edge_based_node_id, current_segment.name_id,
current_segment.name_id, current_segment.forward_weight, current_segment.reverse_weight,
current_segment.forward_weight, current_segment.forward_offset, current_segment.reverse_offset,
current_segment.reverse_weight, current_segment.packed_geometry_id, current_segment.component_id,
current_segment.forward_offset, foot_point_coordinate_on_segment, current_segment.fwd_segment_position,
current_segment.reverse_offset, current_segment.forward_travel_mode, current_segment.backward_travel_mode);
current_segment.packed_geometry_id,
current_segment.component_id,
foot_point_coordinate_on_segment,
current_segment.fwd_segment_position,
current_segment.forward_travel_mode,
current_segment.backward_travel_mode);
// Hack to fix rounding errors and wandering via nodes. // Hack to fix rounding errors and wandering via nodes.
FixUpRoundingIssue(input_coordinate, result_phantom_node_vector.back()); FixUpRoundingIssue(input_coordinate, result_phantom_node_vector.back());
@ -787,16 +777,20 @@ class StaticRTree
} }
// stop the search by flushing the queue // stop the search by flushing the queue
if ((result_phantom_node_vector.size() >= max_number_of_phantom_nodes && number_of_elements_from_big_cc > 0) || if ((result_phantom_node_vector.size() >= max_number_of_phantom_nodes &&
number_of_elements_from_big_cc > 0) ||
inspected_elements >= max_checked_elements) inspected_elements >= max_checked_elements)
{ {
traversal_queue = std::priority_queue<IncrementalQueryCandidate>{}; traversal_queue = std::priority_queue<IncrementalQueryCandidate>{};
} }
} }
// SimpleLogger().Write() << "result_phantom_node_vector.size(): " << result_phantom_node_vector.size(); // SimpleLogger().Write() << "result_phantom_node_vector.size(): " <<
// result_phantom_node_vector.size();
// SimpleLogger().Write() << "max_number_of_phantom_nodes: " << max_number_of_phantom_nodes; // SimpleLogger().Write() << "max_number_of_phantom_nodes: " << max_number_of_phantom_nodes;
// SimpleLogger().Write() << "number_of_elements_from_big_cc: " << number_of_elements_from_big_cc; // SimpleLogger().Write() << "number_of_elements_from_big_cc: " <<
// SimpleLogger().Write() << "number_of_elements_from_tiny_cc: " << number_of_elements_from_tiny_cc; // number_of_elements_from_big_cc;
// SimpleLogger().Write() << "number_of_elements_from_tiny_cc: " <<
// number_of_elements_from_tiny_cc;
// SimpleLogger().Write() << "inspected_elements: " << inspected_elements; // SimpleLogger().Write() << "inspected_elements: " << inspected_elements;
// SimpleLogger().Write() << "max_checked_elements: " << max_checked_elements; // SimpleLogger().Write() << "max_checked_elements: " << max_checked_elements;
// SimpleLogger().Write() << "pruned_elements: " << pruned_elements; // SimpleLogger().Write() << "pruned_elements: " << pruned_elements;
@ -805,13 +799,14 @@ class StaticRTree
} }
// implementation of the Hjaltason/Samet query [3], a BFS traversal of the tree // implementation of the Hjaltason/Samet query [3], a BFS traversal of the tree
bool bool IncrementalFindPhantomNodeForCoordinateWithDistance(
IncrementalFindPhantomNodeForCoordinateWithDistance(const FixedPointCoordinate &input_coordinate, const FixedPointCoordinate &input_coordinate,
std::vector<std::pair<PhantomNode, double>> &result_phantom_node_vector, std::vector<std::pair<PhantomNode, double>> &result_phantom_node_vector,
const unsigned number_of_results, const unsigned number_of_results,
const unsigned max_checked_segments = 4*LEAF_NODE_SIZE) const unsigned max_checked_segments = 4 * LEAF_NODE_SIZE)
{ {
std::vector<float> min_found_distances(number_of_results, std::numeric_limits<float>::max()); std::vector<float> min_found_distances(number_of_results,
std::numeric_limits<float>::max());
unsigned number_of_results_found_in_big_cc = 0; unsigned number_of_results_found_in_big_cc = 0;
unsigned number_of_results_found_in_tiny_cc = 0; unsigned number_of_results_found_in_tiny_cc = 0;
@ -827,7 +822,7 @@ class StaticRTree
const IncrementalQueryCandidate current_query_node = traversal_queue.top(); const IncrementalQueryCandidate current_query_node = traversal_queue.top();
traversal_queue.pop(); traversal_queue.pop();
const float current_min_dist = min_found_distances[number_of_results-1]; const float current_min_dist = min_found_distances[number_of_results - 1];
if (current_query_node.min_dist > current_min_dist) if (current_query_node.min_dist > current_min_dist)
{ {
@ -836,7 +831,8 @@ class StaticRTree
if (current_query_node.RepresentsTreeNode()) if (current_query_node.RepresentsTreeNode())
{ {
const TreeNode & current_tree_node = current_query_node.node.template get<TreeNode>(); const TreeNode &current_tree_node =
current_query_node.node.template get<TreeNode>();
if (current_tree_node.child_is_on_disk) if (current_tree_node.child_is_on_disk)
{ {
LeafNode current_leaf_node; LeafNode current_leaf_node;
@ -848,8 +844,7 @@ class StaticRTree
const float current_perpendicular_distance = const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance( coordinate_calculation::perpendicular_distance(
m_coordinate_list->at(current_edge.u), m_coordinate_list->at(current_edge.u),
m_coordinate_list->at(current_edge.v), m_coordinate_list->at(current_edge.v), input_coordinate);
input_coordinate);
// distance must be non-negative // distance must be non-negative
BOOST_ASSERT(0. <= current_perpendicular_distance); BOOST_ASSERT(0. <= current_perpendicular_distance);
@ -866,8 +861,10 @@ class StaticRTree
{ {
const int32_t child_id = current_tree_node.children[i]; const int32_t child_id = current_tree_node.children[i];
const TreeNode &child_tree_node = m_search_tree[child_id]; const TreeNode &child_tree_node = m_search_tree[child_id];
const RectangleT &child_rectangle = child_tree_node.minimum_bounding_rectangle; const RectangleT &child_rectangle =
const float lower_bound_to_element = child_rectangle.GetMinDist(input_coordinate); child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element =
child_rectangle.GetMinDist(input_coordinate);
// TODO - enough elements found, i.e. nearest distance > maximum distance? // TODO - enough elements found, i.e. nearest distance > maximum distance?
// ie. some measure of 'confidence of accuracy' // ie. some measure of 'confidence of accuracy'
@ -878,23 +875,27 @@ class StaticRTree
traversal_queue.emplace(lower_bound_to_element, child_tree_node); traversal_queue.emplace(lower_bound_to_element, child_tree_node);
} }
} }
// SimpleLogger().Write(logDEBUG) << "added " << current_tree_node.child_count << " mbrs into queue of " << traversal_queue.size(); // SimpleLogger().Write(logDEBUG) << "added " << current_tree_node.child_count
// << " mbrs into queue of " << traversal_queue.size();
} }
} }
else else
{ {
++inspected_segments; ++inspected_segments;
// inspecting an actual road segment // inspecting an actual road segment
const EdgeDataT & current_segment = current_query_node.node.template get<EdgeDataT>(); const EdgeDataT &current_segment =
current_query_node.node.template get<EdgeDataT>();
// don't collect too many results from small components // don't collect too many results from small components
if (number_of_results_found_in_big_cc == number_of_results && !current_segment.is_in_tiny_cc) if (number_of_results_found_in_big_cc == number_of_results &&
!current_segment.is_in_tiny_cc)
{ {
continue; continue;
} }
// don't collect too many results from big components // don't collect too many results from big components
if (number_of_results_found_in_tiny_cc == number_of_results && current_segment.is_in_tiny_cc) if (number_of_results_found_in_tiny_cc == number_of_results &&
current_segment.is_in_tiny_cc)
{ {
continue; continue;
} }
@ -905,10 +906,8 @@ class StaticRTree
const float current_perpendicular_distance = const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance( coordinate_calculation::perpendicular_distance(
m_coordinate_list->at(current_segment.u), m_coordinate_list->at(current_segment.u),
m_coordinate_list->at(current_segment.v), m_coordinate_list->at(current_segment.v), input_coordinate,
input_coordinate, foot_point_coordinate_on_segment, current_ratio);
foot_point_coordinate_on_segment,
current_ratio);
BOOST_ASSERT(0. <= current_perpendicular_distance); BOOST_ASSERT(0. <= current_perpendicular_distance);
@ -918,16 +917,11 @@ class StaticRTree
// store phantom node in result vector // store phantom node in result vector
result_phantom_node_vector.emplace_back( result_phantom_node_vector.emplace_back(
current_segment.forward_edge_based_node_id, current_segment.forward_edge_based_node_id,
current_segment.reverse_edge_based_node_id, current_segment.reverse_edge_based_node_id, current_segment.name_id,
current_segment.name_id, current_segment.forward_weight, current_segment.reverse_weight,
current_segment.forward_weight, current_segment.forward_offset, current_segment.reverse_offset,
current_segment.reverse_weight, current_segment.packed_geometry_id, foot_point_coordinate_on_segment,
current_segment.forward_offset, current_segment.fwd_segment_position, current_perpendicular_distance);
current_segment.reverse_offset,
current_segment.packed_geometry_id,
foot_point_coordinate_on_segment,
current_segment.fwd_segment_position,
current_perpendicular_distance);
// Hack to fix rounding errors and wandering via nodes. // Hack to fix rounding errors and wandering via nodes.
FixUpRoundingIssue(input_coordinate, result_phantom_node_vector.back()); FixUpRoundingIssue(input_coordinate, result_phantom_node_vector.back());
@ -944,17 +938,22 @@ class StaticRTree
else else
{ {
// found an element in a large component // found an element in a large component
min_found_distances[number_of_results_found_in_big_cc] = current_perpendicular_distance; min_found_distances[number_of_results_found_in_big_cc] =
current_perpendicular_distance;
++number_of_results_found_in_big_cc; ++number_of_results_found_in_big_cc;
// SimpleLogger().Write(logDEBUG) << std::setprecision(8) << foot_point_coordinate_on_segment << " at " << current_perpendicular_distance; // SimpleLogger().Write(logDEBUG) << std::setprecision(8) <<
// foot_point_coordinate_on_segment << " at " <<
// current_perpendicular_distance;
} }
} }
} }
// TODO add indicator to prune if maxdist > threshold // TODO add indicator to prune if maxdist > threshold
if (number_of_results == number_of_results_found_in_big_cc || inspected_segments >= max_checked_segments) if (number_of_results == number_of_results_found_in_big_cc ||
inspected_segments >= max_checked_segments)
{ {
// SimpleLogger().Write(logDEBUG) << "flushing queue of " << traversal_queue.size() << " elements"; // SimpleLogger().Write(logDEBUG) << "flushing queue of " << traversal_queue.size()
// << " elements";
// work-around for traversal_queue.clear(); // work-around for traversal_queue.clear();
traversal_queue = std::priority_queue<IncrementalQueryCandidate>{}; traversal_queue = std::priority_queue<IncrementalQueryCandidate>{};
} }
@ -963,8 +962,6 @@ class StaticRTree
return !result_phantom_node_vector.empty(); return !result_phantom_node_vector.empty();
} }
bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate, bool FindPhantomNodeForCoordinate(const FixedPointCoordinate &input_coordinate,
PhantomNode &result_phantom_node, PhantomNode &result_phantom_node,
const unsigned zoom_level) const unsigned zoom_level)
@ -1005,9 +1002,7 @@ class StaticRTree
const float current_perpendicular_distance = const float current_perpendicular_distance =
coordinate_calculation::perpendicular_distance( coordinate_calculation::perpendicular_distance(
m_coordinate_list->at(current_edge.u), m_coordinate_list->at(current_edge.u),
m_coordinate_list->at(current_edge.v), m_coordinate_list->at(current_edge.v), input_coordinate, nearest,
input_coordinate,
nearest,
current_ratio); current_ratio);
BOOST_ASSERT(0. <= current_perpendicular_distance); BOOST_ASSERT(0. <= current_perpendicular_distance);
@ -1035,11 +1030,8 @@ class StaticRTree
} }
else else
{ {
min_max_dist = ExploreTreeNode(current_tree_node, min_max_dist = ExploreTreeNode(current_tree_node, input_coordinate, min_dist,
input_coordinate, min_max_dist, traversal_queue);
min_dist,
min_max_dist,
traversal_queue);
} }
} }
} }
@ -1056,8 +1048,7 @@ class StaticRTree
} }
private: private:
inline void SetForwardAndReverseWeightsOnPhantomNode(const EdgeDataT &nearest_edge,
inline void SetForwardAndReverseWeightsOnPhantomNode(const EdgeDataT & nearest_edge,
PhantomNode &result_phantom_node) const PhantomNode &result_phantom_node) const
{ {
const float distance_1 = coordinate_calculation::euclidean_distance( const float distance_1 = coordinate_calculation::euclidean_distance(
@ -1069,32 +1060,34 @@ class StaticRTree
using TreeWeightType = decltype(result_phantom_node.forward_weight); using TreeWeightType = decltype(result_phantom_node.forward_weight);
static_assert(std::is_same<decltype(result_phantom_node.forward_weight), static_assert(std::is_same<decltype(result_phantom_node.forward_weight),
decltype(result_phantom_node.reverse_weight)>::value, decltype(result_phantom_node.reverse_weight)>::value,
"forward and reverse weight type in tree must be the same"); "forward and reverse weight type in tree must be the same");
if (SPECIAL_NODEID != result_phantom_node.forward_node_id) if (SPECIAL_NODEID != result_phantom_node.forward_node_id)
{ {
const auto new_weight = static_cast<TreeWeightType>(result_phantom_node.forward_weight * ratio); const auto new_weight =
static_cast<TreeWeightType>(result_phantom_node.forward_weight * ratio);
result_phantom_node.forward_weight = new_weight; result_phantom_node.forward_weight = new_weight;
} }
if (SPECIAL_NODEID != result_phantom_node.reverse_node_id) if (SPECIAL_NODEID != result_phantom_node.reverse_node_id)
{ {
const auto new_weight = static_cast<TreeWeightType>(result_phantom_node.reverse_weight * (1.f-ratio)); const auto new_weight =
static_cast<TreeWeightType>(result_phantom_node.reverse_weight * (1.f - ratio));
result_phantom_node.reverse_weight = new_weight; result_phantom_node.reverse_weight = new_weight;
} }
} }
// fixup locations if too close to inputs // fixup locations if too close to inputs
inline void FixUpRoundingIssue(const FixedPointCoordinate &input_coordinate, inline void FixUpRoundingIssue(const FixedPointCoordinate &input_coordinate,
PhantomNode &result_phantom_node) const PhantomNode &result_phantom_node) const
{ {
if (1 == std::abs(input_coordinate.lon - result_phantom_node.location.lon)) if (1 == std::abs(input_coordinate.lon - result_phantom_node.location.lon))
{ {
result_phantom_node.location.lon = input_coordinate.lon; result_phantom_node.location.lon = input_coordinate.lon;
} }
if (1 == std::abs(input_coordinate.lat - result_phantom_node.location.lat)) if (1 == std::abs(input_coordinate.lat - result_phantom_node.location.lat))
{ {
result_phantom_node.location.lat = input_coordinate.lat; result_phantom_node.location.lat = input_coordinate.lat;
} }
} }
template <class QueueT> template <class QueueT>
@ -1140,8 +1133,7 @@ class StaticRTree
} }
const uint64_t seek_pos = sizeof(uint64_t) + leaf_id * sizeof(LeafNode); const uint64_t seek_pos = sizeof(uint64_t) + leaf_id * sizeof(LeafNode);
leaves_stream.seekg(seek_pos); leaves_stream.seekg(seek_pos);
BOOST_ASSERT_MSG(leaves_stream.good(), BOOST_ASSERT_MSG(leaves_stream.good(), "Seeking to position in leaf file failed.");
"Seeking to position in leaf file failed.");
leaves_stream.read((char *)&result_node, sizeof(LeafNode)); leaves_stream.read((char *)&result_node, sizeof(LeafNode));
BOOST_ASSERT_MSG(leaves_stream.good(), "Reading from leaf file failed."); BOOST_ASSERT_MSG(leaves_stream.good(), "Reading from leaf file failed.");
} }
@ -1154,26 +1146,26 @@ class StaticRTree
return (a == b && c == d) || (a == c && b == d) || (a == d && b == c); return (a == b && c == d) || (a == c && b == d) || (a == d && b == c);
} }
inline void InitializeMBRectangle(RectangleT& rectangle, inline void InitializeMBRectangle(RectangleT &rectangle,
const std::array<EdgeDataT, LEAF_NODE_SIZE> &objects, const std::array<EdgeDataT, LEAF_NODE_SIZE> &objects,
const uint32_t element_count, const uint32_t element_count,
const std::vector<QueryNode> &coordinate_list) const std::vector<QueryNode> &coordinate_list)
{ {
for (uint32_t i = 0; i < element_count; ++i) for (uint32_t i = 0; i < element_count; ++i)
{ {
rectangle.min_lon = std::min(rectangle.min_lon, rectangle.min_lon =
std::min(coordinate_list.at(objects[i].u).lon, std::min(rectangle.min_lon, std::min(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon)); coordinate_list.at(objects[i].v).lon));
rectangle.max_lon = std::max(rectangle.max_lon, rectangle.max_lon =
std::max(coordinate_list.at(objects[i].u).lon, std::max(rectangle.max_lon, std::max(coordinate_list.at(objects[i].u).lon,
coordinate_list.at(objects[i].v).lon)); coordinate_list.at(objects[i].v).lon));
rectangle.min_lat = std::min(rectangle.min_lat, rectangle.min_lat =
std::min(coordinate_list.at(objects[i].u).lat, std::min(rectangle.min_lat, std::min(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat)); coordinate_list.at(objects[i].v).lat));
rectangle.max_lat = std::max(rectangle.max_lat, rectangle.max_lat =
std::max(coordinate_list.at(objects[i].u).lat, std::max(rectangle.max_lat, std::max(coordinate_list.at(objects[i].u).lat,
coordinate_list.at(objects[i].v).lat)); coordinate_list.at(objects[i].v).lat));
} }
BOOST_ASSERT(rectangle.min_lat != std::numeric_limits<int>::min()); BOOST_ASSERT(rectangle.min_lat != std::numeric_limits<int>::min());
BOOST_ASSERT(rectangle.min_lon != std::numeric_limits<int>::min()); BOOST_ASSERT(rectangle.min_lon != std::numeric_limits<int>::min());

View File

@ -36,11 +36,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "server/data_structures/datafacade_base.hpp" #include "server/data_structures/datafacade_base.hpp"
#include "server/data_structures/shared_datatype.hpp" #include "server/data_structures/shared_datatype.hpp"
#include "server/data_structures/shared_barriers.hpp" #include "server/data_structures/shared_barriers.hpp"
#include "Util/boost_filesystem_2_fix.hpp" #include "util/boost_filesystem_2_fix.hpp"
#include "Util/datastore_options.hpp" #include "util/datastore_options.hpp"
#include "Util/simple_logger.hpp" #include "util/simple_logger.hpp"
#include "Util/osrm_exception.hpp" #include "util/osrm_exception.hpp"
#include "Util/fingerprint.hpp" #include "util/fingerprint.hpp"
#include "typedefs.h" #include "typedefs.h"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -31,8 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/coordinate_calculation.hpp" #include "../data_structures/coordinate_calculation.hpp"
#include "../data_structures/internal_route_result.hpp" #include "../data_structures/internal_route_result.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
#include "../Util/container.hpp" #include "../util/container.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../typedefs.h" #include "../typedefs.h"
DescriptionFactory::DescriptionFactory() : entire_length(0) { via_indices.push_back(0); } DescriptionFactory::DescriptionFactory() : entire_length(0) { via_indices.push_back(0); }

View File

@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define GPX_DESCRIPTOR_HPP #define GPX_DESCRIPTOR_HPP
#include "descriptor_base.hpp" #include "descriptor_base.hpp"
#include "../Util/xml_renderer.hpp" #include "../util/xml_renderer.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>

View File

@ -34,12 +34,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../algorithms/route_name_extraction.hpp" #include "../algorithms/route_name_extraction.hpp"
#include "../data_structures/segment_information.hpp" #include "../data_structures/segment_information.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
#include "../Util/bearing.hpp" #include "../util/bearing.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>

View File

@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "extractor/extractor.hpp" #include "extractor/extractor.hpp"
#include "extractor/extractor_options.hpp" #include "extractor/extractor_options.hpp"
#include "Util/simple_logger.hpp" #include "util/simple_logger.hpp"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {

View File

@ -32,9 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/node_id.hpp" #include "../data_structures/node_id.hpp"
#include "../data_structures/range_table.hpp" #include "../data_structures/range_table.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>

View File

@ -32,7 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "first_and_last_segment_of_way.hpp" #include "first_and_last_segment_of_way.hpp"
#include "../data_structures/external_memory_node.hpp" #include "../data_structures/external_memory_node.hpp"
#include "../data_structures/restriction.hpp" #include "../data_structures/restriction.hpp"
#include "../Util/fingerprint.hpp" #include "../util/fingerprint.hpp"
#include <stxxl/vector> #include <stxxl/vector>

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef EXTRACTION_HELPER_FUNCTIONS_HPP #ifndef EXTRACTION_HELPER_FUNCTIONS_HPP
#define EXTRACTION_HELPER_FUNCTIONS_HPP #define EXTRACTION_HELPER_FUNCTIONS_HPP
#include "../Util/cast.hpp" #include "../util/cast.hpp"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string_regex.hpp> #include <boost/algorithm/string_regex.hpp>

View File

@ -34,10 +34,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "restriction_parser.hpp" #include "restriction_parser.hpp"
#include "scripting_environment.hpp" #include "scripting_environment.hpp"
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include "../typedefs.h" #include "../typedefs.h"

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -32,8 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/external_memory_node.hpp" #include "../data_structures/external_memory_node.hpp"
#include "../data_structures/restriction.hpp" #include "../data_structures/restriction.hpp"
#include "../Util/container.hpp" #include "../util/container.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -27,9 +27,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "extractor_options.hpp" #include "extractor_options.hpp"
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/ini_file.hpp" #include "../util/ini_file.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>

View File

@ -30,9 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "scripting_environment.hpp" #include "scripting_environment.hpp"
#include "../data_structures/external_memory_node.hpp" #include "../data_structures/external_memory_node.hpp"
#include "../Util/lua_util.hpp" #include "../util/lua_util.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp> #include <boost/algorithm/string/regex.hpp>

View File

@ -31,9 +31,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "extraction_node.hpp" #include "extraction_node.hpp"
#include "extraction_way.hpp" #include "extraction_way.hpp"
#include "../data_structures/external_memory_node.hpp" #include "../data_structures/external_memory_node.hpp"
#include "../Util/lua_util.hpp" #include "../util/lua_util.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <luabind/tag_function.hpp> #include <luabind/tag_function.hpp>

View File

@ -46,9 +46,9 @@ class named_mutex;
#include "../server/data_structures/internal_datafacade.hpp" #include "../server/data_structures/internal_datafacade.hpp"
#include "../server/data_structures/shared_barriers.hpp" #include "../server/data_structures/shared_barriers.hpp"
#include "../server/data_structures/shared_datafacade.hpp" #include "../server/data_structures/shared_datafacade.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/routed_options.hpp" #include "../util/routed_options.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/interprocess/sync/named_condition.hpp> #include <boost/interprocess/sync/named_condition.hpp>

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef DISTANCE_TABLE_PLUGIN_H #ifndef DISTANCE_TABLE_HPP
#define DISTANCE_TABLE_PLUGIN_H #define DISTANCE_TABLE_HPP
#include "plugin_base.hpp" #include "plugin_base.hpp"
@ -34,10 +34,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/query_edge.hpp" #include "../data_structures/query_edge.hpp"
#include "../data_structures/search_engine.hpp" #include "../data_structures/search_engine.hpp"
#include "../descriptors/descriptor_base.hpp" #include "../descriptors/descriptor_base.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
@ -56,8 +56,9 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
int max_locations_distance_table; int max_locations_distance_table;
public: public:
explicit DistanceTablePlugin(DataFacadeT *facade, const int max_locations_distance_table) : explicit DistanceTablePlugin(DataFacadeT *facade, const int max_locations_distance_table)
max_locations_distance_table(max_locations_distance_table), descriptor_string("table"), facade(facade) : max_locations_distance_table(max_locations_distance_table), descriptor_string("table"),
facade(facade)
{ {
search_engine_ptr = osrm::make_unique<SearchEngine<DataFacadeT>>(facade); search_engine_ptr = osrm::make_unique<SearchEngine<DataFacadeT>>(facade);
} }
@ -74,8 +75,9 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
} }
const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum()); const bool checksum_OK = (route_parameters.check_sum == facade->GetCheckSum());
unsigned max_locations = std::min(static_cast<unsigned>(max_locations_distance_table), unsigned max_locations =
static_cast<unsigned>(route_parameters.coordinates.size())); std::min(static_cast<unsigned>(max_locations_distance_table),
static_cast<unsigned>(route_parameters.coordinates.size()));
PhantomNodeArray phantom_node_vector(max_locations); PhantomNodeArray phantom_node_vector(max_locations);
for (const auto i : osrm::irange(0u, max_locations)) for (const auto i : osrm::irange(0u, max_locations))
@ -92,8 +94,7 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
} }
} }
facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i], facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i],
phantom_node_vector[i], phantom_node_vector[i], 1);
1);
BOOST_ASSERT(phantom_node_vector[i].front().is_valid(facade->GetNumberOfNodes())); BOOST_ASSERT(phantom_node_vector[i].front().is_valid(facade->GetNumberOfNodes()));
} }
@ -128,4 +129,4 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
DataFacadeT *facade; DataFacadeT *facade;
}; };
#endif // DISTANCE_TABLE_PLUGIN_H #endif // DISTANCE_TABLE_HPP

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -25,13 +25,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef HELLO_WORLD_PLUGIN_H #ifndef HELLO_WORLD_HPP
#define HELLO_WORLD_PLUGIN_H #define HELLO_WORLD_HPP
#include "plugin_base.hpp" #include "plugin_base.hpp"
#include "../Util/cast.hpp" #include "../util/cast.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
@ -77,8 +77,10 @@ class HelloWorldPlugin final : public BasePlugin
JSON::Object json_location; JSON::Object json_location;
JSON::Array json_coordinates; JSON::Array json_coordinates;
json_coordinates.values.push_back(static_cast<double>(coordinate.lat / COORDINATE_PRECISION)); json_coordinates.values.push_back(
json_coordinates.values.push_back(static_cast<double>(coordinate.lon / COORDINATE_PRECISION)); static_cast<double>(coordinate.lat / COORDINATE_PRECISION));
json_coordinates.values.push_back(
static_cast<double>(coordinate.lon / COORDINATE_PRECISION));
json_location.values[cast::integral_to_string(counter)] = json_coordinates; json_location.values[cast::integral_to_string(counter)] = json_coordinates;
json_locations.values.push_back(json_location); json_locations.values.push_back(json_location);
++counter; ++counter;
@ -101,4 +103,4 @@ class HelloWorldPlugin final : public BasePlugin
std::string descriptor_string; std::string descriptor_string;
}; };
#endif // HELLO_WORLD_PLUGIN_H #endif // HELLO_WORLD_HPP

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -25,13 +25,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef LOCATE_PLUGIN_H #ifndef LOCATE_HPP
#define LOCATE_PLUGIN_H #define LOCATE_HPP
#include "plugin_base.hpp" #include "plugin_base.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
@ -47,7 +47,8 @@ template <class DataFacadeT> class LocatePlugin final : public BasePlugin
int HandleRequest(const RouteParameters &route_parameters, JSON::Object &json_result) final int HandleRequest(const RouteParameters &route_parameters, JSON::Object &json_result) final
{ {
// check number of parameters // check number of parameters
if (route_parameters.coordinates.empty() || !route_parameters.coordinates.front().is_valid()) if (route_parameters.coordinates.empty() ||
!route_parameters.coordinates.front().is_valid())
{ {
return 400; return 400;
} }
@ -74,4 +75,4 @@ template <class DataFacadeT> class LocatePlugin final : public BasePlugin
DataFacadeT *facade; DataFacadeT *facade;
}; };
#endif /* LOCATE_PLUGIN_H */ #endif /* LOCATE_HPP */

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -25,14 +25,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef NEAREST_PLUGIN_H #ifndef NEAREST_HPP
#define NEAREST_PLUGIN_H #define NEAREST_HPP
#include "plugin_base.hpp" #include "plugin_base.hpp"
#include "../data_structures/phantom_node.hpp" #include "../data_structures/phantom_node.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
@ -52,7 +52,8 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
int HandleRequest(const RouteParameters &route_parameters, JSON::Object &json_result) final int HandleRequest(const RouteParameters &route_parameters, JSON::Object &json_result) final
{ {
// check number of parameters // check number of parameters
if (route_parameters.coordinates.empty() || !route_parameters.coordinates.front().is_valid()) if (route_parameters.coordinates.empty() ||
!route_parameters.coordinates.front().is_valid())
{ {
return 400; return 400;
} }
@ -76,7 +77,8 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
JSON::Array results; JSON::Array results;
auto vector_length = phantom_node_vector.size(); auto vector_length = phantom_node_vector.size();
for (const auto i : osrm::irange<std::size_t>(0, std::min(number_of_results, vector_length))) for (const auto i :
osrm::irange<std::size_t>(0, std::min(number_of_results, vector_length)))
{ {
JSON::Array json_coordinate; JSON::Array json_coordinate;
JSON::Object result; JSON::Object result;
@ -113,4 +115,4 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
std::string descriptor_string; std::string descriptor_string;
}; };
#endif /* NEAREST_PLUGIN_H */ #endif /* NEAREST_HPP */

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "plugin_base.hpp" #include "plugin_base.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -35,10 +35,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../descriptors/descriptor_base.hpp" #include "../descriptors/descriptor_base.hpp"
#include "../descriptors/gpx_descriptor.hpp" #include "../descriptors/gpx_descriptor.hpp"
#include "../descriptors/json_descriptor.hpp" #include "../descriptors/json_descriptor.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>

View File

@ -27,9 +27,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "library/osrm.hpp" #include "library/osrm.hpp"
#include "server/server.hpp" #include "server/server.hpp"
#include "Util/git_sha.hpp" #include "util/git_sha.hpp"
#include "Util/routed_options.hpp" #include "util/routed_options.hpp"
#include "Util/simple_logger.hpp" #include "util/simple_logger.hpp"
#ifdef __linux__ #ifdef __linux__
#include <sys/mman.h> #include <sys/mman.h>

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -30,8 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "routing_base.hpp" #include "routing_base.hpp"
#include "../data_structures/search_engine_data.hpp" #include "../data_structures/search_engine_data.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/container.hpp" #include "../util/container.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -44,7 +44,8 @@ const double VIAPATH_ALPHA = 0.10;
const double VIAPATH_EPSILON = 0.15; // alternative at most 15% longer const double VIAPATH_EPSILON = 0.15; // alternative at most 15% longer
const double VIAPATH_GAMMA = 0.75; // alternative shares at most 75% with the shortest. const double VIAPATH_GAMMA = 0.75; // alternative shares at most 75% with the shortest.
template <class DataFacadeT> class AlternativeRouting final : private BasicRoutingInterface<DataFacadeT> template <class DataFacadeT>
class AlternativeRouting final : private BasicRoutingInterface<DataFacadeT>
{ {
using super = BasicRoutingInterface<DataFacadeT>; using super = BasicRoutingInterface<DataFacadeT>;
using EdgeData = typename DataFacadeT::EdgeData; using EdgeData = typename DataFacadeT::EdgeData;
@ -148,22 +149,16 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
{ {
if (0 < forward_heap1.Size()) if (0 < forward_heap1.Size())
{ {
AlternativeRoutingStep<true>(forward_heap1, AlternativeRoutingStep<true>(forward_heap1, reverse_heap1, &middle_node,
reverse_heap1,
&middle_node,
&upper_bound_to_shortest_path_distance, &upper_bound_to_shortest_path_distance,
via_node_candidate_list, via_node_candidate_list, forward_search_space,
forward_search_space,
min_edge_offset); min_edge_offset);
} }
if (0 < reverse_heap1.Size()) if (0 < reverse_heap1.Size())
{ {
AlternativeRoutingStep<false>(reverse_heap1, AlternativeRoutingStep<false>(reverse_heap1, forward_heap1, &middle_node,
forward_heap1,
&middle_node,
&upper_bound_to_shortest_path_distance, &upper_bound_to_shortest_path_distance,
via_node_candidate_list, via_node_candidate_list, reverse_search_space,
reverse_search_space,
min_edge_offset); min_edge_offset);
} }
} }
@ -274,19 +269,16 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
std::vector<NodeID> &packed_shortest_path = packed_forward_path; std::vector<NodeID> &packed_shortest_path = packed_forward_path;
std::reverse(packed_shortest_path.begin(), packed_shortest_path.end()); std::reverse(packed_shortest_path.begin(), packed_shortest_path.end());
packed_shortest_path.emplace_back(middle_node); packed_shortest_path.emplace_back(middle_node);
packed_shortest_path.insert( packed_shortest_path.insert(packed_shortest_path.end(), packed_reverse_path.begin(),
packed_shortest_path.end(), packed_reverse_path.begin(), packed_reverse_path.end()); packed_reverse_path.end());
std::vector<RankedCandidateNode> ranked_candidates_list; std::vector<RankedCandidateNode> ranked_candidates_list;
// prioritizing via nodes for deep inspection // prioritizing via nodes for deep inspection
for (const NodeID node : preselected_node_list) for (const NodeID node : preselected_node_list)
{ {
int length_of_via_path = 0, sharing_of_via_path = 0; int length_of_via_path = 0, sharing_of_via_path = 0;
ComputeLengthAndSharingOfViaPath(node, ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path,
&length_of_via_path, packed_shortest_path, min_edge_offset);
&sharing_of_via_path,
packed_shortest_path,
min_edge_offset);
const int maximum_allowed_sharing = const int maximum_allowed_sharing =
static_cast<int>(upper_bound_to_shortest_path_distance * VIAPATH_GAMMA); static_cast<int>(upper_bound_to_shortest_path_distance * VIAPATH_GAMMA);
if (sharing_of_via_path <= maximum_allowed_sharing && if (sharing_of_via_path <= maximum_allowed_sharing &&
@ -302,16 +294,10 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID; NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID;
for (const RankedCandidateNode &candidate : ranked_candidates_list) for (const RankedCandidateNode &candidate : ranked_candidates_list)
{ {
if (ViaNodeCandidatePassesTTest(forward_heap1, if (ViaNodeCandidatePassesTTest(
reverse_heap1, forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate,
forward_heap2, upper_bound_to_shortest_path_distance, &length_of_via_path, &s_v_middle,
reverse_heap2, &v_t_middle, min_edge_offset))
candidate,
upper_bound_to_shortest_path_distance,
&length_of_via_path,
&s_v_middle,
&v_t_middle,
min_edge_offset))
{ {
// select first admissable // select first admissable
selected_via_node = candidate.node; selected_via_node = candidate.node;
@ -343,13 +329,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
{ {
std::vector<NodeID> packed_alternate_path; std::vector<NodeID> packed_alternate_path;
// retrieve alternate path // retrieve alternate path
RetrievePackedAlternatePath(forward_heap1, RetrievePackedAlternatePath(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2,
reverse_heap1, s_v_middle, v_t_middle, packed_alternate_path);
forward_heap2,
reverse_heap2,
s_v_middle,
v_t_middle,
packed_alternate_path);
raw_route_data.alt_source_traversed_in_reverse.push_back(( raw_route_data.alt_source_traversed_in_reverse.push_back((
packed_alternate_path.front() != phantom_node_pair.source_phantom.forward_node_id)); packed_alternate_path.front() != phantom_node_pair.source_phantom.forward_node_id));
@ -357,8 +338,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
(packed_alternate_path.back() != phantom_node_pair.target_phantom.forward_node_id)); (packed_alternate_path.back() != phantom_node_pair.target_phantom.forward_node_id));
// unpack the alternate path // unpack the alternate path
super::UnpackPath( super::UnpackPath(packed_alternate_path, phantom_node_pair,
packed_alternate_path, phantom_node_pair, raw_route_data.unpacked_alternative); raw_route_data.unpacked_alternative);
raw_route_data.alternative_path_length = length_of_via_path; raw_route_data.alternative_path_length = length_of_via_path;
} }
@ -384,8 +365,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
packed_path.pop_back(); // remove middle node. It's in both half-paths packed_path.pop_back(); // remove middle node. It's in both half-paths
// fetch patched path [v,t] // fetch patched path [v,t]
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(forward_heap2, reverse_heap1, v_t_middle,
forward_heap2, reverse_heap1, v_t_middle, packed_v_t_path); packed_v_t_path);
packed_path.insert(packed_path.end(), packed_v_t_path.begin(), packed_v_t_path.end()); packed_path.insert(packed_path.end(), packed_v_t_path.begin(), packed_v_t_path.end());
} }
@ -420,12 +401,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
// compute path <s,..,v> by reusing forward search from s // compute path <s,..,v> by reusing forward search from s
while (!new_reverse_heap.Empty()) while (!new_reverse_heap.Empty())
{ {
super::RoutingStep(new_reverse_heap, super::RoutingStep(new_reverse_heap, existing_forward_heap, &s_v_middle,
existing_forward_heap, &upper_bound_s_v_path_length, min_edge_offset, false);
&s_v_middle,
&upper_bound_s_v_path_length,
min_edge_offset,
false);
} }
// compute path <v,..,t> by reusing backward search from node t // compute path <v,..,t> by reusing backward search from node t
NodeID v_t_middle = SPECIAL_NODEID; NodeID v_t_middle = SPECIAL_NODEID;
@ -433,12 +410,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
new_forward_heap.Insert(via_node, 0, via_node); new_forward_heap.Insert(via_node, 0, via_node);
while (!new_forward_heap.Empty()) while (!new_forward_heap.Empty())
{ {
super::RoutingStep(new_forward_heap, super::RoutingStep(new_forward_heap, existing_reverse_heap, &v_t_middle,
existing_reverse_heap, &upper_bound_of_v_t_path_length, min_edge_offset, true);
&v_t_middle,
&upper_bound_of_v_t_path_length,
min_edge_offset,
true);
} }
*real_length_of_via_path = upper_bound_s_v_path_length + upper_bound_of_v_t_path_length; *real_length_of_via_path = upper_bound_s_v_path_length + upper_bound_of_v_t_path_length;
@ -448,10 +421,10 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
} }
// retrieve packed paths // retrieve packed paths
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(existing_forward_heap, new_reverse_heap, s_v_middle,
existing_forward_heap, new_reverse_heap, s_v_middle, packed_s_v_path); packed_s_v_path);
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(new_forward_heap, existing_reverse_heap, v_t_middle,
new_forward_heap, existing_reverse_heap, v_t_middle, packed_v_t_path); packed_v_t_path);
// partial unpacking, compute sharing // partial unpacking, compute sharing
// First partially unpack s-->v until paths deviate, note length of common path. // First partially unpack s-->v until paths deviate, note length of common path.
@ -484,12 +457,11 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
const int64_t packed_path_length = const int64_t packed_path_length =
std::min(partially_unpacked_via_path.size(), partially_unpacked_shortest_path.size()) - std::min(partially_unpacked_via_path.size(), partially_unpacked_shortest_path.size()) -
1; 1;
for (int64_t current_node = 0; for (int64_t current_node = 0; (current_node < packed_path_length) &&
(current_node < packed_path_length) && (partially_unpacked_via_path[current_node] ==
(partially_unpacked_via_path[current_node] == partially_unpacked_shortest_path[current_node] &&
partially_unpacked_shortest_path[current_node] && partially_unpacked_via_path[current_node + 1] ==
partially_unpacked_via_path[current_node + 1] == partially_unpacked_shortest_path[current_node + 1]);
partially_unpacked_shortest_path[current_node + 1]);
++current_node) ++current_node)
{ {
EdgeID selected_edge = EdgeID selected_edge =
@ -517,8 +489,7 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
if (packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) if (packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index])
{ {
super::UnpackEdge(packed_v_t_path[via_path_index - 1], super::UnpackEdge(packed_v_t_path[via_path_index - 1],
packed_v_t_path[via_path_index], packed_v_t_path[via_path_index], partially_unpacked_via_path);
partially_unpacked_via_path);
super::UnpackEdge(packed_shortest_path[shortest_path_index - 1], super::UnpackEdge(packed_shortest_path[shortest_path_index - 1],
packed_shortest_path[shortest_path_index], packed_shortest_path[shortest_path_index],
partially_unpacked_shortest_path); partially_unpacked_shortest_path);
@ -696,12 +667,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
new_reverse_heap.Insert(candidate.node, 0, candidate.node); new_reverse_heap.Insert(candidate.node, 0, candidate.node);
while (new_reverse_heap.Size() > 0) while (new_reverse_heap.Size() > 0)
{ {
super::RoutingStep(new_reverse_heap, super::RoutingStep(new_reverse_heap, existing_forward_heap, s_v_middle,
existing_forward_heap, &upper_bound_s_v_path_length, min_edge_offset, false);
s_v_middle,
&upper_bound_s_v_path_length,
min_edge_offset,
false);
} }
if (INVALID_EDGE_WEIGHT == upper_bound_s_v_path_length) if (INVALID_EDGE_WEIGHT == upper_bound_s_v_path_length)
@ -715,12 +682,8 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
new_forward_heap.Insert(candidate.node, 0, candidate.node); new_forward_heap.Insert(candidate.node, 0, candidate.node);
while (new_forward_heap.Size() > 0) while (new_forward_heap.Size() > 0)
{ {
super::RoutingStep(new_forward_heap, super::RoutingStep(new_forward_heap, existing_reverse_heap, v_t_middle,
existing_reverse_heap, &upper_bound_of_v_t_path_length, min_edge_offset, true);
v_t_middle,
&upper_bound_of_v_t_path_length,
min_edge_offset,
true);
} }
if (INVALID_EDGE_WEIGHT == upper_bound_of_v_t_path_length) if (INVALID_EDGE_WEIGHT == upper_bound_of_v_t_path_length)
@ -731,11 +694,11 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
*length_of_via_path = upper_bound_s_v_path_length + upper_bound_of_v_t_path_length; *length_of_via_path = upper_bound_s_v_path_length + upper_bound_of_v_t_path_length;
// retrieve packed paths // retrieve packed paths
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(existing_forward_heap, new_reverse_heap, *s_v_middle,
existing_forward_heap, new_reverse_heap, *s_v_middle, packed_s_v_path); packed_s_v_path);
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(new_forward_heap, existing_reverse_heap, *v_t_middle,
new_forward_heap, existing_reverse_heap, *v_t_middle, packed_v_t_path); packed_v_t_path);
NodeID s_P = *s_v_middle, t_P = *v_t_middle; NodeID s_P = *s_v_middle, t_P = *v_t_middle;
if (SPECIAL_NODEID == s_P) if (SPECIAL_NODEID == s_P)
@ -815,8 +778,7 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
// Traverse path s-->v // Traverse path s-->v
BOOST_ASSERT(!packed_v_t_path.empty()); BOOST_ASSERT(!packed_v_t_path.empty());
for (unsigned i = 0, packed_path_length = static_cast<unsigned>(packed_v_t_path.size() - 1); for (unsigned i = 0, packed_path_length = static_cast<unsigned>(packed_v_t_path.size() - 1);
(i < packed_path_length) && unpack_stack.empty(); (i < packed_path_length) && unpack_stack.empty(); ++i)
++i)
{ {
const EdgeID edgeID = const EdgeID edgeID =
facade->FindEdgeInEitherDirection(packed_v_t_path[i], packed_v_t_path[i + 1]); facade->FindEdgeInEitherDirection(packed_v_t_path[i], packed_v_t_path[i + 1]);
@ -888,13 +850,13 @@ template <class DataFacadeT> class AlternativeRouting final : private BasicRouti
{ {
if (!forward_heap3.Empty()) if (!forward_heap3.Empty())
{ {
super::RoutingStep( super::RoutingStep(forward_heap3, reverse_heap3, &middle, &upper_bound,
forward_heap3, reverse_heap3, &middle, &upper_bound, min_edge_offset, true); min_edge_offset, true);
} }
if (!reverse_heap3.Empty()) if (!reverse_heap3.Empty())
{ {
super::RoutingStep( super::RoutingStep(reverse_heap3, forward_heap3, &middle, &upper_bound,
reverse_heap3, forward_heap3, &middle, &upper_bound, min_edge_offset, false); min_edge_offset, false);
} }
} }
return (upper_bound <= t_test_path_length); return (upper_bound <= t_test_path_length);

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/internal_route_result.hpp" #include "../data_structures/internal_route_result.hpp"
#include "../data_structures/search_engine_data.hpp" #include "../data_structures/search_engine_data.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
// #include "../Util/simple_logger.hpp" // #include "../util/simple_logger.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -56,7 +56,7 @@ template <class DataFacadeT> class BasicRoutingInterface
BasicRoutingInterface() = delete; BasicRoutingInterface() = delete;
BasicRoutingInterface(const BasicRoutingInterface &) = delete; BasicRoutingInterface(const BasicRoutingInterface &) = delete;
explicit BasicRoutingInterface(DataFacadeT *facade) : facade(facade) {} explicit BasicRoutingInterface(DataFacadeT *facade) : facade(facade) {}
virtual ~BasicRoutingInterface() {}; virtual ~BasicRoutingInterface(){};
inline void RoutingStep(SearchEngineData::QueryHeap &forward_heap, inline void RoutingStep(SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &reverse_heap,
@ -69,7 +69,8 @@ template <class DataFacadeT> class BasicRoutingInterface
const int distance = forward_heap.GetKey(node); const int distance = forward_heap.GetKey(node);
// const NodeID parentnode = forward_heap.GetData(node).parent; // const NodeID parentnode = forward_heap.GetData(node).parent;
// SimpleLogger().Write() << (forward_direction ? "[fwd] " : "[rev] ") << "settled edge (" << parentnode << "," << node << "), dist: " << distance; // SimpleLogger().Write() << (forward_direction ? "[fwd] " : "[rev] ") << "settled edge ("
// << parentnode << "," << node << "), dist: " << distance;
if (reverse_heap.WasInserted(node)) if (reverse_heap.WasInserted(node))
{ {
@ -80,9 +81,11 @@ template <class DataFacadeT> class BasicRoutingInterface
{ {
*middle_node_id = node; *middle_node_id = node;
*upper_bound = new_distance; *upper_bound = new_distance;
// SimpleLogger().Write() << "accepted middle node " << node << " at distance " << new_distance; // SimpleLogger().Write() << "accepted middle node " << node << " at
// } else { // distance " << new_distance;
// SimpleLogger().Write() << "discared middle node " << node << " at distance " << new_distance; // } else {
// SimpleLogger().Write() << "discared middle node " << node << " at
// distance " << new_distance;
} }
} }
} }
@ -228,15 +231,11 @@ template <class DataFacadeT> class BasicRoutingInterface
const TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); const TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id);
const TravelMode travel_mode = facade->GetTravelModeForEdgeID(ed.id); const TravelMode travel_mode = facade->GetTravelModeForEdgeID(ed.id);
if (!facade->EdgeIsCompressed(ed.id)) if (!facade->EdgeIsCompressed(ed.id))
{ {
BOOST_ASSERT(!facade->EdgeIsCompressed(ed.id)); BOOST_ASSERT(!facade->EdgeIsCompressed(ed.id));
unpacked_path.emplace_back(facade->GetGeometryIndexForEdgeID(ed.id), unpacked_path.emplace_back(facade->GetGeometryIndexForEdgeID(ed.id), name_index,
name_index, turn_instruction, ed.distance, travel_mode);
turn_instruction,
ed.distance,
travel_mode);
} }
else else
{ {
@ -257,7 +256,8 @@ template <class DataFacadeT> class BasicRoutingInterface
BOOST_ASSERT(start_index <= end_index); BOOST_ASSERT(start_index <= end_index);
for (std::size_t i = start_index; i < end_index; ++i) for (std::size_t i = start_index; i < end_index; ++i)
{ {
unpacked_path.emplace_back(id_vector[i], name_index, TurnInstruction::NoTurn, 0, travel_mode); unpacked_path.emplace_back(id_vector[i], name_index,
TurnInstruction::NoTurn, 0, travel_mode);
} }
unpacked_path.back().turn_instruction = turn_instruction; unpacked_path.back().turn_instruction = turn_instruction;
unpacked_path.back().segment_duration = ed.distance; unpacked_path.back().segment_duration = ed.distance;
@ -294,18 +294,19 @@ template <class DataFacadeT> class BasicRoutingInterface
if (start_index > end_index) if (start_index > end_index)
{ {
start_index = std::min(start_index, id_vector.size()-1); start_index = std::min(start_index, id_vector.size() - 1);
} }
for (std::size_t i = start_index; i != end_index; (start_index < end_index ? ++i : --i)) for (std::size_t i = start_index; i != end_index; (start_index < end_index ? ++i : --i))
{ {
BOOST_ASSERT(i < id_vector.size()); BOOST_ASSERT(i < id_vector.size());
BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode>0 ); BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0);
unpacked_path.emplace_back(PathData{id_vector[i], unpacked_path.emplace_back(
phantom_node_pair.target_phantom.name_id, PathData{id_vector[i],
TurnInstruction::NoTurn, phantom_node_pair.target_phantom.name_id,
0, TurnInstruction::NoTurn,
phantom_node_pair.target_phantom.forward_travel_mode}); 0,
phantom_node_pair.target_phantom.forward_travel_mode});
} }
} }
@ -367,7 +368,8 @@ template <class DataFacadeT> class BasicRoutingInterface
} }
} }
} }
BOOST_ASSERT_MSG(edge_weight != std::numeric_limits<EdgeWeight>::max(), "edge weight invalid"); BOOST_ASSERT_MSG(edge_weight != std::numeric_limits<EdgeWeight>::max(),
"edge weight invalid");
const EdgeData &ed = facade->GetEdgeData(smaller_edge_id); const EdgeData &ed = facade->GetEdgeData(smaller_edge_id);
if (ed.shortcut) if (ed.shortcut)

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -32,10 +32,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "routing_base.hpp" #include "routing_base.hpp"
#include "../data_structures/search_engine_data.hpp" #include "../data_structures/search_engine_data.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../typedefs.h" #include "../typedefs.h"
template <class DataFacadeT> class ShortestPathRouting final : public BasicRoutingInterface<DataFacadeT> template <class DataFacadeT>
class ShortestPathRouting final : public BasicRoutingInterface<DataFacadeT>
{ {
using super = BasicRoutingInterface<DataFacadeT>; using super = BasicRoutingInterface<DataFacadeT>;
using QueryHeap = SearchEngineData::QueryHeap; using QueryHeap = SearchEngineData::QueryHeap;
@ -88,7 +89,8 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
middle1 = SPECIAL_NODEID; middle1 = SPECIAL_NODEID;
middle2 = SPECIAL_NODEID; middle2 = SPECIAL_NODEID;
const bool allow_u_turn = current_leg > 0 && uturn_indicators.size() > current_leg && uturn_indicators[current_leg-1]; const bool allow_u_turn = current_leg > 0 && uturn_indicators.size() > current_leg &&
uturn_indicators[current_leg - 1];
EdgeWeight min_edge_offset = 0; EdgeWeight min_edge_offset = 0;
// insert new starting nodes into forward heap, adjusted by previous distances. // insert new starting nodes into forward heap, adjusted by previous distances.
@ -97,35 +99,58 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
{ {
forward_heap1.Insert( forward_heap1.Insert(
phantom_node_pair.source_phantom.forward_node_id, phantom_node_pair.source_phantom.forward_node_id,
(allow_u_turn ? 0 : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), (allow_u_turn ? 0 : distance1) -
phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(),
phantom_node_pair.source_phantom.forward_node_id); phantom_node_pair.source_phantom.forward_node_id);
min_edge_offset = std::min(min_edge_offset, (allow_u_turn ? 0 : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset()); min_edge_offset =
// SimpleLogger().Write(logDEBUG) << "fwd-a2 insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << (allow_u_turn ? 0 : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); std::min(min_edge_offset,
(allow_u_turn ? 0 : distance1) -
phantom_node_pair.source_phantom.GetForwardWeightPlusOffset());
// SimpleLogger().Write(logDEBUG) << "fwd-a2 insert: " <<
// phantom_node_pair.source_phantom.forward_node_id << ", w: " << (allow_u_turn ? 0
// : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset();
forward_heap2.Insert( forward_heap2.Insert(
phantom_node_pair.source_phantom.forward_node_id, phantom_node_pair.source_phantom.forward_node_id,
(allow_u_turn ? 0 : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), (allow_u_turn ? 0 : distance1) -
phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(),
phantom_node_pair.source_phantom.forward_node_id); phantom_node_pair.source_phantom.forward_node_id);
min_edge_offset = std::min(min_edge_offset, (allow_u_turn ? 0 : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset()); min_edge_offset =
// SimpleLogger().Write(logDEBUG) << "fwd-b2 insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << (allow_u_turn ? 0 : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); std::min(min_edge_offset,
(allow_u_turn ? 0 : distance1) -
phantom_node_pair.source_phantom.GetForwardWeightPlusOffset());
// SimpleLogger().Write(logDEBUG) << "fwd-b2 insert: " <<
// phantom_node_pair.source_phantom.forward_node_id << ", w: " << (allow_u_turn ? 0
// : distance1) - phantom_node_pair.source_phantom.GetForwardWeightPlusOffset();
} }
if ((allow_u_turn || search_from_2nd_node) && if ((allow_u_turn || search_from_2nd_node) &&
phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID) phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID)
{ {
forward_heap1.Insert( forward_heap1.Insert(
phantom_node_pair.source_phantom.reverse_node_id, phantom_node_pair.source_phantom.reverse_node_id,
(allow_u_turn ? 0 : distance2) - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), (allow_u_turn ? 0 : distance2) -
phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(),
phantom_node_pair.source_phantom.reverse_node_id); phantom_node_pair.source_phantom.reverse_node_id);
min_edge_offset = std::min(min_edge_offset, (allow_u_turn ? 0 : distance2) - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset()); min_edge_offset =
// SimpleLogger().Write(logDEBUG) << "fwd-a2 insert: " << phantom_node_pair.source_phantom.reverse_node_id << std::min(min_edge_offset,
// ", w: " << (allow_u_turn ? 0 : distance2) - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); (allow_u_turn ? 0 : distance2) -
phantom_node_pair.source_phantom.GetReverseWeightPlusOffset());
// SimpleLogger().Write(logDEBUG) << "fwd-a2 insert: " <<
// phantom_node_pair.source_phantom.reverse_node_id <<
// ", w: " << (allow_u_turn ? 0 : distance2) -
// phantom_node_pair.source_phantom.GetReverseWeightPlusOffset();
forward_heap2.Insert( forward_heap2.Insert(
phantom_node_pair.source_phantom.reverse_node_id, phantom_node_pair.source_phantom.reverse_node_id,
(allow_u_turn ? 0 : distance2) - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), (allow_u_turn ? 0 : distance2) -
phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(),
phantom_node_pair.source_phantom.reverse_node_id); phantom_node_pair.source_phantom.reverse_node_id);
min_edge_offset = std::min(min_edge_offset, (allow_u_turn ? 0 : distance2) - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset()); min_edge_offset =
// SimpleLogger().Write(logDEBUG) << "fwd-b2 insert: " << phantom_node_pair.source_phantom.reverse_node_id << std::min(min_edge_offset,
// ", w: " << (allow_u_turn ? 0 : distance2) - phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); (allow_u_turn ? 0 : distance2) -
phantom_node_pair.source_phantom.GetReverseWeightPlusOffset());
// SimpleLogger().Write(logDEBUG) << "fwd-b2 insert: " <<
// phantom_node_pair.source_phantom.reverse_node_id <<
// ", w: " << (allow_u_turn ? 0 : distance2) -
// phantom_node_pair.source_phantom.GetReverseWeightPlusOffset();
} }
// insert new backward nodes into backward heap, unadjusted. // insert new backward nodes into backward heap, unadjusted.
@ -134,17 +159,21 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
reverse_heap1.Insert(phantom_node_pair.target_phantom.forward_node_id, reverse_heap1.Insert(phantom_node_pair.target_phantom.forward_node_id,
phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(), phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(),
phantom_node_pair.target_phantom.forward_node_id); phantom_node_pair.target_phantom.forward_node_id);
// SimpleLogger().Write(logDEBUG) << "rev-a insert: " << phantom_node_pair.target_phantom.forward_node_id << // SimpleLogger().Write(logDEBUG) << "rev-a insert: " <<
// ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); // phantom_node_pair.target_phantom.forward_node_id <<
} // ", w: " <<
// phantom_node_pair.target_phantom.GetForwardWeightPlusOffset();
}
if (phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID) if (phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID)
{ {
reverse_heap2.Insert(phantom_node_pair.target_phantom.reverse_node_id, reverse_heap2.Insert(phantom_node_pair.target_phantom.reverse_node_id,
phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(), phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(),
phantom_node_pair.target_phantom.reverse_node_id); phantom_node_pair.target_phantom.reverse_node_id);
// SimpleLogger().Write(logDEBUG) << "rev-a insert: " << phantom_node_pair.target_phantom.reverse_node_id << // SimpleLogger().Write(logDEBUG) << "rev-a insert: " <<
// ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); // phantom_node_pair.target_phantom.reverse_node_id <<
// ", w: " <<
// phantom_node_pair.target_phantom.GetReverseWeightPlusOffset();
} }
// run two-Target Dijkstra routing step. // run two-Target Dijkstra routing step.
@ -152,13 +181,13 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
{ {
if (!forward_heap1.Empty()) if (!forward_heap1.Empty())
{ {
super::RoutingStep( super::RoutingStep(forward_heap1, reverse_heap1, &middle1, &local_upper_bound1,
forward_heap1, reverse_heap1, &middle1, &local_upper_bound1, min_edge_offset, true); min_edge_offset, true);
} }
if (!reverse_heap1.Empty()) if (!reverse_heap1.Empty())
{ {
super::RoutingStep( super::RoutingStep(reverse_heap1, forward_heap1, &middle1, &local_upper_bound1,
reverse_heap1, forward_heap1, &middle1, &local_upper_bound1, min_edge_offset, false); min_edge_offset, false);
} }
} }
@ -168,13 +197,13 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
{ {
if (!forward_heap2.Empty()) if (!forward_heap2.Empty())
{ {
super::RoutingStep( super::RoutingStep(forward_heap2, reverse_heap2, &middle2,
forward_heap2, reverse_heap2, &middle2, &local_upper_bound2, min_edge_offset, true); &local_upper_bound2, min_edge_offset, true);
} }
if (!reverse_heap2.Empty()) if (!reverse_heap2.Empty())
{ {
super::RoutingStep( super::RoutingStep(reverse_heap2, forward_heap2, &middle2,
reverse_heap2, forward_heap2, &middle2, &local_upper_bound2, min_edge_offset, false); &local_upper_bound2, min_edge_offset, false);
} }
} }
} }
@ -200,7 +229,8 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
} }
// Was at most one of the two paths not found? // Was at most one of the two paths not found?
BOOST_ASSERT_MSG((INVALID_EDGE_WEIGHT != distance1 || INVALID_EDGE_WEIGHT != distance2), "no path found"); BOOST_ASSERT_MSG((INVALID_EDGE_WEIGHT != distance1 || INVALID_EDGE_WEIGHT != distance2),
"no path found");
// Unpack paths if they exist // Unpack paths if they exist
std::vector<NodeID> temporary_packed_leg1; std::vector<NodeID> temporary_packed_leg1;
@ -211,18 +241,19 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
if (INVALID_EDGE_WEIGHT != local_upper_bound1) if (INVALID_EDGE_WEIGHT != local_upper_bound1)
{ {
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(forward_heap1, reverse_heap1, middle1,
forward_heap1, reverse_heap1, middle1, temporary_packed_leg1); temporary_packed_leg1);
} }
if (INVALID_EDGE_WEIGHT != local_upper_bound2) if (INVALID_EDGE_WEIGHT != local_upper_bound2)
{ {
super::RetrievePackedPathFromHeap( super::RetrievePackedPathFromHeap(forward_heap2, reverse_heap2, middle2,
forward_heap2, reverse_heap2, middle2, temporary_packed_leg2); temporary_packed_leg2);
} }
// if one of the paths was not found, replace it with the other one. // if one of the paths was not found, replace it with the other one.
if ((allow_u_turn && local_upper_bound1 > local_upper_bound2) || temporary_packed_leg1.empty()) if ((allow_u_turn && local_upper_bound1 > local_upper_bound2) ||
temporary_packed_leg1.empty())
{ {
temporary_packed_leg1.clear(); temporary_packed_leg1.clear();
temporary_packed_leg1.insert(temporary_packed_leg1.end(), temporary_packed_leg1.insert(temporary_packed_leg1.end(),
@ -230,7 +261,8 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
temporary_packed_leg2.end()); temporary_packed_leg2.end());
local_upper_bound1 = local_upper_bound2; local_upper_bound1 = local_upper_bound2;
} }
if ((allow_u_turn && local_upper_bound2 > local_upper_bound1) || temporary_packed_leg2.empty()) if ((allow_u_turn && local_upper_bound2 > local_upper_bound1) ||
temporary_packed_leg2.empty())
{ {
temporary_packed_leg2.clear(); temporary_packed_leg2.clear();
temporary_packed_leg2.insert(temporary_packed_leg2.end(), temporary_packed_leg2.insert(temporary_packed_leg2.end(),
@ -287,7 +319,8 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
temporary_packed_leg2.end()); temporary_packed_leg2.end());
BOOST_ASSERT(packed_legs2[current_leg].size() == temporary_packed_leg2.size()); BOOST_ASSERT(packed_legs2[current_leg].size() == temporary_packed_leg2.size());
if (!allow_u_turn && (packed_legs1[current_leg].back() == packed_legs2[current_leg].back()) && if (!allow_u_turn &&
(packed_legs1[current_leg].back() == packed_legs2[current_leg].back()) &&
phantom_node_pair.target_phantom.is_bidirected()) phantom_node_pair.target_phantom.is_bidirected())
{ {
const NodeID last_node_id = packed_legs2[current_leg].back(); const NodeID last_node_id = packed_legs2[current_leg].back();
@ -324,9 +357,11 @@ template <class DataFacadeT> class ShortestPathRouting final : public BasicRouti
raw_route_data.unpacked_path_segments[index]); raw_route_data.unpacked_path_segments[index]);
raw_route_data.source_traversed_in_reverse.push_back( raw_route_data.source_traversed_in_reverse.push_back(
(packed_legs1[index].front() != phantom_nodes_vector[index].source_phantom.forward_node_id)); (packed_legs1[index].front() !=
phantom_nodes_vector[index].source_phantom.forward_node_id));
raw_route_data.target_traversed_in_reverse.push_back( raw_route_data.target_traversed_in_reverse.push_back(
(packed_legs1[index].back() != phantom_nodes_vector[index].target_phantom.forward_node_id)); (packed_legs1[index].back() !=
phantom_nodes_vector[index].target_phantom.forward_node_id));
} }
raw_route_data.shortest_path_length = std::min(distance1, distance2); raw_route_data.shortest_path_length = std::min(distance1, distance2);
} }

View File

@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "reply.hpp" #include "reply.hpp"
#include "../../Util/cast.hpp" #include "../../util/cast.hpp"
namespace http namespace http
{ {

View File

@ -34,9 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/external_memory_node.hpp" #include "../../data_structures/external_memory_node.hpp"
#include "../../data_structures/phantom_node.hpp" #include "../../data_structures/phantom_node.hpp"
#include "../../data_structures/turn_instructions.hpp" #include "../../data_structures/turn_instructions.hpp"
#include "../../Util/integer_range.hpp" #include "../../util/integer_range.hpp"
#include "../../Util/osrm_exception.hpp" #include "../../util/osrm_exception.hpp"
#include "../../Util/string_util.hpp" #include "../../util/string_util.hpp"
#include "../../typedefs.h" #include "../../typedefs.h"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>

View File

@ -39,9 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/static_graph.hpp" #include "../../data_structures/static_graph.hpp"
#include "../../data_structures/static_rtree.hpp" #include "../../data_structures/static_rtree.hpp"
#include "../../data_structures/range_table.hpp" #include "../../data_structures/range_table.hpp"
#include "../../Util/boost_filesystem_2_fix.hpp" #include "../../util/boost_filesystem_2_fix.hpp"
#include "../../Util/graph_loader.hpp" #include "../../util/graph_loader.hpp"
#include "../../Util/simple_logger.hpp" #include "../../util/simple_logger.hpp"
#include <osrm/coordinate.hpp> #include <osrm/coordinate.hpp>
#include <osrm/server_paths.hpp> #include <osrm/server_paths.hpp>

View File

@ -36,9 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/range_table.hpp" #include "../../data_structures/range_table.hpp"
#include "../../data_structures/static_graph.hpp" #include "../../data_structures/static_graph.hpp"
#include "../../data_structures/static_rtree.hpp" #include "../../data_structures/static_rtree.hpp"
#include "../../Util/boost_filesystem_2_fix.hpp" #include "../../util/boost_filesystem_2_fix.hpp"
#include "../../Util/make_unique.hpp" #include "../../util/make_unique.hpp"
#include "../../Util/simple_logger.hpp" #include "../../util/simple_logger.hpp"
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>

View File

@ -28,8 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SHARED_DATA_TYPE_HPP #ifndef SHARED_DATA_TYPE_HPP
#define SHARED_DATA_TYPE_HPP #define SHARED_DATA_TYPE_HPP
#include "../../Util/osrm_exception.hpp" #include "../../util/osrm_exception.hpp"
#include "../../Util/simple_logger.hpp" #include "../../util/simple_logger.hpp"
#include <cstdint> #include <cstdint>

View File

@ -27,7 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "reply.hpp" #include "reply.hpp"
#include "../../Util/cast.hpp" #include "../../util/cast.hpp"
namespace http namespace http
{ {

View File

@ -32,10 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "http/request.hpp" #include "http/request.hpp"
#include "../library/osrm.hpp" #include "../library/osrm.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/string_util.hpp" #include "../util/string_util.hpp"
#include "../Util/xml_renderer.hpp" #include "../util/xml_renderer.hpp"
#include "../typedefs.h" #include "../typedefs.h"
#include <osrm/route_parameters.hpp> #include <osrm/route_parameters.hpp>

View File

@ -31,9 +31,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "connection.hpp" #include "connection.hpp"
#include "request_handler.hpp" #include "request_handler.hpp"
#include "../Util/cast.hpp" #include "../util/cast.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>

View File

@ -27,10 +27,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/percent.hpp" #include "../data_structures/percent.hpp"
#include "../data_structures/query_edge.hpp" #include "../data_structures/query_edge.hpp"
#include "../data_structures/static_graph.hpp" #include "../data_structures/static_graph.hpp"
#include "../Util/integer_range.hpp" #include "../util/integer_range.hpp"
#include "../Util/graph_loader.hpp" #include "../util/graph_loader.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -86,17 +86,17 @@ int main(int argc, char *argv[])
if (SPECIAL_EDGEID == edge_id_1) if (SPECIAL_EDGEID == edge_id_1)
{ {
throw osrm::exception("cannot find first segment of edge (" + throw osrm::exception("cannot find first segment of edge (" +
std::to_string(node_u) + "," + std::to_string(data.id) + std::to_string(node_u) + "," + std::to_string(data.id) +
"," + std::to_string(node_v) + "), eid: " + "," + std::to_string(node_v) + "), eid: " +
std::to_string(eid)); std::to_string(eid));
} }
const EdgeID edge_id_2 = m_query_graph->FindEdgeInEitherDirection(data.id, node_v); const EdgeID edge_id_2 = m_query_graph->FindEdgeInEitherDirection(data.id, node_v);
if (SPECIAL_EDGEID == edge_id_2) if (SPECIAL_EDGEID == edge_id_2)
{ {
throw osrm::exception("cannot find second segment of edge (" + throw osrm::exception("cannot find second segment of edge (" +
std::to_string(node_u) + "," + std::to_string(data.id) + std::to_string(node_u) + "," + std::to_string(data.id) +
"," + std::to_string(node_v) + "), eid: " + "," + std::to_string(node_v) + "), eid: " +
std::to_string(eid)); std::to_string(eid));
} }
} }
progress.printStatus(node_u); progress.printStatus(node_u);

View File

@ -29,15 +29,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../algorithms/tiny_components.hpp" #include "../algorithms/tiny_components.hpp"
#include "../data_structures/static_graph.hpp" #include "../data_structures/static_graph.hpp"
#include "../data_structures/coordinate_calculation.hpp" #include "../data_structures/coordinate_calculation.hpp"
#include "../Util/fingerprint.hpp" #include "../util/fingerprint.hpp"
#include "../Util/graph_loader.hpp" #include "../util/graph_loader.hpp"
#include "../Util/make_unique.hpp" #include "../util/make_unique.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#if defined(__APPLE__) || defined (_WIN32) #if defined(__APPLE__) || defined(_WIN32)
#include <gdal.h> #include <gdal.h>
#include <ogrsf_frmts.h> #include <ogrsf_frmts.h>
#else #else
@ -52,7 +52,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
#include <vector> #include <vector>
namespace { namespace
{
struct TarjanEdgeData struct TarjanEdgeData
{ {
@ -129,15 +130,11 @@ int main(int argc, char *argv[])
// load graph data // load graph data
std::vector<ImportEdge> edge_list; std::vector<ImportEdge> edge_list;
const NodeID number_of_nodes = readBinaryOSRMGraphFromStream(input_stream, const NodeID number_of_nodes =
edge_list, readBinaryOSRMGraphFromStream(input_stream, edge_list, bollard_node_list,
bollard_node_list, traffic_lights_list, &coordinate_list, restriction_list);
traffic_lights_list,
&coordinate_list,
restriction_list);
input_stream.close(); input_stream.close();
BOOST_ASSERT_MSG(restriction_list.size() == usable_restrictions, BOOST_ASSERT_MSG(restriction_list.size() == usable_restrictions,
"size of restriction_list changed"); "size of restriction_list changed");
@ -159,17 +156,15 @@ int main(int argc, char *argv[])
if (input_edge.forward) if (input_edge.forward)
{ {
graph_edge_list.emplace_back(input_edge.source, graph_edge_list.emplace_back(input_edge.source, input_edge.target,
input_edge.target, (std::max)((int)input_edge.weight, 1),
(std::max)((int)input_edge.weight, 1), input_edge.name_id);
input_edge.name_id);
} }
if (input_edge.backward) if (input_edge.backward)
{ {
graph_edge_list.emplace_back(input_edge.target, graph_edge_list.emplace_back(input_edge.target, input_edge.source,
input_edge.source, (std::max)((int)input_edge.weight, 1),
(std::max)((int)input_edge.weight, 1), input_edge.name_id);
input_edge.name_id);
} }
} }
edge_list.clear(); edge_list.clear();
@ -185,12 +180,11 @@ int main(int argc, char *argv[])
SimpleLogger().Write() << "Starting SCC graph traversal"; SimpleLogger().Write() << "Starting SCC graph traversal";
RestrictionMap restriction_map(restriction_list); RestrictionMap restriction_map(restriction_list);
auto tarjan = osrm::make_unique<TarjanSCC<TarjanGraph>>(graph, auto tarjan =
restriction_map, osrm::make_unique<TarjanSCC<TarjanGraph>>(graph, restriction_map, bollard_node_list);
bollard_node_list);
tarjan->run(); tarjan->run();
SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components() SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
<< " many components"; << " many components";
SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs"; SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs";
// output // output
@ -229,7 +223,8 @@ int main(int argc, char *argv[])
throw osrm::exception("Layer creation failed."); throw osrm::exception("Layer creation failed.");
} }
TIMER_STOP(SCC_RUN_SETUP); TIMER_STOP(SCC_RUN_SETUP);
SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP)/1000. << "s"; SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000.
<< "s";
uint64_t total_network_distance = 0; uint64_t total_network_distance = 0;
p.reinit(graph->GetNumberOfNodes()); p.reinit(graph->GetNumberOfNodes());
@ -245,18 +240,15 @@ int main(int argc, char *argv[])
{ {
total_network_distance += total_network_distance +=
100 * coordinate_calculation::euclidean_distance( 100 * coordinate_calculation::euclidean_distance(
coordinate_list[source].lat, coordinate_list[source].lat, coordinate_list[source].lon,
coordinate_list[source].lon, coordinate_list[target].lat, coordinate_list[target].lon);
coordinate_list[target].lat,
coordinate_list[target].lon);
BOOST_ASSERT(current_edge != SPECIAL_EDGEID); BOOST_ASSERT(current_edge != SPECIAL_EDGEID);
BOOST_ASSERT(source != SPECIAL_NODEID); BOOST_ASSERT(source != SPECIAL_NODEID);
BOOST_ASSERT(target != SPECIAL_NODEID); BOOST_ASSERT(target != SPECIAL_NODEID);
const unsigned size_of_containing_component = const unsigned size_of_containing_component = std::min(
std::min(tarjan->get_component_size(source), tarjan->get_component_size(source), tarjan->get_component_size(target));
tarjan->get_component_size(target));
// edges that end on bollard nodes may actually be in two distinct components // edges that end on bollard nodes may actually be in two distinct components
if (size_of_containing_component < 1000) if (size_of_containing_component < 1000)
@ -282,7 +274,8 @@ int main(int argc, char *argv[])
OGRSpatialReference::DestroySpatialReference(poSRS); OGRSpatialReference::DestroySpatialReference(poSRS);
OGRDataSource::DestroyDataSource(poDS); OGRDataSource::DestroyDataSource(poDS);
TIMER_STOP(SCC_OUTPUT); TIMER_STOP(SCC_OUTPUT);
SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT)/1000. << "s"; SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000.
<< "s";
SimpleLogger().Write() << "total network distance: " SimpleLogger().Write() << "total network distance: "
<< (uint64_t)total_network_distance / 100 / 1000. << " km"; << (uint64_t)total_network_distance / 100 / 1000. << " km";

View File

@ -25,10 +25,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/osrm_exception.hpp" #include "../util/osrm_exception.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../Util/timing_util.hpp" #include "../util/timing_util.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
@ -63,8 +63,8 @@ void RunStatistics(std::vector<double> &timings_vector, Statistics &stats)
double primary_sum = std::accumulate(timings_vector.begin(), timings_vector.end(), 0.0); double primary_sum = std::accumulate(timings_vector.begin(), timings_vector.end(), 0.0);
stats.mean = primary_sum / timings_vector.size(); stats.mean = primary_sum / timings_vector.size();
double primary_sq_sum = std::inner_product( double primary_sq_sum = std::inner_product(timings_vector.begin(), timings_vector.end(),
timings_vector.begin(), timings_vector.end(), timings_vector.begin(), 0.0); timings_vector.begin(), 0.0);
stats.dev = std::sqrt(primary_sq_sum / timings_vector.size() - (stats.mean * stats.mean)); stats.dev = std::sqrt(primary_sq_sum / timings_vector.size() - (stats.mean * stats.mean));
} }
@ -72,12 +72,12 @@ int main(int argc, char *argv[])
{ {
#ifdef __FreeBSD__ #ifdef __FreeBSD__
SimpleLogger().Write() << "Not supported on FreeBSD"; SimpleLogger().Write() << "Not supported on FreeBSD";
return 0; return 0;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
SimpleLogger().Write() << "Not supported on Windows"; SimpleLogger().Write() << "Not supported on Windows";
return 0; return 0;
#else #else
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
@ -206,7 +206,7 @@ int main(int argc, char *argv[])
std::uniform_int_distribution<unsigned> uniform_dist(0, number_of_blocks - 1); std::uniform_int_distribution<unsigned> uniform_dist(0, number_of_blocks - 1);
for (unsigned i = 0; i < 1000; ++i) for (unsigned i = 0; i < 1000; ++i)
{ {
unsigned block_to_read =uniform_dist(e1); unsigned block_to_read = uniform_dist(e1);
off_t current_offset = block_to_read * 4096; off_t current_offset = block_to_read * 4096;
TIMER_START(random_access); TIMER_START(random_access);
#ifdef __APPLE__ #ifdef __APPLE__

View File

@ -26,10 +26,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "../library/osrm.hpp" #include "../library/osrm.hpp"
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/json_renderer.hpp" #include "../util/json_renderer.hpp"
#include "../Util/routed_options.hpp" #include "../util/routed_options.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include <osrm/json_container.hpp> #include <osrm/json_container.hpp>
#include <osrm/libosrm_config.hpp> #include <osrm/libosrm_config.hpp>

View File

@ -29,8 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/shared_memory_factory.hpp" #include "../data_structures/shared_memory_factory.hpp"
#include "../server/data_structures/shared_datatype.hpp" #include "../server/data_structures/shared_datatype.hpp"
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
void delete_region(const SharedDataType region) void delete_region(const SharedDataType region)
{ {

View File

@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "../Util/git_sha.hpp" #include "../util/git_sha.hpp"
#include "../Util/simple_logger.hpp" #include "../util/simple_logger.hpp"
#include "../server/data_structures/shared_barriers.hpp" #include "../server/data_structures/shared_barriers.hpp"
#include <iostream> #include <iostream>

View File

@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../../data_structures/static_rtree.hpp" #include "../../data_structures/static_rtree.hpp"
#include "../../data_structures/query_node.hpp" #include "../../data_structures/query_node.hpp"
#include "../../data_structures/edge_based_node.hpp" #include "../../data_structures/edge_based_node.hpp"
#include "../../Util/floating_point.hpp" #include "../../util/floating_point.hpp"
#include "../../typedefs.h" #include "../../typedefs.h"
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>

65
util/bearing.cpp Normal file
View File

@ -0,0 +1,65 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bearing.hpp"
std::string bearing::get(const double heading)
{
if (heading <= 22.5)
{
return "N";
}
if (heading <= 67.5)
{
return "NE";
}
if (heading <= 112.5)
{
return "E";
}
if (heading <= 157.5)
{
return "SE";
}
if (heading <= 202.5)
{
return "S";
}
if (heading <= 247.5)
{
return "SW";
}
if (heading <= 292.5)
{
return "W";
}
if (heading <= 337.5)
{
return "NW";
}
return "N";
}

38
util/bearing.hpp Normal file
View File

@ -0,0 +1,38 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BEARING_HPP
#define BEARING_HPP
#include <string>
struct bearing
{
static std::string get(const double heading);
};
#endif // BEARING_HPP

View File

@ -0,0 +1,144 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BOOST_FILE_SYSTEM_FIX_H
#define BOOST_FILE_SYSTEM_FIX_H
#include "osrm_exception.hpp"
// #include <boost/any.hpp>
#include <boost/filesystem.hpp>
// #include <boost/program_options.hpp>
// This is one big workaround for latest boost renaming woes.
#if BOOST_FILESYSTEM_VERSION < 3
#warning Boost Installation with Filesystem3 missing, activating workaround
#include <cstdio>
#endif
namespace boost
{
namespace filesystem
{
// Validator for boost::filesystem::path, that verifies that the file
// exists. The validate() function must be defined in the same namespace
// as the target type, (boost::filesystem::path in this case), otherwise
// it is not called
// inline void validate(
// boost::any & v,
// const std::vector<std::string> & values,
// boost::filesystem::path *,
// int
// ) {
// boost::program_options::validators::check_first_occurrence(v);
// const std::string & input_string =
// boost::program_options::validators::get_single_string(values);
// if(boost::filesystem::is_regular_file(input_string)) {
// v = boost::any(boost::filesystem::path(input_string));
// } else {
// throw osrm::exception(input_string + " not found");
// }
// }
// adapted from:
// http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem
inline boost::filesystem::path
portable_canonical(const boost::filesystem::path &relative_path,
const boost::filesystem::path &current_path = boost::filesystem::current_path())
{
const boost::filesystem::path absolute_path =
boost::filesystem::absolute(relative_path, current_path);
boost::filesystem::path canonical_path;
for (auto path_iterator = absolute_path.begin(); path_iterator != absolute_path.end();
++path_iterator)
{
if (".." == path_iterator->string())
{
// /a/b/.. is not necessarily /a if b is a symbolic link
if (boost::filesystem::is_symlink(canonical_path))
{
canonical_path /= *path_iterator;
}
else if (".." == canonical_path.filename())
{
// /a/b/../.. is not /a/b/.. under most circumstances
// We can end up with ..s in our result because of symbolic links
canonical_path /= *path_iterator;
}
else
{
// Otherwise it should be safe to resolve the parent
canonical_path = canonical_path.parent_path();
}
}
else if ("." == path_iterator->string())
{
// Ignore
}
else
{
// Just cat other path entries
canonical_path /= *path_iterator;
}
}
BOOST_ASSERT(canonical_path.is_absolute());
BOOST_ASSERT(boost::filesystem::exists(canonical_path));
return canonical_path;
}
#if BOOST_FILESYSTEM_VERSION < 3
inline path temp_directory_path()
{
char *buffer;
buffer = tmpnam(nullptr);
return path(buffer);
}
inline path unique_path(const path &) { return temp_directory_path(); }
#endif
}
}
#ifndef BOOST_FILESYSTEM_VERSION
#define BOOST_FILESYSTEM_VERSION 3
#endif
inline void AssertPathExists(const boost::filesystem::path &path)
{
if (!boost::filesystem::is_regular_file(path))
{
throw osrm::exception(path.string() + " not found.");
}
}
#endif /* BOOST_FILE_SYSTEM_FIX_H */

185
util/cast.hpp Normal file
View File

@ -0,0 +1,185 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CAST_HPP
#define CAST_HPP
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/qi.hpp>
#include <string>
#include <type_traits>
struct cast
{
// convert scoped enums to integers
template <typename Enumeration>
static auto enum_to_underlying(Enumeration const value) ->
typename std::underlying_type<Enumeration>::type
{
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
}
template <typename Number>
static typename std::enable_if<std::is_integral<Number>::value, std::string>::type
integral_to_string(const Number value)
{
std::string output;
std::back_insert_iterator<std::string> sink(output);
if (8 == sizeof(Number))
{
boost::spirit::karma::generate(sink, boost::spirit::karma::long_long, value);
}
else
{
if (std::is_signed<Number>::value)
{
boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value);
}
else
{
boost::spirit::karma::generate(sink, boost::spirit::karma::uint_, value);
}
}
return output;
}
static int string_to_int(const std::string &input)
{
auto first_digit = input.begin();
// Delete any trailing white-spaces
while (first_digit != input.end() && std::isspace(*first_digit))
{
++first_digit;
}
int value = 0;
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::int_, value);
return value;
}
static unsigned string_to_uint(const std::string &input)
{
auto first_digit = input.begin();
// Delete any trailing white-spaces
while (first_digit != input.end() && (std::isspace(*first_digit) || '-' == *first_digit))
{
++first_digit;
}
unsigned value = 0;
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::uint_, value);
return value;
}
static uint64_t string_to_uint64(const std::string &input)
{
auto first_digit = input.begin();
// Delete any trailing white-spaces
while (first_digit != input.end() && std::isspace(*first_digit))
{
++first_digit;
}
uint64_t value = 0;
boost::spirit::qi::parse(first_digit, input.end(), boost::spirit::long_long, value);
return value;
}
// source: http://tinodidriksen.com/2011/05/28/cpp-convert-string-to-double-speed/
static double string_to_double(const char *p)
{
double r = 0.0;
bool neg = false;
if (*p == '-')
{
neg = true;
++p;
}
while (*p >= '0' && *p <= '9')
{
r = (r * 10.0) + (*p - '0');
++p;
}
if (*p == '.')
{
double f = 0.0;
int n = 0;
++p;
while (*p >= '0' && *p <= '9')
{
f = (f * 10.0) + (*p - '0');
++p;
++n;
}
r += f / std::pow(10.0, n);
}
if (neg)
{
r = -r;
}
return r;
}
template <typename T> struct scientific_policy : boost::spirit::karma::real_policies<T>
{
// we want the numbers always to be in fixed format
static int floatfield(T) { return boost::spirit::karma::real_policies<T>::fmtflags::fixed; }
static unsigned int precision(T) { return 6; }
};
typedef boost::spirit::karma::real_generator<double, scientific_policy<double>> science_type;
static std::string double_fixed_to_string(const double value)
{
std::string output;
std::back_insert_iterator<std::string> sink(output);
boost::spirit::karma::generate(sink, science_type(), value);
if (output.size() >= 2 && output[output.size() - 2] == '.' &&
output[output.size() - 1] == '0')
{
output.resize(output.size() - 2);
}
return output;
}
static std::string double_to_string(const double value)
{
std::string output;
std::back_insert_iterator<std::string> sink(output);
boost::spirit::karma::generate(sink, value);
return output;
}
static void double_with_two_digits_to_string(const double value, std::string &output)
{
// The largest 32-bit integer is 4294967295, that is 10 chars
// On the safe side, add 1 for sign, and 1 for trailing zero
char buffer[12];
sprintf(buffer, "%g", value);
output = buffer;
}
};
#endif // CAST_HPP

54
util/compute_angle.cpp Normal file
View File

@ -0,0 +1,54 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "compute_angle.hpp"
#include "trigonometry_table.hpp"
#include "../util/mercator.hpp"
#include <osrm/coordinate.hpp>
#include <cmath>
double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &first,
const FixedPointCoordinate &second,
const FixedPointCoordinate &third)
{
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION;
const double v1y = mercator::lat2y(first.lat / COORDINATE_PRECISION) -
mercator::lat2y(second.lat / COORDINATE_PRECISION);
const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION;
const double v2y = mercator::lat2y(third.lat / COORDINATE_PRECISION) -
mercator::lat2y(second.lat / COORDINATE_PRECISION);
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
while (angle < 0.)
{
angle += 360.;
}
return angle;
}

42
util/compute_angle.hpp Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COMPUTE_ANGLE_HPP
#define COMPUTE_ANGLE_HPP
struct FixedPointCoordinate;
struct ComputeAngle
{
// Get angle of line segment (A,C)->(C,B)
// atan2 magic, formerly cosine theorem
static double OfThreeFixedPointCoordinates(const FixedPointCoordinate &first,
const FixedPointCoordinate &second,
const FixedPointCoordinate &third);
};
#endif // COMPUTE_ANGLE_HPP

85
util/container.hpp Normal file
View File

@ -0,0 +1,85 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CONTAINER_HPP_
#define CONTAINER_HPP_
#include <algorithm>
#include <iterator>
#include <vector>
namespace osrm
{
template <typename T> void sort_unique_resize(std::vector<T> &vector)
{
std::sort(vector.begin(), vector.end());
const auto number_of_unique_elements =
std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements);
}
// template <typename T> inline void sort_unique_resize_shrink_vector(std::vector<T> &vector)
// {
// sort_unique_resize(vector);
// vector.shrink_to_fit();
// }
// template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T>
// &vector)
// {
// const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) -
// vector.begin();
// vector.resize(number_of_unique_elements);
// }
template <typename ForwardIterator, typename Function>
Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function function)
{
if (begin == end)
{
return function;
}
auto next = begin;
next = std::next(next);
while (next != end)
{
function(*begin, *next);
begin = std::next(begin);
next = std::next(next);
}
return function;
}
template <class ContainerT, typename Function>
Function for_each_pair(ContainerT &container, Function function)
{
return for_each_pair(std::begin(container), std::end(container), function);
}
}
#endif /* CONTAINER_HPP_ */

273
util/datastore_options.hpp Normal file
View File

@ -0,0 +1,273 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DATASTORE_OPTIONS_HPP
#define DATASTORE_OPTIONS_HPP
#include "boost_filesystem_2_fix.hpp"
#include "git_sha.hpp"
#include "ini_file.hpp"
#include "osrm_exception.hpp"
#include "simple_logger.hpp"
#include <osrm/server_paths.hpp>
#include <boost/any.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <string>
// generate boost::program_options object for the routing part
bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &paths)
{
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"springclean,s", "Remove all regions in shared memory")(
"config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])
->default_value("server.ini"),
"Path to a configuration file");
// declare a group of options that will be allowed both on command line
// as well as in a config file
boost::program_options::options_description config_options("Configuration");
config_options.add_options()(
"hsgrdata", boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
".hsgr file")("nodesdata",
boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
".nodes file")(
"edgesdata", boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
".edges file")("geometry",
boost::program_options::value<boost::filesystem::path>(&paths["geometry"]),
".geometry file")(
"ramindex", boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
".ramIndex file")(
"fileindex", boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
".fileIndex file")(
"namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
".names file")("timestamp",
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
".timestamp file");
// hidden options, will be allowed both on command line and in config
// file, but will not be shown to the user
boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()(
"base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
"base path to .osrm file");
// positional option
boost::program_options::positional_options_description positional_options;
positional_options.add("base", 1);
// combine above options for parsing
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(
boost::filesystem::basename(argv[0]) + " [<options>] <configuration>");
visible_options.add(generic_options).add(config_options);
// parse command line options
boost::program_options::variables_map option_variables;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
.options(cmdline_options)
.positional(positional_options)
.run(),
option_variables);
if (option_variables.count("version"))
{
SimpleLogger().Write() << g_GIT_DESCRIPTION;
return false;
}
if (option_variables.count("help"))
{
SimpleLogger().Write() << visible_options;
return false;
}
boost::program_options::notify(option_variables);
const bool parameter_present = (paths.find("hsgrdata") != paths.end() &&
!paths.find("hsgrdata")->second.string().empty()) ||
(paths.find("nodesdata") != paths.end() &&
!paths.find("nodesdata")->second.string().empty()) ||
(paths.find("edgesdata") != paths.end() &&
!paths.find("edgesdata")->second.string().empty()) ||
(paths.find("geometry") != paths.end() &&
!paths.find("geometry")->second.string().empty()) ||
(paths.find("ramindex") != paths.end() &&
!paths.find("ramindex")->second.string().empty()) ||
(paths.find("fileindex") != paths.end() &&
!paths.find("fileindex")->second.string().empty()) ||
(paths.find("timestamp") != paths.end() &&
!paths.find("timestamp")->second.string().empty());
if (parameter_present)
{
if ((paths.find("config") != paths.end() &&
boost::filesystem::is_regular_file(paths.find("config")->second)) ||
option_variables.count("base"))
{
SimpleLogger().Write(logWARNING) << "conflicting parameters";
SimpleLogger().Write() << visible_options;
return false;
}
}
// parse config file
ServerPaths::iterator path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
std::string ini_file_contents = read_file_lower_content(path_iterator->second);
std::stringstream config_stream(ini_file_contents);
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
}
else if (option_variables.count("base"))
{
path_iterator = paths.find("base");
BOOST_ASSERT(paths.end() != path_iterator);
std::string base_string = path_iterator->second.string();
path_iterator = paths.find("hsgrdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".hsgr";
}
path_iterator = paths.find("nodesdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".nodes";
}
path_iterator = paths.find("edgesdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".edges";
}
path_iterator = paths.find("geometry");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".geometry";
}
path_iterator = paths.find("ramindex");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".ramIndex";
}
path_iterator = paths.find("fileindex");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".fileIndex";
}
path_iterator = paths.find("namesdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".names";
}
path_iterator = paths.find("timestamp");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".timestamp";
}
}
path_iterator = paths.find("hsgrdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".hsgr file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("nodesdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".nodes file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("edgesdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".edges file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("geometry");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".geometry file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("ramindex");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".ramindex file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("fileindex");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".fileindex file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("namesdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".names file must be specified");
}
AssertPathExists(path_iterator->second);
path_iterator = paths.find("timestamp");
if (path_iterator == paths.end() || path_iterator->second.string().empty())
{
throw osrm::exception(".timestamp file must be specified");
}
return true;
}
#endif /* DATASTORE_OPTIONS_HPP */

103
util/fingerprint.cpp.in Normal file
View File

@ -0,0 +1,103 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "fingerprint.hpp"
#include "osrm_exception.hpp"
#include <boost/uuid/name_generator.hpp>
#include <algorithm>
#include <string>
#cmakedefine01 HAS64BITS
#cmakedefine MD5PREPARE "${MD5PREPARE}"
#cmakedefine MD5RTREE "${MD5RTREE}"
#cmakedefine MD5GRAPH "${MD5GRAPH}"
#cmakedefine MD5OBJECTS "${MD5OBJECTS}"
FingerPrint::FingerPrint() : magic_number(1297240911)
{
md5_prepare[32] = md5_tree[32] = md5_graph[32] = md5_objects[32] = '\0';
boost::uuids::name_generator gen(named_uuid);
std::string temp_string;
std::memcpy(md5_prepare, MD5PREPARE, strlen(MD5PREPARE));
temp_string += md5_prepare;
std::memcpy(md5_tree, MD5RTREE, 32);
temp_string += md5_tree;
std::memcpy(md5_graph, MD5GRAPH, 32);
temp_string += md5_graph;
std::memcpy(md5_objects, MD5OBJECTS, 32);
temp_string += md5_objects;
named_uuid = gen(temp_string);
has_64_bits = HAS64BITS;
}
FingerPrint::~FingerPrint() {}
const boost::uuids::uuid &FingerPrint::GetFingerPrint() const { return named_uuid; }
bool FingerPrint::IsMagicNumberOK() const { return 1297240911 == magic_number; }
bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
{
throw osrm::exception("hsgr input file misses magic number. Check or reprocess the file");
}
return std::equal(md5_graph, md5_graph + 32, other.md5_graph);
}
bool FingerPrint::TestPrepare(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
{
throw osrm::exception("osrm input file misses magic number. Check or reprocess the file");
}
return std::equal(md5_prepare, md5_prepare + 32, other.md5_prepare);
}
bool FingerPrint::TestRTree(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
{
throw osrm::exception("r-tree input file misses magic number. Check or reprocess the file");
}
return std::equal(md5_tree, md5_tree + 32, other.md5_tree);
}
bool FingerPrint::TestQueryObjects(const FingerPrint &other) const
{
if (!other.IsMagicNumberOK())
{
throw osrm::exception("missing magic number. Check or reprocess the file");
}
return std::equal(md5_objects, md5_objects + 32, other.md5_objects);
}

59
util/fingerprint.hpp Normal file
View File

@ -0,0 +1,59 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FINGERPRINT_H
#define FINGERPRINT_H
#include <boost/uuid/uuid.hpp>
// implements a singleton, i.e. there is one and only one conviguration object
class FingerPrint
{
public:
FingerPrint();
FingerPrint(const FingerPrint &) = delete;
~FingerPrint();
const boost::uuids::uuid &GetFingerPrint() const;
bool IsMagicNumberOK() const;
bool TestGraphUtil(const FingerPrint &other) const;
bool TestPrepare(const FingerPrint &other) const;
bool TestRTree(const FingerPrint &other) const;
bool TestQueryObjects(const FingerPrint &other) const;
private:
const unsigned magic_number;
char md5_prepare[33];
char md5_tree[33];
char md5_graph[33];
char md5_objects[33];
// initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
boost::uuids::uuid named_uuid;
bool has_64_bits;
};
#endif /* FingerPrint_H */

44
util/floating_point.hpp Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FLOATING_POINT_HPP
#define FLOATING_POINT_HPP
#include <cmath>
#include <limits>
#include <type_traits>
namespace osrm
{
template <typename FloatT> bool epsilon_compare(const FloatT number1, const FloatT number2)
{
static_assert(std::is_floating_point<FloatT>::value, "type must be floating point");
return (std::abs(number1 - number2) < std::numeric_limits<FloatT>::epsilon());
}
}
#endif // FLOATING_POINT_HPP

31
util/git_sha.cpp.in Normal file
View File

@ -0,0 +1,31 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "git_sha.hpp"
#define GIT_DESCRIPTION "${GIT_DESCRIPTION}"
char g_GIT_DESCRIPTION[] = GIT_DESCRIPTION;

33
util/git_sha.hpp Normal file
View File

@ -0,0 +1,33 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GIT_SHA_HPP
#define GIT_SHA_HPP
extern char g_GIT_DESCRIPTION[];
#endif // GIT_SHA_HPP

320
util/graph_loader.hpp Normal file
View File

@ -0,0 +1,320 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GRAPH_LOADER_HPP
#define GRAPH_LOADER_HPP
#include "fingerprint.hpp"
#include "osrm_exception.hpp"
#include "simple_logger.hpp"
#include "../data_structures/external_memory_node.hpp"
#include "../data_structures/import_edge.hpp"
#include "../data_structures/query_node.hpp"
#include "../data_structures/restriction.hpp"
#include "../typedefs.h"
#include <boost/assert.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <tbb/parallel_sort.h>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <vector>
template <typename EdgeT>
NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
std::vector<EdgeT> &edge_list,
std::vector<NodeID> &barrier_node_list,
std::vector<NodeID> &traffic_light_node_list,
std::vector<QueryNode> *int_to_ext_node_id_map,
std::vector<TurnRestriction> &restriction_list)
{
const FingerPrint fingerprint_orig;
FingerPrint fingerprint_loaded;
input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
{
SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
"Reprocess to get rid of this warning.";
}
std::unordered_map<NodeID, NodeID> ext_to_int_id_map;
NodeID n;
input_stream.read((char *)&n, sizeof(NodeID));
SimpleLogger().Write() << "Importing n = " << n << " nodes ";
ExternalMemoryNode current_node;
for (NodeID i = 0; i < n; ++i)
{
input_stream.read((char *)&current_node, sizeof(ExternalMemoryNode));
int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon,
current_node.node_id);
ext_to_int_id_map.emplace(current_node.node_id, i);
if (current_node.barrier)
{
barrier_node_list.emplace_back(i);
}
if (current_node.traffic_lights)
{
traffic_light_node_list.emplace_back(i);
}
}
// tighten vector sizes
barrier_node_list.shrink_to_fit();
traffic_light_node_list.shrink_to_fit();
// renumber nodes in turn restrictions
for (TurnRestriction &current_restriction : restriction_list)
{
auto internal_id_iter = ext_to_int_id_map.find(current_restriction.from.node);
if (internal_id_iter == ext_to_int_id_map.end())
{
SimpleLogger().Write(logDEBUG) << "Unmapped from node " << current_restriction.from.node
<< " of restriction";
continue;
}
current_restriction.from.node = internal_id_iter->second;
internal_id_iter = ext_to_int_id_map.find(current_restriction.via.node);
if (internal_id_iter == ext_to_int_id_map.end())
{
SimpleLogger().Write(logDEBUG) << "Unmapped via node " << current_restriction.via.node
<< " of restriction";
continue;
}
current_restriction.via.node = internal_id_iter->second;
internal_id_iter = ext_to_int_id_map.find(current_restriction.to.node);
if (internal_id_iter == ext_to_int_id_map.end())
{
SimpleLogger().Write(logDEBUG) << "Unmapped to node " << current_restriction.to.node
<< " of restriction";
continue;
}
current_restriction.to.node = internal_id_iter->second;
}
EdgeWeight weight;
NodeID source, target;
unsigned nameID;
int length;
short dir; // direction (0 = open, 1 = forward, 2+ = open)
bool is_roundabout, ignore_in_grid, is_access_restricted, is_split;
TravelMode travel_mode;
EdgeID m;
input_stream.read((char *)&m, sizeof(unsigned));
edge_list.reserve(m);
SimpleLogger().Write() << " and " << m << " edges ";
for (EdgeID i = 0; i < m; ++i)
{
input_stream.read((char *)&source, sizeof(unsigned));
input_stream.read((char *)&target, sizeof(unsigned));
input_stream.read((char *)&length, sizeof(int));
input_stream.read((char *)&dir, sizeof(short));
input_stream.read((char *)&weight, sizeof(int));
input_stream.read((char *)&nameID, sizeof(unsigned));
input_stream.read((char *)&is_roundabout, sizeof(bool));
input_stream.read((char *)&ignore_in_grid, sizeof(bool));
input_stream.read((char *)&is_access_restricted, sizeof(bool));
input_stream.read((char *)&travel_mode, sizeof(TravelMode));
input_stream.read((char *)&is_split, sizeof(bool));
BOOST_ASSERT_MSG(length > 0, "loaded null length edge");
BOOST_ASSERT_MSG(weight > 0, "loaded null weight");
BOOST_ASSERT_MSG(0 <= dir && dir <= 2, "loaded bogus direction");
bool forward = true;
bool backward = true;
if (1 == dir)
{
backward = false;
}
if (2 == dir)
{
forward = false;
}
// translate the external NodeIDs to internal IDs
auto internal_id_iter = ext_to_int_id_map.find(source);
if (ext_to_int_id_map.find(source) == ext_to_int_id_map.end())
{
#ifndef NDEBUG
SimpleLogger().Write(logWARNING) << " unresolved source NodeID: " << source;
#endif
continue;
}
source = internal_id_iter->second;
internal_id_iter = ext_to_int_id_map.find(target);
if (ext_to_int_id_map.find(target) == ext_to_int_id_map.end())
{
#ifndef NDEBUG
SimpleLogger().Write(logWARNING) << "unresolved target NodeID : " << target;
#endif
continue;
}
target = internal_id_iter->second;
BOOST_ASSERT_MSG(source != SPECIAL_NODEID && target != SPECIAL_NODEID,
"nonexisting source or target");
if (source > target)
{
std::swap(source, target);
std::swap(forward, backward);
}
edge_list.emplace_back(source, target, nameID, weight, forward, backward, is_roundabout,
ignore_in_grid, is_access_restricted, travel_mode, is_split);
}
ext_to_int_id_map.clear();
tbb::parallel_sort(edge_list.begin(), edge_list.end());
for (unsigned i = 1; i < edge_list.size(); ++i)
{
if ((edge_list[i - 1].target == edge_list[i].target) &&
(edge_list[i - 1].source == edge_list[i].source))
{
const bool edge_flags_equivalent = (edge_list[i - 1].forward == edge_list[i].forward) &&
(edge_list[i - 1].backward == edge_list[i].backward);
const bool edge_flags_are_superset1 =
(edge_list[i - 1].forward && edge_list[i - 1].backward) &&
(edge_list[i].forward != edge_list[i].backward);
const bool edge_flags_are_superset_2 =
(edge_list[i].forward && edge_list[i].backward) &&
(edge_list[i - 1].forward != edge_list[i - 1].backward);
if (edge_flags_equivalent)
{
edge_list[i].weight = std::min(edge_list[i - 1].weight, edge_list[i].weight);
edge_list[i - 1].source = SPECIAL_NODEID;
}
else if (edge_flags_are_superset1)
{
if (edge_list[i - 1].weight <= edge_list[i].weight)
{
// edge i-1 is smaller and goes in both directions. Throw away the other edge
edge_list[i].source = SPECIAL_NODEID;
}
else
{
// edge i-1 is open in both directions, but edge i is smaller in one direction.
// Close edge i-1 in this direction
edge_list[i - 1].forward = !edge_list[i].forward;
edge_list[i - 1].backward = !edge_list[i].backward;
}
}
else if (edge_flags_are_superset_2)
{
if (edge_list[i - 1].weight <= edge_list[i].weight)
{
// edge i-1 is smaller for one direction. edge i is open in both. close edge i
// in the other direction
edge_list[i].forward = !edge_list[i - 1].forward;
edge_list[i].backward = !edge_list[i - 1].backward;
}
else
{
// edge i is smaller and goes in both direction. Throw away edge i-1
edge_list[i - 1].source = SPECIAL_NODEID;
}
}
}
}
const auto new_end_iter =
std::remove_if(edge_list.begin(), edge_list.end(), [](const EdgeT &edge)
{
return edge.source == SPECIAL_NODEID || edge.target == SPECIAL_NODEID;
});
edge_list.erase(new_end_iter, edge_list.end()); // remove excess candidates.
edge_list.shrink_to_fit();
SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";
return n;
}
template <typename NodeT, typename EdgeT>
unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
std::vector<NodeT> &node_list,
std::vector<EdgeT> &edge_list,
unsigned *check_sum)
{
if (!boost::filesystem::exists(hsgr_file))
{
throw osrm::exception("hsgr file does not exist");
}
if (0 == boost::filesystem::file_size(hsgr_file))
{
throw osrm::exception("hsgr file is empty");
}
boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);
FingerPrint fingerprint_loaded, fingerprint_orig;
hsgr_input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
{
SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
"Reprocess to get rid of this warning.";
}
unsigned number_of_nodes = 0;
unsigned number_of_edges = 0;
hsgr_input_stream.read((char *)check_sum, sizeof(unsigned));
hsgr_input_stream.read((char *)&number_of_nodes, sizeof(unsigned));
BOOST_ASSERT_MSG(0 != number_of_nodes, "number of nodes is zero");
hsgr_input_stream.read((char *)&number_of_edges, sizeof(unsigned));
SimpleLogger().Write() << "number_of_nodes: " << number_of_nodes
<< ", number_of_edges: " << number_of_edges;
// BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero");
node_list.resize(number_of_nodes);
hsgr_input_stream.read((char *)&(node_list[0]), number_of_nodes * sizeof(NodeT));
edge_list.resize(number_of_edges);
if (number_of_edges > 0)
{
hsgr_input_stream.read((char *)&(edge_list[0]), number_of_edges * sizeof(EdgeT));
}
hsgr_input_stream.close();
return number_of_nodes;
}
#endif // GRAPH_LOADER_HPP

51
util/ini_file.hpp Normal file
View File

@ -0,0 +1,51 @@
/*
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef INI_FILE_HPP
#define INI_FILE_HPP
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <algorithm>
#include <string>
namespace
{
// support old capitalized option names by down-casing them with a regex replace
std::string read_file_lower_content(const boost::filesystem::path &path)
{
boost::filesystem::fstream config_stream(path);
std::string ini_file_content((std::istreambuf_iterator<char>(config_stream)),
std::istreambuf_iterator<char>());
std::transform(std::begin(ini_file_content), std::end(ini_file_content),
std::begin(ini_file_content), ::tolower);
return ini_file_content;
}
}
#endif // INI_FILE_HPP

70
util/integer_range.hpp Normal file
View File

@ -0,0 +1,70 @@
/*
Copyright (c) 2013,2014, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef INTEGER_RANGE_HPP
#define INTEGER_RANGE_HPP
#include <type_traits>
namespace osrm
{
template <typename Integer> class range
{
private:
Integer last;
Integer iter;
public:
range(Integer start, Integer end) : last(end), iter(start)
{
static_assert(std::is_integral<Integer>::value, "range type must be integral");
}
// Iterable functions
const range &begin() const { return *this; }
const range &end() const { return *this; }
Integer front() const { return iter; }
Integer back() const { return last - 1; }
// Iterator functions
bool operator!=(const range &) const { return iter < last; }
void operator++() { ++iter; }
Integer operator*() const { return iter; }
};
// convenience function to construct an integer range with type deduction
template <typename Integer>
range<Integer> irange(const Integer first,
const Integer last,
typename std::enable_if<std::is_integral<Integer>::value>::type * = 0)
{
return range<Integer>(first, last);
}
}
#endif // INTEGER_RANGE_HPP

72
util/iterator_range.hpp Normal file
View File

@ -0,0 +1,72 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RANGE_HPP_
#define RANGE_HPP_
namespace osrm
{
namespace util
{
template <typename Iterator> class Range
{
public:
Range(Iterator begin, Iterator end) : begin_(begin), end_(end) {}
Iterator begin() const { return begin_; }
Iterator end() const { return end_; }
private:
Iterator begin_;
Iterator end_;
};
// Convenience functions for template parameter inference,
// akin to std::make_pair.
template <typename Iterator> Range<Iterator> range(Iterator begin, Iterator end)
{
return Range<Iterator>(begin, end);
}
template <typename Reversable>
Range<typename Reversable::reverse_iterator> reverse(Reversable *reversable)
{
return Range<typename Reversable::reverse_iterator>(reversable->rbegin(), reversable->rend());
}
template <typename ConstReversable>
Range<typename ConstReversable::const_reverse_iterator>
const_reverse(const ConstReversable *const_reversable)
{
return Range<typename ConstReversable::const_reverse_iterator>(const_reversable->crbegin(),
const_reversable->crend());
}
}
}
#endif // RANGE_HPP_

184
util/json_renderer.hpp Normal file
View File

@ -0,0 +1,184 @@
/*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// based on
// https://svn.apache.org/repos/asf/mesos/tags/release-0.9.0-incubating-RC0/src/common/json.hpp
#ifndef JSON_RENDERER_HPP
#define JSON_RENDERER_HPP
#include "cast.hpp"
#include <osrm/json_container.hpp>
namespace JSON
{
struct Renderer : mapbox::util::static_visitor<>
{
explicit Renderer(std::ostream &_out) : out(_out) {}
void operator()(const String &string) const { out << "\"" << string.value << "\""; }
void operator()(const Number &number) const
{
out.precision(10);
out << number.value;
}
void operator()(const Object &object) const
{
out << "{";
auto iterator = object.values.begin();
while (iterator != object.values.end())
{
out << "\"" << (*iterator).first << "\":";
mapbox::util::apply_visitor(Renderer(out), (*iterator).second);
if (++iterator != object.values.end())
{
out << ",";
}
}
out << "}";
}
void operator()(const Array &array) const
{
out << "[";
std::vector<Value>::const_iterator iterator;
iterator = array.values.begin();
while (iterator != array.values.end())
{
mapbox::util::apply_visitor(Renderer(out), *iterator);
if (++iterator != array.values.end())
{
out << ",";
}
}
out << "]";
}
void operator()(const True &) const { out << "true"; }
void operator()(const False &) const { out << "false"; }
void operator()(const Null &) const { out << "null"; }
private:
std::ostream &out;
};
struct ArrayRenderer : mapbox::util::static_visitor<>
{
explicit ArrayRenderer(std::vector<char> &_out) : out(_out) {}
void operator()(const String &string) const
{
out.push_back('\"');
out.insert(out.end(), string.value.begin(), string.value.end());
out.push_back('\"');
}
void operator()(const Number &number) const
{
const std::string number_string = cast::double_fixed_to_string(number.value);
out.insert(out.end(), number_string.begin(), number_string.end());
}
void operator()(const Object &object) const
{
out.push_back('{');
auto iterator = object.values.begin();
while (iterator != object.values.end())
{
out.push_back('\"');
out.insert(out.end(), (*iterator).first.begin(), (*iterator).first.end());
out.push_back('\"');
out.push_back(':');
mapbox::util::apply_visitor(ArrayRenderer(out), (*iterator).second);
if (++iterator != object.values.end())
{
out.push_back(',');
}
}
out.push_back('}');
}
void operator()(const Array &array) const
{
out.push_back('[');
std::vector<Value>::const_iterator iterator;
iterator = array.values.begin();
while (iterator != array.values.end())
{
mapbox::util::apply_visitor(ArrayRenderer(out), *iterator);
if (++iterator != array.values.end())
{
out.push_back(',');
}
}
out.push_back(']');
}
void operator()(const True &) const
{
const std::string temp("true");
out.insert(out.end(), temp.begin(), temp.end());
}
void operator()(const False &) const
{
const std::string temp("false");
out.insert(out.end(), temp.begin(), temp.end());
}
void operator()(const Null &) const
{
const std::string temp("null");
out.insert(out.end(), temp.begin(), temp.end());
}
private:
std::vector<char> &out;
};
inline void render(std::ostream &out, const Object &object)
{
Value value = object;
mapbox::util::apply_visitor(Renderer(out), value);
}
inline void render(std::vector<char> &out, const Object &object)
{
Value value = object;
mapbox::util::apply_visitor(ArrayRenderer(out), value);
}
} // namespace JSON
#endif // JSON_RENDERER_HPP

66
util/lua_util.hpp Normal file
View File

@ -0,0 +1,66 @@
/*
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LUA_UTIL_HPP
#define LUA_UTIL_HPP
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <boost/filesystem/convenience.hpp>
#include <luabind/luabind.hpp>
#include <iostream>
#include <string>
template <typename T> void LUA_print(T output) { std::cout << "[LUA] " << output << std::endl; }
// Check if the lua function <name> is defined
inline bool lua_function_exists(lua_State *lua_state, const char *name)
{
luabind::object globals_table = luabind::globals(lua_state);
luabind::object lua_function = globals_table[name];
return lua_function && (luabind::type(lua_function) == LUA_TFUNCTION);
}
// Add the folder contain the script to the lua load path, so script can easily require() other lua
// scripts inside that folder, or subfolders.
// See http://lua-users.org/wiki/PackagePath for details on the package.path syntax.
inline void luaAddScriptFolderToLoadPath(lua_State *lua_state, const char *file_name)
{
const boost::filesystem::path profile_path(file_name);
std::string folder = profile_path.parent_path().string();
// TODO: This code is most probably not Windows safe since it uses UNIX'ish path delimiters
const std::string lua_code =
"package.path = \"" + folder + "/?.lua;profiles/?.lua;\" .. package.path";
luaL_dostring(lua_state, lua_code.c_str());
}
#endif // LUA_UTIL_HPP

57
util/make_unique.hpp Normal file
View File

@ -0,0 +1,57 @@
/*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MAKE_UNIQUE_H_
#define MAKE_UNIQUE_H_
#include <cstdlib>
#include <memory>
#include <type_traits>
namespace osrm
{
// Taken from http://msdn.microsoft.com/en-us/library/dn439780.asp
// Note, that the snippet was broken there and needed minor massaging
// make_unique<T>
template <class T, class... Types> std::unique_ptr<T> make_unique(Types &&... Args)
{
return (std::unique_ptr<T>(new T(std::forward<Types>(Args)...)));
}
// make_unique<T[]>
template <class T> std::unique_ptr<T[]> make_unique(std::size_t Size)
{
return (std::unique_ptr<T>(new T[Size]()));
}
// make_unique<T[N]> disallowed
template <class T, class... Types>
typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(Types &&...) = delete;
}
#endif // MAKE_UNIQUE_H_

Some files were not shown because too many files have changed in this diff Show More