Skip to content

Commit

Permalink
Renamed EdgeBasedNode to EdgeBasedNodeSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed May 16, 2017
1 parent 879e474 commit 5bfb104
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using StringView = util::StringView;
class BaseDataFacade
{
public:
using RTreeLeaf = extractor::EdgeBasedNode;
using RTreeLeaf = extractor::EdgeBasedNodeSegment;
BaseDataFacade() {}
virtual ~BaseDataFacade() {}

Expand Down
8 changes: 4 additions & 4 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class EdgeBasedGraphFactory

// The following get access functions destroy the content in the factory
void GetEdgeBasedEdges(util::DeallocatingVector<EdgeBasedEdge> &edges);
void GetEdgeBasedNodes(EdgeBasedNodeDataContainer &ebg_node_data_container);
void GetNodeBasedEdges(std::vector<EdgeBasedNode> &nodes);
void GetEdgeBasedNodes(EdgeBasedNodeDataContainer &data_container);
void GetEdgeBasedNodeSegments(std::vector<EdgeBasedNodeSegment> &nodes);
void GetStartPointMarkers(std::vector<bool> &node_is_startpoint);
void GetEdgeBasedNodeWeights(std::vector<EdgeWeight> &output_node_weights);

Expand Down Expand Up @@ -129,8 +129,8 @@ class EdgeBasedGraphFactory
std::vector<EdgeWeight> m_edge_based_node_weights;

//! list of edge based nodes (compressed segments)
std::vector<EdgeBasedNode> m_edge_based_node_list;
EdgeBasedNodeDataContainer m_ebg_node_data_container;
std::vector<EdgeBasedNodeSegment> m_edge_based_node_segments;
EdgeBasedNodeDataContainer m_edge_based_node_container;
util::DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
EdgeID m_max_edge_id;

Expand Down
14 changes: 7 additions & 7 deletions include/extractor/edge_based_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ namespace extractor

/// This is what util::StaticRTree serialized and stores on disk
/// It is generated in EdgeBasedGraphFactory.
struct EdgeBasedNode
struct EdgeBasedNodeSegment
{
EdgeBasedNode()
EdgeBasedNodeSegment()
: forward_segment_id{SPECIAL_SEGMENTID, false},
reverse_segment_id{SPECIAL_SEGMENTID, false}, u(SPECIAL_NODEID), v(SPECIAL_NODEID),
fwd_segment_position(std::numeric_limits<unsigned short>::max())
{
}

explicit EdgeBasedNode(const SegmentID forward_segment_id_,
const SegmentID reverse_segment_id_,
NodeID u,
NodeID v,
unsigned short fwd_segment_position)
explicit EdgeBasedNodeSegment(const SegmentID forward_segment_id_,
const SegmentID reverse_segment_id_,
NodeID u,
NodeID v,
unsigned short fwd_segment_position)
: forward_segment_id(forward_segment_id_), reverse_segment_id(reverse_segment_id_), u(u),
v(v), fwd_segment_position(fwd_segment_position)
{
Expand Down
6 changes: 3 additions & 3 deletions include/extractor/extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Extractor
BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
std::vector<util::Coordinate> &coordinates,
extractor::PackedOSMIDs &osm_node_ids,
EdgeBasedNodeDataContainer &ebg_node_data_container,
std::vector<EdgeBasedNode> &node_based_edge_list,
EdgeBasedNodeDataContainer &edge_based_nodes_container,
std::vector<EdgeBasedNodeSegment> &edge_based_node_segments,
std::vector<bool> &node_is_startpoint,
std::vector<EdgeWeight> &edge_based_node_weights,
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
Expand All @@ -75,7 +75,7 @@ class Extractor
void FindComponents(unsigned max_edge_id,
const util::DeallocatingVector<EdgeBasedEdge> &edges,
EdgeBasedNodeDataContainer &nodes) const;
void BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
void BuildRTree(std::vector<EdgeBasedNodeSegment> edge_based_node_segments,
std::vector<bool> node_is_startpoint,
const std::vector<util::Coordinate> &coordinates);
std::shared_ptr<RestrictionMap> LoadRestrictionMap();
Expand Down
2 changes: 1 addition & 1 deletion include/extractor/node_data_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ template <storage::Ownership Ownership> class EdgeBasedNodeDataContainerImpl

// Used by EdgeBasedGraphFactory to fill data structure
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
void SetData(NodeID node_id, ComponentID component_id)
void SetComponentID(NodeID node_id, ComponentID component_id)
{
component_ids[node_id] = component_id;
}
Expand Down
43 changes: 22 additions & 21 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges(
swap(m_edge_based_edge_list, output_edge_list);
}

void EdgeBasedGraphFactory::GetEdgeBasedNodes(EdgeBasedNodeDataContainer &ebg_node_data_container)
void EdgeBasedGraphFactory::GetEdgeBasedNodes(EdgeBasedNodeDataContainer &data_container)
{
using std::swap; // Koenig swap
swap(ebg_node_data_container, m_ebg_node_data_container);
swap(data_container, m_edge_based_node_container);
}

void EdgeBasedGraphFactory::GetNodeBasedEdges(std::vector<EdgeBasedNode> &nodes)
void EdgeBasedGraphFactory::GetEdgeBasedNodeSegments(std::vector<EdgeBasedNodeSegment> &nodes)
{
using std::swap; // Koenig swap
swap(nodes, m_edge_based_node_list);
swap(nodes, m_edge_based_node_segments);
}

void EdgeBasedGraphFactory::GetStartPointMarkers(std::vector<bool> &node_is_startpoint)
Expand Down Expand Up @@ -142,16 +142,16 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N

// Add edge-based node data for forward and reverse nodes indexed by edge_id
BOOST_ASSERT(forward_data.edge_id != SPECIAL_EDGEID);
m_ebg_node_data_container.SetData(forward_data.edge_id,
GeometryID{packed_geometry_id, true},
forward_data.name_id,
forward_data.travel_mode);
m_edge_based_node_container.SetData(forward_data.edge_id,
GeometryID{packed_geometry_id, true},
forward_data.name_id,
forward_data.travel_mode);
if (reverse_data.edge_id != SPECIAL_EDGEID)
{
m_ebg_node_data_container.SetData(reverse_data.edge_id,
GeometryID{packed_geometry_id, false},
reverse_data.name_id,
reverse_data.travel_mode);
m_edge_based_node_container.SetData(reverse_data.edge_id,
GeometryID{packed_geometry_id, false},
reverse_data.name_id,
reverse_data.travel_mode);
}

// Add segments of edge-based nodes
Expand All @@ -165,11 +165,11 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N
BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id);

// build edges
m_edge_based_node_list.emplace_back(edge_id_to_segment_id(forward_data.edge_id),
edge_id_to_segment_id(reverse_data.edge_id),
current_edge_source_coordinate_id,
current_edge_target_coordinate_id,
i);
m_edge_based_node_segments.emplace_back(edge_id_to_segment_id(forward_data.edge_id),
edge_id_to_segment_id(reverse_data.edge_id),
current_edge_source_coordinate_id,
current_edge_target_coordinate_id,
i);

m_edge_based_node_is_startpoint.push_back(forward_data.startpoint ||
reverse_data.startpoint);
Expand Down Expand Up @@ -257,7 +257,7 @@ std::vector<NBGToEBG> EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
std::vector<NBGToEBG> mapping;

// Allocate memory for edge-based nodes
m_ebg_node_data_container = EdgeBasedNodeDataContainer(m_max_edge_id + 1);
m_edge_based_node_container = EdgeBasedNodeDataContainer(m_max_edge_id + 1);

util::Log() << "Generating edge expanded nodes ... ";
{
Expand Down Expand Up @@ -300,10 +300,11 @@ std::vector<NBGToEBG> EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
}
}

BOOST_ASSERT(m_edge_based_node_list.size() == m_edge_based_node_is_startpoint.size());
BOOST_ASSERT(m_edge_based_node_segments.size() == m_edge_based_node_is_startpoint.size());
BOOST_ASSERT(m_max_edge_id + 1 == m_edge_based_node_weights.size());

util::Log() << "Generated " << m_edge_based_node_list.size() << " nodes in edge-expanded graph";
util::Log() << "Generated " << (m_max_edge_id + 1) << " nodes and "
<< m_edge_based_node_segments.size() << " segments in edge-expanded graph";

return mapping;
}
Expand Down Expand Up @@ -576,7 +577,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(

files::writeTurnData(turn_data_filename, turn_data_container);

util::Log() << "Generated " << m_edge_based_node_list.size() << " edge based nodes";
util::Log() << "Generated " << m_edge_based_node_segments.size() << " edge based node segments";
util::Log() << "Node-based graph contains " << node_based_edge_counter << " edges";
util::Log() << "Edge-expanded graph ...";
util::Log() << " contains " << m_edge_based_edge_list.size() << " edges";
Expand Down
44 changes: 21 additions & 23 deletions src/extractor/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
TIMER_START(expansion);

EdgeBasedNodeDataContainer edge_based_nodes_container;
std::vector<EdgeBasedNode> node_based_edges_list;
std::vector<EdgeBasedNodeSegment> edge_based_node_segments;
util::DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
std::vector<bool> node_is_startpoint;
std::vector<EdgeWeight> edge_based_node_weights;
Expand All @@ -142,7 +142,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
coordinates,
osm_node_ids,
edge_based_nodes_container,
node_based_edges_list,
edge_based_node_segments,
node_is_startpoint,
edge_based_node_weights,
edge_based_edge_list,
Expand All @@ -169,7 +169,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)

