Add the uncompressible edges to the compressed edge container during the graph compressor run, rather than in the EdgeBasedGraphFactory. This keeps the logic a lot simpler to follow, although it's not quite as fast.

This commit is contained in:
Daniel Patterson 2016-03-03 18:48:39 -08:00
parent 017ff53702
commit 27babfec3d
4 changed files with 29 additions and 50 deletions

View File

@ -189,9 +189,6 @@ void CompressedEdgeContainer::AddUncompressedEdge(const EdgeID edge_id,
BOOST_ASSERT(SPECIAL_NODEID != target_node_id);
BOOST_ASSERT(INVALID_EDGE_WEIGHT != weight);
// There should be no entry for uncompressed edges
BOOST_ASSERT(!HasEntryForID(edge_id));
// Add via node id. List is created if it does not exist
if (!HasEntryForID(edge_id))
{
@ -215,10 +212,9 @@ void CompressedEdgeContainer::AddUncompressedEdge(const EdgeID edge_id,
std::vector<CompressedEdge> &edge_bucket_list = m_compressed_geometries[edge_bucket_id];
// We're adding uncompressed edges, there should be no entry
BOOST_ASSERT(edge_bucket_list.empty());
// note we don't save the start coordinate: it is implicitly given by edge_id
// weight is the distance to the (currently) last coordinate in the bucket
// Don't re-add this if it's already in there.
if (edge_bucket_list.empty())
{
edge_bucket_list.emplace_back(CompressedEdge { target_node_id, weight });

View File

@ -124,43 +124,16 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_1) ==
m_compressed_edge_container.HasEntryForID(edge_id_2));
if (m_compressed_edge_container.HasEntryForID(edge_id_1))
BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_1));
BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_2));
const auto &forward_geometry = m_compressed_edge_container.GetBucketReference(edge_id_1);
const auto &reverse_geometry = m_compressed_edge_container.GetBucketReference(edge_id_2);
BOOST_ASSERT(forward_geometry.size() == reverse_geometry.size());
BOOST_ASSERT(0 != forward_geometry.size());
const unsigned geometry_size = static_cast<unsigned>(forward_geometry.size());
if (geometry_size > 1)
{
BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_2));
// reconstruct geometry and put in each individual edge with its offset
const auto &forward_geometry = m_compressed_edge_container.GetBucketReference(edge_id_1);
const auto &reverse_geometry = m_compressed_edge_container.GetBucketReference(edge_id_2);
BOOST_ASSERT(forward_geometry.size() == reverse_geometry.size());
BOOST_ASSERT(0 != forward_geometry.size());
const unsigned geometry_size = static_cast<unsigned>(forward_geometry.size());
BOOST_ASSERT(geometry_size > 1);
// reconstruct bidirectional edge with individual weights and put each into the NN index
std::vector<int> forward_offsets(forward_geometry.size(), 0);
std::vector<int> reverse_offsets(reverse_geometry.size(), 0);
// quick'n'dirty prefix sum as std::partial_sum needs addtional casts
// TODO: move to lambda function with C++11
int temp_sum = 0;
for (const auto i : util::irange(0u, geometry_size))
{
forward_offsets[i] = temp_sum;
temp_sum += forward_geometry[i].weight;
BOOST_ASSERT(forward_data.distance >= temp_sum);
}
temp_sum = 0;
for (const auto i : util::irange(0u, geometry_size))
{
temp_sum += reverse_geometry[reverse_geometry.size() - 1 - i].weight;
reverse_offsets[i] = reverse_data.distance - temp_sum;
// BOOST_ASSERT(reverse_data.distance >= temp_sum);
}
NodeID current_edge_source_coordinate_id = node_u;
// traverse arrays from start and end respectively
@ -194,7 +167,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
}
else
{
BOOST_ASSERT(!m_compressed_edge_container.HasEntryForID(edge_id_2));
//BOOST_ASSERT(!m_compressed_edge_container.HasEntryForID(edge_id_2));
if (forward_data.edge_id != SPECIAL_NODEID)
{
@ -217,8 +190,8 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
BOOST_ASSERT(forward_data.edge_id != SPECIAL_NODEID ||
reverse_data.edge_id != SPECIAL_NODEID);
m_compressed_edge_container.AddUncompressedEdge(edge_id_1, node_v, forward_data.distance);
m_compressed_edge_container.AddUncompressedEdge(edge_id_2, node_u, reverse_data.distance);
//m_compressed_edge_container.AddUncompressedEdge(edge_id_1, node_v, forward_data.distance);
//m_compressed_edge_container.AddUncompressedEdge(edge_id_2, node_u, reverse_data.distance);
m_edge_based_node_list.emplace_back(
forward_data.edge_id, reverse_data.edge_id, node_u, node_v, forward_data.name_id,

View File

@ -517,12 +517,13 @@ Extractor::BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_n
graph_compressor.Compress(barrier_nodes, traffic_lights, *restriction_map, *node_based_graph,
compressed_edge_container);
compressed_edge_container.SerializeInternalVector(config.geometry_output_path);
EdgeBasedGraphFactory edge_based_graph_factory(
node_based_graph, compressed_edge_container, barrier_nodes, traffic_lights,
std::const_pointer_cast<RestrictionMap const>(restriction_map),
internal_to_external_node_map, speed_profile);
edge_based_graph_factory.Run(config.edge_output_path, lua_state,
config.edge_segment_lookup_path, config.edge_penalty_path,
config.generate_edge_lookup
@ -532,11 +533,6 @@ Extractor::BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_n
#endif
);
// Note: this needs to be done *after* the edge-based-graph-factory runs,
// becase it will insert all the uncompressable segments into the compressed
// edge container (necessary for later use)
compressed_edge_container.SerializeInternalVector(config.geometry_output_path);
lua_close(lua_state);
edge_based_graph_factory.GetEdgeBasedEdges(edge_based_edge_list);

View File

@ -166,6 +166,20 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
}
PrintStatistics(original_number_of_nodes, original_number_of_edges, graph);
// Repeate the loop, but now add all edges as uncompressed values.
// The function AddUncompressedEdge does nothing if the edge is already
// in the CompressedEdgeContainer.
for (const NodeID node_u : util::irange(0u, original_number_of_nodes))
{
for (const auto edge_id : util::irange(graph.BeginEdges(node_u), graph.EndEdges(node_u)))
{
const EdgeData &data = graph.GetEdgeData(edge_id);
const NodeID target = graph.GetTarget(edge_id);
geometry_compressor.AddUncompressedEdge(edge_id, target, data.distance);
}
}
}
void GraphCompressor::PrintStatistics(unsigned original_number_of_nodes,