Rename GraphView -> BisectionGraphView to avoid name conflicts

This commit is contained in:
Patrick Niklaus 2017-08-22 19:52:42 +00:00 committed by Patrick Niklaus
parent e23dc8977f
commit 53f87c08b5
14 changed files with 101 additions and 101 deletions

View File

@ -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;

View File

@ -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 <cstdint>
#include <functional>
@ -31,12 +31,12 @@ class DinicMaxFlow
// input parameter storing the set o
using SourceSinkNodes = std::unordered_set<NodeID>;
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<NodeID> &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<NodeID> &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<NodeID> 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

View File

@ -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);

View File

@ -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"

View File

@ -6,7 +6,7 @@
#include <vector>
#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<GraphView> PrePartitionWithSCC(const std::size_t small_component_size);
std::vector<BisectionGraphView> PrePartitionWithSCC(const std::size_t small_component_size);
const std::vector<BisectionID> &BisectionIDs() const;

View File

@ -0,0 +1,53 @@
#include "partition/bisection_graph_view.hpp"
#include <iostream>
#include <iterator>
#include <boost/assert.hpp>
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<NodeID>(&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

View File

@ -18,7 +18,7 @@ namespace
const auto constexpr INVALID_LEVEL = std::numeric_limits<DinicMaxFlow::Level>::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<NodeID> &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<NodeID> &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<NodeID> 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<NodeID> 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
{

View File

@ -1,53 +0,0 @@
#include "partition/graph_view.hpp"
#include <iostream>
#include <iterator>
#include <boost/assert.hpp>
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<NodeID>(&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

View File

@ -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 <algorithm>
@ -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)

View File

@ -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))

View File

@ -85,7 +85,7 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin,
return const_begin + std::distance(begin, center);
}
std::vector<GraphView>
std::vector<BisectionGraphView>
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<GraphView> views;
std::vector<BisectionGraphView> views;
auto last = bisection_graph.CBegin();
auto last_id = transform_id(bisection_graph.Begin()->original_id);
std::set<std::size_t> 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))

View File

@ -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<Coordinate> left_coordinates;

View File

@ -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 <algorithm>
@ -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;

View File

@ -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 <algorithm>