util::Log() << "Building r-tree ...";
TIMER_START(rtree);
BuildRTree(std::move(node_based_edges_list), std::move(node_is_startpoint), coordinates);
BuildRTree(std::move(edge_based_node_segments), std::move(node_is_startpoint), coordinates);

TIMER_STOP(rtree);

Expand Down Expand Up @@ -370,14 +370,12 @@ void Extractor::FindComponents(unsigned max_edge_id,
TarjanSCC<UncontractedGraph> component_search(uncontracted_graph);
component_search.Run();

stxxl::vector<ComponentID> component_ids;
component_ids.reserve(max_edge_id + 1);
for (NodeID node_id = 0; node_id <= max_edge_id; ++node_id)
{
const auto forward_component = component_search.GetComponentID(node_id);
const auto component_size = component_search.GetComponentSize(forward_component);
const auto is_tiny = component_size < config.small_component_size;
input_nodes.SetData(node_id, {1 + forward_component, is_tiny});
input_nodes.SetComponentID(node_id, {1 + forward_component, is_tiny});
}
}

Expand Down Expand Up @@ -421,8 +419,8 @@ std::pair<std::size_t, EdgeID>
Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
std::vector<util::Coordinate> &coordinates,
extractor::PackedOSMIDs &osm_node_ids,
EdgeBasedNodeDataContainer &ebg_node_data_container,
std::vector<EdgeBasedNode> &node_based_edges_list,
EdgeBasedNodeDataContainer &edge_based_nodes_container,
std::vector<EdgeBasedNodeSegment> &edge_based_node_segments,
std::vector<bool> &node_is_startpoint,
std::vector<EdgeWeight> &edge_based_node_weights,
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
Expand Down Expand Up @@ -501,8 +499,8 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
*compressed_edge_container.ToSegmentData());

