Deduplicate foward/reverse geometries

Changes the internal representation of compressed geometries to be a
single array shared between forward and reverse geometries that can be
read in either direction. Includes a change on
extractor::OriginalEdgeData to store via_geometry ids that indicate
which direction to read the geometry for that edge based edge.

Closes #2592
This commit is contained in:
Lauren Budorick
2016-07-22 18:23:54 +02:00
committed by Jake Pruitt
parent 73179641b1
commit a75e16e26b
24 changed files with 769 additions and 428 deletions
+10 -7
View File
@@ -8,6 +8,7 @@
#include "extractor/external_memory_node.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/original_edge_data.hpp"
#include "engine/phantom_node.hpp"
#include "util/exception.hpp"
#include "util/guidance/bearing_class.hpp"
@@ -74,20 +75,22 @@ class BaseDataFacade
virtual util::Coordinate GetCoordinateOfNode(const unsigned id) const = 0;
virtual OSMNodeID GetOSMNodeIDOfNode(const unsigned id) const = 0;
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0;
virtual GeometryID GetGeometryIndexForEdgeID(const unsigned id) const = 0;
virtual void GetUncompressedGeometry(const EdgeID id,
std::vector<NodeID> &result_nodes) const = 0;
virtual std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID id) const = 0;
virtual std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID id) const = 0;
// Gets the weight values for each segment in an uncompressed geometry.
// Should always be 1 shorter than GetUncompressedGeometry
virtual void GetUncompressedWeights(const EdgeID id,
std::vector<EdgeWeight> &result_weights) const = 0;
virtual std::vector<EdgeWeight> GetUncompressedForwardWeights(const EdgeID id) const = 0;
virtual std::vector<EdgeWeight> GetUncompressedReverseWeights(const EdgeID id) const = 0;
// Returns the data source ids that were used to supply the edge
// weights. Will return an empty array when only the base profile is used.
virtual void GetUncompressedDatasources(const EdgeID id,
std::vector<uint8_t> &data_sources) const = 0;
virtual std::vector<uint8_t> GetUncompressedForwardDatasources(const EdgeID id) const = 0;
virtual std::vector<uint8_t> GetUncompressedReverseDatasources(const EdgeID id) const = 0;
// Gets the name of a datasource
virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const = 0;
+140 -18
View File
@@ -76,7 +76,7 @@ class InternalDataFacade final : public BaseDataFacade
util::ShM<util::Coordinate, false>::vector m_coordinate_list;
util::PackedVector<OSMNodeID, false> m_osmnodeid_list;
util::ShM<NodeID, false>::vector m_via_node_list;
util::ShM<GeometryID, false>::vector m_via_geometry_list;
util::ShM<unsigned, false>::vector m_name_ID_list;
util::ShM<extractor::guidance::TurnInstruction, false>::vector m_turn_instruction_list;
util::ShM<LaneDataID, false>::vector m_lane_data_id;
@@ -189,7 +189,7 @@ class InternalDataFacade final : public BaseDataFacade
boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary);
unsigned number_of_edges = 0;
edges_input_stream.read((char *)&number_of_edges, sizeof(unsigned));
m_via_node_list.resize(number_of_edges);
m_via_geometry_list.resize(number_of_edges);
m_name_ID_list.resize(number_of_edges);
m_turn_instruction_list.resize(number_of_edges);
m_lane_data_id.resize(number_of_edges);
@@ -201,7 +201,7 @@ class InternalDataFacade final : public BaseDataFacade
{
edges_input_stream.read((char *)&(current_edge_data),
sizeof(extractor::OriginalEdgeData));
m_via_node_list[i] = current_edge_data.via_node;
m_via_geometry_list[i] = current_edge_data.via_geometry;
m_name_ID_list[i] = current_edge_data.name_id;
m_turn_instruction_list[i] = current_edge_data.turn_instruction;
m_lane_data_id[i] = current_edge_data.lane_data_id;
@@ -670,9 +670,9 @@ class InternalDataFacade final : public BaseDataFacade
return GetNameForID(name_id + 1);
}
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const override final
virtual GeometryID GetGeometryIndexForEdgeID(const unsigned id) const override final
{
return m_via_node_list.at(id);
return m_via_geometry_list.at(id);
}
virtual std::size_t GetCoreSize() const override final { return m_is_core_node.size(); }
@@ -689,47 +689,128 @@ class InternalDataFacade final : public BaseDataFacade
}
}
virtual void GetUncompressedGeometry(const EdgeID id,
std::vector<NodeID> &result_nodes) const override final
virtual std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID id) const override final
{
/*
* NodeID's for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector.
* */
const unsigned begin = m_geometry_indices.at(id);
const unsigned end = m_geometry_indices.at(id + 1);
result_nodes.clear();
std::vector<NodeID> result_nodes;
result_nodes.reserve(end - begin);
std::for_each(m_geometry_list.begin() + begin,
m_geometry_list.begin() + end,
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_nodes.emplace_back(edge.node_id);
});
return result_nodes;
}
virtual void
GetUncompressedWeights(const EdgeID id,
std::vector<EdgeWeight> &result_weights) const override final
virtual std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID id) const override final
{
/*
* NodeID's for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector.
* */
const unsigned begin = m_geometry_indices.at(id);
const unsigned end = m_geometry_indices.at(id + 1);
result_weights.clear();
std::vector<NodeID> result_nodes;
result_nodes.reserve(end - begin);
std::for_each(m_geometry_list.rbegin() + (m_geometry_list.size() - end),
m_geometry_list.rbegin() + (m_geometry_list.size() - begin),
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_nodes.emplace_back(edge.node_id);
});
return result_nodes;
}
virtual std::vector<EdgeWeight>
GetUncompressedForwardWeights(const EdgeID id) const override final
{
/*
* EdgeWeights's for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* forward weights of bi-directional edges, edges 2 to
* n of that edge need to be read.
*/
const unsigned begin = m_geometry_indices.at(id) + 1;
const unsigned end = m_geometry_indices.at(id + 1);
std::vector<EdgeWeight> result_weights;
result_weights.reserve(end - begin);
std::for_each(m_geometry_list.begin() + begin,
m_geometry_list.begin() + end,
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_weights.emplace_back(edge.weight);
result_weights.emplace_back(edge.forward_weight);
});
return result_weights;
}
virtual std::vector<EdgeWeight>
GetUncompressedReverseWeights(const EdgeID id) const override final
{
/*
* EdgeWeights for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* reverse weights of bi-directional edges, edges 1 to
* n-1 of that edge need to be read in reverse.
*/
const unsigned begin = m_geometry_indices.at(id);
const unsigned end = m_geometry_indices.at(id + 1) - 1;
std::vector<EdgeWeight> result_weights;
result_weights.reserve(end - begin);
std::for_each(m_geometry_list.rbegin() + (m_geometry_list.size() - end),
m_geometry_list.rbegin() + (m_geometry_list.size() - begin),
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_weights.emplace_back(edge.reverse_weight);
});
return result_weights;
}
// Returns the data source ids that were used to supply the edge
// weights.
virtual void
GetUncompressedDatasources(const EdgeID id,
std::vector<uint8_t> &result_datasources) const override final
virtual std::vector<uint8_t>
GetUncompressedForwardDatasources(const EdgeID id) const override final
{
const unsigned begin = m_geometry_indices.at(id);
/*
* Data sources for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* forward datasources of bi-directional edges, edges 2 to
* n of that edge need to be read.
*/
const unsigned begin = m_geometry_indices.at(id) + 1;
const unsigned end = m_geometry_indices.at(id + 1);
result_datasources.clear();
std::vector<uint8_t> result_datasources;
result_datasources.reserve(end - begin);
// If there was no datasource info, return an array of 0's.
@@ -747,6 +828,47 @@ class InternalDataFacade final : public BaseDataFacade
m_datasource_list.begin() + end,
[&](const uint8_t &datasource_id) { result_datasources.push_back(datasource_id); });
}
return result_datasources;
}
// Returns the data source ids that were used to supply the edge
// weights.
virtual std::vector<uint8_t>
GetUncompressedReverseDatasources(const EdgeID id) const override final
{
/*
* Datasources for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* reverse datasources of bi-directional edges, edges 1 to
* n-1 of that edge need to be read in reverse.
*/
const unsigned begin = m_geometry_indices.at(id);
const unsigned end = m_geometry_indices.at(id + 1) - 1;
std::vector<uint8_t> result_datasources;
result_datasources.reserve(end - begin);
// If there was no datasource info, return an array of 0's.
if (m_datasource_list.empty())
{
for (unsigned i = 0; i < end - begin; ++i)
{
result_datasources.push_back(0);
}
}
else
{
std::for_each(
m_datasource_list.rbegin() + (m_datasource_list.size() - end),
m_datasource_list.rbegin() + (m_datasource_list.size() - begin),
[&](const uint8_t &datasource_id) { result_datasources.push_back(datasource_id); });
}
return result_datasources;
}
virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const override final
+144 -21
View File
@@ -79,7 +79,7 @@ class SharedDataFacade final : public BaseDataFacade
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
util::PackedVector<OSMNodeID, true> m_osmnodeid_list;
util::ShM<NodeID, true>::vector m_via_node_list;
util::ShM<GeometryID, true>::vector m_via_geometry_list;
util::ShM<unsigned, true>::vector m_name_ID_list;
util::ShM<LaneDataID, true>::vector m_lane_data_id;
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
@@ -229,11 +229,12 @@ class SharedDataFacade final : public BaseDataFacade
void LoadViaNodeList()
{
auto via_node_list_ptr = data_layout->GetBlockPtr<NodeID>(
auto via_geometry_list_ptr = data_layout->GetBlockPtr<GeometryID>(
shared_memory, storage::SharedDataLayout::VIA_NODE_LIST);
util::ShM<NodeID, true>::vector via_node_list(
via_node_list_ptr, data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]);
m_via_node_list = std::move(via_node_list);
util::ShM<GeometryID, true>::vector via_geometry_list(
via_geometry_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::VIA_NODE_LIST]);
m_via_geometry_list = std::move(via_geometry_list);
}
void LoadNames()
@@ -525,40 +526,113 @@ class SharedDataFacade final : public BaseDataFacade
return m_osmnodeid_list.at(id);
}
virtual void GetUncompressedGeometry(const EdgeID id,
std::vector<NodeID> &result_nodes) const override final
virtual std::vector<NodeID> GetUncompressedForwardGeometry(const EdgeID id) const override final
{
/*
* NodeID's for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* forward geometries of bi-directional edges, edges 2 to
* n of that edge need to be read.
*/
const unsigned begin = m_geometry_indices.at(id);
const unsigned end = m_geometry_indices.at(id + 1);
result_nodes.clear();
std::vector<NodeID> result_nodes;
result_nodes.reserve(end - begin);
std::for_each(m_geometry_list.begin() + begin,
m_geometry_list.begin() + end,
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_nodes.emplace_back(edge.node_id);
});
return result_nodes;
}
virtual void
GetUncompressedWeights(const EdgeID id,
std::vector<EdgeWeight> &result_weights) const override final
virtual std::vector<NodeID> GetUncompressedReverseGeometry(const EdgeID id) const override final
{
const unsigned begin = m_geometry_indices.at(id);
/*
* NodeID's for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector.
* */
const signed begin = m_geometry_indices.at(id);
const signed end = m_geometry_indices.at(id + 1);
std::vector<NodeID> result_nodes;
result_nodes.reserve(end - begin);
std::for_each(m_geometry_list.rbegin() + (m_geometry_list.size() - end),
m_geometry_list.rbegin() + (m_geometry_list.size() - begin),
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_nodes.emplace_back(edge.node_id);
});
return result_nodes;
}
virtual std::vector<EdgeWeight>
GetUncompressedForwardWeights(const EdgeID id) const override final
{
/*
* EdgeWeights's for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector.
* */
const unsigned begin = m_geometry_indices.at(id) + 1;
const unsigned end = m_geometry_indices.at(id + 1);
result_weights.clear();
std::vector<EdgeWeight> result_weights;
result_weights.reserve(end - begin);
std::for_each(m_geometry_list.begin() + begin,
m_geometry_list.begin() + end,
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_weights.emplace_back(edge.weight);
result_weights.emplace_back(edge.forward_weight);
});
return result_weights;
}
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const override final
virtual std::vector<EdgeWeight>
GetUncompressedReverseWeights(const EdgeID id) const override final
{
return m_via_node_list.at(id);
/*
* EdgeWeights for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* reverse weights of bi-directional edges, edges 1 to
* n-1 of that edge need to be read in reverse.
*/
const signed begin = m_geometry_indices.at(id);
const signed end = m_geometry_indices.at(id + 1) - 1;
std::vector<EdgeWeight> result_weights;
result_weights.reserve(end - begin);
std::for_each(m_geometry_list.rbegin() + (m_geometry_list.size() - end),
m_geometry_list.rbegin() + (m_geometry_list.size() - begin),
[&](const osrm::extractor::CompressedEdgeContainer::CompressedEdge &edge) {
result_weights.emplace_back(edge.reverse_weight);
});
return result_weights;
}
virtual GeometryID GetGeometryIndexForEdgeID(const unsigned id) const override final
{
return m_via_geometry_list.at(id);
}
extractor::guidance::TurnInstruction
@@ -755,14 +829,22 @@ class SharedDataFacade final : public BaseDataFacade
// Returns the data source ids that were used to supply the edge
// weights.
virtual void
GetUncompressedDatasources(const EdgeID id,
std::vector<uint8_t> &result_datasources) const override final
virtual std::vector<uint8_t>
GetUncompressedForwardDatasources(const EdgeID id) const override final
{
const unsigned begin = m_geometry_indices.at(id);
/*
* Data sources for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* forward datasources of bi-directional edges, edges 2 to
* n of that edge need to be read.
*/
const unsigned begin = m_geometry_indices.at(id) + 1;
const unsigned end = m_geometry_indices.at(id + 1);
result_datasources.clear();
std::vector<uint8_t> result_datasources;
result_datasources.reserve(end - begin);
// If there was no datasource info, return an array of 0's.
@@ -780,6 +862,47 @@ class SharedDataFacade final : public BaseDataFacade
m_datasource_list.begin() + end,
[&](const uint8_t &datasource_id) { result_datasources.push_back(datasource_id); });
}
return result_datasources;
}
// Returns the data source ids that were used to supply the edge
// weights.
virtual std::vector<uint8_t>
GetUncompressedReverseDatasources(const EdgeID id) const override final
{
/*
* Datasources for geometries are stored in one place for
* both forward and reverse segments along the same bi-
* directional edge. The m_geometry_indices stores
* refences to where to find the beginning of the bi-
* directional edge in the m_geometry_list vector. For
* reverse datasources of bi-directional edges, edges 1 to
* n-1 of that edge need to be read in reverse.
*/
const unsigned begin = m_geometry_indices.at(id);
const unsigned end = m_geometry_indices.at(id + 1) - 1;
std::vector<uint8_t> result_datasources;
result_datasources.reserve(end - begin);
// If there was no datasource info, return an array of 0's.
if (m_datasource_list.empty())
{
for (unsigned i = 0; i < end - begin; ++i)
{
result_datasources.push_back(0);
}
}
else
{
std::for_each(
m_datasource_list.rbegin() + (m_datasource_list.size() - end),
m_datasource_list.rbegin() + (m_datasource_list.size() - begin),
[&](const uint8_t &datasource_id) { result_datasources.push_back(datasource_id); });
}
return result_datasources;
}
virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const override final
+22 -45
View File
@@ -372,35 +372,25 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
int forward_offset = 0, forward_weight = 0;
int reverse_offset = 0, reverse_weight = 0;
if (data.forward_packed_geometry_id != SPECIAL_EDGEID)
const std::vector<EdgeWeight> forward_weight_vector = datafacade.GetUncompressedForwardWeights(data.packed_geometry_id);
const std::vector<EdgeWeight> reverse_weight_vector = datafacade.GetUncompressedReverseWeights(data.packed_geometry_id);
for (std::size_t i = 0; i < data.fwd_segment_position; i++)
{
std::vector<EdgeWeight> forward_weight_vector;
datafacade.GetUncompressedWeights(data.forward_packed_geometry_id,
forward_weight_vector);
for (std::size_t i = 0; i < data.fwd_segment_position; i++)
{
forward_offset += forward_weight_vector[i];
}
forward_weight = forward_weight_vector[data.fwd_segment_position];
forward_offset += forward_weight_vector[i];
}
forward_weight = forward_weight_vector[data.fwd_segment_position];
if (data.reverse_packed_geometry_id != SPECIAL_EDGEID)
BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size());
for (std::size_t i = 0;
i < reverse_weight_vector.size() - data.fwd_segment_position - 1;
i++)
{
std::vector<EdgeWeight> reverse_weight_vector;
datafacade.GetUncompressedWeights(data.reverse_packed_geometry_id,
reverse_weight_vector);
BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size());
for (std::size_t i = 0;
i < reverse_weight_vector.size() - data.fwd_segment_position - 1;
i++)
{
reverse_offset += reverse_weight_vector[i];
}
reverse_weight =
reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1];
reverse_offset += reverse_weight_vector[i];
}
reverse_weight =
reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1];
ratio = std::min(1.0, std::max(0.0, ratio));
if (data.forward_segment_id.id != SPECIAL_SEGMENTID)
@@ -479,31 +469,18 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
bool forward_edge_valid = false;
bool reverse_edge_valid = false;
if (segment.data.forward_packed_geometry_id != SPECIAL_EDGEID)
{
std::vector<EdgeWeight> forward_weight_vector;
datafacade.GetUncompressedWeights(segment.data.forward_packed_geometry_id,
forward_weight_vector);
const std::vector<EdgeWeight> forward_weight_vector = datafacade.GetUncompressedForwardWeights(segment.data.packed_geometry_id);
if (forward_weight_vector[segment.data.fwd_segment_position] != INVALID_EDGE_WEIGHT)
{
forward_edge_valid = segment.data.forward_segment_id.enabled;
}
if (forward_weight_vector[segment.data.fwd_segment_position] != INVALID_EDGE_WEIGHT)
{
forward_edge_valid = segment.data.forward_segment_id.enabled;
}
if (segment.data.reverse_packed_geometry_id != SPECIAL_EDGEID)
const std::vector<EdgeWeight> reverse_weight_vector = datafacade.GetUncompressedReverseWeights(segment.data.packed_geometry_id);
if (reverse_weight_vector[reverse_weight_vector.size() -
segment.data.fwd_segment_position - 1] != INVALID_EDGE_WEIGHT)
{
std::vector<EdgeWeight> reverse_weight_vector;
datafacade.GetUncompressedWeights(segment.data.reverse_packed_geometry_id,
reverse_weight_vector);
BOOST_ASSERT(segment.data.fwd_segment_position < reverse_weight_vector.size());
if (reverse_weight_vector[reverse_weight_vector.size() -
segment.data.fwd_segment_position - 1] != INVALID_EDGE_WEIGHT)
{
reverse_edge_valid = segment.data.reverse_segment_id.enabled;
}
reverse_edge_valid = segment.data.reverse_segment_id.enabled;
}
return std::make_pair(forward_edge_valid, reverse_edge_valid);
+8 -12
View File
@@ -45,14 +45,10 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
// Need to get the node ID preceding the source phantom node
// TODO: check if this was traversed in reverse?
std::vector<NodeID> reverse_geometry;
facade.GetUncompressedGeometry(source_node.reverse_packed_geometry_id, reverse_geometry);
const std::vector<NodeID> source_geometry =
facade.GetUncompressedForwardGeometry(source_node.packed_geometry_id);
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(
reverse_geometry[reverse_geometry.size() - source_node.fwd_segment_position - 1]));
std::vector<uint8_t> forward_datasource_vector;
facade.GetUncompressedDatasources(source_node.forward_packed_geometry_id,
forward_datasource_vector);
source_geometry[source_node.fwd_segment_position]));
auto cumulative_distance = 0.;
auto current_distance = 0.;
@@ -84,8 +80,8 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
// segment leading to the target node
geometry.segment_distances.push_back(cumulative_distance);
std::vector<DatasourceID> forward_datasources;
facade.GetUncompressedDatasources(target_node.forward_packed_geometry_id, forward_datasources);
const std::vector<DatasourceID> forward_datasources =
facade.GetUncompressedForwardDatasources(target_node.packed_geometry_id);
geometry.annotations.emplace_back(
LegGeometry::Annotation{current_distance,
@@ -96,10 +92,10 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
// Need to get the node ID following the destination phantom node
// TODO: check if this was traversed in reverse??
std::vector<NodeID> forward_geometry;
facade.GetUncompressedGeometry(target_node.forward_packed_geometry_id, forward_geometry);
const std::vector<NodeID> target_geometry =
facade.GetUncompressedForwardGeometry(target_node.packed_geometry_id);
geometry.osm_node_ids.push_back(
facade.GetOSMNodeIDOfNode(forward_geometry[target_node.fwd_segment_position]));
facade.GetOSMNodeIDOfNode(target_geometry[target_node.fwd_segment_position + 1]));
BOOST_ASSERT(geometry.segment_distances.size() == geometry.segment_offsets.size() - 1);
BOOST_ASSERT(geometry.locations.size() > geometry.segment_distances.size());
+2 -2
View File
@@ -63,8 +63,8 @@ struct Hint
friend std::ostream &operator<<(std::ostream &, const Hint &);
};
static_assert(sizeof(Hint) == 60 + 4, "Hint is bigger than expected");
constexpr std::size_t ENCODED_HINT_SIZE = 88;
static_assert(sizeof(Hint) == 56 + 4, "Hint is bigger than expected");
constexpr std::size_t ENCODED_HINT_SIZE = 80;
static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint),
"ENCODED_HINT_SIZE does not match size of Hint");
}
+7 -12
View File
@@ -53,8 +53,7 @@ struct PhantomNode
int reverse_weight,
int forward_offset,
int reverse_offset,
unsigned forward_packed_geometry_id_,
unsigned reverse_packed_geometry_id_,
unsigned packed_geometry_id_,
bool is_tiny_component,
unsigned component_id,
util::Coordinate location,
@@ -65,8 +64,7 @@ struct PhantomNode
: forward_segment_id(forward_segment_id), reverse_segment_id(reverse_segment_id),
name_id(name_id), forward_weight(forward_weight), reverse_weight(reverse_weight),
forward_offset(forward_offset), reverse_offset(reverse_offset),
forward_packed_geometry_id(forward_packed_geometry_id_),
reverse_packed_geometry_id(reverse_packed_geometry_id_),
packed_geometry_id(packed_geometry_id_),
component{component_id, is_tiny_component}, location(std::move(location)),
input_location(std::move(input_location)), fwd_segment_position(fwd_segment_position),
forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode)
@@ -78,7 +76,7 @@ struct PhantomNode
reverse_segment_id{SPECIAL_SEGMENTID, false},
name_id(std::numeric_limits<unsigned>::max()), forward_weight(INVALID_EDGE_WEIGHT),
reverse_weight(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0),
forward_packed_geometry_id(SPECIAL_EDGEID), reverse_packed_geometry_id(SPECIAL_EDGEID),
packed_geometry_id(SPECIAL_GEOMETRYID),
component{INVALID_COMPONENTID, false}, fwd_segment_position(0),
forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
backward_travel_mode(TRAVEL_MODE_INACCESSIBLE)
@@ -129,8 +127,7 @@ struct PhantomNode
reverse_segment_id{other.reverse_segment_id}, name_id{other.name_id},
forward_weight{forward_weight_}, reverse_weight{reverse_weight_},
forward_offset{forward_offset_}, reverse_offset{reverse_offset_},
forward_packed_geometry_id{other.forward_packed_geometry_id},
reverse_packed_geometry_id{other.reverse_packed_geometry_id},
packed_geometry_id{other.packed_geometry_id},
component{other.component.id, other.component.is_tiny}, location{location_},
input_location{input_location_}, fwd_segment_position{other.fwd_segment_position},
forward_travel_mode{other.forward_travel_mode},
@@ -145,8 +142,7 @@ struct PhantomNode
int reverse_weight;
int forward_offset;
int reverse_offset;
unsigned forward_packed_geometry_id;
unsigned reverse_packed_geometry_id;
unsigned packed_geometry_id;
struct ComponentType
{
std::uint32_t id : 31;
@@ -163,7 +159,7 @@ struct PhantomNode
extractor::TravelMode backward_travel_mode;
};
static_assert(sizeof(PhantomNode) == 60, "PhantomNode has more padding then expected");
static_assert(sizeof(PhantomNode) == 56, "PhantomNode has more padding then expected");
using PhantomNodePair = std::pair<PhantomNode, PhantomNode>;
@@ -195,8 +191,7 @@ inline std::ostream &operator<<(std::ostream &out, const PhantomNode &pn)
<< "rev-w: " << pn.reverse_weight << ", "
<< "fwd-o: " << pn.forward_offset << ", "
<< "rev-o: " << pn.reverse_offset << ", "
<< "fwd_geom: " << pn.forward_packed_geometry_id << ", "
<< "rev_geom: " << pn.reverse_packed_geometry_id << ", "
<< "geom: " << pn.packed_geometry_id << ", "
<< "comp: " << pn.component.is_tiny << " / " << pn.component.id << ", "
<< "pos: " << pn.fwd_segment_position << ", "
<< "loc: " << pn.location;
@@ -244,80 +244,90 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
const auto geometry_index = facade.GetGeometryIndexForEdgeID(edge_data.id);
std::vector<NodeID> id_vector;
facade.GetUncompressedGeometry(geometry_index, id_vector);
BOOST_ASSERT(id_vector.size() > 0);
std::vector<EdgeWeight> weight_vector;
facade.GetUncompressedWeights(geometry_index, weight_vector);
BOOST_ASSERT(weight_vector.size() > 0);
std::vector<DatasourceID> datasource_vector;
facade.GetUncompressedDatasources(geometry_index, datasource_vector);
const auto total_weight =
std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
BOOST_ASSERT(weight_vector.size() == id_vector.size());
const bool is_first_segment = unpacked_path.empty();
const std::size_t start_index =
(is_first_segment
? ((start_traversed_in_reverse)
? id_vector.size() -
phantom_node_pair.source_phantom.fwd_segment_position - 1
: phantom_node_pair.source_phantom.fwd_segment_position)
: 0);
const std::size_t end_index = id_vector.size();
BOOST_ASSERT(start_index >= 0);
BOOST_ASSERT(start_index < end_index);
for (std::size_t i = start_index; i < end_index; ++i)
if (geometry_index.forward)
{
unpacked_path.push_back(
PathData{id_vector[i],
name_index,
weight_vector[i],
extractor::guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
travel_mode,
INVALID_ENTRY_CLASSID,
datasource_vector[i]});
id_vector = facade.GetUncompressedForwardGeometry(geometry_index.id);
weight_vector = facade.GetUncompressedForwardWeights(geometry_index.id);
datasource_vector =
facade.GetUncompressedForwardDatasources(geometry_index.id);
}
BOOST_ASSERT(unpacked_path.size() > 0);
if (facade.hasLaneData(edge_data.id))
unpacked_path.back().lane_data = facade.GetLaneData(edge_data.id);
else
{
id_vector = facade.GetUncompressedReverseGeometry(geometry_index.id);
weight_vector = facade.GetUncompressedReverseWeights(geometry_index.id);
datasource_vector =
facade.GetUncompressedReverseDatasources(geometry_index.id);
}
BOOST_ASSERT(id_vector.size() > 0);
BOOST_ASSERT(weight_vector.size() > 0);
BOOST_ASSERT(datasource_vector.size() > 0);
unpacked_path.back().entry_classid = facade.GetEntryClassID(edge_data.id);
unpacked_path.back().turn_instruction = turn_instruction;
unpacked_path.back().duration_until_turn += (edge_data.distance - total_weight);
});
const auto total_weight =
std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
std::size_t start_index = 0, end_index = 0;
std::vector<unsigned> id_vector;
std::vector<EdgeWeight> weight_vector;
std::vector<DatasourceID> datasource_vector;
const bool is_local_path = (phantom_node_pair.source_phantom.forward_packed_geometry_id ==
phantom_node_pair.target_phantom.forward_packed_geometry_id) &&
unpacked_path.empty();
BOOST_ASSERT(weight_vector.size() == id_vector.size() - 1);
const bool is_first_segment = unpacked_path.empty();
if (target_traversed_in_reverse)
{
facade.GetUncompressedGeometry(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, id_vector);
const std::size_t start_index =
(is_first_segment
? ((start_traversed_in_reverse)
? weight_vector.size() -
phantom_node_pair.source_phantom.fwd_segment_position - 1
: phantom_node_pair.source_phantom.fwd_segment_position)
: 0);
const std::size_t end_index = weight_vector.size();
facade.GetUncompressedWeights(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, weight_vector);
BOOST_ASSERT(start_index >= 0);
BOOST_ASSERT(start_index < end_index);
for (std::size_t segment_idx = start_index; segment_idx < end_index; ++segment_idx)
{
unpacked_path.push_back(
PathData{id_vector[segment_idx + 1],
name_index,
weight_vector[segment_idx],
extractor::guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
travel_mode,
INVALID_ENTRY_CLASSID,
datasource_vector[segment_idx]});
}
BOOST_ASSERT(unpacked_path.size() > 0);
if (facade.hasLaneData(edge_data.id))
unpacked_path.back().lane_data = facade.GetLaneData(edge_data.id);
facade.GetUncompressedDatasources(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, datasource_vector);
unpacked_path.back().entry_classid = facade.GetEntryClassID(edge_data.id);
unpacked_path.back().turn_instruction = turn_instruction;
unpacked_path.back().duration_until_turn += (edge_data.distance - total_weight);
});
std::size_t start_index = 0, end_index = 0;
std::vector<unsigned> id_vector;
std::vector<EdgeWeight> weight_vector;
std::vector<DatasourceID> datasource_vector;
const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id ==
phantom_node_pair.target_phantom.packed_geometry_id) &&
unpacked_path.empty();
if (target_traversed_in_reverse)
{
id_vector = facade.GetUncompressedReverseGeometry(
phantom_node_pair.target_phantom.packed_geometry_id);
weight_vector = facade.GetUncompressedReverseWeights(
phantom_node_pair.target_phantom.packed_geometry_id);
datasource_vector = facade.GetUncompressedReverseDatasources(
phantom_node_pair.target_phantom.packed_geometry_id);
if (is_local_path)
{
start_index =
id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1;
weight_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1;
}
end_index =
id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position - 1;
weight_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position - 1;
}
else
{
@@ -326,14 +336,15 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
start_index = phantom_node_pair.source_phantom.fwd_segment_position;
}
end_index = phantom_node_pair.target_phantom.fwd_segment_position;
facade.GetUncompressedGeometry(
phantom_node_pair.target_phantom.forward_packed_geometry_id, id_vector);
facade.GetUncompressedWeights(
phantom_node_pair.target_phantom.forward_packed_geometry_id, weight_vector);
id_vector = facade.GetUncompressedForwardGeometry(
phantom_node_pair.target_phantom.packed_geometry_id);
facade.GetUncompressedDatasources(
phantom_node_pair.target_phantom.forward_packed_geometry_id, datasource_vector);
weight_vector = facade.GetUncompressedForwardWeights(
phantom_node_pair.target_phantom.packed_geometry_id);
datasource_vector = facade.GetUncompressedForwardDatasources(
phantom_node_pair.target_phantom.packed_geometry_id);
}
// Given the following compressed geometry:
@@ -343,20 +354,20 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// t: fwd_segment 3
// -> (U, v), (v, w), (w, x)
// note that (x, t) is _not_ included but needs to be added later.
for (std::size_t i = start_index; i != end_index; (start_index < end_index ? ++i : --i))
for (std::size_t segment_idx = start_index; segment_idx != end_index; (start_index < end_index ? ++segment_idx : --segment_idx))
{
BOOST_ASSERT(i < id_vector.size());
BOOST_ASSERT(segment_idx < id_vector.size() - 1);
BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0);
unpacked_path.push_back(PathData{
id_vector[i],
id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1],
phantom_node_pair.target_phantom.name_id,
weight_vector[i],
weight_vector[segment_idx],
extractor::guidance::TurnInstruction::NO_TURN(),
{{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID},
target_traversed_in_reverse ? phantom_node_pair.target_phantom.backward_travel_mode
: phantom_node_pair.target_phantom.forward_travel_mode,
INVALID_ENTRY_CLASSID,
datasource_vector[i]});
datasource_vector[segment_idx]});
}
if (unpacked_path.size() > 0)