Rename GraphView -> BisectionGraphView to avoid name conflicts
This commit is contained in:
parent
e23dc8977f
commit
53f87c08b5
@ -1,5 +1,5 @@
|
|||||||
#ifndef OSRM_PARTITION_GRAPHVIEW_HPP_
|
#ifndef OSRM_PARTITION_BISECTION_GRAPHVIEW_HPP_
|
||||||
#define OSRM_PARTITION_GRAPHVIEW_HPP_
|
#define OSRM_PARTITION_BISECTION_GRAPHVIEW_HPP_
|
||||||
|
|
||||||
#include "partition/bisection_graph.hpp"
|
#include "partition/bisection_graph.hpp"
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ namespace partition
|
|||||||
|
|
||||||
// Non-owning immutable sub-graph view into a base graph.
|
// Non-owning immutable sub-graph view into a base graph.
|
||||||
// The part of the graph to select is determined by the recursive bisection state.
|
// The part of the graph to select is determined by the recursive bisection state.
|
||||||
class GraphView
|
class BisectionGraphView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using ConstNodeIterator = BisectionGraph::ConstNodeIterator;
|
using ConstNodeIterator = BisectionGraph::ConstNodeIterator;
|
||||||
@ -26,13 +26,13 @@ class GraphView
|
|||||||
using EdgeT = BisectionGraph::EdgeT;
|
using EdgeT = BisectionGraph::EdgeT;
|
||||||
|
|
||||||
// Construction either for a subrange, or for a full range
|
// Construction either for a subrange, or for a full range
|
||||||
GraphView(const BisectionGraph &graph);
|
BisectionGraphView(const BisectionGraph &graph);
|
||||||
GraphView(const BisectionGraph &graph,
|
BisectionGraphView(const BisectionGraph &graph,
|
||||||
const ConstNodeIterator begin,
|
const ConstNodeIterator begin,
|
||||||
const ConstNodeIterator end);
|
const ConstNodeIterator end);
|
||||||
|
|
||||||
// construction from a different view, no need to keep the graph around
|
// 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.
|
// Number of nodes _in this sub-graph.
|
||||||
std::size_t NumberOfNodes() const;
|
std::size_t NumberOfNodes() const;
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef OSRM_PARTITION_DINIC_MAX_FLOW_HPP_
|
#ifndef OSRM_PARTITION_DINIC_MAX_FLOW_HPP_
|
||||||
#define 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 <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -31,12 +31,12 @@ class DinicMaxFlow
|
|||||||
// input parameter storing the set o
|
// input parameter storing the set o
|
||||||
using SourceSinkNodes = std::unordered_set<NodeID>;
|
using SourceSinkNodes = std::unordered_set<NodeID>;
|
||||||
|
|
||||||
MinCut operator()(const GraphView &view,
|
MinCut operator()(const BisectionGraphView &view,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const SourceSinkNodes &sink_nodes) const;
|
const SourceSinkNodes &sink_nodes) const;
|
||||||
|
|
||||||
// validates the inpiut parameters to the flow algorithm (e.g. not intersecting)
|
// 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 &source_nodes,
|
||||||
const SourceSinkNodes &sink_nodes) const;
|
const SourceSinkNodes &sink_nodes) const;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class DinicMaxFlow
|
|||||||
// \ /
|
// \ /
|
||||||
// b
|
// b
|
||||||
// would assign s = 0, a,b = 1, t=2
|
// 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 std::vector<NodeID> &border_source_nodes,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const SourceSinkNodes &sink_nodes,
|
const SourceSinkNodes &sink_nodes,
|
||||||
@ -68,7 +68,7 @@ class DinicMaxFlow
|
|||||||
// with increasing level exists from `s` to `t`).
|
// with increasing level exists from `s` to `t`).
|
||||||
std::size_t BlockingFlow(FlowEdges &flow,
|
std::size_t BlockingFlow(FlowEdges &flow,
|
||||||
LevelGraph &levels,
|
LevelGraph &levels,
|
||||||
const GraphView &view,
|
const BisectionGraphView &view,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const std::vector<NodeID> &border_sink_nodes) const;
|
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
|
// sink nodes, instead of the source, so we can save a few dfs runs
|
||||||
std::vector<NodeID> GetAugmentingPath(LevelGraph &levels,
|
std::vector<NodeID> GetAugmentingPath(LevelGraph &levels,
|
||||||
const NodeID from,
|
const NodeID from,
|
||||||
const GraphView &view,
|
const BisectionGraphView &view,
|
||||||
const FlowEdges &flow,
|
const FlowEdges &flow,
|
||||||
const SourceSinkNodes &source_nodes) const;
|
const SourceSinkNodes &source_nodes) const;
|
||||||
|
|
||||||
// Builds an actual cut result from a level graph
|
// Builds an actual cut result from a level graph
|
||||||
MinCut
|
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
|
} // namespace partition
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
#define OSRM_PARTITION_INERTIAL_FLOW_HPP_
|
#define OSRM_PARTITION_INERTIAL_FLOW_HPP_
|
||||||
|
|
||||||
#include "partition/dinic_max_flow.hpp"
|
#include "partition/dinic_max_flow.hpp"
|
||||||
#include "partition/graph_view.hpp"
|
#include "partition/bisection_graph_view.hpp"
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
namespace partition
|
namespace partition
|
||||||
{
|
{
|
||||||
|
|
||||||
DinicMaxFlow::MinCut computeInertialFlowCut(const GraphView &view,
|
DinicMaxFlow::MinCut computeInertialFlowCut(const BisectionGraphView &view,
|
||||||
const std::size_t num_slopes,
|
const std::size_t num_slopes,
|
||||||
const double balance,
|
const double balance,
|
||||||
const double source_sink_rate);
|
const double source_sink_rate);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define OSRM_PARTITION_RECURSIVE_BISECTION_HPP_
|
#define OSRM_PARTITION_RECURSIVE_BISECTION_HPP_
|
||||||
|
|
||||||
#include "partition/bisection_graph.hpp"
|
#include "partition/bisection_graph.hpp"
|
||||||
#include "partition/graph_view.hpp"
|
|
||||||
#include "partition/recursive_bisection_state.hpp"
|
#include "partition/recursive_bisection_state.hpp"
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "partition/bisection_graph.hpp"
|
#include "partition/bisection_graph.hpp"
|
||||||
#include "partition/graph_view.hpp"
|
#include "partition/bisection_graph_view.hpp"
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
@ -37,7 +37,7 @@ class RecursiveBisectionState
|
|||||||
// perform an initial pre-partitioning into small components
|
// perform an initial pre-partitioning into small components
|
||||||
// on larger graphs, SCCs give perfect cuts (think Amerika vs Europe)
|
// on larger graphs, SCCs give perfect cuts (think Amerika vs Europe)
|
||||||
// This function performs an initial pre-partitioning using these sccs.
|
// 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;
|
const std::vector<BisectionID> &BisectionIDs() const;
|
||||||
|
|
||||||
|
53
src/partition/bisection_graph_view.cpp
Normal file
53
src/partition/bisection_graph_view.cpp
Normal 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
|
@ -18,7 +18,7 @@ namespace
|
|||||||
|
|
||||||
const auto constexpr INVALID_LEVEL = std::numeric_limits<DinicMaxFlow::Level>::max();
|
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) {
|
return [&](const NodeID nid) {
|
||||||
const auto is_not_contained = [&set](const BisectionEdge &edge) {
|
const auto is_not_contained = [&set](const BisectionEdge &edge) {
|
||||||
@ -31,7 +31,7 @@ auto makeHasNeighborNotInCheck(const DinicMaxFlow::SourceSinkNodes &set, const G
|
|||||||
|
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
|
||||||
DinicMaxFlow::MinCut DinicMaxFlow::operator()(const GraphView &view,
|
DinicMaxFlow::MinCut DinicMaxFlow::operator()(const BisectionGraphView &view,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const SourceSinkNodes &sink_nodes) const
|
const SourceSinkNodes &sink_nodes) const
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ DinicMaxFlow::MinCut DinicMaxFlow::operator()(const GraphView &view,
|
|||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
DinicMaxFlow::MinCut DinicMaxFlow::MakeCut(const GraphView &view,
|
DinicMaxFlow::MinCut DinicMaxFlow::MakeCut(const BisectionGraphView &view,
|
||||||
const LevelGraph &levels,
|
const LevelGraph &levels,
|
||||||
const std::size_t flow_value) const
|
const std::size_t flow_value) const
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ DinicMaxFlow::MinCut DinicMaxFlow::MakeCut(const GraphView &view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DinicMaxFlow::LevelGraph
|
DinicMaxFlow::LevelGraph
|
||||||
DinicMaxFlow::ComputeLevelGraph(const GraphView &view,
|
DinicMaxFlow::ComputeLevelGraph(const BisectionGraphView &view,
|
||||||
const std::vector<NodeID> &border_source_nodes,
|
const std::vector<NodeID> &border_source_nodes,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const SourceSinkNodes &sink_nodes,
|
const SourceSinkNodes &sink_nodes,
|
||||||
@ -172,7 +172,7 @@ DinicMaxFlow::ComputeLevelGraph(const GraphView &view,
|
|||||||
|
|
||||||
std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow,
|
std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow,
|
||||||
LevelGraph &levels,
|
LevelGraph &levels,
|
||||||
const GraphView &view,
|
const BisectionGraphView &view,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const std::vector<NodeID> &border_sink_nodes) const
|
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))
|
// 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,
|
std::vector<NodeID> DinicMaxFlow::GetAugmentingPath(LevelGraph &levels,
|
||||||
const NodeID node_id,
|
const NodeID node_id,
|
||||||
const GraphView &view,
|
const BisectionGraphView &view,
|
||||||
const FlowEdges &flow,
|
const FlowEdges &flow,
|
||||||
const SourceSinkNodes &source_nodes) const
|
const SourceSinkNodes &source_nodes) const
|
||||||
{
|
{
|
||||||
@ -290,7 +290,7 @@ std::vector<NodeID> DinicMaxFlow::GetAugmentingPath(LevelGraph &levels,
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DinicMaxFlow::Validate(const GraphView &view,
|
bool DinicMaxFlow::Validate(const BisectionGraphView &view,
|
||||||
const SourceSinkNodes &source_nodes,
|
const SourceSinkNodes &source_nodes,
|
||||||
const SourceSinkNodes &sink_nodes) const
|
const SourceSinkNodes &sink_nodes) const
|
||||||
{
|
{
|
||||||
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||||||
#include "partition/inertial_flow.hpp"
|
#include "partition/inertial_flow.hpp"
|
||||||
#include "partition/bisection_graph.hpp"
|
#include "partition/bisection_graph.hpp"
|
||||||
|
#include "partition/bisection_graph_view.hpp"
|
||||||
#include "partition/reorder_first_last.hpp"
|
#include "partition/reorder_first_last.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -32,7 +33,7 @@ struct SpatialOrder
|
|||||||
|
|
||||||
// Creates a spatial order of n * sources "first" and n * sink "last" node ids.
|
// Creates a spatial order of n * sources "first" and n * sink "last" node ids.
|
||||||
// The slope determines the spatial order for sorting node coordinates.
|
// 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
|
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.
|
// Makes n cuts with different spatial orders and returns the best.
|
||||||
DinicMaxFlow::MinCut
|
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;
|
DinicMaxFlow::MinCut best;
|
||||||
best.num_edges = -1;
|
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 std::size_t num_slopes,
|
||||||
const double balance,
|
const double balance,
|
||||||
const double source_sink_rate)
|
const double source_sink_rate)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "partition/recursive_bisection.hpp"
|
#include "partition/recursive_bisection.hpp"
|
||||||
#include "partition/inertial_flow.hpp"
|
#include "partition/inertial_flow.hpp"
|
||||||
|
|
||||||
#include "partition/graph_view.hpp"
|
#include "partition/bisection_graph_view.hpp"
|
||||||
#include "partition/recursive_bisection_state.hpp"
|
#include "partition/recursive_bisection_state.hpp"
|
||||||
|
|
||||||
#include "util/log.hpp"
|
#include "util/log.hpp"
|
||||||
@ -46,7 +46,7 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_,
|
|||||||
|
|
||||||
struct TreeNode
|
struct TreeNode
|
||||||
{
|
{
|
||||||
GraphView graph;
|
BisectionGraphView graph;
|
||||||
std::uint64_t depth;
|
std::uint64_t depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,13 +82,13 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_,
|
|||||||
return too_small || too_deep;
|
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};
|
TreeNode left_node{std::move(left_graph), node.depth + 1};
|
||||||
|
|
||||||
if (!terminal(left_node))
|
if (!terminal(left_node))
|
||||||
feeder.add(std::move(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};
|
TreeNode right_node{std::move(right_graph), node.depth + 1};
|
||||||
|
|
||||||
if (!terminal(right_node))
|
if (!terminal(right_node))
|
||||||
|
@ -85,7 +85,7 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin,
|
|||||||
return const_begin + std::distance(begin, center);
|
return const_begin + std::distance(begin, center);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<GraphView>
|
std::vector<BisectionGraphView>
|
||||||
RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_size)
|
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
|
// 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];
|
edge.target = mapping[edge.target];
|
||||||
});
|
});
|
||||||
|
|
||||||
std::vector<GraphView> views;
|
std::vector<BisectionGraphView> views;
|
||||||
auto last = bisection_graph.CBegin();
|
auto last = bisection_graph.CBegin();
|
||||||
auto last_id = transform_id(bisection_graph.Begin()->original_id);
|
auto last_id = transform_id(bisection_graph.Begin()->original_id);
|
||||||
std::set<std::size_t> ordered_component_ids;
|
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);
|
ordered_component_ids.insert(itr_id);
|
||||||
if (last_id != 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_id = itr_id;
|
||||||
last = itr;
|
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 = [&]() {
|
bool has_small_component = [&]() {
|
||||||
for (std::size_t i = 0; i < scc_algo.GetNumberOfComponents(); ++i)
|
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)
|
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 =
|
// apply scc as bisections, we need scc_level bits for this with scc_levels =
|
||||||
// ceil(log_2(components))
|
// ceil(log_2(components))
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "partition/graph_view.hpp"
|
#include "partition/bisection_graph_view.hpp"
|
||||||
#include "partition/graph_generator.hpp"
|
#include "partition/graph_generator.hpp"
|
||||||
#include "partition/recursive_bisection_state.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;
|
partition[4] = partition[5] = partition[6] = partition[7] = true;
|
||||||
|
|
||||||
const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition);
|
const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition);
|
||||||
GraphView left(graph, graph.Begin(), center);
|
BisectionGraphView left(graph, graph.Begin(), center);
|
||||||
GraphView right(graph, center, graph.End());
|
BisectionGraphView right(graph, center, graph.End());
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(left.NumberOfNodes(), 4);
|
BOOST_CHECK_EQUAL(left.NumberOfNodes(), 4);
|
||||||
for (const auto &node : left.Nodes())
|
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;
|
partition[4] = partition[5] = partition[6] = partition[7] = true;
|
||||||
|
|
||||||
const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition);
|
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);
|
BisectionGraphView left(total, total.Begin(), center);
|
||||||
GraphView right(total, center, total.End());
|
BisectionGraphView right(total, center, total.End());
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(left.NumberOfNodes(), 4);
|
BOOST_CHECK_EQUAL(left.NumberOfNodes(), 4);
|
||||||
for (const auto &node : left.Nodes())
|
for (const auto &node : left.Nodes())
|
||||||
@ -134,8 +134,8 @@ BOOST_AUTO_TEST_CASE(separate_left_right)
|
|||||||
partition[0] = partition[4] = false;
|
partition[0] = partition[4] = false;
|
||||||
|
|
||||||
const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition);
|
const auto center = bisection_state.ApplyBisection(graph.Begin(), graph.End(), 0, partition);
|
||||||
GraphView left(graph, graph.Begin(), center);
|
BisectionGraphView left(graph, graph.Begin(), center);
|
||||||
GraphView right(graph, center, graph.End());
|
BisectionGraphView right(graph, center, graph.End());
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(left.NumberOfNodes(), 2);
|
BOOST_CHECK_EQUAL(left.NumberOfNodes(), 2);
|
||||||
std::vector<Coordinate> left_coordinates;
|
std::vector<Coordinate> left_coordinates;
|
@ -1,6 +1,6 @@
|
|||||||
#include "partition/dinic_max_flow.hpp"
|
#include "partition/dinic_max_flow.hpp"
|
||||||
#include "partition/graph_generator.hpp"
|
#include "partition/graph_generator.hpp"
|
||||||
#include "partition/graph_view.hpp"
|
#include "partition/bisection_graph_view.hpp"
|
||||||
#include "partition/recursive_bisection_state.hpp"
|
#include "partition/recursive_bisection_state.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(horizontal_cut_between_two_grids)
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
RecursiveBisectionState bisection_state(graph);
|
RecursiveBisectionState bisection_state(graph);
|
||||||
GraphView view(graph);
|
BisectionGraphView view(graph);
|
||||||
|
|
||||||
DinicMaxFlow::SourceSinkNodes sources, sinks;
|
DinicMaxFlow::SourceSinkNodes sources, sinks;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "partition/graph_generator.hpp"
|
#include "partition/graph_generator.hpp"
|
||||||
#include "partition/graph_view.hpp"
|
#include "partition/bisection_graph_view.hpp"
|
||||||
#include "partition/recursive_bisection_state.hpp"
|
#include "partition/recursive_bisection_state.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
Loading…
Reference in New Issue
Block a user