From b41af5f58045d356bf9c08dffe4bad4b9ca5470e Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 9 Dec 2015 22:34:22 +0100 Subject: [PATCH] Incoperate PR comments --- algorithms/geospatial_query.hpp | 36 +++++++++---------- benchmarks/static_rtree.cpp | 4 +-- data_structures/hidden_markov_model.hpp | 2 +- data_structures/phantom_node.hpp | 6 ++++ data_structures/static_rtree.hpp | 4 +-- extractor/extractor.cpp | 4 +-- plugins/match.hpp | 32 ++++++++--------- plugins/nearest.hpp | 10 +++--- plugins/trip.hpp | 2 +- routing_algorithms/map_matching.hpp | 10 +++--- server/data_structures/datafacade_base.hpp | 4 +-- .../data_structures/internal_datafacade.hpp | 4 +-- server/data_structures/shared_datafacade.hpp | 6 ++-- util/matching_debug_info.hpp | 4 +-- 14 files changed, 68 insertions(+), 60 deletions(-) diff --git a/algorithms/geospatial_query.hpp b/algorithms/geospatial_query.hpp index cef178f5e..96b4fc5a2 100644 --- a/algorithms/geospatial_query.hpp +++ b/algorithms/geospatial_query.hpp @@ -28,7 +28,7 @@ template class GeospatialQuery // Returns nearest PhantomNodes in the given bearing range within max_distance. // Does not filter by small/big component! - std::vector> + std::vector NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate, const float max_distance, const int bearing = 0, @@ -50,7 +50,7 @@ template class GeospatialQuery // Returns max_results nearest PhantomNodes in the given bearing range. // Does not filter by small/big component! - std::vector> + std::vector NearestPhantomNodes(const FixedPointCoordinate &input_coordinate, const unsigned max_results, const int bearing = 0, @@ -84,7 +84,7 @@ template class GeospatialQuery &has_small_component](const EdgeData &data) { auto use_segment = - (!has_small_component || (!has_big_component && !data.component.is_tiny)) ; + (!has_small_component || (!has_big_component && !data.component.is_tiny)); auto use_directions = std::make_pair(use_segment, use_segment); if (use_segment) @@ -104,22 +104,22 @@ template class GeospatialQuery return num_results > 0 && has_big_component; }); - if (results.size() == 0) { - return std::make_pair(PhantomNode {}, PhantomNode {}); + return std::make_pair(PhantomNode{}, PhantomNode{}); } BOOST_ASSERT(results.size() > 0); - return std::make_pair(MakePhantomNode(input_coordinate, results.front()).second, MakePhantomNode(input_coordinate, results.back()).second); + return std::make_pair(MakePhantomNode(input_coordinate, results.front()).phantom_node, + MakePhantomNode(input_coordinate, results.back()).phantom_node); } private: - inline std::vector> + std::vector MakePhantomNodes(const FixedPointCoordinate &input_coordinate, const std::vector &results) const { - std::vector> distance_and_phantoms(results.size()); + std::vector distance_and_phantoms(results.size()); std::transform(results.begin(), results.end(), distance_and_phantoms.begin(), [this, &input_coordinate](const EdgeData &data) { @@ -128,8 +128,8 @@ template class GeospatialQuery return distance_and_phantoms; } - inline std::pair - MakePhantomNode(const FixedPointCoordinate &input_coordinate, const EdgeData &data) const + PhantomNodeWithDistance MakePhantomNode(const FixedPointCoordinate &input_coordinate, + const EdgeData &data) const { FixedPointCoordinate point_on_segment; float ratio; @@ -138,24 +138,24 @@ template class GeospatialQuery ratio); auto transformed = - std::make_pair(current_perpendicular_distance, PhantomNode{data, point_on_segment}); + PhantomNodeWithDistance { PhantomNode{data, point_on_segment}, current_perpendicular_distance }; ratio = std::min(1.f, std::max(0.f, ratio)); - if (SPECIAL_NODEID != transformed.second.forward_node_id) + if (SPECIAL_NODEID != transformed.phantom_node.forward_node_id) { - transformed.second.forward_weight *= ratio; + transformed.phantom_node.forward_weight *= ratio; } - if (SPECIAL_NODEID != transformed.second.reverse_node_id) + if (SPECIAL_NODEID != transformed.phantom_node.reverse_node_id) { - transformed.second.reverse_weight *= 1.f - ratio; + transformed.phantom_node.reverse_weight *= 1.f - ratio; } return transformed; } - inline std::pair checkSegmentBearing(const EdgeData &segment, - const float filter_bearing, - const float filter_bearing_range) + std::pair checkSegmentBearing(const EdgeData &segment, + const float filter_bearing, + const float filter_bearing_range) { const float forward_edge_bearing = coordinate_calculation::bearing(coordinates->at(segment.u), coordinates->at(segment.v)); diff --git a/benchmarks/static_rtree.cpp b/benchmarks/static_rtree.cpp index c8d70594d..ebe055cce 100644 --- a/benchmarks/static_rtree.cpp +++ b/benchmarks/static_rtree.cpp @@ -69,7 +69,7 @@ FixedPointCoordinateListPtr LoadCoordinates(const boost::filesystem::path &nodes template void BenchmarkQuery(const std::vector &queries, - std::string name, + const std::string& name, QueryT query) { std::cout << "Running " << name << " with " << queries.size() << " coordinates: " << std::flush; @@ -96,7 +96,7 @@ void Benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer std::vector queries; for (unsigned i = 0; i < num_queries; i++) { - queries.emplace_back(FixedPointCoordinate(lat_udist(mt_rand), lon_udist(mt_rand))); + queries.emplace_back(lat_udist(mt_rand), lon_udist(mt_rand)); } BenchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const FixedPointCoordinate &q) diff --git a/data_structures/hidden_markov_model.hpp b/data_structures/hidden_markov_model.hpp index 0e8d8a464..e3efcea08 100644 --- a/data_structures/hidden_markov_model.hpp +++ b/data_structures/hidden_markov_model.hpp @@ -140,7 +140,7 @@ template struct HiddenMarkovModel for (const auto s : osrm::irange(0u, viterbi[initial_timestamp].size())) { viterbi[initial_timestamp][s] = - emission_log_probability(candidates_list[initial_timestamp][s].first); + emission_log_probability(candidates_list[initial_timestamp][s].distance); parents[initial_timestamp][s] = std::make_pair(initial_timestamp, s); pruned[initial_timestamp][s] = viterbi[initial_timestamp][s] < osrm::matching::MINIMAL_LOG_PROB; diff --git a/data_structures/phantom_node.hpp b/data_structures/phantom_node.hpp index af5632227..b12c4feb6 100644 --- a/data_structures/phantom_node.hpp +++ b/data_structures/phantom_node.hpp @@ -124,6 +124,12 @@ static_assert(sizeof(PhantomNode) == 48, "PhantomNode has more padding then expe using PhantomNodePair = std::pair; +struct PhantomNodeWithDistance +{ + PhantomNode phantom_node; + double distance; +}; + struct PhantomNodes { PhantomNode source_phantom; diff --git a/data_structures/static_rtree.hpp b/data_structures/static_rtree.hpp index 0e0aaf781..6bc367824 100644 --- a/data_structures/static_rtree.hpp +++ b/data_structures/static_rtree.hpp @@ -412,7 +412,7 @@ class StaticRTree } // store phantom node in result vector - results.emplace_back(std::move(current_segment)); + results.push_back(std::move(current_segment)); if (!use_segment.first) { @@ -476,7 +476,7 @@ class StaticRTree } if (!leaves_stream.good()) { - leaves_stream.clear(std::ios::goodbit); + 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); diff --git a/extractor/extractor.cpp b/extractor/extractor.cpp index 4fa6997aa..87cfb4d88 100644 --- a/extractor/extractor.cpp +++ b/extractor/extractor.cpp @@ -580,8 +580,8 @@ void extractor::BuildRTree(const std::vector &node_based_edge_lis << " coordinates"; TIMER_START(construction); - StaticRTree(node_based_edge_list, config.rtree_nodes_output_path.c_str(), - config.rtree_leafs_output_path.c_str(), + StaticRTree(node_based_edge_list, config.rtree_nodes_output_path, + config.rtree_leafs_output_path, internal_to_external_node_map); TIMER_STOP(construction); diff --git a/plugins/match.hpp b/plugins/match.hpp index 79d479b81..441bbb798 100644 --- a/plugins/match.hpp +++ b/plugins/match.hpp @@ -135,18 +135,18 @@ template class MapMatchingPlugin : public BasePlugin // sort by foward id, then by reverse id and then by distance std::sort(candidates.begin(), candidates.end(), - [](const std::pair& lhs, const std::pair& rhs) { - return lhs.second.forward_node_id < rhs.second.forward_node_id || - (lhs.second.forward_node_id == rhs.second.forward_node_id && - (lhs.second.reverse_node_id < rhs.second.reverse_node_id || - (lhs.second.reverse_node_id == rhs.second.reverse_node_id && - lhs.first < rhs.first))); + [](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) { + return lhs.phantom_node.forward_node_id < rhs.phantom_node.forward_node_id || + (lhs.phantom_node.forward_node_id == rhs.phantom_node.forward_node_id && + (lhs.phantom_node.reverse_node_id < rhs.phantom_node.reverse_node_id || + (lhs.phantom_node.reverse_node_id == rhs.phantom_node.reverse_node_id && + lhs.distance < rhs.distance))); }); auto new_end = std::unique(candidates.begin(), candidates.end(), - [](const std::pair& lhs, const std::pair& rhs) { - return lhs.second.forward_node_id == rhs.second.forward_node_id && - lhs.second.reverse_node_id == rhs.second.reverse_node_id; + [](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) { + return lhs.phantom_node.forward_node_id == rhs.phantom_node.forward_node_id && + lhs.phantom_node.reverse_node_id == rhs.phantom_node.reverse_node_id; }); candidates.resize(new_end - candidates.begin()); @@ -156,22 +156,22 @@ template class MapMatchingPlugin : public BasePlugin for (const auto i : osrm::irange(0, compact_size)) { // Split edge if it is bidirectional and append reverse direction to end of list - if (candidates[i].second.forward_node_id != SPECIAL_NODEID && - candidates[i].second.reverse_node_id != SPECIAL_NODEID) + if (candidates[i].phantom_node.forward_node_id != SPECIAL_NODEID && + candidates[i].phantom_node.reverse_node_id != SPECIAL_NODEID) { - PhantomNode reverse_node(candidates[i].second); + PhantomNode reverse_node(candidates[i].phantom_node); reverse_node.forward_node_id = SPECIAL_NODEID; - candidates.push_back(std::make_pair(candidates[i].first, reverse_node)); + candidates.push_back(PhantomNodeWithDistance { reverse_node, candidates[i].distance}); - candidates[i].second.reverse_node_id = SPECIAL_NODEID; + candidates[i].phantom_node.reverse_node_id = SPECIAL_NODEID; } } } // sort by distance to make pruning effective std::sort(candidates.begin(), candidates.end(), - [](const std::pair& lhs, const std::pair& rhs) { - return lhs.first < rhs.first; + [](const PhantomNodeWithDistance& lhs, const PhantomNodeWithDistance& rhs) { + return lhs.distance < rhs.distance; }); candidates_lists.push_back(std::move(candidates)); diff --git a/plugins/nearest.hpp b/plugins/nearest.hpp index 87458b182..d92e720b4 100644 --- a/plugins/nearest.hpp +++ b/plugins/nearest.hpp @@ -71,7 +71,7 @@ template class NearestPlugin final : public BasePlugin const int range = input_bearings.size() > 0 ? (input_bearings.front().second?*input_bearings.front().second:10) : 180; auto phantom_node_vector = facade->NearestPhantomNodes(route_parameters.coordinates.front(), number_of_results, bearing, range); - if (phantom_node_vector.empty() || !phantom_node_vector.front().second.is_valid()) + if (phantom_node_vector.empty() || !phantom_node_vector.front().phantom_node.is_valid()) { json_result.values["status"] = 207; } @@ -88,7 +88,7 @@ template class NearestPlugin final : public BasePlugin for (const auto i : osrm::irange(0, std::min(number_of_results, vector_length))) { - const auto& node = phantom_node_vector[i].second; + const auto& node = phantom_node_vector[i].phantom_node; osrm::json::Array json_coordinate; osrm::json::Object result; json_coordinate.values.push_back(node.location.lat / COORDINATE_PRECISION); @@ -103,13 +103,13 @@ template class NearestPlugin final : public BasePlugin else { osrm::json::Array json_coordinate; - json_coordinate.values.push_back(phantom_node_vector.front().second.location.lat / + json_coordinate.values.push_back(phantom_node_vector.front().phantom_node.location.lat / COORDINATE_PRECISION); - json_coordinate.values.push_back(phantom_node_vector.front().second.location.lon / + json_coordinate.values.push_back(phantom_node_vector.front().phantom_node.location.lon / COORDINATE_PRECISION); json_result.values["mapped_coordinate"] = json_coordinate; json_result.values["name"] = - facade->get_name_for_id(phantom_node_vector.front().second.name_id); + facade->get_name_for_id(phantom_node_vector.front().phantom_node.name_id); } } return 200; diff --git a/plugins/trip.hpp b/plugins/trip.hpp index 13e53fe83..de9c7f682 100644 --- a/plugins/trip.hpp +++ b/plugins/trip.hpp @@ -97,7 +97,7 @@ template class RoundTripPlugin final : public BasePlugin const int range = input_bearings.size() > 0 ? (input_bearings[i].second?*input_bearings[i].second:10) : 180; auto phantom_nodes = facade->NearestPhantomNodes(route_parameters.coordinates[i], 1, bearing, range); // FIXME we only use the pair because that is what DistanceTable expects - phantom_node_pair_list[i] = std::make_pair(phantom_nodes.front().second, phantom_nodes.front().second); + phantom_node_pair_list[i] = std::make_pair(phantom_nodes.front().phantom_node, phantom_nodes.front().phantom_node); BOOST_ASSERT(phantom_node_pair_list[i].first.is_valid(facade->GetNumberOfNodes())); } } diff --git a/routing_algorithms/map_matching.hpp b/routing_algorithms/map_matching.hpp index 02d9279b9..a36fabd35 100644 --- a/routing_algorithms/map_matching.hpp +++ b/routing_algorithms/map_matching.hpp @@ -57,7 +57,7 @@ struct SubMatching double confidence; }; -using CandidateList = std::vector>; +using CandidateList = std::vector; using CandidateLists = std::vector; using HMM = HiddenMarkovModel; using SubMatchingList = std::vector; @@ -232,7 +232,7 @@ class MapMatching final : public BasicRoutingInterface new_value) { @@ -244,8 +244,8 @@ class MapMatching final : public BasicRoutingInterface class BaseDataFacade virtual TravelMode GetTravelModeForEdgeID(const unsigned id) const = 0; - virtual std::vector> + virtual std::vector NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate, const float max_distance, const int bearing = 0, const int bearing_range = 180) = 0; - virtual std::vector> + virtual std::vector NearestPhantomNodes(const FixedPointCoordinate &input_coordinate, const unsigned max_results, const int bearing = 0, diff --git a/server/data_structures/internal_datafacade.hpp b/server/data_structures/internal_datafacade.hpp index 9bdb5f2d2..f16c2585a 100644 --- a/server/data_structures/internal_datafacade.hpp +++ b/server/data_structures/internal_datafacade.hpp @@ -360,7 +360,7 @@ template class InternalDataFacade final : public BaseDataFacad } - std::vector> + std::vector NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate, const float max_distance, const int bearing = 0, @@ -375,7 +375,7 @@ template class InternalDataFacade final : public BaseDataFacad return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, bearing, bearing_range); } - std::vector> + std::vector NearestPhantomNodes(const FixedPointCoordinate &input_coordinate, const unsigned max_results, const int bearing = 0, diff --git a/server/data_structures/shared_datafacade.hpp b/server/data_structures/shared_datafacade.hpp index b7ac21a66..851ed249d 100644 --- a/server/data_structures/shared_datafacade.hpp +++ b/server/data_structures/shared_datafacade.hpp @@ -40,6 +40,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../../util/make_unique.hpp" #include "../../util/simple_logger.hpp" +#include + #include #include #include @@ -382,7 +384,7 @@ template class SharedDataFacade final : public BaseDataFacade< return m_travel_mode_list.at(id); } - std::vector> + std::vector NearestPhantomNodesInRange(const FixedPointCoordinate &input_coordinate, const float max_distance, const int bearing = 0, @@ -397,7 +399,7 @@ template class SharedDataFacade final : public BaseDataFacade< return m_geospatial_query->NearestPhantomNodesInRange(input_coordinate, max_distance, bearing, bearing_range); } - std::vector> + std::vector NearestPhantomNodes(const FixedPointCoordinate &input_coordinate, const unsigned max_results, const int bearing = 0, diff --git a/util/matching_debug_info.hpp b/util/matching_debug_info.hpp index da8ca819e..28bc6ee3f 100644 --- a/util/matching_debug_info.hpp +++ b/util/matching_debug_info.hpp @@ -62,8 +62,8 @@ struct MatchingDebugInfo osrm::json::Object state; state.values["transitions"] = osrm::json::Array(); state.values["coordinate"] = - osrm::json::make_array(elem_s.second.location.lat / COORDINATE_PRECISION, - elem_s.second.location.lon / COORDINATE_PRECISION); + osrm::json::make_array(elem_s.phantom_node.location.lat / COORDINATE_PRECISION, + elem_s.phantom_node.location.lon / COORDINATE_PRECISION); state.values["viterbi"] = osrm::json::clamp_float(osrm::matching::IMPOSSIBLE_LOG_PROB); state.values["pruned"] = 0u;