Skip to content

Commit

Permalink
offset functions but packing and padding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshkaj committed Apr 4, 2018
1 parent 09e1628 commit ea8cdc7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 45 deletions.
53 changes: 46 additions & 7 deletions include/engine/geospatial_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ template <typename RTreeT, typename DataFacadeT> 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,
Expand All @@ -458,15 +461,27 @@ template <typename RTreeT, typename DataFacadeT> 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()));
Expand All @@ -481,10 +496,30 @@ template <typename RTreeT, typename DataFacadeT> 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)
Expand Down Expand Up @@ -530,7 +565,11 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
point_on_segment,
input_coordinate,
static_cast<unsigned short>(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;
Expand Down
2 changes: 1 addition & 1 deletion include/engine/hint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
45 changes: 28 additions & 17 deletions include/engine/phantom_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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; }

Expand All @@ -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);
}

Expand Down Expand Up @@ -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,
Expand All @@ -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}
{
}

Expand All @@ -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
Expand All @@ -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<PhantomNode, PhantomNode>;

Expand Down
20 changes: 0 additions & 20 deletions include/engine/routing_algorithms/routing_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit ea8cdc7

Please sign in to comment.