diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 0c6ce83498c..7614554a7ec 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -448,6 +448,9 @@ template class GeospatialQuery const auto forward_duration_range = datafacade.GetUncompressedForwardDurations(geometry_id); const auto reverse_duration_range = datafacade.GetUncompressedReverseDurations(geometry_id); + const auto forward_geometry_range = datafacade.GetUncompressedForwardGeometry(geometry_id); + const auto reverse_geometry_range = datafacade.GetUncompressedReverseGeometry(geometry_id); + const auto forward_weight_offset = std::accumulate(forward_weight_range.begin(), forward_weight_range.begin() + data.fwd_segment_position, @@ -458,15 +461,27 @@ template class GeospatialQuery forward_duration_range.begin() + data.fwd_segment_position, EdgeDuration{0}); - // TO THIS AND THE REVERSE FOR GetUncompressedForwardGeometry WHICH THEN GETS STORED IN - // PHANTOM NODE - // const auto forward_duration_offset = - // std::accumulate(forward_duration_range.begin(), - // forward_duration_range.begin() + data.fwd_segment_position, - // EdgeDuration{0}); + // const auto forward_geometries_offset = + // std::accumulate(forward_geometry_range.begin(), + // forward_geometry_range.begin() + data.fwd_segment_position, + // EdgeDistance{0}); + + const auto forward_distance_offset = 0; + for (auto current = forward_geometry_range.begin() + 1; + current != forward_geometry_range.begin() + data.fwd_segment_position + 1; + ++current) + { + auto prev = current - 1; + + forward_distance_offset += util::coordinate_calculation::haversineDistance( + facade.GetCoordinateOfNode(*prev), facade.GetCoordinateOfNode(*current)); + } EdgeWeight forward_weight = forward_weight_range[data.fwd_segment_position]; EdgeDuration forward_duration = forward_duration_range[data.fwd_segment_position]; + EdgeDistance forward_geometry = HaversineDistance( + facade.GetCoordinateOfNode(forward_geometry_range[data.fwd_segment_position]), + point_on_segment); BOOST_ASSERT(data.fwd_segment_position < std::distance(forward_duration_range.begin(), forward_duration_range.end())); @@ -481,10 +496,30 @@ template class GeospatialQuery reverse_duration_range.end() - data.fwd_segment_position - 1, EdgeDuration{0}); + // const auto reverse_geometries_offset = + // std::accumulate(reverse_geometry_range.begin(), + // reverse_geometry_range.begin() + data.fwd_segment_position, + // EdgeDistance{0}); + + const auto reverse_distance_offset = 0; + for (auto current = reverse_geometry_range.begin() + 1; + current != reverse_geometry_range.begin() + data.fwd_segment_position + 1; + ++current) + { + auto prev = current - 1; + + reverse_distance_offset += util::coordinate_calculation::haversineDistance( + facade.GetCoordinateOfNode(*prev), facade.GetCoordinateOfNode(*current)); + } + EdgeWeight reverse_weight = reverse_weight_range[reverse_weight_range.size() - data.fwd_segment_position - 1]; EdgeDuration reverse_duration = reverse_duration_range[reverse_duration_range.size() - data.fwd_segment_position - 1]; + EdgeDistance reverse_distance = HaversineDistance( + facade.GetCoordinateOfNode(reverse_geometry_range[reverse_geometry_range.size() - + data.fwd_segment_position - 1]), + point_on_segment); ratio = std::min(1.0, std::max(0.0, ratio)); if (data.forward_segment_id.id != SPECIAL_SEGMENTID) @@ -530,7 +565,11 @@ template class GeospatialQuery point_on_segment, input_coordinate, static_cast(util::coordinate_calculation::bearing( - coordinates[data.u], coordinates[data.v]))}, + coordinates[data.u], coordinates[data.v])), + forward_distance, + reverse_distance, + forward_distance_offset, + reverse_distance_offset}, current_perpendicular_distance}; return transformed; diff --git a/include/engine/hint.hpp b/include/engine/hint.hpp index 7334b673796..5ad735cc77f 100644 --- a/include/engine/hint.hpp +++ b/include/engine/hint.hpp @@ -63,7 +63,7 @@ struct Hint friend std::ostream &operator<<(std::ostream &, const Hint &); }; -static_assert(sizeof(Hint) == 64 + 4, "Hint is bigger than expected"); +static_assert(sizeof(Hint) == 128 + 4, "Hint is bigger than expected"); constexpr std::size_t ENCODED_HINT_SIZE = 92; static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint), "ENCODED_HINT_SIZE does not match size of Hint"); diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 8b6ebb2fe9c..ebd1d716434 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -50,7 +50,9 @@ struct PhantomNode forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), forward_duration_offset(0), reverse_duration_offset(0), fwd_segment_position(0), is_valid_forward_source{false}, is_valid_forward_target{false}, - is_valid_reverse_source{false}, is_valid_reverse_target{false}, bearing(0) + is_valid_reverse_source{false}, is_valid_reverse_target{false}, bearing(0), + forward_distance(MAXIMAL_EDGE_DISTANCE), reverse_distance(MAXIMAL_EDGE_DISTANCE), + forward_distance_offset(0), reverse_distance_offset(0) { } @@ -80,17 +82,17 @@ struct PhantomNode // DO THIS FOR DISTANCE - // EdgeWeight GetForwardDuration() const - // { - // BOOST_ASSERT(forward_segment_id.enabled); - // return forward_duration + forward_duration_offset; - // } + EdgeWeight GetForwardDistance() const + { + BOOST_ASSERT(forward_segment_id.enabled); + return forward_distance + forward_distance_offset; + } - // EdgeWeight GetReverseDuration() const - // { - // BOOST_ASSERT(reverse_segment_id.enabled); - // return reverse_duration + reverse_duration_offset; - // } + EdgeWeight GetReverseDistance() const + { + BOOST_ASSERT(reverse_segment_id.enabled); + return reverse_distance + reverse_distance_offset; + } bool IsBidirected() const { return forward_segment_id.enabled && reverse_segment_id.enabled; } @@ -102,6 +104,8 @@ struct PhantomNode (reverse_weight != INVALID_EDGE_WEIGHT)) && ((forward_duration != MAXIMAL_EDGE_DURATION) || (reverse_duration != MAXIMAL_EDGE_DURATION)) && + ((forward_distance != MAXIMAL_EDGE_DISTANCE) || + (reverse_distance != MAXIMAL_EDGE_DISTANCE)) && (component.id != INVALID_COMPONENTID); } @@ -148,6 +152,10 @@ struct PhantomNode EdgeWeight reverse_duration, EdgeWeight forward_duration_offset, EdgeWeight reverse_duration_offset, + EdgeDistance forward_distance, + EdgeDistance reverse_distance, + EdgeDistance forward_distance_offset, + EdgeDistance reverse_distance_offset, bool is_valid_forward_source, bool is_valid_forward_target, bool is_valid_reverse_source, @@ -166,7 +174,10 @@ struct PhantomNode is_valid_forward_source{is_valid_forward_source}, is_valid_forward_target{is_valid_forward_target}, is_valid_reverse_source{is_valid_reverse_source}, - is_valid_reverse_target{is_valid_reverse_target}, bearing{bearing} + is_valid_reverse_target{is_valid_reverse_target}, bearing{bearing}, + forward_distance{forward_distance}, reverse_distance{reverse_distance}, + forward_distance_offset{forward_distance_offset}, + reverse_distance_offset{reverse_distance_offset} { } @@ -176,10 +187,10 @@ struct PhantomNode EdgeWeight reverse_weight; EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes - // EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes - // // DO THIS FOR DISTANCE - // EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes - // // DO THIS FOR DISTANCE + EdgeDistance forward_distance; + EdgeDistance reverse_distance; + EdgeDistance forward_distance_offset; + EdgeDistance reverse_distance_offset; EdgeWeight forward_duration; EdgeWeight reverse_duration; EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes @@ -198,7 +209,7 @@ struct PhantomNode unsigned short bearing : 12; }; -static_assert(sizeof(PhantomNode) == 64, "PhantomNode has more padding then expected"); +static_assert(sizeof(PhantomNode) == 128, "PhantomNode has more padding then expected"); using PhantomNodePair = std::pair; diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 11c8b7db609..1922c99faea 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -436,10 +436,8 @@ EdgeDistance computeEdgeDistance(const FacadeT &facade, NodeID node_id_1, NodeID if (geometry_index.forward) { auto geometry_range = facade.GetUncompressedForwardGeometry(geometry_index.id); - for (auto current = geometry_range.begin() + 1; current != geometry_range.end(); ++current) { - auto prev = current - 1; const auto coordinate_1 = facade.GetCoordinateOfNode(*prev); @@ -454,7 +452,6 @@ EdgeDistance computeEdgeDistance(const FacadeT &facade, NodeID node_id_1, NodeID auto geometry_range = facade.GetUncompressedReverseDurations(geometry_index.id); for (auto current = geometry_range.begin() + 1; current != geometry_range.end(); ++current) { - auto prev = current - 1; const auto coordinate_1 = facade.GetCoordinateOfNode(*prev); @@ -466,23 +463,6 @@ EdgeDistance computeEdgeDistance(const FacadeT &facade, NodeID node_id_1, NodeID } return total_distance; - - // // how do we get the second node_id? - // // node_id_2 is not the node id that we want - - // const auto coordinate_1 = facade.GetCoordinateOfNode(node_id_1); - // const auto coordinate_2 = facade.GetCoordinateOfNode(node_id_2); - // const auto osm_id_1 = facade.GetOSMNodeIDOfNode(node_id_1); - // const auto osm_id_2 = facade.GetOSMNodeIDOfNode(node_id_2); - // std::cout << "node_id_1: " << node_id_1 << std::endl; - // std::cout << "node_id_2: " << node_id_2 << std::endl; - // std::cout << "node_id_1 as coordinate: " << coordinate_1.lon << ";" << coordinate_1.lat - // << std::endl; - // std::cout << "node_id_2 as coordinate: " << coordinate_2.lon << ";" << coordinate_2.lat - // << std::endl; - // std::cout << "node_id_1 as osm_id: " << osm_id_1 << std::endl; - // std::cout << "node_id_2 as osm_id: " << osm_id_2 << std::endl; - // return util::coordinate_calculation::haversineDistance(coordinate_1, coordinate_2); } } // namespace routing_algorithms