Apply clang-format

This commit is contained in:
Patrick Niklaus
2016-01-05 12:04:04 +01:00
parent 552cdbfe20
commit 028ca5c9d9
84 changed files with 988 additions and 903 deletions
+87 -77
View File
@@ -130,15 +130,14 @@ class Contractor
};
public:
template <class ContainerT> Contractor(int nodes, ContainerT &input_edge_list)
: Contractor(nodes, input_edge_list, {}, {})
template <class ContainerT>
Contractor(int nodes, ContainerT &input_edge_list)
: Contractor(nodes, input_edge_list, {}, {})
{
}
template <class ContainerT>
Contractor(int nodes,
ContainerT &input_edge_list,
std::vector<float> &&node_levels_)
Contractor(int nodes, ContainerT &input_edge_list, std::vector<float> &&node_levels_)
: node_levels(std::move(node_levels_))
{
std::vector<ContractorEdge> edges;
@@ -317,8 +316,8 @@ class Contractor
std::cout << "initializing elimination PQ ..." << std::flush;
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(), end = range.end(); x != end; ++x)
@@ -360,7 +359,7 @@ class Contractor
for (const auto new_node_id : osrm::irange<std::size_t>(0, remaining_nodes.size()))
{
auto& node = remaining_nodes[new_node_id];
auto &node = remaining_nodes[new_node_id];
BOOST_ASSERT(node_priorities.size() > node.id);
new_node_priority[new_node_id] = node_priorities[node.id];
}
@@ -368,7 +367,7 @@ class Contractor
// build forward and backward renumbering map and remap ids in remaining_nodes
for (const auto new_node_id : osrm::irange<std::size_t>(0, remaining_nodes.size()))
{
auto& node = remaining_nodes[new_node_id];
auto &node = remaining_nodes[new_node_id];
// create renumbering maps in both directions
orig_node_id_from_new_node_id_map[new_node_id] = node.id;
new_node_id_from_orig_id_map[node.id] = new_node_id;
@@ -392,8 +391,7 @@ class Contractor
// node is not yet contracted.
// add (renumbered) outgoing edges to new DynamicGraph.
ContractorEdge new_edge = {new_node_id_from_orig_id_map[source],
new_node_id_from_orig_id_map[target],
data};
new_node_id_from_orig_id_map[target], data};
new_edge.data.is_original_via_node_ID = true;
BOOST_ASSERT_MSG(UINT_MAX != new_node_id_from_orig_id_map[source],
@@ -430,39 +428,44 @@ class Contractor
thread_data_list.number_of_nodes = contractor_graph->GetNumberOfNodes();
}
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, remaining_nodes.size(), IndependentGrainSize),
[this, &node_priorities, &remaining_nodes, &thread_data_list](
const tbb::blocked_range<std::size_t> &range)
{
ContractorThreadData *data = thread_data_list.getThreadData();
// determine independent node set
for (auto i = range.begin(), end = range.end(); i != end; ++i)
{
const NodeID node = remaining_nodes[i].id;
remaining_nodes[i].is_independent =
this->IsNodeIndependent(node_priorities, data, node);
}
});
tbb::parallel_for(
tbb::blocked_range<std::size_t>(0, remaining_nodes.size(), IndependentGrainSize),
[this, &node_priorities, &remaining_nodes,
&thread_data_list](const tbb::blocked_range<std::size_t> &range)
{
ContractorThreadData *data = thread_data_list.getThreadData();
// determine independent node set
for (auto i = range.begin(), end = range.end(); i != end; ++i)
{
const NodeID node = remaining_nodes[i].id;
remaining_nodes[i].is_independent =
this->IsNodeIndependent(node_priorities, data, node);
}
});
// sort all remaining nodes to the beginning of the sequence
const auto begin_independent_nodes = stable_partition(remaining_nodes.begin(), remaining_nodes.end(),
[](RemainingNodeData node_data)
{
return !node_data.is_independent;
});
auto begin_independent_nodes_idx = std::distance(remaining_nodes.begin(), begin_independent_nodes);
const auto begin_independent_nodes = stable_partition(
remaining_nodes.begin(), remaining_nodes.end(), [](RemainingNodeData node_data)
{
return !node_data.is_independent;
});
auto begin_independent_nodes_idx =
std::distance(remaining_nodes.begin(), begin_independent_nodes);
auto end_independent_nodes_idx = remaining_nodes.size();
if (!use_cached_node_priorities)
{
// write out contraction level
tbb::parallel_for(
tbb::blocked_range<std::size_t>(begin_independent_nodes_idx, end_independent_nodes_idx, ContractGrainSize),
[this, remaining_nodes, flushed_contractor, current_level](const tbb::blocked_range<std::size_t> &range)
tbb::blocked_range<std::size_t>(begin_independent_nodes_idx,
end_independent_nodes_idx, ContractGrainSize),
[this, remaining_nodes, flushed_contractor,
current_level](const tbb::blocked_range<std::size_t> &range)
{
if (flushed_contractor)
{
for (int position = range.begin(), end = range.end(); position != end; ++position)
for (int position = range.begin(), end = range.end(); position != end;
++position)
{
const NodeID x = remaining_nodes[position].id;
node_levels[orig_node_id_from_new_node_id_map[x]] = current_level;
@@ -470,7 +473,8 @@ class Contractor
}
else
{
for (int position = range.begin(), end = range.end(); position != end; ++position)
for (int position = range.begin(), end = range.end(); position != end;
++position)
{
const NodeID x = remaining_nodes[position].id;
node_levels[x] = current_level;
@@ -480,24 +484,29 @@ class Contractor
}
// contract independent nodes
tbb::parallel_for(
tbb::blocked_range<std::size_t>(begin_independent_nodes_idx, end_independent_nodes_idx, ContractGrainSize),
[this, &remaining_nodes, &thread_data_list](const tbb::blocked_range<std::size_t> &range)
{
ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(), end = range.end(); position != end; ++position)
{
const NodeID x = remaining_nodes[position].id;
this->ContractNode<false>(data, x);
}
});
tbb::parallel_for(tbb::blocked_range<std::size_t>(begin_independent_nodes_idx,
end_independent_nodes_idx,
ContractGrainSize),
[this, &remaining_nodes,
&thread_data_list](const tbb::blocked_range<std::size_t> &range)
{
ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(), end = range.end();
position != end; ++position)
{
const NodeID x = remaining_nodes[position].id;
this->ContractNode<false>(data, x);
}
});
tbb::parallel_for(
tbb::blocked_range<int>(begin_independent_nodes_idx, end_independent_nodes_idx, DeleteGrainSize),
tbb::blocked_range<int>(begin_independent_nodes_idx, end_independent_nodes_idx,
DeleteGrainSize),
[this, &remaining_nodes, &thread_data_list](const tbb::blocked_range<int> &range)
{
ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(), end = range.end(); position != end; ++position)
for (int position = range.begin(), end = range.end(); position != end;
++position)
{
const NodeID x = remaining_nodes[position].id;
this->DeleteIncomingEdges(data, x);
@@ -542,12 +551,14 @@ class Contractor
if (!use_cached_node_priorities)
{
tbb::parallel_for(
tbb::blocked_range<int>(begin_independent_nodes_idx, end_independent_nodes_idx, NeighboursGrainSize),
[this, &node_priorities, &remaining_nodes, &node_data, &thread_data_list](
const tbb::blocked_range<int> &range)
tbb::blocked_range<int>(begin_independent_nodes_idx, end_independent_nodes_idx,
NeighboursGrainSize),
[this, &node_priorities, &remaining_nodes, &node_data,
&thread_data_list](const tbb::blocked_range<int> &range)
{
ContractorThreadData *data = thread_data_list.getThreadData();
for (int position = range.begin(), end = range.end(); position != end; ++position)
for (int position = range.begin(), end = range.end(); position != end;
++position)
{
NodeID x = remaining_nodes[position].id;
this->UpdateNodeNeighbours(node_priorities, node_data, data, x);
@@ -589,32 +600,31 @@ class Contractor
if (remaining_nodes.size() > 2)
{
if (orig_node_id_from_new_node_id_map.size() > 0)
{
tbb::parallel_for(
tbb::blocked_range<int>(0, remaining_nodes.size(), InitGrainSize),
[this, &remaining_nodes](const tbb::blocked_range<int> &range)
{
for (int x = range.begin(), end = range.end(); x != end; ++x)
{
const auto orig_id = remaining_nodes[x].id;
is_core_node[orig_node_id_from_new_node_id_map[orig_id]] = true;
}
});
}
else
{
tbb::parallel_for(
tbb::blocked_range<int>(0, remaining_nodes.size(), InitGrainSize),
[this, &remaining_nodes](const tbb::blocked_range<int> &range)
{
for (int x = range.begin(), end = range.end(); x != end; ++x)
{
const auto orig_id = remaining_nodes[x].id;
is_core_node[orig_id] = true;
}
});
}
if (orig_node_id_from_new_node_id_map.size() > 0)
{
tbb::parallel_for(tbb::blocked_range<int>(0, remaining_nodes.size(), InitGrainSize),
[this, &remaining_nodes](const tbb::blocked_range<int> &range)
{
for (int x = range.begin(), end = range.end(); x != end; ++x)
{
const auto orig_id = remaining_nodes[x].id;
is_core_node[orig_node_id_from_new_node_id_map[orig_id]] =
true;
}
});
}
else
{
tbb::parallel_for(tbb::blocked_range<int>(0, remaining_nodes.size(), InitGrainSize),
[this, &remaining_nodes](const tbb::blocked_range<int> &range)
{
for (int x = range.begin(), end = range.end(); x != end; ++x)
{
const auto orig_id = remaining_nodes[x].id;
is_core_node[orig_id] = true;
}
});
}
}
else
{
+3 -3
View File
@@ -31,9 +31,9 @@ struct ContractorConfig
unsigned requested_num_threads;
//A percentage of vertices that will be contracted for the hierarchy.
//Offers a trade-off between preprocessing and query time.
//The remaining vertices form the core of the hierarchy
// A percentage of vertices that will be contracted for the hierarchy.
// Offers a trade-off between preprocessing and query time.
// The remaining vertices form the core of the hierarchy
//(e.g. 0.8 contracts 80 percent of the hierarchy, leaving a core of 20%)
double core_factor;
@@ -232,7 +232,8 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
m_geospatial_query.reset();
}
explicit InternalDataFacade(const std::unordered_map<std::string, boost::filesystem::path> &server_paths)
explicit InternalDataFacade(
const std::unordered_map<std::string, boost::filesystem::path> &server_paths)
{
// cache end iterator to quickly check .find against
const auto end_it = end(server_paths);
@@ -331,7 +332,6 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
return m_travel_mode_list.at(id);
}
std::vector<PhantomNodeWithDistance>
NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate,
const float max_distance,
@@ -344,7 +344,8 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, bearing, bearing_range);
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance,
bearing, bearing_range);
}
std::vector<PhantomNodeWithDistance>
@@ -359,7 +360,8 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing, bearing_range);
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing,
bearing_range);
}
std::pair<PhantomNode, PhantomNode>
@@ -373,10 +375,10 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(input_coordinate, bearing, bearing_range);
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, bearing, bearing_range);
}
unsigned GetCheckSum() const override final { return m_check_sum; }
unsigned GetNameIndexFromEdgeID(const unsigned id) const override final
@@ -408,10 +410,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
return m_via_node_list.at(id);
}
virtual std::size_t GetCoreSize() const override final
{
return m_is_core_node.size();
}
virtual std::size_t GetCoreSize() const override final { return m_is_core_node.size(); }
virtual bool IsCoreNode(const NodeID id) const override final
{
+14 -13
View File
@@ -96,7 +96,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
osrm::make_unique<SharedRTree>(
tree_ptr, data_layout->num_entries[SharedDataLayout::R_SEARCH_TREE],
file_index_path, m_coordinate_list)));
m_geospatial_query.reset(new SharedGeospatialQuery(*m_static_rtree->second, m_coordinate_list));
m_geospatial_query.reset(
new SharedGeospatialQuery(*m_static_rtree->second, m_coordinate_list));
}
void LoadGraph()
@@ -179,11 +180,10 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
return;
}
unsigned *core_marker_ptr = data_layout->GetBlockPtr<unsigned>(
shared_memory, SharedDataLayout::CORE_MARKER);
unsigned *core_marker_ptr =
data_layout->GetBlockPtr<unsigned>(shared_memory, SharedDataLayout::CORE_MARKER);
typename ShM<bool, true>::vector is_core_node(
core_marker_ptr,
data_layout->num_entries[SharedDataLayout::CORE_MARKER]);
core_marker_ptr, data_layout->num_entries[SharedDataLayout::CORE_MARKER]);
m_is_core_node.swap(is_core_node);
}
@@ -215,7 +215,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
SharedDataFacade()
{
data_timestamp_ptr = (SharedDataTimestamp *)SharedMemoryFactory::Get(
CURRENT_REGIONS, sizeof(SharedDataTimestamp), false, false)->Ptr();
CURRENT_REGIONS, sizeof(SharedDataTimestamp), false, false)
->Ptr();
CURRENT_LAYOUT = LAYOUT_NONE;
CURRENT_DATA = DATA_NONE;
CURRENT_TIMESTAMP = 0;
@@ -369,7 +370,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, bearing, bearing_range);
return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance,
bearing, bearing_range);
}
std::vector<PhantomNodeWithDistance>
@@ -384,7 +386,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing, bearing_range);
return m_geospatial_query->NearestPhantomNodes(input_coordinate, max_results, bearing,
bearing_range);
}
std::pair<PhantomNode, PhantomNode>
@@ -398,7 +401,8 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
BOOST_ASSERT(m_geospatial_query.get());
}
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(input_coordinate, bearing, bearing_range);
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
input_coordinate, bearing, bearing_range);
}
unsigned GetCheckSum() const override final { return m_check_sum; }
@@ -437,10 +441,7 @@ template <class EdgeDataT> class SharedDataFacade final : public BaseDataFacade<
return false;
}
virtual std::size_t GetCoreSize() const override final
{
return m_is_core_node.size();
}
virtual std::size_t GetCoreSize() const override final { return m_is_core_node.size(); }
std::string GetTimestamp() const override final { return m_timestamp; }
};
@@ -95,8 +95,7 @@ struct SharedDataLayout
// special bit encoding
if (bid == GEOMETRIES_INDICATORS || bid == CORE_MARKER)
{
return (num_entries[bid] / 32 + 1) *
entry_size[bid];
return (num_entries[bid] / 32 + 1) * entry_size[bid];
}
return num_entries[bid] * entry_size[bid];
+15 -9
View File
@@ -38,14 +38,13 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
int length;
unsigned position;
};
private:
std::vector<Segment> shortest_path_segments, alternative_path_segments;
ExtractRouteNames<DataFacadeT, Segment> GenerateRouteNames;
public:
explicit JSONDescriptor(DataFacadeT *facade) : facade(facade)
{
}
explicit JSONDescriptor(DataFacadeT *facade) : facade(facade) {}
virtual void SetConfig(const DescriptorConfig &c) override final { config = c; }
@@ -108,7 +107,8 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
}
if (config.instructions)
{
osrm::json::Array json_route_instructions = BuildTextualDescription(description_factory, shortest_path_segments);
osrm::json::Array json_route_instructions =
BuildTextualDescription(description_factory, shortest_path_segments);
json_result.values["route_instructions"] = json_route_instructions;
}
description_factory.BuildRouteSummary(description_factory.get_entire_length(),
@@ -185,7 +185,8 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
osrm::json::Array json_current_alt_instructions;
if (config.instructions)
{
json_current_alt_instructions = BuildTextualDescription(alternate_description_factory, alternative_path_segments);
json_current_alt_instructions = BuildTextualDescription(
alternate_description_factory, alternative_path_segments);
json_alt_instructions.values.push_back(json_current_alt_instructions);
json_result.values["alternative_instructions"] = json_alt_instructions;
}
@@ -240,7 +241,7 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
json_result.values["hint_data"] = BuildHintData(raw_route);
}
inline osrm::json::Object BuildHintData(const InternalRouteResult& raw_route) const
inline osrm::json::Object BuildHintData(const InternalRouteResult &raw_route) const
{
osrm::json::Object json_hint_object;
json_hint_object.values["checksum"] = facade->GetCheckSum();
@@ -260,8 +261,9 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
return json_hint_object;
}
inline osrm::json::Array BuildTextualDescription(const DescriptionFactory &description_factory,
std::vector<Segment> &route_segments_list) const
inline osrm::json::Array
BuildTextualDescription(const DescriptionFactory &description_factory,
std::vector<Segment> &route_segments_list) const
{
osrm::json::Array json_instruction_array;
// Segment information has following format:
@@ -270,7 +272,11 @@ template <class DataFacadeT> class JSONDescriptor final : public BaseDescriptor<
struct RoundAbout
{
RoundAbout() : start_index(std::numeric_limits<int>::max()), name_id(INVALID_NAMEID), leave_at_exit(std::numeric_limits<int>::max()) {}
RoundAbout()
: start_index(std::numeric_limits<int>::max()), name_id(INVALID_NAMEID),
leave_at_exit(std::numeric_limits<int>::max())
{
}
int start_index;
unsigned name_id;
int leave_at_exit;
+9 -7
View File
@@ -129,7 +129,7 @@ template <typename RTreeT> class GeospatialQuery
}
PhantomNodeWithDistance MakePhantomNode(const FixedPointCoordinate &input_coordinate,
const EdgeData &data) const
const EdgeData &data) const
{
FixedPointCoordinate point_on_segment;
double ratio;
@@ -137,8 +137,8 @@ template <typename RTreeT> class GeospatialQuery
coordinates->at(data.u), coordinates->at(data.v), input_coordinate, point_on_segment,
ratio);
auto transformed =
PhantomNodeWithDistance { PhantomNode{data, point_on_segment}, current_perpendicular_distance };
auto transformed = PhantomNodeWithDistance{PhantomNode{data, point_on_segment},
current_perpendicular_distance};
ratio = std::min(1.0, std::max(0.0, ratio));
@@ -161,14 +161,16 @@ template <typename RTreeT> class GeospatialQuery
coordinate_calculation::bearing(coordinates->at(segment.u), coordinates->at(segment.v));
const double backward_edge_bearing = (forward_edge_bearing + 180) > 360
? (forward_edge_bearing - 180)
: (forward_edge_bearing + 180);
? (forward_edge_bearing - 180)
: (forward_edge_bearing + 180);
const bool forward_bearing_valid =
bearing::CheckInBounds(std::round(forward_edge_bearing), filter_bearing, filter_bearing_range) &&
bearing::CheckInBounds(std::round(forward_edge_bearing), filter_bearing,
filter_bearing_range) &&
segment.forward_edge_based_node_id != SPECIAL_NODEID;
const bool backward_bearing_valid =
bearing::CheckInBounds(std::round(backward_edge_bearing), filter_bearing, filter_bearing_range) &&
bearing::CheckInBounds(std::round(backward_edge_bearing), filter_bearing,
filter_bearing_range) &&
segment.reverse_edge_based_node_id != SPECIAL_NODEID;
return std::make_pair(forward_bearing_valid, backward_bearing_valid);
}
@@ -72,7 +72,7 @@ template <class CandidateLists> struct HiddenMarkovModel
breakage.resize(candidates_list.size());
for (const auto i : osrm::irange<std::size_t>(0u, candidates_list.size()))
{
const auto& num_candidates = candidates_list[i].size();
const auto &num_candidates = candidates_list[i].size();
// add empty vectors
if (num_candidates > 0)
{
+2 -1
View File
@@ -61,7 +61,8 @@ struct PhantomNode
int forward_offset;
int reverse_offset;
unsigned packed_geometry_id;
struct ComponentType {
struct ComponentType
{
uint32_t id : 31;
bool is_tiny : 1;
} component;
+5 -3
View File
@@ -41,7 +41,7 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
const std::string GetDescriptor() const override final { return descriptor_string; }
Status HandleRequest(const RouteParameters &route_parameters,
osrm::json::Object &json_result) override final
osrm::json::Object &json_result) override final
{
if (!check_all_coordinates(route_parameters.coordinates))
{
@@ -132,7 +132,8 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
if (!phantom_node_source_out_iter->first.is_valid(facade->GetNumberOfNodes()))
{
json_result.values["status_message"] =
std::string("Could not find a matching segment for coordinate ") + std::to_string(i);
std::string("Could not find a matching segment for coordinate ") +
std::to_string(i);
return Status::NoSegment;
}
@@ -154,7 +155,8 @@ template <class DataFacadeT> class DistanceTablePlugin final : public BasePlugin
if (!phantom_node_target_out_iter->first.is_valid(facade->GetNumberOfNodes()))
{
json_result.values["status_message"] =
std::string("Could not find a matching segment for coordinate ") + std::to_string(i);
std::string("Could not find a matching segment for coordinate ") +
std::to_string(i);
return Status::NoSegment;
}
phantom_node_target_out_iter++;
+1 -1
View File
@@ -20,7 +20,7 @@ class HelloWorldPlugin final : public BasePlugin
const std::string GetDescriptor() const override final { return descriptor_string; }
Status HandleRequest(const RouteParameters &routeParameters,
osrm::json::Object &json_result) override final
osrm::json::Object &json_result) override final
{
std::string temp_string;
json_result.values["title"] = "Hello World";
+1 -1
View File
@@ -23,7 +23,7 @@ template <class DataFacadeT> class NearestPlugin final : public BasePlugin
const std::string GetDescriptor() const override final { return descriptor_string; }
Status HandleRequest(const RouteParameters &route_parameters,
osrm::json::Object &json_result) override final
osrm::json::Object &json_result) override final
{
// check number of parameters
if (route_parameters.coordinates.empty() ||
+4 -4
View File
@@ -16,10 +16,10 @@ class BasePlugin
public:
enum class Status : int
{
Ok = 200,
EmptyResult = 207,
NoSegment = 208,
Error = 400
Ok = 200,
EmptyResult = 207,
NoSegment = 208,
Error = 400
};
BasePlugin() {}
+1 -1
View File
@@ -18,7 +18,7 @@ template <class DataFacadeT> class TimestampPlugin final : public BasePlugin
}
const std::string GetDescriptor() const override final { return descriptor_string; }
Status HandleRequest(const RouteParameters &route_parameters,
osrm::json::Object &json_result) override final
osrm::json::Object &json_result) override final
{
(void)route_parameters; // unused
+9 -9
View File
@@ -9,15 +9,15 @@
#include "engine/trip/trip_farthest_insertion.hpp"
#include "engine/trip/trip_brute_force.hpp"
#include "engine/search_engine.hpp"
#include "util/matrix_graph_wrapper.hpp" // wrapper to use tarjan
// scc on dist table
#include "engine/descriptors/descriptor_base.hpp" // to make json output
#include "engine/descriptors/json_descriptor.hpp" // to make json output
#include "util/matrix_graph_wrapper.hpp" // wrapper to use tarjan
// scc on dist table
#include "engine/descriptors/descriptor_base.hpp" // to make json output
#include "engine/descriptors/json_descriptor.hpp" // to make json output
#include "util/make_unique.hpp"
#include "util/timing_util.hpp" // to time runtime
#include "util/timing_util.hpp" // to time runtime
//#include "util/simple_logger.hpp" // for logging output
#include "util/dist_table_wrapper.hpp" // to access the dist
// table more easily
// table more easily
#include "osrm/json_container.hpp"
#include <boost/assert.hpp>
@@ -74,7 +74,8 @@ template <class DataFacadeT> class RoundTripPlugin final : public BasePlugin
const int range = input_bearings.size() > 0
? (input_bearings[i].second ? *input_bearings[i].second : 10)
: 180;
auto results = facade->NearestPhantomNodes(route_parameters.coordinates[i], 1, bearing, range);
auto results =
facade->NearestPhantomNodes(route_parameters.coordinates[i], 1, bearing, range);
if (results.empty())
{
break;
@@ -222,7 +223,7 @@ template <class DataFacadeT> class RoundTripPlugin final : public BasePlugin
}
Status HandleRequest(const RouteParameters &route_parameters,
osrm::json::Object &json_result) override final
osrm::json::Object &json_result) override final
{
if (max_locations_trip > 0 &&
(static_cast<int>(route_parameters.coordinates.size()) > max_locations_trip))
@@ -357,7 +358,6 @@ template <class DataFacadeT> class RoundTripPlugin final : public BasePlugin
trip.values.push_back(std::move(scc_trip));
}
if (trip.values.empty())
{
json_result.values["status_message"] = "Cannot find trips";
+1 -1
View File
@@ -49,7 +49,7 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
const std::string GetDescriptor() const override final { return descriptor_string; }
Status HandleRequest(const RouteParameters &route_parameters,
osrm::json::Object &json_result) override final
osrm::json::Object &json_result) override final
{
if (max_locations_viaroute > 0 &&
(static_cast<int>(route_parameters.coordinates.size()) > max_locations_viaroute))
+1 -1
View File
@@ -17,7 +17,7 @@ class PolylineCompressor
public:
std::string get_encoded_string(const std::vector<SegmentInformation> &polyline) const;
std::vector<FixedPointCoordinate> decode_string(const std::string &geometry_string) const;
};
@@ -40,10 +40,11 @@ class DirectShortestPathRouting final
// Get distance to next pair of target nodes.
BOOST_ASSERT_MSG(1 == phantom_nodes_vector.size(),
"Direct Shortest Path Query only accepts a single source and target pair. Multiple ones have been specified.");
const auto& phantom_node_pair = phantom_nodes_vector.front();
const auto& source_phantom = phantom_node_pair.source_phantom;
const auto& target_phantom = phantom_node_pair.target_phantom;
"Direct Shortest Path Query only accepts a single source and target pair. "
"Multiple ones have been specified.");
const auto &phantom_node_pair = phantom_nodes_vector.front();
const auto &source_phantom = phantom_node_pair.source_phantom;
const auto &target_phantom = phantom_node_pair.target_phantom;
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
super::facade->GetNumberOfNodes());
@@ -94,7 +95,6 @@ class DirectShortestPathRouting final
forward_core_heap.Clear();
reverse_core_heap.Clear();
super::SearchWithCore(forward_heap, reverse_heap, forward_core_heap, reverse_core_heap,
distance, packed_leg);
}
@@ -120,8 +120,8 @@ class DirectShortestPathRouting final
raw_route_data.target_traversed_in_reverse.push_back(
(packed_leg.back() != phantom_node_pair.target_phantom.forward_node_id));
super::UnpackPath(packed_leg.begin(), packed_leg.end(), phantom_node_pair, raw_route_data.unpacked_path_segments.front());
super::UnpackPath(packed_leg.begin(), packed_leg.end(), phantom_node_pair,
raw_route_data.unpacked_path_segments.front());
}
};
@@ -40,7 +40,8 @@ class ManyToManyRouting final
~ManyToManyRouting() {}
std::shared_ptr<std::vector<EdgeWeight>>
operator()(const std::vector<PhantomNode> &phantom_sources_array, const std::vector<PhantomNode> &phantom_targets_array) const
operator()(const std::vector<PhantomNode> &phantom_sources_array,
const std::vector<PhantomNode> &phantom_targets_array) const
{
const auto number_of_sources = phantom_sources_array.size();
const auto number_of_targets = phantom_targets_array.size();
@@ -63,14 +64,12 @@ class ManyToManyRouting final
if (SPECIAL_NODEID != phantom.forward_node_id)
{
query_heap.Insert(phantom.forward_node_id,
phantom.GetForwardWeightPlusOffset(),
query_heap.Insert(phantom.forward_node_id, phantom.GetForwardWeightPlusOffset(),
phantom.forward_node_id);
}
if (SPECIAL_NODEID != phantom.reverse_node_id)
{
query_heap.Insert(phantom.reverse_node_id,
phantom.GetReverseWeightPlusOffset(),
query_heap.Insert(phantom.reverse_node_id, phantom.GetReverseWeightPlusOffset(),
phantom.reverse_node_id);
}
@@ -91,14 +90,12 @@ class ManyToManyRouting final
if (SPECIAL_NODEID != phantom.forward_node_id)
{
query_heap.Insert(phantom.forward_node_id,
-phantom.GetForwardWeightPlusOffset(),
query_heap.Insert(phantom.forward_node_id, -phantom.GetForwardWeightPlusOffset(),
phantom.forward_node_id);
}
if (SPECIAL_NODEID != phantom.reverse_node_id)
{
query_heap.Insert(phantom.reverse_node_id,
-phantom.GetReverseWeightPlusOffset(),
query_heap.Insert(phantom.reverse_node_id, -phantom.GetReverseWeightPlusOffset(),
phantom.reverse_node_id);
}
@@ -50,7 +50,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
using QueryHeap = SearchEngineData::QueryHeap;
SearchEngineData &engine_working_data;
unsigned GetMedianSampleTime(const std::vector<unsigned>& timestamps) const
unsigned GetMedianSampleTime(const std::vector<unsigned> &timestamps) const
{
BOOST_ASSERT(timestamps.size() > 1);
@@ -60,7 +60,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
// don't use first element of sample_times -> will not be a difference.
auto first_elem = std::next(sample_times.begin());
auto median = first_elem + std::distance(first_elem, sample_times.end())/2;
auto median = first_elem + std::distance(first_elem, sample_times.end()) / 2;
std::nth_element(first_elem, median, sample_times.end());
return *median;
}
@@ -83,7 +83,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
const bool use_timestamps = trace_timestamps.size() > 1;
const auto median_sample_time = [&]() {
const auto median_sample_time = [&]()
{
if (use_timestamps)
{
return std::max(1u, GetMedianSampleTime(trace_timestamps));
@@ -94,7 +95,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
}
}();
const auto max_broken_time = median_sample_time * osrm::matching::MAX_BROKEN_STATES;
const auto max_distance_delta = [&]() {
const auto max_distance_delta = [&]()
{
if (use_timestamps)
{
return median_sample_time * osrm::matching::MAX_SPEED;
@@ -193,7 +195,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
const auto &current_timestamps_list = candidates_list[t];
const auto &current_coordinate = trace_coordinates[t];
const auto haversine_distance = coordinate_calculation::haversine_distance(prev_coordinate, current_coordinate);
const auto haversine_distance =
coordinate_calculation::haversine_distance(prev_coordinate, current_coordinate);
// compute d_t for this timestamp and the next one
for (const auto s : osrm::irange<std::size_t>(0u, prev_viterbi.size()))
@@ -244,7 +247,8 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
current_parents[s_prime] = std::make_pair(prev_unbroken_timestamp, s);
current_lengths[s_prime] = network_distance;
current_pruned[s_prime] = false;
current_suspicious[s_prime] = d_t > osrm::matching::SUSPICIOUS_DISTANCE_DELTA;
current_suspicious[s_prime] =
d_t > osrm::matching::SUSPICIOUS_DISTANCE_DELTA;
model.breakage[t] = false;
}
}
@@ -286,8 +290,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
{
--parent_timestamp_index;
}
while (sub_matching_begin < sub_matching_end &&
model.breakage[sub_matching_begin])
while (sub_matching_begin < sub_matching_end && model.breakage[sub_matching_begin])
{
++sub_matching_begin;
}
@@ -295,12 +295,9 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
{
BOOST_ASSERT(i < id_vector.size());
BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0);
unpacked_path.emplace_back(
PathData{id_vector[i],
phantom_node_pair.target_phantom.name_id,
TurnInstruction::NoTurn,
0,
phantom_node_pair.target_phantom.forward_travel_mode});
unpacked_path.emplace_back(PathData{
id_vector[i], phantom_node_pair.target_phantom.name_id, TurnInstruction::NoTurn,
0, phantom_node_pair.target_phantom.forward_travel_mode});
}
}
@@ -498,8 +495,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// TODO check if unordered_set might be faster
// sort by id and increasing by distance
auto entry_point_comparator =
[](const std::pair<NodeID, EdgeWeight> &lhs, const std::pair<NodeID, EdgeWeight> &rhs)
auto entry_point_comparator = [](const std::pair<NodeID, EdgeWeight> &lhs,
const std::pair<NodeID, EdgeWeight> &rhs)
{
return lhs.first < rhs.first || (lhs.first == rhs.first && lhs.second < rhs.second);
};
@@ -86,17 +86,17 @@ class ShortestPathRouting final
// | ^target
// ------^
void SearchLoop(QueryHeap &forward_heap,
QueryHeap &reverse_heap,
const bool search_forward_node,
const bool search_reverse_node,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
const int total_distance_to_forward,
const int total_distance_to_reverse,
int &new_total_distance_to_forward,
int &new_total_distance_to_reverse,
std::vector<NodeID> &leg_packed_path_forward,
std::vector<NodeID> &leg_packed_path_reverse) const
QueryHeap &reverse_heap,
const bool search_forward_node,
const bool search_reverse_node,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
const int total_distance_to_forward,
const int total_distance_to_reverse,
int &new_total_distance_to_forward,
int &new_total_distance_to_reverse,
std::vector<NodeID> &leg_packed_path_forward,
std::vector<NodeID> &leg_packed_path_reverse) const
{
BOOST_ASSERT(source_phantom.forward_node_id == target_phantom.forward_node_id);
BOOST_ASSERT(source_phantom.reverse_node_id == target_phantom.reverse_node_id);
@@ -110,11 +110,12 @@ class ShortestPathRouting final
for (const auto edge : super::facade->GetAdjacentEdgeRange(node_id))
{
const auto& data = super::facade->GetEdgeData(edge);
const auto &data = super::facade->GetEdgeData(edge);
if (data.forward)
{
auto target = super::facade->GetTarget(edge);
auto offset = total_distance_to_forward + data.distance - source_phantom.GetForwardWeightPlusOffset();
auto offset = total_distance_to_forward + data.distance -
source_phantom.GetForwardWeightPlusOffset();
forward_heap.Insert(target, offset, target);
}
@@ -147,11 +148,12 @@ class ShortestPathRouting final
for (const auto edge : super::facade->GetAdjacentEdgeRange(node_id))
{
const auto& data = super::facade->GetEdgeData(edge);
const auto &data = super::facade->GetEdgeData(edge);
if (data.forward)
{
auto target = super::facade->GetTarget(edge);
auto offset = total_distance_to_reverse + data.distance - source_phantom.GetReverseWeightPlusOffset();
auto offset = total_distance_to_reverse + data.distance -
source_phantom.GetReverseWeightPlusOffset();
forward_heap.Insert(target, offset, target);
}
@@ -174,7 +176,6 @@ class ShortestPathRouting final
leg_packed_path_reverse.push_back(node_id);
std::reverse(leg_packed_path_reverse.begin(), leg_packed_path_reverse.end());
}
}
// searches shortest path between:
@@ -290,8 +291,10 @@ class ShortestPathRouting final
int total_distance_to_forward = 0;
int total_distance_to_reverse = 0;
bool search_from_forward_node = phantom_nodes_vector.front().source_phantom.forward_node_id != SPECIAL_NODEID;
bool search_from_reverse_node = phantom_nodes_vector.front().source_phantom.reverse_node_id != SPECIAL_NODEID;
bool search_from_forward_node =
phantom_nodes_vector.front().source_phantom.forward_node_id != SPECIAL_NODEID;
bool search_from_reverse_node =
phantom_nodes_vector.front().source_phantom.reverse_node_id != SPECIAL_NODEID;
std::vector<NodeID> prev_packed_leg_to_forward;
std::vector<NodeID> prev_packed_leg_to_reverse;
@@ -315,30 +318,33 @@ class ShortestPathRouting final
const auto &source_phantom = phantom_node_pair.source_phantom;
const auto &target_phantom = phantom_node_pair.target_phantom;
BOOST_ASSERT(current_leg + 1 < uturn_indicators.size());
const bool allow_u_turn_at_via = uturn_indicators[current_leg + 1];
bool search_to_forward_node = target_phantom.forward_node_id != SPECIAL_NODEID;
bool search_to_reverse_node = target_phantom.reverse_node_id != SPECIAL_NODEID;
BOOST_ASSERT(!search_from_forward_node || source_phantom.forward_node_id != SPECIAL_NODEID);
BOOST_ASSERT(!search_from_reverse_node || source_phantom.reverse_node_id != SPECIAL_NODEID);
BOOST_ASSERT(!search_from_forward_node ||
source_phantom.forward_node_id != SPECIAL_NODEID);
BOOST_ASSERT(!search_from_reverse_node ||
source_phantom.reverse_node_id != SPECIAL_NODEID);
if (source_phantom.forward_node_id == target_phantom.forward_node_id &&
source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset())
source_phantom.GetForwardWeightPlusOffset() >
target_phantom.GetForwardWeightPlusOffset())
{
search_to_forward_node = search_from_reverse_node;
}
if (source_phantom.reverse_node_id == target_phantom.reverse_node_id &&
source_phantom.GetReverseWeightPlusOffset() > target_phantom.GetReverseWeightPlusOffset())
source_phantom.GetReverseWeightPlusOffset() >
target_phantom.GetReverseWeightPlusOffset())
{
search_to_reverse_node = search_from_forward_node;
}
BOOST_ASSERT(search_from_forward_node || search_from_reverse_node);
if(search_to_reverse_node || search_to_forward_node)
if (search_to_reverse_node || search_to_forward_node)
{
if (allow_u_turn_at_via)
{
@@ -347,7 +353,8 @@ class ShortestPathRouting final
search_to_reverse_node, source_phantom, target_phantom,
total_distance_to_forward, total_distance_to_reverse,
new_total_distance_to_forward, packed_leg_to_forward);
// if only the reverse node is valid (e.g. when using the match plugin) we actually need to move
// if only the reverse node is valid (e.g. when using the match plugin) we
// actually need to move
if (target_phantom.forward_node_id == SPECIAL_NODEID)
{
BOOST_ASSERT(target_phantom.reverse_node_id != SPECIAL_NODEID);
@@ -367,7 +374,8 @@ class ShortestPathRouting final
search_from_reverse_node, search_to_forward_node, search_to_reverse_node,
source_phantom, target_phantom, total_distance_to_forward,
total_distance_to_reverse, new_total_distance_to_forward,
new_total_distance_to_reverse, packed_leg_to_forward, packed_leg_to_reverse);
new_total_distance_to_reverse, packed_leg_to_forward,
packed_leg_to_reverse);
}
}
else
@@ -377,9 +385,10 @@ class ShortestPathRouting final
BOOST_ASSERT(search_from_reverse_node == search_to_reverse_node);
BOOST_ASSERT(search_from_forward_node == search_to_forward_node);
SearchLoop(forward_heap, reverse_heap, search_from_forward_node,
search_from_reverse_node, source_phantom, target_phantom, total_distance_to_forward,
total_distance_to_reverse, new_total_distance_to_forward,
new_total_distance_to_reverse, packed_leg_to_forward, packed_leg_to_reverse);
search_from_reverse_node, source_phantom, target_phantom,
total_distance_to_forward, total_distance_to_reverse,
new_total_distance_to_forward, new_total_distance_to_reverse,
packed_leg_to_forward, packed_leg_to_reverse);
}
// No path found for both target nodes?
+2 -4
View File
@@ -24,12 +24,10 @@ template <class DataFacadeT> class SearchEngine
MapMatching<DataFacadeT> map_matching;
explicit SearchEngine(DataFacadeT *facade)
: facade(facade),
shortest_path(facade, engine_working_data),
: facade(facade), shortest_path(facade, engine_working_data),
direct_shortest_path(facade, engine_working_data),
alternative_path(facade, engine_working_data),
distance_table(facade, engine_working_data),
map_matching(facade, engine_working_data)
distance_table(facade, engine_working_data), map_matching(facade, engine_working_data)
{
static_assert(!std::is_pointer<DataFacadeT>::value, "don't instantiate with ptr type");
static_assert(std::is_object<DataFacadeT>::value,
+5 -4
View File
@@ -32,8 +32,8 @@ struct SegmentInformation
const bool is_via_location,
const TravelMode travel_mode)
: location(std::move(location)), name_id(name_id), duration(duration), length(length),
pre_turn_bearing(0), post_turn_bearing(0), turn_instruction(turn_instruction), travel_mode(travel_mode),
necessary(necessary), is_via_location(is_via_location)
pre_turn_bearing(0), post_turn_bearing(0), turn_instruction(turn_instruction),
travel_mode(travel_mode), necessary(necessary), is_via_location(is_via_location)
{
}
@@ -44,8 +44,9 @@ struct SegmentInformation
const TurnInstruction turn_instruction,
const TravelMode travel_mode)
: location(std::move(location)), name_id(name_id), duration(duration), length(length),
pre_turn_bearing(0), post_turn_bearing(0), turn_instruction(turn_instruction), travel_mode(travel_mode),
necessary(turn_instruction != TurnInstruction::NoTurn), is_via_location(false)
pre_turn_bearing(0), post_turn_bearing(0), turn_instruction(turn_instruction),
travel_mode(travel_mode), necessary(turn_instruction != TurnInstruction::NoTurn),
is_via_location(false)
{
}
};
@@ -26,7 +26,7 @@ class CompressedEdgeContainer
void PrintStatistics() const;
void SerializeInternalVector(const std::string &path) const;
unsigned GetPositionForID(const EdgeID edge_id) const;
const EdgeBucket& GetBucketReference(const EdgeID edge_id) const;
const EdgeBucket &GetBucketReference(const EdgeID edge_id) const;
NodeID GetFirstEdgeTargetID(const EdgeID edge_id) const;
NodeID GetLastEdgeSourceID(const EdgeID edge_id) const;
@@ -63,27 +63,29 @@ class EdgeBasedGraphFactory
unsigned GetHighestEdgeID();
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, const double angle) const;
TurnInstruction
AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, const double angle) const;
int GetTurnPenalty(double angle, lua_State *lua_state) const;
private:
using EdgeData = NodeBasedDynamicGraph::EdgeData;
//! maps index from m_edge_based_node_list to ture/false if the node is an entry point to the graph
//! maps index from m_edge_based_node_list to ture/false if the node is an entry point to the
//! graph
std::vector<bool> m_edge_based_node_is_startpoint;
//! list of edge based nodes (compressed segments)
std::vector<EdgeBasedNode> m_edge_based_node_list;
DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
unsigned m_max_edge_id;
const std::vector<QueryNode>& m_node_info_list;
const std::vector<QueryNode> &m_node_info_list;
std::shared_ptr<NodeBasedDynamicGraph> m_node_based_graph;
std::shared_ptr<RestrictionMap const> m_restriction_map;
const std::unordered_set<NodeID>& m_barrier_nodes;
const std::unordered_set<NodeID>& m_traffic_lights;
const CompressedEdgeContainer& m_compressed_edge_container;
const std::unordered_set<NodeID> &m_barrier_nodes;
const std::unordered_set<NodeID> &m_traffic_lights;
const CompressedEdgeContainer &m_compressed_edge_container;
SpeedProfileProperties speed_profile;
@@ -103,13 +105,12 @@ class EdgeBasedGraphFactory
const std::string &edge_segment_lookup_filename,
const std::string &edge_fixed_penalties_filename,
const bool generate_edge_lookup);
#endif
#endif
void InsertEdgeBasedNode(const NodeID u, const NodeID v);
void FlushVectorToStream(std::ofstream &edge_data_file,
std::vector<OriginalEdgeData> &original_edge_data_vector) const;
};
#endif /* EDGE_BASED_GRAPH_FACTORY_HPP_ */
+4 -2
View File
@@ -19,7 +19,8 @@ struct EdgeBasedNode
u(SPECIAL_NODEID), v(SPECIAL_NODEID), name_id(0),
forward_weight(INVALID_EDGE_WEIGHT >> 1), reverse_weight(INVALID_EDGE_WEIGHT >> 1),
forward_offset(0), reverse_offset(0), packed_geometry_id(SPECIAL_EDGEID),
component{INVALID_COMPONENTID, false}, fwd_segment_position(std::numeric_limits<unsigned short>::max()),
component{INVALID_COMPONENTID, false},
fwd_segment_position(std::numeric_limits<unsigned short>::max()),
forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
backward_travel_mode(TRAVEL_MODE_INACCESSIBLE)
{
@@ -74,7 +75,8 @@ struct EdgeBasedNode
int forward_offset; // prefix sum of the weight up the edge TODO: short must suffice
int reverse_offset; // prefix sum of the weight from the edge TODO: short must suffice
unsigned packed_geometry_id; // if set, then the edge represents a packed geometry
struct {
struct
{
unsigned id : 31;
bool is_tiny : 1;
} component;
+5 -4
View File
@@ -29,10 +29,11 @@ class ExtractionContainers
void PrepareRestrictions();
void PrepareEdges(lua_State *segment_state);
void WriteNodes(std::ofstream& file_out_stream) const;
void WriteRestrictions(const std::string& restrictions_file_name) const;
void WriteEdges(std::ofstream& file_out_stream) const;
void WriteNames(const std::string& names_file_name) const;
void WriteNodes(std::ofstream &file_out_stream) const;
void WriteRestrictions(const std::string &restrictions_file_name) const;
void WriteEdges(std::ofstream &file_out_stream) const;
void WriteNames(const std::string &names_file_name) const;
public:
using STXXLNodeIDVector = stxxl::vector<OSMNodeID>;
using STXXLNodeVector = stxxl::vector<ExternalMemoryNode>;
@@ -16,10 +16,8 @@ struct FirstAndLastSegmentOfWay
OSMNodeID last_segment_target_id;
FirstAndLastSegmentOfWay()
: way_id(SPECIAL_OSM_WAYID),
first_segment_source_id(SPECIAL_OSM_NODEID),
first_segment_target_id(SPECIAL_OSM_NODEID),
last_segment_source_id(SPECIAL_OSM_NODEID),
: way_id(SPECIAL_OSM_WAYID), first_segment_source_id(SPECIAL_OSM_NODEID),
first_segment_target_id(SPECIAL_OSM_NODEID), last_segment_source_id(SPECIAL_OSM_NODEID),
last_segment_target_id(SPECIAL_OSM_NODEID)
{
}
@@ -32,19 +30,11 @@ struct FirstAndLastSegmentOfWay
static FirstAndLastSegmentOfWay min_value()
{
return {MIN_OSM_WAYID,
MIN_OSM_NODEID,
MIN_OSM_NODEID,
MIN_OSM_NODEID,
MIN_OSM_NODEID};
return {MIN_OSM_WAYID, MIN_OSM_NODEID, MIN_OSM_NODEID, MIN_OSM_NODEID, MIN_OSM_NODEID};
}
static FirstAndLastSegmentOfWay max_value()
{
return {MAX_OSM_WAYID,
MAX_OSM_NODEID,
MAX_OSM_NODEID,
MAX_OSM_NODEID,
MAX_OSM_NODEID};
return {MAX_OSM_WAYID, MAX_OSM_NODEID, MAX_OSM_NODEID, MAX_OSM_NODEID, MAX_OSM_NODEID};
}
};
+11 -11
View File
@@ -16,19 +16,19 @@ class GraphCompressor
{
using EdgeData = NodeBasedDynamicGraph::EdgeData;
public:
GraphCompressor(SpeedProfileProperties speed_profile);
public:
GraphCompressor(SpeedProfileProperties speed_profile);
void Compress(const std::unordered_set<NodeID>& barrier_nodes,
const std::unordered_set<NodeID>& traffic_lights,
RestrictionMap& restriction_map,
NodeBasedDynamicGraph& graph,
CompressedEdgeContainer& geometry_compressor);
private:
void Compress(const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
RestrictionMap &restriction_map,
NodeBasedDynamicGraph &graph,
CompressedEdgeContainer &geometry_compressor);
void PrintStatistics(unsigned original_number_of_nodes,
unsigned original_number_of_edges,
const NodeBasedDynamicGraph& graph) const;
private:
void PrintStatistics(unsigned original_number_of_nodes,
unsigned original_number_of_edges,
const NodeBasedDynamicGraph &graph) const;
SpeedProfileProperties speed_profile;
};
+24 -12
View File
@@ -37,18 +37,30 @@ struct NodeBasedEdge
struct NodeBasedEdgeWithOSM : NodeBasedEdge
{
explicit NodeBasedEdgeWithOSM(OSMNodeID source,
OSMNodeID target,
NodeID name_id,
EdgeWeight weight,
bool forward,
bool backward,
bool roundabout,
bool access_restricted,
bool startpoint,
TravelMode travel_mode,
bool is_split)
: NodeBasedEdge(SPECIAL_NODEID, SPECIAL_NODEID, name_id, weight, forward, backward, roundabout, access_restricted, startpoint, travel_mode, is_split),
osm_source_id(source), osm_target_id(target) {}
OSMNodeID target,
NodeID name_id,
EdgeWeight weight,
bool forward,
bool backward,
bool roundabout,
bool access_restricted,
bool startpoint,
TravelMode travel_mode,
bool is_split)
: NodeBasedEdge(SPECIAL_NODEID,
SPECIAL_NODEID,
name_id,
weight,
forward,
backward,
roundabout,
access_restricted,
startpoint,
travel_mode,
is_split),
osm_source_id(source), osm_target_id(target)
{
}
OSMNodeID osm_source_id;
OSMNodeID osm_target_id;
+21 -15
View File
@@ -13,7 +13,8 @@
struct InternalExtractorEdge
{
// specify the type of the weight data
enum class WeightType : char {
enum class WeightType : char
{
INVALID,
SPEED,
EDGE_DURATION,
@@ -23,9 +24,7 @@ struct InternalExtractorEdge
struct WeightData
{
WeightData() : duration(0.0), type(WeightType::INVALID)
{
}
WeightData() : duration(0.0), type(WeightType::INVALID) {}
union
{
@@ -36,8 +35,17 @@ struct InternalExtractorEdge
};
explicit InternalExtractorEdge()
: result(MIN_OSM_NODEID, MIN_OSM_NODEID, 0, 0, false, false, false, false, true,
TRAVEL_MODE_INACCESSIBLE, false)
: result(MIN_OSM_NODEID,
MIN_OSM_NODEID,
0,
0,
false,
false,
false,
false,
true,
TRAVEL_MODE_INACCESSIBLE,
false)
{
}
@@ -74,17 +82,16 @@ struct InternalExtractorEdge
// coordinate of the source node
FixedPointCoordinate source_coordinate;
// necessary static util functions for stxxl's sorting
static InternalExtractorEdge min_osm_value()
{
return InternalExtractorEdge(MIN_OSM_NODEID, MIN_OSM_NODEID, 0, WeightData(), false, false, false,
false, true, TRAVEL_MODE_INACCESSIBLE, false);
return InternalExtractorEdge(MIN_OSM_NODEID, MIN_OSM_NODEID, 0, WeightData(), false, false,
false, false, true, TRAVEL_MODE_INACCESSIBLE, false);
}
static InternalExtractorEdge max_osm_value()
{
return InternalExtractorEdge(MAX_OSM_NODEID, MAX_OSM_NODEID, 0, WeightData(), false,
false, false, false, true, TRAVEL_MODE_INACCESSIBLE, false);
return InternalExtractorEdge(MAX_OSM_NODEID, MAX_OSM_NODEID, 0, WeightData(), false, false,
false, false, true, TRAVEL_MODE_INACCESSIBLE, false);
}
static InternalExtractorEdge min_internal_value()
@@ -101,7 +108,6 @@ struct InternalExtractorEdge
v.result.target = std::numeric_limits<NodeID>::max();
return v;
}
};
struct CmpEdgeByInternalStartThenInternalTargetID
@@ -109,9 +115,9 @@ struct CmpEdgeByInternalStartThenInternalTargetID
using value_type = InternalExtractorEdge;
bool operator()(const InternalExtractorEdge &lhs, const InternalExtractorEdge &rhs) const
{
return (lhs.result.source < rhs.result.source) ||
((lhs.result.source == rhs.result.source) &&
(lhs.result.target < rhs.result.target));
return (lhs.result.source < rhs.result.source) ||
((lhs.result.source == rhs.result.source) &&
(lhs.result.target < rhs.result.target));
}
value_type max_value() { return InternalExtractorEdge::max_internal_value(); }
+6 -6
View File
@@ -12,9 +12,11 @@
struct QueryNode
{
using key_type = OSMNodeID; // type of NodeID
using value_type = int; // type of lat,lons
using value_type = int; // type of lat,lons
explicit QueryNode(int lat, int lon, OSMNodeID node_id) : lat(lat), lon(lon), node_id(node_id) {}
explicit QueryNode(int lat, int lon, OSMNodeID node_id) : lat(lat), lon(lon), node_id(node_id)
{
}
QueryNode()
: lat(std::numeric_limits<int>::max()), lon(std::numeric_limits<int>::max()),
node_id(SPECIAL_OSM_NODEID)
@@ -28,15 +30,13 @@ struct QueryNode
static QueryNode min_value()
{
return QueryNode(static_cast<int>(-90 * COORDINATE_PRECISION),
static_cast<int>(-180 * COORDINATE_PRECISION),
MIN_OSM_NODEID);
static_cast<int>(-180 * COORDINATE_PRECISION), MIN_OSM_NODEID);
}
static QueryNode max_value()
{
return QueryNode(static_cast<int>(90 * COORDINATE_PRECISION),
static_cast<int>(180 * COORDINATE_PRECISION),
MAX_OSM_NODEID);
static_cast<int>(180 * COORDINATE_PRECISION), MAX_OSM_NODEID);
}
value_type operator[](const std::size_t n) const
+1 -1
View File
@@ -52,7 +52,7 @@ struct TurnRestriction
/**
* This is just a wrapper around TurnRestriction used in the extractor.
*
*
* Could be merged with TurnRestriction. For now the type-destiction makes sense
* as the format in which the restriction is presented in the extractor and in the
* preprocessing is different. (see restriction_parser.cpp)
+1 -1
View File
@@ -64,7 +64,7 @@ template <> struct hash<RestrictionTarget>
class RestrictionMap
{
public:
RestrictionMap() : m_count(0) {};
RestrictionMap() : m_count(0){};
RestrictionMap(const std::vector<TurnRestriction> &restriction_list);
// Replace end v with w in each turn restriction containing u as via node
+7 -7
View File
@@ -3,14 +3,14 @@
struct SpeedProfileProperties
{
SpeedProfileProperties()
: traffic_signal_penalty(0), u_turn_penalty(0), has_turn_penalty_function(false)
{
}
SpeedProfileProperties()
: traffic_signal_penalty(0), u_turn_penalty(0), has_turn_penalty_function(false)
{
}
int traffic_signal_penalty;
int u_turn_penalty;
bool has_turn_penalty_function;
int traffic_signal_penalty;
int u_turn_penalty;
bool has_turn_penalty_function;
};
#endif
+4 -2
View File
@@ -72,7 +72,9 @@ struct RouteParameters
void addTimestamp(const unsigned timestamp);
void addBearing(const boost::fusion::vector<int, boost::optional<int>> &received_bearing, boost::spirit::qi::unused_type unused, bool& pass);
void addBearing(const boost::fusion::vector<int, boost::optional<int>> &received_bearing,
boost::spirit::qi::unused_type unused,
bool &pass);
void setLanguage(const std::string &language);
@@ -106,7 +108,7 @@ struct RouteParameters
std::string language;
std::vector<std::string> hints;
std::vector<unsigned> timestamps;
std::vector<std::pair<const int,const boost::optional<int>>> bearings;
std::vector<std::pair<const int, const boost::optional<int>>> bearings;
std::vector<bool> uturns;
std::vector<FixedPointCoordinate> coordinates;
std::vector<bool> is_destination;
+29 -28
View File
@@ -36,33 +36,34 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* etc. Also clarifies what this random "int" value is
* being used for.
*/
#define OSRM_STRONG_TYPEDEF(From, To) \
class To final { \
static_assert(std::is_arithmetic<From>(), ""); \
From x; \
\
public: \
To() = default; \
explicit To(const From x_) : x(x_) {} \
explicit operator From&() { return x; } \
explicit operator const From&() const { return x; } \
bool operator <(const To &z_) const { return x < static_cast<const From>(z_) ; } \
bool operator >(const To &z_) const { return x > static_cast<const From>(z_) ; } \
bool operator <=(const To &z_) const { return x <= static_cast<const From>(z_) ; } \
bool operator >=(const To &z_) const { return x >= static_cast<const From>(z_) ; } \
bool operator ==(const To &z_) const { return x == static_cast<const From>(z_) ; } \
bool operator !=(const To &z_) const { return x != static_cast<const From>(z_) ; } \
}; \
inline From To##_to_##From(To to) { return static_cast<From>(to); } \
namespace std { \
template <> \
struct hash<To> \
{ \
std::size_t operator()(const To& k) const \
{ \
return std::hash<From>()(static_cast<const From>(k)); \
} \
}; \
}
#define OSRM_STRONG_TYPEDEF(From, To) \
class To final \
{ \
static_assert(std::is_arithmetic<From>(), ""); \
From x; \
\
public: \
To() = default; \
explicit To(const From x_) : x(x_) {} \
explicit operator From &() { return x; } \
explicit operator const From &() const { return x; } \
bool operator<(const To &z_) const { return x < static_cast<const From>(z_); } \
bool operator>(const To &z_) const { return x > static_cast<const From>(z_); } \
bool operator<=(const To &z_) const { return x <= static_cast<const From>(z_); } \
bool operator>=(const To &z_) const { return x >= static_cast<const From>(z_); } \
bool operator==(const To &z_) const { return x == static_cast<const From>(z_); } \
bool operator!=(const To &z_) const { return x != static_cast<const From>(z_); } \
}; \
inline From To##_to_##From(To to) { return static_cast<From>(to); } \
namespace std \
{ \
template <> struct hash<To> \
{ \
std::size_t operator()(const To &k) const \
{ \
return std::hash<From>()(static_cast<const From>(k)); \
} \
}; \
}
#endif // OSRM_STRONG_TYPEDEF_HPP
+28 -22
View File
@@ -11,19 +11,21 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
{
explicit APIGrammar(HandlerT *h) : APIGrammar::base_type(api_call), handler(h)
{
api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >>
-query;
query = ('?') >> +(zoom | output | jsonp | checksum | uturns | location_with_options | destination_with_options | source_with_options | cmp |
language | instruction | geometry | alt_route | old_API | num_results |
matching_beta | gps_precision | classify | locs);
api_call =
qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> -query;
query = ('?') >> +(zoom | output | jsonp | checksum | uturns | location_with_options |
destination_with_options | source_with_options | cmp | language |
instruction | geometry | alt_route | old_API | num_results |
matching_beta | gps_precision | classify | locs);
// all combinations of timestamp, uturn, hint and bearing without duplicates
t_u = (u >> -timestamp) | (timestamp >> -u);
t_h = (hint >> -timestamp) | (timestamp >> -hint);
u_h = (u >> -hint) | (hint >> -u);
t_u_h = (hint >> -t_u) | (u >> -t_h) | (timestamp >> -u_h);
location_options = (bearing >> -t_u_h) | (t_u_h >> -bearing) | //
(u >> bearing >> -t_h) | (timestamp >> bearing >> -u_h) | (hint >> bearing >> t_u) | //
(t_h >> bearing >> -u) | (u_h >> bearing >> -timestamp) | (t_u >> bearing >> -hint);
location_options =
(bearing >> -t_u_h) | (t_u_h >> -bearing) | //
(u >> bearing >> -t_h) | (timestamp >> bearing >> -u_h) | (hint >> bearing >> t_u) | //
(t_h >> bearing >> -u) | (u_h >> bearing >> -timestamp) | (t_u >> bearing >> -hint);
location_with_options = location >> -location_options;
source_with_options = source >> -location_options;
destination_with_options = destination >> -location_options;
@@ -45,17 +47,19 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
(qi::double_ >> qi::lit(',') >>
qi::double_)[boost::bind(&HandlerT::addCoordinate, handler, ::_1)];
destination = (-qi::lit('&')) >> qi::lit("dst") >> '=' >>
(qi::double_ >> qi::lit(',') >>
qi::double_)[boost::bind(&HandlerT::addDestination, handler, ::_1)];
(qi::double_ >> qi::lit(',') >>
qi::double_)[boost::bind(&HandlerT::addDestination, handler, ::_1)];
source = (-qi::lit('&')) >> qi::lit("src") >> '=' >>
(qi::double_ >> qi::lit(',') >>
qi::double_)[boost::bind(&HandlerT::addSource, handler, ::_1)];
(qi::double_ >> qi::lit(',') >>
qi::double_)[boost::bind(&HandlerT::addSource, handler, ::_1)];
hint = (-qi::lit('&')) >> qi::lit("hint") >> '=' >>
stringwithDot[boost::bind(&HandlerT::addHint, handler, ::_1)];
timestamp = (-qi::lit('&')) >> qi::lit("t") >> '=' >>
qi::uint_[boost::bind(&HandlerT::addTimestamp, handler, ::_1)];
qi::uint_[boost::bind(&HandlerT::addTimestamp, handler, ::_1)];
bearing = (-qi::lit('&')) >> qi::lit("b") >> '=' >>
(qi::int_ >> -(qi::lit(',') >> qi::int_ | qi::attr(10)))[boost::bind(&HandlerT::addBearing, handler, ::_1, ::_2, ::_3)];
(qi::int_ >>
-(qi::lit(',') >> qi::int_ |
qi::attr(10)))[boost::bind(&HandlerT::addBearing, handler, ::_1, ::_2, ::_3)];
u = (-qi::lit('&')) >> qi::lit("u") >> '=' >>
qi::bool_[boost::bind(&HandlerT::setUTurn, handler, ::_1)];
uturns = (-qi::lit('&')) >> qi::lit("uturns") >> '=' >>
@@ -69,13 +73,13 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
num_results = (-qi::lit('&')) >> qi::lit("num_results") >> '=' >>
qi::short_[boost::bind(&HandlerT::setNumberOfResults, handler, ::_1)];
matching_beta = (-qi::lit('&')) >> qi::lit("matching_beta") >> '=' >>
qi::float_[boost::bind(&HandlerT::setMatchingBeta, handler, ::_1)];
qi::float_[boost::bind(&HandlerT::setMatchingBeta, handler, ::_1)];
gps_precision = (-qi::lit('&')) >> qi::lit("gps_precision") >> '=' >>
qi::float_[boost::bind(&HandlerT::setGPSPrecision, handler, ::_1)];
qi::float_[boost::bind(&HandlerT::setGPSPrecision, handler, ::_1)];
classify = (-qi::lit('&')) >> qi::lit("classify") >> '=' >>
qi::bool_[boost::bind(&HandlerT::setClassify, handler, ::_1)];
qi::bool_[boost::bind(&HandlerT::setClassify, handler, ::_1)];
locs = (-qi::lit('&')) >> qi::lit("locs") >> '=' >>
stringforPolyline[boost::bind(&HandlerT::getCoordinatesFromGeometry, handler, ::_1)];
stringforPolyline[boost::bind(&HandlerT::getCoordinatesFromGeometry, handler, ::_1)];
string = +(qi::char_("a-zA-Z"));
stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));
@@ -84,10 +88,12 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
stringforPolyline = +(qi::char_("a-zA-Z0-9_.-[]{}@?|\\%~`^"));
}
qi::rule<Iterator> api_call, query, location_options, location_with_options, destination_with_options, source_with_options, t_u, t_h, u_h, t_u_h;
qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location, destination, source,
hint, timestamp, bearing, stringwithDot, stringwithPercent, language, geometry, cmp, alt_route, u,
uturns, old_API, num_results, matching_beta, gps_precision, classify, locs, instruction, stringforPolyline;
qi::rule<Iterator> api_call, query, location_options, location_with_options,
destination_with_options, source_with_options, t_u, t_h, u_h, t_u_h;
qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location,
destination, source, hint, timestamp, bearing, stringwithDot, stringwithPercent, language,
geometry, cmp, alt_route, u, uturns, old_API, num_results, matching_beta, gps_precision,
classify, locs, instruction, stringforPolyline;
HandlerT *handler;
};
+4 -3
View File
@@ -162,9 +162,10 @@ class BinaryHeap
return inserted_nodes[heap[1].index].node;
}
Weight MinKey() const {
BOOST_ASSERT(heap.size() > 1);
return heap[1].weight;
Weight MinKey() const
{
BOOST_ASSERT(heap.size() > 1);
return heap[1].weight;
}
NodeID DeleteMin()
+30 -31
View File
@@ -8,48 +8,47 @@ struct FixedPointCoordinate;
namespace coordinate_calculation
{
double
haversine_distance(const int lat1, const int lon1, const int lat2, const int lon2);
double haversine_distance(const int lat1, const int lon1, const int lat2, const int lon2);
double haversine_distance(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
double haversine_distance(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
double great_circle_distance(const FixedPointCoordinate &first_coordinate,
double great_circle_distance(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
double great_circle_distance(const int lat1, const int lon1, const int lat2, const int lon2);
double great_circle_distance(const int lat1, const int lon1, const int lat2, const int lon2);
void lat_or_lon_to_string(const int value, std::string &output);
void lat_or_lon_to_string(const int value, std::string &output);
double perpendicular_distance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location);
double perpendicular_distance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location);
double perpendicular_distance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
FixedPointCoordinate &nearest_location,
double &ratio);
double perpendicular_distance(const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
FixedPointCoordinate &nearest_location,
double &ratio);
double perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate);
double perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate);
double perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate,
FixedPointCoordinate &nearest_location,
double &ratio);
double perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location,
const std::pair<double, double> &projected_coordinate,
FixedPointCoordinate &nearest_location,
double &ratio);
double deg_to_rad(const double degree);
double rad_to_deg(const double radian);
double deg_to_rad(const double degree);
double rad_to_deg(const double radian);
double bearing(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
double bearing(const FixedPointCoordinate &first_coordinate,
const FixedPointCoordinate &second_coordinate);
}
#endif // COORDINATE_CALCULATION
+3 -1
View File
@@ -14,7 +14,9 @@
#include <unordered_map>
// generate boost::program_options object for the routing part
bool GenerateDataStoreOptions(const int argc, const char *argv[], std::unordered_map<std::string, boost::filesystem::path> &paths)
bool GenerateDataStoreOptions(const int argc,
const char *argv[],
std::unordered_map<std::string, boost::filesystem::path> &paths)
{
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
+10 -9
View File
@@ -20,14 +20,15 @@ template <typename ElementT> struct ConstDeallocatingVectorIteratorState
{
}
explicit ConstDeallocatingVectorIteratorState(const std::size_t idx,
const std::vector<ElementT *> *input_list)
const std::vector<ElementT *> *input_list)
: index(idx), bucket_list(input_list)
{
}
std::size_t index;
const std::vector<ElementT *> *bucket_list;
ConstDeallocatingVectorIteratorState &operator=(const ConstDeallocatingVectorIteratorState &other)
ConstDeallocatingVectorIteratorState &
operator=(const ConstDeallocatingVectorIteratorState &other)
{
index = other.index;
bucket_list = other.bucket_list;
@@ -210,11 +211,10 @@ class DeallocatingVectorRemoveIterator
}
};
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK>
class DeallocatingVector;
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK> class DeallocatingVector;
template<typename T, std::size_t S>
void swap(DeallocatingVector<T, S>& lhs, DeallocatingVector<T, S>& rhs);
template <typename T, std::size_t S>
void swap(DeallocatingVector<T, S> &lhs, DeallocatingVector<T, S> &rhs);
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK = 8388608 / sizeof(ElementT)>
class DeallocatingVector
@@ -236,7 +236,8 @@ class DeallocatingVector
~DeallocatingVector() { clear(); }
friend void swap<>(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK>& lhs, DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK>& rhs);
friend void swap<>(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK> &lhs,
DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK> &rhs);
void swap(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK> &other)
{
@@ -367,8 +368,8 @@ class DeallocatingVector
}
};
template<typename T, std::size_t S>
void swap(DeallocatingVector<T, S>& lhs, DeallocatingVector<T, S>& rhs)
template <typename T, std::size_t S>
void swap(DeallocatingVector<T, S> &lhs, DeallocatingVector<T, S> &rhs)
{
lhs.swap(rhs);
}
+83 -55
View File
@@ -7,18 +7,32 @@
#ifndef DEBUG_GEOMETRY
inline void DEBUG_GEOMETRY_START(ContractorConfig & /* config */) {}
inline void DEBUG_GEOMETRY_EDGE(int /* new_segment_weight */ , double /* segment_length */,
OSMNodeID /* previous_osm_node_id */, OSMNodeID /* this_osm_node_id */) {}
inline void DEBUG_GEOMETRY_EDGE(int /* new_segment_weight */,
double /* segment_length */,
OSMNodeID /* previous_osm_node_id */,
OSMNodeID /* this_osm_node_id */)
{
}
inline void DEBUG_GEOMETRY_STOP() {}
inline void DEBUG_TURNS_START(const std::string & /* debug_turns_filename */) {}
inline void DEBUG_TURN( const NodeID /* node */, const std::vector<QueryNode>& /* m_node_info_list */,
const FixedPointCoordinate & /* first_coordinate */, const int /* turn_angle */,
const int /* turn_penalty */) {}
inline void DEBUG_UTURN( const NodeID /* node */, const std::vector<QueryNode>& /* m_node_info_list */,
const int /* uturn_penalty */ ) {}
inline void DEBUG_SIGNAL( const NodeID /* node */, const std::vector<QueryNode>& /* m_node_info_list */,
const int /* signal_penalty */ ) {}
inline void DEBUG_TURN(const NodeID /* node */,
const std::vector<QueryNode> & /* m_node_info_list */,
const FixedPointCoordinate & /* first_coordinate */,
const int /* turn_angle */,
const int /* turn_penalty */)
{
}
inline void DEBUG_UTURN(const NodeID /* node */,
const std::vector<QueryNode> & /* m_node_info_list */,
const int /* uturn_penalty */)
{
}
inline void DEBUG_SIGNAL(const NodeID /* node */,
const std::vector<QueryNode> & /* m_node_info_list */,
const int /* signal_penalty */)
{
}
inline void DEBUG_TURNS_STOP() {}
@@ -59,26 +73,27 @@ inline void DEBUG_GEOMETRY_START(const ContractorConfig &config)
}
}
inline void DEBUG_GEOMETRY_EDGE(int new_segment_weight, double segment_length, OSMNodeID previous_osm_node_id, OSMNodeID this_osm_node_id)
inline void DEBUG_GEOMETRY_EDGE(int new_segment_weight,
double segment_length,
OSMNodeID previous_osm_node_id,
OSMNodeID this_osm_node_id)
{
if (dg_output_debug_geometry)
{
if (!dg_first_debug_geometry)
debug_geometry_file << "," << std::endl;
debug_geometry_file
<< "{ \"type\":\"Feature\",\"properties\":{\"original\":false, "
"\"weight\":"
<< new_segment_weight / 10.0 << ",\"speed\":"
<< static_cast<int>(
std::floor((segment_length / new_segment_weight) * 10. * 3.6))
<< ",";
debug_geometry_file << "{ \"type\":\"Feature\",\"properties\":{\"original\":false, "
"\"weight\":"
<< new_segment_weight / 10.0 << ",\"speed\":"
<< static_cast<int>(
std::floor((segment_length / new_segment_weight) * 10. * 3.6))
<< ",";
debug_geometry_file << "\"from_node\": " << previous_osm_node_id
<< ", \"to_node\": " << this_osm_node_id << ",";
debug_geometry_file << "\"timestamp\": \"" << dg_time_buffer << "\"},";
debug_geometry_file
<< "\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[!!"
<< previous_osm_node_id << "!!],[!!" << this_osm_node_id << "!!]]}}"
<< std::endl;
debug_geometry_file << "\"geometry\":{\"type\":\"LineString\",\"coordinates\":[[!!"
<< previous_osm_node_id << "!!],[!!" << this_osm_node_id << "!!]]}}"
<< std::endl;
dg_first_debug_geometry = false;
}
}
@@ -92,66 +107,80 @@ inline void DEBUG_GEOMETRY_STOP()
}
}
inline void DEBUG_TURNS_START(const std::string & debug_turns_path)
{
inline void DEBUG_TURNS_START(const std::string &debug_turns_path)
{
dg_output_turn_debug = debug_turns_path != "";
if (dg_output_turn_debug)
if (dg_output_turn_debug)
{
dg_debug_turns_file.open(debug_turns_path);
dg_debug_turns_file << "{\"type\":\"FeatureCollection\", \"features\":[" << std::endl;
}
}
}
inline void DEBUG_SIGNAL(
const NodeID node,
const std::vector<QueryNode>& m_node_info_list,
const int traffic_signal_penalty)
inline void DEBUG_SIGNAL(const NodeID node,
const std::vector<QueryNode> &m_node_info_list,
const int traffic_signal_penalty)
{
if (dg_output_turn_debug)
{
const QueryNode &nodeinfo = m_node_info_list[node];
if (!dg_first_turn_debug) dg_debug_turns_file << "," << std::endl;
dg_debug_turns_file << "{ \"type\":\"Feature\",\"properties\":{\"type\":\"trafficlights\",\"cost\":" << traffic_signal_penalty/10. << "},";
dg_debug_turns_file << " \"geometry\":{\"type\":\"Point\",\"coordinates\":[" << std::setprecision(12) << nodeinfo.lon/COORDINATE_PRECISION << "," << nodeinfo.lat/COORDINATE_PRECISION << "]}}";
if (!dg_first_turn_debug)
dg_debug_turns_file << "," << std::endl;
dg_debug_turns_file
<< "{ \"type\":\"Feature\",\"properties\":{\"type\":\"trafficlights\",\"cost\":"
<< traffic_signal_penalty / 10. << "},";
dg_debug_turns_file << " \"geometry\":{\"type\":\"Point\",\"coordinates\":["
<< std::setprecision(12) << nodeinfo.lon / COORDINATE_PRECISION << ","
<< nodeinfo.lat / COORDINATE_PRECISION << "]}}";
dg_first_turn_debug = false;
}
}
inline void DEBUG_UTURN(
const NodeID node,
const std::vector<QueryNode>& m_node_info_list,
const int traffic_signal_penalty)
inline void DEBUG_UTURN(const NodeID node,
const std::vector<QueryNode> &m_node_info_list,
const int traffic_signal_penalty)
{
if (dg_output_turn_debug)
{
const QueryNode &nodeinfo = m_node_info_list[node];
if (!dg_first_turn_debug) dg_debug_turns_file << "," << std::endl;
dg_debug_turns_file << "{ \"type\":\"Feature\",\"properties\":{\"type\":\"trafficlights\",\"cost\":" << traffic_signal_penalty/10. << "},";
dg_debug_turns_file << " \"geometry\":{\"type\":\"Point\",\"coordinates\":[" << std::setprecision(12) << nodeinfo.lon/COORDINATE_PRECISION << "," << nodeinfo.lat/COORDINATE_PRECISION << "]}}";
if (!dg_first_turn_debug)
dg_debug_turns_file << "," << std::endl;
dg_debug_turns_file
<< "{ \"type\":\"Feature\",\"properties\":{\"type\":\"trafficlights\",\"cost\":"
<< traffic_signal_penalty / 10. << "},";
dg_debug_turns_file << " \"geometry\":{\"type\":\"Point\",\"coordinates\":["
<< std::setprecision(12) << nodeinfo.lon / COORDINATE_PRECISION << ","
<< nodeinfo.lat / COORDINATE_PRECISION << "]}}";
dg_first_turn_debug = false;
}
}
inline void DEBUG_TURN(
const NodeID node,
const std::vector<QueryNode>& m_node_info_list,
const FixedPointCoordinate & first_coordinate,
const int turn_angle,
const int turn_penalty)
inline void DEBUG_TURN(const NodeID node,
const std::vector<QueryNode> &m_node_info_list,
const FixedPointCoordinate &first_coordinate,
const int turn_angle,
const int turn_penalty)
{
if (turn_penalty > 0 && dg_output_turn_debug)
if (turn_penalty > 0 && dg_output_turn_debug)
{
const QueryNode &v = m_node_info_list[node];
const float bearing_uv = coordinate_calculation::bearing(first_coordinate,v);
float uvw_normal = bearing_uv + turn_angle/2;
while (uvw_normal >= 360.) { uvw_normal -= 360.; }
const float bearing_uv = coordinate_calculation::bearing(first_coordinate, v);
float uvw_normal = bearing_uv + turn_angle / 2;
while (uvw_normal >= 360.)
{
uvw_normal -= 360.;
}
if (!dg_first_turn_debug) dg_debug_turns_file << "," << std::endl;
dg_debug_turns_file << "{ \"type\":\"Feature\",\"properties\":{\"type\":\"turn\",\"cost\":" << turn_penalty/10. << ",\"turn_angle\":" << static_cast<int>(turn_angle) << ",\"normal\":" << static_cast<int>(uvw_normal) << "},";
dg_debug_turns_file << " \"geometry\":{\"type\":\"Point\",\"coordinates\":[" << std::setprecision(12) << v.lon/COORDINATE_PRECISION << "," << v.lat/COORDINATE_PRECISION << "]}}";
if (!dg_first_turn_debug)
dg_debug_turns_file << "," << std::endl;
dg_debug_turns_file << "{ \"type\":\"Feature\",\"properties\":{\"type\":\"turn\",\"cost\":"
<< turn_penalty / 10.
<< ",\"turn_angle\":" << static_cast<int>(turn_angle)
<< ",\"normal\":" << static_cast<int>(uvw_normal) << "},";
dg_debug_turns_file << " \"geometry\":{\"type\":\"Point\",\"coordinates\":["
<< std::setprecision(12) << v.lon / COORDINATE_PRECISION << ","
<< v.lat / COORDINATE_PRECISION << "]}}";
dg_first_turn_debug = false;
}
}
@@ -167,5 +196,4 @@ inline void DEBUG_TURNS_STOP()
#endif // DEBUG_GEOMETRY
#endif // DEBUG_GEOMETRY_H
+2 -1
View File
@@ -64,7 +64,8 @@ template <typename EdgeDataT> class DynamicGraph
template <class ContainerT> DynamicGraph(const NodeIterator nodes, const ContainerT &graph)
{
// we need to cast here because DeallocatingVector does not have a valid const iterator
BOOST_ASSERT(std::is_sorted(const_cast<ContainerT&>(graph).begin(), const_cast<ContainerT&>(graph).end()));
BOOST_ASSERT(std::is_sorted(const_cast<ContainerT &>(graph).begin(),
const_cast<ContainerT &>(graph).end()));
number_of_nodes = nodes;
number_of_edges = static_cast<EdgeIterator>(graph.size());
-2
View File
@@ -25,10 +25,8 @@ class FingerPrint
// initialize to {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
boost::uuids::uuid named_uuid;
};
static_assert(std::is_trivial<FingerPrint>::value, "FingerPrint needs to be trivial.");
#endif /* FingerPrint_H */
+8 -8
View File
@@ -7,20 +7,20 @@
#include <vector>
/// This function checks if the graph (consisting of directed edges) is undirected
template<typename GraphT>
bool isUndirectedGraph(const GraphT& graph)
template <typename GraphT> bool isUndirectedGraph(const GraphT &graph)
{
for (auto source = 0u; source < graph.GetNumberOfNodes(); ++source)
{
for (auto edge = graph.BeginEdges(source); edge < graph.EndEdges(source); ++edge)
{
const auto& data = graph.GetEdgeData(edge);
const auto &data = graph.GetEdgeData(edge);
auto target = graph.GetTarget(edge);
BOOST_ASSERT(target != SPECIAL_NODEID);
bool found_reverse = false;
for (auto rev_edge = graph.BeginEdges(target); rev_edge < graph.EndEdges(target); ++rev_edge)
for (auto rev_edge = graph.BeginEdges(target); rev_edge < graph.EndEdges(target);
++rev_edge)
{
auto rev_target = graph.GetTarget(rev_edge);
BOOST_ASSERT(rev_target != SPECIAL_NODEID);
@@ -44,7 +44,6 @@ bool isUndirectedGraph(const GraphT& graph)
return true;
}
/// Since DynamicGraph assumes directed edges we have to make sure we transformed
/// the compressed edge format into single directed edges. We do this to make sure
/// every node also knows its incoming edges, not only its outgoing edges and use the reversed=true
@@ -60,13 +59,14 @@ bool isUndirectedGraph(const GraphT& graph)
/// (a <-- b gets reducted to b --> a)
/// 2. a --> b will be transformed to a --> b and b <-- a
/// 3. a <-> b will be transformed to a --> b and b --> a
template<typename OutputEdgeT, typename InputEdgeT, typename FunctorT>
std::vector<OutputEdgeT> directedEdgesFromCompressed(const std::vector<InputEdgeT>& input_edge_list, FunctorT copy_data)
template <typename OutputEdgeT, typename InputEdgeT, typename FunctorT>
std::vector<OutputEdgeT> directedEdgesFromCompressed(const std::vector<InputEdgeT> &input_edge_list,
FunctorT copy_data)
{
std::vector<OutputEdgeT> output_edge_list;
OutputEdgeT edge;
for (const auto& input_edge : input_edge_list)
for (const auto &input_edge : input_edge_list)
{
// edges that are not forward get converted by flipping the end points
BOOST_ASSERT(input_edge.forward);
+1 -4
View File
@@ -28,10 +28,7 @@ template <typename Integer> class range
const range &end() const noexcept { return *this; }
Integer front() const noexcept { return iter; }
Integer back() const noexcept { return last - 1; }
std::size_t size() const noexcept
{
return static_cast<std::size_t>(last - iter);
}
std::size_t size() const noexcept { return static_cast<std::size_t>(last - iter); }
// Iterator functions
bool operator!=(const range &) const noexcept { return iter < last; }
+3 -8
View File
@@ -20,7 +20,7 @@ class Logger
using MapT = std::unordered_map<std::string, osrm::json::Value>;
public:
static Logger* get()
static Logger *get()
{
static Logger logger;
@@ -40,7 +40,7 @@ class Logger
return nullptr;
}
void initialize(const std::string& name)
void initialize(const std::string &name)
{
if (!map.get())
{
@@ -49,15 +49,10 @@ class Logger
(*map)[name] = Object();
}
void render(const std::string& name, Object& obj) const
{
obj.values["debug"] = map->at(name);
}
void render(const std::string &name, Object &obj) const { obj.values["debug"] = map->at(name); }
boost::thread_specific_ptr<MapT> map;
};
}
}
+18 -12
View File
@@ -13,17 +13,22 @@ struct NodeBasedEdgeData
{
NodeBasedEdgeData()
: distance(INVALID_EDGE_WEIGHT), edge_id(SPECIAL_NODEID),
name_id(std::numeric_limits<unsigned>::max()), access_restricted(false),
reversed(false), roundabout(false), travel_mode(TRAVEL_MODE_INACCESSIBLE)
name_id(std::numeric_limits<unsigned>::max()), access_restricted(false), reversed(false),
roundabout(false), travel_mode(TRAVEL_MODE_INACCESSIBLE)
{
}
NodeBasedEdgeData(int distance, unsigned edge_id, unsigned name_id,
bool access_restricted, bool reversed,
bool roundabout, bool startpoint, TravelMode travel_mode)
NodeBasedEdgeData(int distance,
unsigned edge_id,
unsigned name_id,
bool access_restricted,
bool reversed,
bool roundabout,
bool startpoint,
TravelMode travel_mode)
: distance(distance), edge_id(edge_id), name_id(name_id),
access_restricted(access_restricted), reversed(reversed),
roundabout(roundabout), startpoint(startpoint), travel_mode(travel_mode)
access_restricted(access_restricted), reversed(reversed), roundabout(roundabout),
startpoint(startpoint), travel_mode(travel_mode)
{
}
@@ -49,10 +54,12 @@ using NodeBasedDynamicGraph = DynamicGraph<NodeBasedEdgeData>;
/// Since DynamicGraph expects directed edges, we need to insert
/// two edges for undirected edges.
inline std::shared_ptr<NodeBasedDynamicGraph>
NodeBasedDynamicGraphFromEdges(std::size_t number_of_nodes, const std::vector<NodeBasedEdge> &input_edge_list)
NodeBasedDynamicGraphFromEdges(std::size_t number_of_nodes,
const std::vector<NodeBasedEdge> &input_edge_list)
{
auto edges_list = directedEdgesFromCompressed<NodeBasedDynamicGraph::InputEdge>(input_edge_list,
[](NodeBasedDynamicGraph::InputEdge& output_edge, const NodeBasedEdge& input_edge)
auto edges_list = directedEdgesFromCompressed<NodeBasedDynamicGraph::InputEdge>(
input_edge_list,
[](NodeBasedDynamicGraph::InputEdge &output_edge, const NodeBasedEdge &input_edge)
{
output_edge.data.distance = static_cast<int>(input_edge.weight);
BOOST_ASSERT(output_edge.data.distance > 0);
@@ -62,8 +69,7 @@ NodeBasedDynamicGraphFromEdges(std::size_t number_of_nodes, const std::vector<No
output_edge.data.access_restricted = input_edge.access_restricted;
output_edge.data.travel_mode = input_edge.travel_mode;
output_edge.data.startpoint = input_edge.startpoint;
}
);
});
tbb::parallel_sort(edges_list.begin(), edges_list.end());
+1 -2
View File
@@ -53,8 +53,7 @@ template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> class RangeTable
}
// construct table from length vector
template<typename VectorT>
explicit RangeTable(const VectorT &lengths)
template <typename VectorT> explicit RangeTable(const VectorT &lengths)
{
const unsigned number_of_blocks = [&lengths]()
{
+3 -3
View File
@@ -60,10 +60,10 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
return osrm::irange(BeginEdges(node), EndEdges(node));
}
template<typename ContainerT>
StaticGraph(const int nodes, const ContainerT &graph)
template <typename ContainerT> StaticGraph(const int nodes, const ContainerT &graph)
{
BOOST_ASSERT(std::is_sorted(const_cast<ContainerT&>(graph).begin(), const_cast<ContainerT&>(graph).end()));
BOOST_ASSERT(std::is_sorted(const_cast<ContainerT &>(graph).begin(),
const_cast<ContainerT &>(graph).end()));
number_of_nodes = nodes;
number_of_edges = static_cast<EdgeIterator>(graph.size());
+8 -8
View File
@@ -319,7 +319,7 @@ class StaticRTree
// Override filter and terminator for the desired behaviour.
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate &input_coordinate,
const std::size_t max_results)
const std::size_t max_results)
{
return Nearest(input_coordinate,
[](const EdgeDataT &)
@@ -335,8 +335,8 @@ class StaticRTree
// Override filter and terminator for the desired behaviour.
template <typename FilterT, typename TerminationT>
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate &input_coordinate,
const FilterT filter,
const TerminationT terminate)
const FilterT filter,
const TerminationT terminate)
{
std::vector<EdgeDataT> results;
std::pair<double, double> projected_coordinate = {
@@ -345,7 +345,7 @@ class StaticRTree
// initialize queue with root element
std::priority_queue<QueryCandidate> traversal_queue;
traversal_queue.push(QueryCandidate {0.f, m_search_tree[0]});
traversal_queue.push(QueryCandidate{0.f, m_search_tree[0]});
while (!traversal_queue.empty())
{
@@ -377,7 +377,6 @@ class StaticRTree
// inspecting an actual road segment
const auto &current_segment = current_query_node.node.template get<EdgeDataT>();
auto use_segment = filter(current_segment);
if (!use_segment.first && !use_segment.second)
{
@@ -422,7 +421,8 @@ class StaticRTree
// distance must be non-negative
BOOST_ASSERT(0.f <= current_perpendicular_distance);
traversal_queue.push(QueryCandidate {current_perpendicular_distance, std::move(current_edge)});
traversal_queue.push(
QueryCandidate{current_perpendicular_distance, std::move(current_edge)});
}
}
@@ -437,7 +437,7 @@ class StaticRTree
const auto &child_tree_node = m_search_tree[child_id];
const auto &child_rectangle = child_tree_node.minimum_bounding_rectangle;
const float lower_bound_to_element = child_rectangle.GetMinDist(input_coordinate);
traversal_queue.push(QueryCandidate {lower_bound_to_element, m_search_tree[child_id]});
traversal_queue.push(QueryCandidate{lower_bound_to_element, m_search_tree[child_id]});
}
}
@@ -449,7 +449,7 @@ class StaticRTree
}
if (!leaves_stream.good())
{
throw osrm::exception("Could not read from leaf file.");
throw osrm::exception("Could not read from leaf file.");
}
const uint64_t seek_pos = sizeof(uint64_t) + leaf_id * sizeof(LeafNode);
leaves_stream.seekg(seek_pos);