From 53f87c08b5114532d76f87b60555cc13ca31ee11 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Tue, 22 Aug 2017 19:52:42 +0000 Subject: [PATCH] Rename GraphView -> BisectionGraphView to avoid name conflicts --- ...raph_view.hpp => bisection_graph_view.hpp} | 12 ++--- include/partition/dinic_max_flow.hpp | 14 ++--- include/partition/inertial_flow.hpp | 4 +- include/partition/recursive_bisection.hpp | 1 - .../partition/recursive_bisection_state.hpp | 4 +- src/partition/bisection_graph_view.cpp | 53 +++++++++++++++++++ src/partition/dinic_max_flow.cpp | 14 ++--- src/partition/graph_view.cpp | 53 ------------------- src/partition/inertial_flow.cpp | 7 +-- src/partition/recursive_bisection.cpp | 8 +-- src/partition/recursive_bisection_state.cpp | 10 ++-- ...raph_view.cpp => bisection_graph_view.cpp} | 16 +++--- unit_tests/partition/dinic.cpp | 4 +- unit_tests/partition/scc_integration.cpp | 2 +- 14 files changed, 101 insertions(+), 101 deletions(-) rename include/partition/{graph_view.hpp => bisection_graph_view.hpp} (85%) create mode 100644 src/partition/bisection_graph_view.cpp delete mode 100644 src/partition/graph_view.cpp rename unit_tests/partition/{graph_view.cpp => bisection_graph_view.cpp} (93%) diff --git a/include/partition/graph_view.hpp b/include/partition/bisection_graph_view.hpp similarity index 85% rename from include/partition/graph_view.hpp rename to include/partition/bisection_graph_view.hpp index 3320d0dff..056141720 100644 --- a/include/partition/graph_view.hpp +++ b/include/partition/bisection_graph_view.hpp @@ -1,5 +1,5 @@ -#ifndef OSRM_PARTITION_GRAPHVIEW_HPP_ -#define OSRM_PARTITION_GRAPHVIEW_HPP_ +#ifndef OSRM_PARTITION_BISECTION_GRAPHVIEW_HPP_ +#define OSRM_PARTITION_BISECTION_GRAPHVIEW_HPP_ #include "partition/bisection_graph.hpp" @@ -17,7 +17,7 @@ namespace partition // Non-owning immutable sub-graph view into a base graph. // The part of the graph to select is determined by the recursive bisection state. -class GraphView +class BisectionGraphView { public: using ConstNodeIterator = BisectionGraph::ConstNodeIterator; @@ -26,13 +26,13 @@ class GraphView using EdgeT = BisectionGraph::EdgeT; // Construction either for a subrange, or for a full range - GraphView(const BisectionGraph &graph); - GraphView(const BisectionGraph &graph, + BisectionGraphView(const BisectionGraph &graph); + BisectionGraphView(const BisectionGraph &graph, const ConstNodeIterator begin, const ConstNodeIterator end); // construction from a different view, no need to keep the graph around - GraphView(const GraphView &view, const ConstNodeIterator begin, const ConstNodeIterator end); + BisectionGraphView(const BisectionGraphView &view, const ConstNodeIterator begin, const ConstNodeIterator end); // Number of nodes _in this sub-graph. std::size_t NumberOfNodes() const; diff --git a/include/partition/dinic_max_flow.hpp b/include/partition/dinic_max_flow.hpp index 14ba216d3..8882c9890 100644 --- a/include/partition/dinic_max_flow.hpp +++ b/include/partition/dinic_max_flow.hpp @@ -1,7 +1,7 @@ #ifndef OSRM_PARTITION_DINIC_MAX_FLOW_HPP_ #define OSRM_PARTITION_DINIC_MAX_FLOW_HPP_ -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" #include #include @@ -31,12 +31,12 @@ class DinicMaxFlow // input parameter storing the set o using SourceSinkNodes = std::unordered_set; - MinCut operator()(const GraphView &view, + MinCut operator()(const BisectionGraphView &view, const SourceSinkNodes &source_nodes, const SourceSinkNodes &sink_nodes) const; // validates the inpiut parameters to the flow algorithm (e.g. not intersecting) - bool Validate(const GraphView &view, + bool Validate(const BisectionGraphView &view, const SourceSinkNodes &source_nodes, const SourceSinkNodes &sink_nodes) const; @@ -57,7 +57,7 @@ class DinicMaxFlow // \ / // b // would assign s = 0, a,b = 1, t=2 - LevelGraph ComputeLevelGraph(const GraphView &view, + LevelGraph ComputeLevelGraph(const BisectionGraphView &view, const std::vector &border_source_nodes, const SourceSinkNodes &source_nodes, const SourceSinkNodes &sink_nodes, @@ -68,7 +68,7 @@ class DinicMaxFlow // with increasing level exists from `s` to `t`). std::size_t BlockingFlow(FlowEdges &flow, LevelGraph &levels, - const GraphView &view, + const BisectionGraphView &view, const SourceSinkNodes &source_nodes, const std::vector &border_sink_nodes) const; @@ -78,13 +78,13 @@ class DinicMaxFlow // sink nodes, instead of the source, so we can save a few dfs runs std::vector GetAugmentingPath(LevelGraph &levels, const NodeID from, - const GraphView &view, + const BisectionGraphView &view, const FlowEdges &flow, const SourceSinkNodes &source_nodes) const; // Builds an actual cut result from a level graph MinCut - MakeCut(const GraphView &view, const LevelGraph &levels, const std::size_t flow_value) const; + MakeCut(const BisectionGraphView &view, const LevelGraph &levels, const std::size_t flow_value) const; }; } // namespace partition diff --git a/include/partition/inertial_flow.hpp b/include/partition/inertial_flow.hpp index ae8cf076e..96eb2a548 100644 --- a/include/partition/inertial_flow.hpp +++ b/include/partition/inertial_flow.hpp @@ -2,14 +2,14 @@ #define OSRM_PARTITION_INERTIAL_FLOW_HPP_ #include "partition/dinic_max_flow.hpp" -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" namespace osrm { namespace partition { -DinicMaxFlow::MinCut computeInertialFlowCut(const GraphView &view, +DinicMaxFlow::MinCut computeInertialFlowCut(const BisectionGraphView &view, const std::size_t num_slopes, const double balance, const double source_sink_rate); diff --git a/include/partition/recursive_bisection.hpp b/include/partition/recursive_bisection.hpp index 4c42e3c0d..a4c1c5e61 100644 --- a/include/partition/recursive_bisection.hpp +++ b/include/partition/recursive_bisection.hpp @@ -2,7 +2,6 @@ #define OSRM_PARTITION_RECURSIVE_BISECTION_HPP_ #include "partition/bisection_graph.hpp" -#include "partition/graph_view.hpp" #include "partition/recursive_bisection_state.hpp" #include "util/typedefs.hpp" diff --git a/include/partition/recursive_bisection_state.hpp b/include/partition/recursive_bisection_state.hpp index a4edb7f35..1f8fec448 100644 --- a/include/partition/recursive_bisection_state.hpp +++ b/include/partition/recursive_bisection_state.hpp @@ -6,7 +6,7 @@ #include #include "partition/bisection_graph.hpp" -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" #include "util/typedefs.hpp" namespace osrm @@ -37,7 +37,7 @@ class RecursiveBisectionState // perform an initial pre-partitioning into small components // on larger graphs, SCCs give perfect cuts (think Amerika vs Europe) // This function performs an initial pre-partitioning using these sccs. - std::vector PrePartitionWithSCC(const std::size_t small_component_size); + std::vector PrePartitionWithSCC(const std::size_t small_component_size); const std::vector &BisectionIDs() const; diff --git a/src/partition/bisection_graph_view.cpp b/src/partition/bisection_graph_view.cpp new file mode 100644 index 000000000..4c3299fa5 --- /dev/null +++ b/src/partition/bisection_graph_view.cpp @@ -0,0 +1,53 @@ +#include "partition/bisection_graph_view.hpp" + +#include +#include + +#include + +namespace osrm +{ +namespace partition +{ + +BisectionGraphView::BisectionGraphView(const BisectionGraph &bisection_graph_) + : BisectionGraphView(bisection_graph_, bisection_graph_.CBegin(), bisection_graph_.CEnd()) +{ +} + +BisectionGraphView::BisectionGraphView(const BisectionGraph &bisection_graph_, + const BisectionGraph::ConstNodeIterator begin_, + const BisectionGraph::ConstNodeIterator end_) + : bisection_graph(bisection_graph_), begin(begin_), end(end_) +{ +} + +BisectionGraphView::BisectionGraphView(const BisectionGraphView &other_view, + const BisectionGraph::ConstNodeIterator begin_, + const BisectionGraph::ConstNodeIterator end_) + : BisectionGraphView(other_view.bisection_graph, begin_, end_) +{ +} + +std::size_t BisectionGraphView::NumberOfNodes() const { return std::distance(begin, end); } + +NodeID BisectionGraphView::GetID(const NodeT &node) const +{ + const auto node_id = static_cast(&node - &(*begin)); + BOOST_ASSERT(node_id < NumberOfNodes()); + return node_id; +} + +BisectionGraph::ConstNodeIterator BisectionGraphView::Begin() const { return begin; } + +BisectionGraph::ConstNodeIterator BisectionGraphView::End() const { return end; } + +const BisectionGraphView::NodeT &BisectionGraphView::Node(const NodeID nid) const { return *(begin + nid); } + +const BisectionGraphView::EdgeT &BisectionGraphView::Edge(const EdgeID eid) const +{ + return bisection_graph.Edge(eid); +} + +} // namespace partition +} // namespace osrm diff --git a/src/partition/dinic_max_flow.cpp b/src/partition/dinic_max_flow.cpp index 1a2b4c9fd..c71de204d 100644 --- a/src/partition/dinic_max_flow.cpp +++ b/src/partition/dinic_max_flow.cpp @@ -18,7 +18,7 @@ namespace const auto constexpr INVALID_LEVEL = std::numeric_limits::max(); -auto makeHasNeighborNotInCheck(const DinicMaxFlow::SourceSinkNodes &set, const GraphView &view) +auto makeHasNeighborNotInCheck(const DinicMaxFlow::SourceSinkNodes &set, const BisectionGraphView &view) { return [&](const NodeID nid) { const auto is_not_contained = [&set](const BisectionEdge &edge) { @@ -31,7 +31,7 @@ auto makeHasNeighborNotInCheck(const DinicMaxFlow::SourceSinkNodes &set, const G } // end namespace -DinicMaxFlow::MinCut DinicMaxFlow::operator()(const GraphView &view, +DinicMaxFlow::MinCut DinicMaxFlow::operator()(const BisectionGraphView &view, const SourceSinkNodes &source_nodes, const SourceSinkNodes &sink_nodes) const { @@ -93,7 +93,7 @@ DinicMaxFlow::MinCut DinicMaxFlow::operator()(const GraphView &view, } while (true); } -DinicMaxFlow::MinCut DinicMaxFlow::MakeCut(const GraphView &view, +DinicMaxFlow::MinCut DinicMaxFlow::MakeCut(const BisectionGraphView &view, const LevelGraph &levels, const std::size_t flow_value) const { @@ -112,7 +112,7 @@ DinicMaxFlow::MinCut DinicMaxFlow::MakeCut(const GraphView &view, } DinicMaxFlow::LevelGraph -DinicMaxFlow::ComputeLevelGraph(const GraphView &view, +DinicMaxFlow::ComputeLevelGraph(const BisectionGraphView &view, const std::vector &border_source_nodes, const SourceSinkNodes &source_nodes, const SourceSinkNodes &sink_nodes, @@ -172,7 +172,7 @@ DinicMaxFlow::ComputeLevelGraph(const GraphView &view, std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow, LevelGraph &levels, - const GraphView &view, + const BisectionGraphView &view, const SourceSinkNodes &source_nodes, const std::vector &border_sink_nodes) const { @@ -228,7 +228,7 @@ std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow, // INVALID_LEVEL and by following the level graph, this looks at every edge at most `c` times (O(E)) std::vector DinicMaxFlow::GetAugmentingPath(LevelGraph &levels, const NodeID node_id, - const GraphView &view, + const BisectionGraphView &view, const FlowEdges &flow, const SourceSinkNodes &source_nodes) const { @@ -290,7 +290,7 @@ std::vector DinicMaxFlow::GetAugmentingPath(LevelGraph &levels, return path; } -bool DinicMaxFlow::Validate(const GraphView &view, +bool DinicMaxFlow::Validate(const BisectionGraphView &view, const SourceSinkNodes &source_nodes, const SourceSinkNodes &sink_nodes) const { diff --git a/src/partition/graph_view.cpp b/src/partition/graph_view.cpp deleted file mode 100644 index a674e2736..000000000 --- a/src/partition/graph_view.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "partition/graph_view.hpp" - -#include -#include - -#include - -namespace osrm -{ -namespace partition -{ - -GraphView::GraphView(const BisectionGraph &bisection_graph_) - : GraphView(bisection_graph_, bisection_graph_.CBegin(), bisection_graph_.CEnd()) -{ -} - -GraphView::GraphView(const BisectionGraph &bisection_graph_, - const BisectionGraph::ConstNodeIterator begin_, - const BisectionGraph::ConstNodeIterator end_) - : bisection_graph(bisection_graph_), begin(begin_), end(end_) -{ -} - -GraphView::GraphView(const GraphView &other_view, - const BisectionGraph::ConstNodeIterator begin_, - const BisectionGraph::ConstNodeIterator end_) - : GraphView(other_view.bisection_graph, begin_, end_) -{ -} - -std::size_t GraphView::NumberOfNodes() const { return std::distance(begin, end); } - -NodeID GraphView::GetID(const NodeT &node) const -{ - const auto node_id = static_cast(&node - &(*begin)); - BOOST_ASSERT(node_id < NumberOfNodes()); - return node_id; -} - -BisectionGraph::ConstNodeIterator GraphView::Begin() const { return begin; } - -BisectionGraph::ConstNodeIterator GraphView::End() const { return end; } - -const GraphView::NodeT &GraphView::Node(const NodeID nid) const { return *(begin + nid); } - -const GraphView::EdgeT &GraphView::Edge(const EdgeID eid) const -{ - return bisection_graph.Edge(eid); -} - -} // namespace partition -} // namespace osrm diff --git a/src/partition/inertial_flow.cpp b/src/partition/inertial_flow.cpp index 0df110d53..8dc3133f6 100644 --- a/src/partition/inertial_flow.cpp +++ b/src/partition/inertial_flow.cpp @@ -1,5 +1,6 @@ #include "partition/inertial_flow.hpp" #include "partition/bisection_graph.hpp" +#include "partition/bisection_graph_view.hpp" #include "partition/reorder_first_last.hpp" #include @@ -32,7 +33,7 @@ struct SpatialOrder // Creates a spatial order of n * sources "first" and n * sink "last" node ids. // The slope determines the spatial order for sorting node coordinates. -SpatialOrder makeSpatialOrder(const GraphView &view, const double ratio, const double slope) +SpatialOrder makeSpatialOrder(const BisectionGraphView &view, const double ratio, const double slope) { struct NodeWithCoordinate { @@ -89,7 +90,7 @@ SpatialOrder makeSpatialOrder(const GraphView &view, const double ratio, const d // Makes n cuts with different spatial orders and returns the best. DinicMaxFlow::MinCut -bestMinCut(const GraphView &view, const std::size_t n, const double ratio, const double balance) +bestMinCut(const BisectionGraphView &view, const std::size_t n, const double ratio, const double balance) { DinicMaxFlow::MinCut best; best.num_edges = -1; @@ -147,7 +148,7 @@ bestMinCut(const GraphView &view, const std::size_t n, const double ratio, const } } -DinicMaxFlow::MinCut computeInertialFlowCut(const GraphView &view, +DinicMaxFlow::MinCut computeInertialFlowCut(const BisectionGraphView &view, const std::size_t num_slopes, const double balance, const double source_sink_rate) diff --git a/src/partition/recursive_bisection.cpp b/src/partition/recursive_bisection.cpp index c491b4582..795a2b23e 100644 --- a/src/partition/recursive_bisection.cpp +++ b/src/partition/recursive_bisection.cpp @@ -1,7 +1,7 @@ #include "partition/recursive_bisection.hpp" #include "partition/inertial_flow.hpp" -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" #include "partition/recursive_bisection_state.hpp" #include "util/log.hpp" @@ -46,7 +46,7 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_, struct TreeNode { - GraphView graph; + BisectionGraphView graph; std::uint64_t depth; }; @@ -82,13 +82,13 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_, return too_small || too_deep; }; - GraphView left_graph{bisection_graph, node.graph.Begin(), center}; + BisectionGraphView left_graph{bisection_graph, node.graph.Begin(), center}; TreeNode left_node{std::move(left_graph), node.depth + 1}; if (!terminal(left_node)) feeder.add(std::move(left_node)); - GraphView right_graph{bisection_graph, center, node.graph.End()}; + BisectionGraphView right_graph{bisection_graph, center, node.graph.End()}; TreeNode right_node{std::move(right_graph), node.depth + 1}; if (!terminal(right_node)) diff --git a/src/partition/recursive_bisection_state.cpp b/src/partition/recursive_bisection_state.cpp index d5f2874b3..e1baf828a 100644 --- a/src/partition/recursive_bisection_state.cpp +++ b/src/partition/recursive_bisection_state.cpp @@ -85,7 +85,7 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin, return const_begin + std::distance(begin, center); } -std::vector +std::vector RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_size) { // since our graphs are unidirectional, we don't realy need the scc. But tarjan is so nice and @@ -124,7 +124,7 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s edge.target = mapping[edge.target]; }); - std::vector views; + std::vector views; auto last = bisection_graph.CBegin(); auto last_id = transform_id(bisection_graph.Begin()->original_id); std::set ordered_component_ids; @@ -134,12 +134,12 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s ordered_component_ids.insert(itr_id); if (last_id != itr_id) { - views.push_back(GraphView(bisection_graph, last, itr)); + views.push_back(BisectionGraphView(bisection_graph, last, itr)); last_id = itr_id; last = itr; } } - views.push_back(GraphView(bisection_graph, last, bisection_graph.CEnd())); + views.push_back(BisectionGraphView(bisection_graph, last, bisection_graph.CEnd())); bool has_small_component = [&]() { for (std::size_t i = 0; i < scc_algo.GetNumberOfComponents(); ++i) @@ -149,7 +149,7 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s }(); if (!has_small_component) - views.push_back(GraphView(bisection_graph, bisection_graph.CEnd(), bisection_graph.CEnd())); + views.push_back(BisectionGraphView(bisection_graph, bisection_graph.CEnd(), bisection_graph.CEnd())); // apply scc as bisections, we need scc_level bits for this with scc_levels = // ceil(log_2(components)) diff --git a/unit_tests/partition/graph_view.cpp b/unit_tests/partition/bisection_graph_view.cpp similarity index 93% rename from unit_tests/partition/graph_view.cpp rename to unit_tests/partition/bisection_graph_view.cpp index 4407751fd..6cfe4f20a 100644 --- a/unit_tests/partition/graph_view.cpp +++ b/unit_tests/partition/bisection_graph_view.cpp @@ -1,4 +1,4 @@ -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" #include "partition/graph_generator.hpp" #include "partition/recursive_bisection_state.hpp" @@ -33,8 +33,8 @@ BOOST_AUTO_TEST_CASE(separate_top_bottom) partition[4] = partition[5] = partition[6] = partition[7] = true; const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition); - GraphView left(graph, graph.Begin(), center); - GraphView right(graph, center, graph.End()); + BisectionGraphView left(graph, graph.Begin(), center); + BisectionGraphView right(graph, center, graph.End()); BOOST_CHECK_EQUAL(left.NumberOfNodes(), 4); for (const auto &node : left.Nodes()) @@ -82,10 +82,10 @@ BOOST_AUTO_TEST_CASE(separate_top_bottom_copy) partition[4] = partition[5] = partition[6] = partition[7] = true; const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition); - GraphView total(graph, graph.Begin(), graph.End()); + BisectionGraphView total(graph, graph.Begin(), graph.End()); - GraphView left(total, total.Begin(), center); - GraphView right(total, center, total.End()); + BisectionGraphView left(total, total.Begin(), center); + BisectionGraphView right(total, center, total.End()); BOOST_CHECK_EQUAL(left.NumberOfNodes(), 4); for (const auto &node : left.Nodes()) @@ -134,8 +134,8 @@ BOOST_AUTO_TEST_CASE(separate_left_right) partition[0] = partition[4] = false; const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition); - GraphView left(graph, graph.Begin(), center); - GraphView right(graph, center, graph.End()); + BisectionGraphView left(graph, graph.Begin(), center); + BisectionGraphView right(graph, center, graph.End()); BOOST_CHECK_EQUAL(left.NumberOfNodes(), 2); std::vector left_coordinates; diff --git a/unit_tests/partition/dinic.cpp b/unit_tests/partition/dinic.cpp index 9941674fc..87e0a17e2 100644 --- a/unit_tests/partition/dinic.cpp +++ b/unit_tests/partition/dinic.cpp @@ -1,6 +1,6 @@ #include "partition/dinic_max_flow.hpp" #include "partition/graph_generator.hpp" -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" #include "partition/recursive_bisection_state.hpp" #include @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(horizontal_cut_between_two_grids) }(); RecursiveBisectionState bisection_state(graph); - GraphView view(graph); + BisectionGraphView view(graph); DinicMaxFlow::SourceSinkNodes sources, sinks; diff --git a/unit_tests/partition/scc_integration.cpp b/unit_tests/partition/scc_integration.cpp index f8be1c5f5..46c70eca7 100644 --- a/unit_tests/partition/scc_integration.cpp +++ b/unit_tests/partition/scc_integration.cpp @@ -1,5 +1,5 @@ #include "partition/graph_generator.hpp" -#include "partition/graph_view.hpp" +#include "partition/bisection_graph_view.hpp" #include "partition/recursive_bisection_state.hpp" #include