edge_based_graph_factory.GetEdgeBasedEdges(edge_based_edge_list);
edge_based_graph_factory.GetEdgeBasedNodes(ebg_node_data_container);
edge_based_graph_factory.GetNodeBasedEdges(node_based_edges_list);
edge_based_graph_factory.GetEdgeBasedNodes(edge_based_nodes_container);
edge_based_graph_factory.GetEdgeBasedNodeSegments(edge_based_node_segments);
edge_based_graph_factory.GetStartPointMarkers(node_is_startpoint);
edge_based_graph_factory.GetEdgeBasedNodeWeights(edge_based_node_weights);
auto max_edge_id = edge_based_graph_factory.GetHighestEdgeID();
Expand All @@ -522,42 +520,42 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
Saves tree into '.ramIndex' and leaves into '.fileIndex'.
*/
void Extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edges_list,
void Extractor::BuildRTree(std::vector<EdgeBasedNodeSegment> edge_based_node_segments,
std::vector<bool> node_is_startpoint,
const std::vector<util::Coordinate> &coordinates)
{
util::Log() << "constructing r-tree of " << node_based_edges_list.size()
<< " edge elements build on-top of " << coordinates.size() << " coordinates";
util::Log() << "Constructing r-tree of " << edge_based_node_segments.size()
<< " segments build on-top of " << coordinates.size() << " coordinates";

BOOST_ASSERT(node_is_startpoint.size() == node_based_edges_list.size());
BOOST_ASSERT(node_is_startpoint.size() == edge_based_node_segments.size());

// Filter node based edges based on startpoint
auto out_iter = node_based_edges_list.begin();
auto in_iter = node_based_edges_list.begin();
auto out_iter = edge_based_node_segments.begin();
auto in_iter = edge_based_node_segments.begin();
for (auto index : util::irange<std::size_t>(0UL, node_is_startpoint.size()))
{
BOOST_ASSERT(in_iter != node_based_edges_list.end());
BOOST_ASSERT(in_iter != edge_based_node_segments.end());
if (node_is_startpoint[index])
{
*out_iter = *in_iter;
out_iter++;
}
in_iter++;
}
auto new_size = out_iter - node_based_edges_list.begin();
auto new_size = out_iter - edge_based_node_segments.begin();
if (new_size == 0)
{
throw util::exception("There are no snappable edges left after processing. Are you "
"setting travel modes correctly in the profile? Cannot continue." +
SOURCE_REF);
}
node_based_edges_list.resize(new_size);
edge_based_node_segments.resize(new_size);

TIMER_START(construction);
util::StaticRTree<EdgeBasedNode> rtree(node_based_edges_list,
config.rtree_nodes_output_path,
config.rtree_leafs_output_path,
coordinates);
util::StaticRTree<EdgeBasedNodeSegment> rtree(edge_based_node_segments,
config.rtree_nodes_output_path,
config.rtree_leafs_output_path,
coordinates);

TIMER_STOP(construction);
util::Log() << "finished r-tree construction in " << TIMER_SEC(construction) << " seconds";
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/util/static_rtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace osrm::test;
constexpr uint32_t TEST_BRANCHING_FACTOR = 8;
constexpr uint32_t TEST_LEAF_NODE_SIZE = 64;

using TestData = extractor::EdgeBasedNode;
using TestData = extractor::EdgeBasedNodeSegment;
using TestStaticRTree = StaticRTree<TestData,
osrm::storage::Ownership::Container,
TEST_BRANCHING_FACTOR,
Expand Down

0 comments on commit 5bfb104

Please sign in to comment.