Rename GeometryCompressor and add unit tests
This commit is contained in:
parent
7345dc6861
commit
3ef34fbb56
@ -64,7 +64,7 @@ add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<T
|
|||||||
|
|
||||||
add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp)
|
add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp)
|
||||||
|
|
||||||
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp {RestrictionMapGlob})
|
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp data_structures/compressed_edge_container.cpp {RestrictionMapGlob})
|
||||||
set(PrepareSources prepare.cpp ${PrepareGlob})
|
set(PrepareSources prepare.cpp ${PrepareGlob})
|
||||||
add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:ANGLE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>)
|
add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:ANGLE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>)
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ file(GLOB CoordinateGlob data_structures/coordinate*.cpp)
|
|||||||
file(GLOB AlgorithmGlob algorithms/*.cpp)
|
file(GLOB AlgorithmGlob algorithms/*.cpp)
|
||||||
file(GLOB HttpGlob server/http/*.cpp)
|
file(GLOB HttpGlob server/http/*.cpp)
|
||||||
file(GLOB LibOSRMGlob library/*.cpp)
|
file(GLOB LibOSRMGlob library/*.cpp)
|
||||||
file(GLOB DataStructureTestsGlob unit_tests/data_structures/*.cpp data_structures/hilbert_value.cpp)
|
file(GLOB DataStructureTestsGlob unit_tests/data_structures/*.cpp data_structures/hilbert_value.cpp data_structures/compressed_edge_container.cpp)
|
||||||
file(GLOB AlgorithmTestsGlob unit_tests/algorithms/*.cpp)
|
file(GLOB AlgorithmTestsGlob unit_tests/algorithms/*.cpp)
|
||||||
|
|
||||||
set(
|
set(
|
||||||
|
@ -41,7 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
EdgeBasedGraphFactory::EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
|
EdgeBasedGraphFactory::EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
|
||||||
const GeometryCompressor& geometry_compressor,
|
const CompressedEdgeContainer& compressed_edge_container,
|
||||||
const std::unordered_set<NodeID>& barrier_nodes,
|
const std::unordered_set<NodeID>& barrier_nodes,
|
||||||
const std::unordered_set<NodeID>& traffic_lights,
|
const std::unordered_set<NodeID>& traffic_lights,
|
||||||
std::shared_ptr<const RestrictionMap> restriction_map,
|
std::shared_ptr<const RestrictionMap> restriction_map,
|
||||||
@ -52,7 +52,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGra
|
|||||||
m_restriction_map(restriction_map),
|
m_restriction_map(restriction_map),
|
||||||
m_barrier_nodes(barrier_nodes),
|
m_barrier_nodes(barrier_nodes),
|
||||||
m_traffic_lights(traffic_lights),
|
m_traffic_lights(traffic_lights),
|
||||||
m_geometry_compressor(geometry_compressor),
|
m_compressed_edge_container(compressed_edge_container),
|
||||||
speed_profile(speed_profile)
|
speed_profile(speed_profile)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -103,17 +103,15 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_ASSERT(m_geometry_compressor.HasEntryForID(edge_id_1) ==
|
BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_1) ==
|
||||||
m_geometry_compressor.HasEntryForID(edge_id_2));
|
m_compressed_edge_container.HasEntryForID(edge_id_2));
|
||||||
if (m_geometry_compressor.HasEntryForID(edge_id_1))
|
if (m_compressed_edge_container.HasEntryForID(edge_id_1))
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(m_geometry_compressor.HasEntryForID(edge_id_2));
|
BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_2));
|
||||||
|
|
||||||
// reconstruct geometry and put in each individual edge with its offset
|
// reconstruct geometry and put in each individual edge with its offset
|
||||||
const std::vector<GeometryCompressor::CompressedNode> &forward_geometry =
|
const auto& forward_geometry = m_compressed_edge_container.GetBucketReference(edge_id_1);
|
||||||
m_geometry_compressor.GetBucketReference(edge_id_1);
|
const auto& reverse_geometry = m_compressed_edge_container.GetBucketReference(edge_id_2);
|
||||||
const std::vector<GeometryCompressor::CompressedNode> &reverse_geometry =
|
|
||||||
m_geometry_compressor.GetBucketReference(edge_id_2);
|
|
||||||
BOOST_ASSERT(forward_geometry.size() == reverse_geometry.size());
|
BOOST_ASSERT(forward_geometry.size() == reverse_geometry.size());
|
||||||
BOOST_ASSERT(0 != forward_geometry.size());
|
BOOST_ASSERT(0 != forward_geometry.size());
|
||||||
const unsigned geometry_size = static_cast<unsigned>(forward_geometry.size());
|
const unsigned geometry_size = static_cast<unsigned>(forward_geometry.size());
|
||||||
@ -160,7 +158,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
|
|||||||
current_edge_source_coordinate_id, current_edge_target_coordinate_id,
|
current_edge_source_coordinate_id, current_edge_target_coordinate_id,
|
||||||
forward_data.nameID, forward_geometry[i].second,
|
forward_data.nameID, forward_geometry[i].second,
|
||||||
reverse_geometry[geometry_size - 1 - i].second, forward_dist_prefix_sum[i],
|
reverse_geometry[geometry_size - 1 - i].second, forward_dist_prefix_sum[i],
|
||||||
reverse_dist_prefix_sum[i], m_geometry_compressor.GetPositionForID(edge_id_1),
|
reverse_dist_prefix_sum[i], m_compressed_edge_container.GetPositionForID(edge_id_1),
|
||||||
component_id, i, forward_data.travel_mode, reverse_data.travel_mode);
|
component_id, i, forward_data.travel_mode, reverse_data.travel_mode);
|
||||||
current_edge_source_coordinate_id = current_edge_target_coordinate_id;
|
current_edge_source_coordinate_id = current_edge_target_coordinate_id;
|
||||||
|
|
||||||
@ -178,7 +176,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(!m_geometry_compressor.HasEntryForID(edge_id_2));
|
BOOST_ASSERT(!m_compressed_edge_container.HasEntryForID(edge_id_2));
|
||||||
|
|
||||||
if (forward_data.edgeBasedNodeID != SPECIAL_NODEID)
|
if (forward_data.edgeBasedNodeID != SPECIAL_NODEID)
|
||||||
{
|
{
|
||||||
@ -454,14 +452,14 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
|||||||
|
|
||||||
// unpack last node of first segment if packed
|
// unpack last node of first segment if packed
|
||||||
const auto first_coordinate =
|
const auto first_coordinate =
|
||||||
m_node_info_list[(m_geometry_compressor.HasEntryForID(e1)
|
m_node_info_list[(m_compressed_edge_container.HasEntryForID(e1)
|
||||||
? m_geometry_compressor.GetLastNodeIDOfBucket(e1)
|
? m_compressed_edge_container.GetLastEdgeSourceID(e1)
|
||||||
: node_u)];
|
: node_u)];
|
||||||
|
|
||||||
// unpack first node of second segment if packed
|
// unpack first node of second segment if packed
|
||||||
const auto third_coordinate =
|
const auto third_coordinate =
|
||||||
m_node_info_list[(m_geometry_compressor.HasEntryForID(e2)
|
m_node_info_list[(m_compressed_edge_container.HasEntryForID(e2)
|
||||||
? m_geometry_compressor.GetFirstNodeIDOfBucket(e2)
|
? m_compressed_edge_container.GetFirstEdgeTargetID(e2)
|
||||||
: node_w)];
|
: node_w)];
|
||||||
|
|
||||||
const double turn_angle = ComputeAngle::OfThreeFixedPointCoordinates(
|
const double turn_angle = ComputeAngle::OfThreeFixedPointCoordinates(
|
||||||
@ -475,7 +473,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
|||||||
}
|
}
|
||||||
distance += turn_penalty;
|
distance += turn_penalty;
|
||||||
|
|
||||||
const bool edge_is_compressed = m_geometry_compressor.HasEntryForID(e1);
|
const bool edge_is_compressed = m_compressed_edge_container.HasEntryForID(e1);
|
||||||
|
|
||||||
if (edge_is_compressed)
|
if (edge_is_compressed)
|
||||||
{
|
{
|
||||||
@ -483,7 +481,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
|
|||||||
}
|
}
|
||||||
|
|
||||||
original_edge_data_vector.emplace_back(
|
original_edge_data_vector.emplace_back(
|
||||||
(edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : node_v),
|
(edge_is_compressed ? m_compressed_edge_container.GetPositionForID(e1) : node_v),
|
||||||
edge_data1.nameID, turn_instruction, edge_is_compressed,
|
edge_data1.nameID, turn_instruction, edge_is_compressed,
|
||||||
edge_data2.travel_mode);
|
edge_data2.travel_mode);
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define EDGE_BASED_GRAPH_FACTORY_HPP_
|
#define EDGE_BASED_GRAPH_FACTORY_HPP_
|
||||||
|
|
||||||
#include "speed_profile.hpp"
|
#include "speed_profile.hpp"
|
||||||
#include "geometry_compressor.hpp"
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
#include "../data_structures/compressed_edge_container.hpp"
|
||||||
#include "../data_structures/deallocating_vector.hpp"
|
#include "../data_structures/deallocating_vector.hpp"
|
||||||
#include "../data_structures/edge_based_node.hpp"
|
#include "../data_structures/edge_based_node.hpp"
|
||||||
#include "../data_structures/original_edge_data.hpp"
|
#include "../data_structures/original_edge_data.hpp"
|
||||||
@ -60,7 +60,7 @@ class EdgeBasedGraphFactory
|
|||||||
|
|
||||||
|
|
||||||
explicit EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
|
explicit EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
|
||||||
const GeometryCompressor& geometry_compressor,
|
const CompressedEdgeContainer& compressed_edge_container,
|
||||||
const std::unordered_set<NodeID>& barrier_nodes,
|
const std::unordered_set<NodeID>& barrier_nodes,
|
||||||
const std::unordered_set<NodeID>& traffic_lights,
|
const std::unordered_set<NodeID>& traffic_lights,
|
||||||
std::shared_ptr<const RestrictionMap> restriction_map,
|
std::shared_ptr<const RestrictionMap> restriction_map,
|
||||||
@ -92,7 +92,7 @@ class EdgeBasedGraphFactory
|
|||||||
|
|
||||||
const std::unordered_set<NodeID>& m_barrier_nodes;
|
const std::unordered_set<NodeID>& m_barrier_nodes;
|
||||||
const std::unordered_set<NodeID>& m_traffic_lights;
|
const std::unordered_set<NodeID>& m_traffic_lights;
|
||||||
const GeometryCompressor& m_geometry_compressor;
|
const CompressedEdgeContainer& m_compressed_edge_container;
|
||||||
|
|
||||||
SpeedProfileProperties speed_profile;
|
SpeedProfileProperties speed_profile;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "graph_compressor.hpp"
|
#include "graph_compressor.hpp"
|
||||||
|
|
||||||
#include "geometry_compressor.hpp"
|
#include "../data_structures/compressed_edge_container.hpp"
|
||||||
#include "../data_structures/dynamic_graph.hpp"
|
#include "../data_structures/dynamic_graph.hpp"
|
||||||
#include "../data_structures/node_based_graph.hpp"
|
#include "../data_structures/node_based_graph.hpp"
|
||||||
#include "../data_structures/restriction_map.hpp"
|
#include "../data_structures/restriction_map.hpp"
|
||||||
@ -16,7 +16,7 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID>& barrier_nodes,
|
|||||||
const std::unordered_set<NodeID>& traffic_lights,
|
const std::unordered_set<NodeID>& traffic_lights,
|
||||||
RestrictionMap& restriction_map,
|
RestrictionMap& restriction_map,
|
||||||
NodeBasedDynamicGraph& graph,
|
NodeBasedDynamicGraph& graph,
|
||||||
GeometryCompressor& geometry_compressor)
|
CompressedEdgeContainer& geometry_compressor)
|
||||||
{
|
{
|
||||||
const unsigned original_number_of_nodes = graph.GetNumberOfNodes();
|
const unsigned original_number_of_nodes = graph.GetNumberOfNodes();
|
||||||
const unsigned original_number_of_edges = graph.GetNumberOfEdges();
|
const unsigned original_number_of_edges = graph.GetNumberOfEdges();
|
||||||
|
@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
class GeometryCompressor;
|
class CompressedEdgeContainer;
|
||||||
class RestrictionMap;
|
class RestrictionMap;
|
||||||
|
|
||||||
class GraphCompressor
|
class GraphCompressor
|
||||||
@ -49,7 +49,7 @@ public:
|
|||||||
const std::unordered_set<NodeID>& traffic_lights,
|
const std::unordered_set<NodeID>& traffic_lights,
|
||||||
RestrictionMap& restriction_map,
|
RestrictionMap& restriction_map,
|
||||||
NodeBasedDynamicGraph& graph,
|
NodeBasedDynamicGraph& graph,
|
||||||
GeometryCompressor& geometry_compressor);
|
CompressedEdgeContainer& geometry_compressor);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void PrintStatistics(unsigned original_number_of_nodes,
|
void PrintStatistics(unsigned original_number_of_nodes,
|
||||||
|
@ -28,10 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "processing_chain.hpp"
|
#include "processing_chain.hpp"
|
||||||
|
|
||||||
#include "contractor.hpp"
|
#include "contractor.hpp"
|
||||||
#include "geometry_compressor.hpp"
|
|
||||||
#include "graph_compressor.hpp"
|
#include "graph_compressor.hpp"
|
||||||
|
|
||||||
#include "../algorithms/crc32_processor.hpp"
|
#include "../algorithms/crc32_processor.hpp"
|
||||||
|
#include "../data_structures/compressed_edge_container.hpp"
|
||||||
#include "../data_structures/deallocating_vector.hpp"
|
#include "../data_structures/deallocating_vector.hpp"
|
||||||
#include "../data_structures/static_rtree.hpp"
|
#include "../data_structures/static_rtree.hpp"
|
||||||
#include "../data_structures/restriction_map.hpp"
|
#include "../data_structures/restriction_map.hpp"
|
||||||
@ -380,19 +380,19 @@ Prepare::BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_nod
|
|||||||
auto node_based_graph = LoadNodeBasedGraph(barrier_nodes, traffic_lights, internal_to_external_node_map);
|
auto node_based_graph = LoadNodeBasedGraph(barrier_nodes, traffic_lights, internal_to_external_node_map);
|
||||||
|
|
||||||
|
|
||||||
GeometryCompressor geometry_compressor;
|
CompressedEdgeContainer compressed_edge_container;
|
||||||
GraphCompressor graph_compressor(speed_profile);
|
GraphCompressor graph_compressor(speed_profile);
|
||||||
graph_compressor.Compress(barrier_nodes, traffic_lights, *restriction_map, *node_based_graph, geometry_compressor);
|
graph_compressor.Compress(barrier_nodes, traffic_lights, *restriction_map, *node_based_graph, compressed_edge_container);
|
||||||
|
|
||||||
EdgeBasedGraphFactory edge_based_graph_factory(node_based_graph,
|
EdgeBasedGraphFactory edge_based_graph_factory(node_based_graph,
|
||||||
geometry_compressor,
|
compressed_edge_container,
|
||||||
barrier_nodes,
|
barrier_nodes,
|
||||||
traffic_lights,
|
traffic_lights,
|
||||||
std::const_pointer_cast<RestrictionMap const>(restriction_map),
|
std::const_pointer_cast<RestrictionMap const>(restriction_map),
|
||||||
internal_to_external_node_map,
|
internal_to_external_node_map,
|
||||||
speed_profile);
|
speed_profile);
|
||||||
|
|
||||||
geometry_compressor.SerializeInternalVector(config.geometry_output_path);
|
compressed_edge_container.SerializeInternalVector(config.geometry_output_path);
|
||||||
|
|
||||||
edge_based_graph_factory.Run(config.edge_output_path, lua_state);
|
edge_based_graph_factory.Run(config.edge_output_path, lua_state);
|
||||||
lua_close(lua_state);
|
lua_close(lua_state);
|
||||||
|
@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "geometry_compressor.hpp"
|
#include "compressed_edge_container.hpp"
|
||||||
#include "../util/simple_logger.hpp"
|
#include "../util/simple_logger.hpp"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
@ -35,13 +35,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
GeometryCompressor::GeometryCompressor()
|
#include <iostream>
|
||||||
|
|
||||||
|
CompressedEdgeContainer::CompressedEdgeContainer()
|
||||||
{
|
{
|
||||||
m_free_list.reserve(100);
|
m_free_list.reserve(100);
|
||||||
IncreaseFreeList();
|
IncreaseFreeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCompressor::IncreaseFreeList()
|
void CompressedEdgeContainer::IncreaseFreeList()
|
||||||
{
|
{
|
||||||
m_compressed_geometries.resize(m_compressed_geometries.size() + 100);
|
m_compressed_geometries.resize(m_compressed_geometries.size() + 100);
|
||||||
for (unsigned i = 100; i > 0; --i)
|
for (unsigned i = 100; i > 0; --i)
|
||||||
@ -51,13 +53,13 @@ void GeometryCompressor::IncreaseFreeList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeometryCompressor::HasEntryForID(const EdgeID edge_id) const
|
bool CompressedEdgeContainer::HasEntryForID(const EdgeID edge_id) const
|
||||||
{
|
{
|
||||||
auto iter = m_edge_id_to_list_index_map.find(edge_id);
|
auto iter = m_edge_id_to_list_index_map.find(edge_id);
|
||||||
return iter != m_edge_id_to_list_index_map.end();
|
return iter != m_edge_id_to_list_index_map.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const
|
unsigned CompressedEdgeContainer::GetPositionForID(const EdgeID edge_id) const
|
||||||
{
|
{
|
||||||
auto map_iterator = m_edge_id_to_list_index_map.find(edge_id);
|
auto map_iterator = m_edge_id_to_list_index_map.find(edge_id);
|
||||||
BOOST_ASSERT(map_iterator != m_edge_id_to_list_index_map.end());
|
BOOST_ASSERT(map_iterator != m_edge_id_to_list_index_map.end());
|
||||||
@ -65,7 +67,7 @@ unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const
|
|||||||
return map_iterator->second;
|
return map_iterator->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCompressor::SerializeInternalVector(const std::string &path) const
|
void CompressedEdgeContainer::SerializeInternalVector(const std::string &path) const
|
||||||
{
|
{
|
||||||
|
|
||||||
boost::filesystem::fstream geometry_out_stream(path, std::ios::binary | std::ios::out);
|
boost::filesystem::fstream geometry_out_stream(path, std::ios::binary | std::ios::out);
|
||||||
@ -108,7 +110,7 @@ void GeometryCompressor::SerializeInternalVector(const std::string &path) const
|
|||||||
geometry_out_stream.close();
|
geometry_out_stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCompressor::CompressEdge(const EdgeID edge_id_1,
|
void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
|
||||||
const EdgeID edge_id_2,
|
const EdgeID edge_id_2,
|
||||||
const NodeID via_node_id,
|
const NodeID via_node_id,
|
||||||
const NodeID target_node_id,
|
const NodeID target_node_id,
|
||||||
@ -153,6 +155,8 @@ void GeometryCompressor::CompressEdge(const EdgeID edge_id_1,
|
|||||||
|
|
||||||
std::vector<CompressedNode> &edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1];
|
std::vector<CompressedNode> &edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1];
|
||||||
|
|
||||||
|
// note we don't save the start coordinate: it is implicitly given by edge 1
|
||||||
|
// weight1 is the distance to the (currently) last coordinate in the bucket
|
||||||
if (edge_bucket_list1.empty())
|
if (edge_bucket_list1.empty())
|
||||||
{
|
{
|
||||||
edge_bucket_list1.emplace_back(via_node_id, weight1);
|
edge_bucket_list1.emplace_back(via_node_id, weight1);
|
||||||
@ -190,7 +194,7 @@ void GeometryCompressor::CompressEdge(const EdgeID edge_id_1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCompressor::PrintStatistics() const
|
void CompressedEdgeContainer::PrintStatistics() const
|
||||||
{
|
{
|
||||||
const uint64_t compressed_edges = m_compressed_geometries.size();
|
const uint64_t compressed_edges = m_compressed_geometries.size();
|
||||||
BOOST_ASSERT(0 == compressed_edges % 2);
|
BOOST_ASSERT(0 == compressed_edges % 2);
|
||||||
@ -215,20 +219,20 @@ void GeometryCompressor::PrintStatistics() const
|
|||||||
std::max((uint64_t)1, compressed_edges);
|
std::max((uint64_t)1, compressed_edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<GeometryCompressor::CompressedNode> &
|
const CompressedEdgeContainer::EdgeBucket&
|
||||||
GeometryCompressor::GetBucketReference(const EdgeID edge_id) const
|
CompressedEdgeContainer::GetBucketReference(const EdgeID edge_id) const
|
||||||
{
|
{
|
||||||
const unsigned index = m_edge_id_to_list_index_map.at(edge_id);
|
const unsigned index = m_edge_id_to_list_index_map.at(edge_id);
|
||||||
return m_compressed_geometries.at(index);
|
return m_compressed_geometries.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID GeometryCompressor::GetFirstNodeIDOfBucket(const EdgeID edge_id) const
|
NodeID CompressedEdgeContainer::GetFirstEdgeTargetID(const EdgeID edge_id) const
|
||||||
{
|
{
|
||||||
const auto &bucket = GetBucketReference(edge_id);
|
const auto &bucket = GetBucketReference(edge_id);
|
||||||
BOOST_ASSERT(bucket.size() >= 2);
|
BOOST_ASSERT(bucket.size() >= 2);
|
||||||
return bucket[1].first;
|
return bucket.front().first;
|
||||||
}
|
}
|
||||||
NodeID GeometryCompressor::GetLastNodeIDOfBucket(const EdgeID edge_id) const
|
NodeID CompressedEdgeContainer::GetLastEdgeSourceID(const EdgeID edge_id) const
|
||||||
{
|
{
|
||||||
const auto &bucket = GetBucketReference(edge_id);
|
const auto &bucket = GetBucketReference(edge_id);
|
||||||
BOOST_ASSERT(bucket.size() >= 2);
|
BOOST_ASSERT(bucket.size() >= 2);
|
@ -35,12 +35,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class GeometryCompressor
|
class CompressedEdgeContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using CompressedNode = std::pair<NodeID, EdgeWeight>;
|
using CompressedNode = std::pair<NodeID, EdgeWeight>;
|
||||||
|
using EdgeBucket = std::vector<CompressedNode>;
|
||||||
|
|
||||||
GeometryCompressor();
|
CompressedEdgeContainer();
|
||||||
void CompressEdge(const EdgeID surviving_edge_id,
|
void CompressEdge(const EdgeID surviving_edge_id,
|
||||||
const EdgeID removed_edge_id,
|
const EdgeID removed_edge_id,
|
||||||
const NodeID via_node_id,
|
const NodeID via_node_id,
|
||||||
@ -52,16 +53,15 @@ class GeometryCompressor
|
|||||||
void PrintStatistics() const;
|
void PrintStatistics() const;
|
||||||
void SerializeInternalVector(const std::string &path) const;
|
void SerializeInternalVector(const std::string &path) const;
|
||||||
unsigned GetPositionForID(const EdgeID edge_id) const;
|
unsigned GetPositionForID(const EdgeID edge_id) const;
|
||||||
const std::vector<GeometryCompressor::CompressedNode> &
|
const EdgeBucket& GetBucketReference(const EdgeID edge_id) const;
|
||||||
GetBucketReference(const EdgeID edge_id) const;
|
NodeID GetFirstEdgeTargetID(const EdgeID edge_id) const;
|
||||||
NodeID GetFirstNodeIDOfBucket(const EdgeID edge_id) const;
|
NodeID GetLastEdgeSourceID(const EdgeID edge_id) const;
|
||||||
NodeID GetLastNodeIDOfBucket(const EdgeID edge_id) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int free_list_maximum = 0;
|
int free_list_maximum = 0;
|
||||||
|
|
||||||
void IncreaseFreeList();
|
void IncreaseFreeList();
|
||||||
std::vector<std::vector<CompressedNode>> m_compressed_geometries;
|
std::vector<EdgeBucket> m_compressed_geometries;
|
||||||
std::vector<unsigned> m_free_list;
|
std::vector<unsigned> m_free_list;
|
||||||
std::unordered_map<EdgeID, unsigned> m_edge_id_to_list_index_map;
|
std::unordered_map<EdgeID, unsigned> m_edge_id_to_list_index_map;
|
||||||
};
|
};
|
87
unit_tests/data_structures/compressed_edge_container.cpp
Normal file
87
unit_tests/data_structures/compressed_edge_container.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include "../../data_structures/compressed_edge_container.hpp"
|
||||||
|
#include "../../typedefs.h"
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/test/test_case_template.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(compressed_edge_container)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(long_road_test)
|
||||||
|
{
|
||||||
|
// 0 1 2 3
|
||||||
|
// 0---1----2----3----4
|
||||||
|
CompressedEdgeContainer container;
|
||||||
|
|
||||||
|
// compress 0---1---2 to 0---2
|
||||||
|
container.CompressEdge(0, 1, 1, 2, 1, 1);
|
||||||
|
BOOST_CHECK(container.HasEntryForID(0));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(1));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(2));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(3));
|
||||||
|
BOOST_CHECK_EQUAL(container.GetFirstEdgeTargetID(0), 1);
|
||||||
|
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(0), 1);
|
||||||
|
|
||||||
|
// compress 2---3---4 to 2---4
|
||||||
|
container.CompressEdge(2, 3, 3, 4, 1, 1);
|
||||||
|
BOOST_CHECK(container.HasEntryForID(0));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(1));
|
||||||
|
BOOST_CHECK(container.HasEntryForID(2));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(3));
|
||||||
|
BOOST_CHECK_EQUAL(container.GetFirstEdgeTargetID(2), 3);
|
||||||
|
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(2), 3);
|
||||||
|
|
||||||
|
// compress 0---2---4 to 0---4
|
||||||
|
container.CompressEdge(0, 2, 2, 4, 2, 2);
|
||||||
|
BOOST_CHECK(container.HasEntryForID(0));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(1));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(2));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(3));
|
||||||
|
BOOST_CHECK_EQUAL(container.GetFirstEdgeTargetID(0), 1);
|
||||||
|
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(0), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(t_crossing)
|
||||||
|
{
|
||||||
|
// 0 1 2 3
|
||||||
|
// 0---1---2---3---4
|
||||||
|
// | 4
|
||||||
|
// 5
|
||||||
|
// | 5
|
||||||
|
// 6
|
||||||
|
CompressedEdgeContainer container;
|
||||||
|
|
||||||
|
// compress 0---1---2 to 0---2
|
||||||
|
container.CompressEdge(0, 1, 1, 2, 1, 1);
|
||||||
|
BOOST_CHECK(container.HasEntryForID(0));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(1));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(2));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(3));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(4));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(5));
|
||||||
|
BOOST_CHECK_EQUAL(container.GetFirstEdgeTargetID(0), 1);
|
||||||
|
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(0), 1);
|
||||||
|
|
||||||
|
// compress 2---5---6 to 2---6
|
||||||
|
container.CompressEdge(4, 5, 5, 6, 1, 1);
|
||||||
|
BOOST_CHECK(container.HasEntryForID(0));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(1));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(2));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(3));
|
||||||
|
BOOST_CHECK(container.HasEntryForID(4));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(5));
|
||||||
|
BOOST_CHECK_EQUAL(container.GetFirstEdgeTargetID(4), 5);
|
||||||
|
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(4), 5);
|
||||||
|
|
||||||
|
// compress 2---3---4 to 2---4
|
||||||
|
container.CompressEdge(2, 3, 3, 4, 1, 1);
|
||||||
|
BOOST_CHECK(container.HasEntryForID(0));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(1));
|
||||||
|
BOOST_CHECK(container.HasEntryForID(2));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(3));
|
||||||
|
BOOST_CHECK(container.HasEntryForID(4));
|
||||||
|
BOOST_CHECK(!container.HasEntryForID(5));
|
||||||
|
BOOST_CHECK_EQUAL(container.GetFirstEdgeTargetID(2), 3);
|
||||||
|
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(2), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in New Issue
Block a user