Upgrade clang-format to version 15 (#6859)

This commit is contained in:
Dennis Luxen
2024-05-06 09:14:46 +02:00
committed by GitHub
parent b503e96a98
commit 7f9d591ab7
156 changed files with 2357 additions and 1894 deletions
+4 -6
View File
@@ -64,9 +64,8 @@ void partitionLevel(const std::vector<BisectionID> &node_to_bisection_id,
std::accumulate(permutation.begin() + cell.begin,
permutation.begin() + cell.end,
BisectionID{0},
[&node_to_bisection_id](const BisectionID lhs, const NodeID rhs) {
return lhs | node_to_bisection_id[rhs];
});
[&node_to_bisection_id](const BisectionID lhs, const NodeID rhs)
{ return lhs | node_to_bisection_id[rhs]; });
// masks all bit strictly higher then cell.bit
BOOST_ASSERT(sizeof(unsigned long long) * CHAR_BIT > sizeof(BisectionID) * CHAR_BIT);
const BisectionID mask = (1ULL << (cell.bit + 1)) - 1;
@@ -88,9 +87,8 @@ void partitionLevel(const std::vector<BisectionID> &node_to_bisection_id,
std::uint32_t middle =
std::partition(permutation.begin() + cell.begin,
permutation.begin() + cell.end,
[is_left_mask, &node_to_bisection_id](const auto node_id) {
return node_to_bisection_id[node_id] & is_left_mask;
}) -
[is_left_mask, &node_to_bisection_id](const auto node_id)
{ return node_to_bisection_id[node_id] & is_left_mask; }) -
permutation.begin();
if (bit > 0)
+18 -15
View File
@@ -19,10 +19,10 @@ const auto constexpr INVALID_LEVEL = std::numeric_limits<DinicMaxFlow::Level>::m
auto makeHasNeighborNotInCheck(const DinicMaxFlow::SourceSinkNodes &set,
const BisectionGraphView &view)
{
return [&](const NodeID nid) {
const auto is_not_contained = [&set](const BisectionEdge &edge) {
return set.count(edge.target) == 0;
};
return [&](const NodeID nid)
{
const auto is_not_contained = [&set](const BisectionEdge &edge)
{ return set.count(edge.target) == 0; };
return view.EndEdges(nid) !=
std::find_if(view.BeginEdges(nid), view.EndEdges(nid), is_not_contained);
};
@@ -132,12 +132,12 @@ DinicMaxFlow::ComputeLevelGraph(const BisectionGraphView &view,
levels[edge.target] = 0;
}
// check if there is flow present on an edge
const auto has_flow = [&](const NodeID from, const NodeID to) {
return flow[from].find(to) != flow[from].end();
};
const auto has_flow = [&](const NodeID from, const NodeID to)
{ return flow[from].find(to) != flow[from].end(); };
// perform a relaxation step in the BFS algorithm
const auto relax_node = [&](const NodeID node_id) {
const auto relax_node = [&](const NodeID node_id)
{
// don't relax sink nodes
if (sink_nodes.count(node_id))
return;
@@ -180,9 +180,11 @@ std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow,
std::size_t flow_increase = 0;
// augment the flow along a path in the level graph
const auto augment_flow = [&flow](const std::vector<NodeID> &path) {
const auto augment_flow = [&flow](const std::vector<NodeID> &path)
{
// add/remove flow edges from the current residual graph
const auto augment_one = [&flow](const NodeID from, const NodeID to) {
const auto augment_one = [&flow](const NodeID from, const NodeID to)
{
// check if there is flow in the opposite direction
auto existing_edge = flow[to].find(from);
if (existing_edge != flow[to].end())
@@ -200,7 +202,8 @@ std::size_t DinicMaxFlow::BlockingFlow(FlowEdges &flow,
[[maybe_unused]] auto _ = std::adjacent_find(path.begin(), path.end(), augment_one);
};
const auto augment_all_paths = [&](const NodeID sink_node_id) {
const auto augment_all_paths = [&](const NodeID sink_node_id)
{
// only augment sinks
if (levels[sink_node_id] == INVALID_LEVEL)
return;
@@ -295,10 +298,10 @@ bool DinicMaxFlow::Validate(const BisectionGraphView &view,
const SourceSinkNodes &sink_nodes) const
{
// sink and source cannot share a common node
const auto separated =
std::find_if(source_nodes.begin(), source_nodes.end(), [&sink_nodes](const auto node) {
return sink_nodes.count(node);
}) == source_nodes.end();
const auto separated = std::find_if(source_nodes.begin(),
source_nodes.end(),
[&sink_nodes](const auto node)
{ return sink_nodes.count(node); }) == source_nodes.end();
const auto invalid_id = [&view](const NodeID nid) { return nid >= view.NumberOfNodes(); };
const auto in_range_source =
+41 -31
View File
@@ -53,21 +53,25 @@ makeSpatialOrder(const BisectionGraphView &view, const double ratio, const doubl
// adress of the very first node
const auto node_zero = &(*view.Begin());
std::transform(view.Begin(), view.End(), std::back_inserter(embedding), [&](const auto &node) {
const auto node_id = static_cast<NodeID>(&node - node_zero);
return NodeWithCoordinate{node_id, node.coordinate};
});
std::transform(view.Begin(),
view.End(),
std::back_inserter(embedding),
[&](const auto &node)
{
const auto node_id = static_cast<NodeID>(&node - node_zero);
return NodeWithCoordinate{node_id, node.coordinate};
});
const auto project = [slope](const auto &each) {
const auto project = [slope](const auto &each)
{
auto lon = static_cast<std::int32_t>(each.coordinate.lon);
auto lat = static_cast<std::int32_t>(each.coordinate.lat);
return slope * lon + (1. - std::fabs(slope)) * lat;
};
const auto spatially = [&](const auto &lhs, const auto &rhs) {
return project(lhs) < project(rhs);
};
const auto spatially = [&](const auto &lhs, const auto &rhs)
{ return project(lhs) < project(rhs); };
const std::size_t n = ratio * embedding.size();
@@ -96,7 +100,8 @@ DinicMaxFlow::MinCut bestMinCut(const BisectionGraphView &view,
DinicMaxFlow::MinCut best;
best.num_edges = -1;
const auto get_balance = [&view, balance](const auto num_nodes_source) {
const auto get_balance = [&view, balance](const auto num_nodes_source)
{
const auto perfect_balance = view.NumberOfNodes() / 2;
const auto allowed_balance = balance * perfect_balance;
const auto bigger_side =
@@ -114,36 +119,41 @@ DinicMaxFlow::MinCut bestMinCut(const BisectionGraphView &view,
tbb::blocked_range<std::size_t> range{0, n, 1};
const auto balance_delta = [&view](const auto num_nodes_source) {
const auto balance_delta = [&view](const auto num_nodes_source)
{
const std::int64_t difference =
static_cast<std::int64_t>(view.NumberOfNodes()) / 2 - num_nodes_source;
return std::abs(difference);
};
tbb::parallel_for(range, [&](const auto &chunk) {
for (auto round = chunk.begin(), end = chunk.end(); round != end; ++round)
{
const auto slope = -1. + round * (2. / n);
tbb::parallel_for(range,
[&](const auto &chunk)
{
for (auto round = chunk.begin(), end = chunk.end(); round != end; ++round)
{
const auto slope = -1. + round * (2. / n);
auto order = makeSpatialOrder(view, ratio, slope);
auto cut = DinicMaxFlow()(view, order.sources, order.sinks);
auto cut_balance = get_balance(cut.num_nodes_source);
auto order = makeSpatialOrder(view, ratio, slope);
auto cut = DinicMaxFlow()(view, order.sources, order.sinks);
auto cut_balance = get_balance(cut.num_nodes_source);
{
std::lock_guard<std::mutex> guard{lock};
{
std::lock_guard<std::mutex> guard{lock};
// Swap to keep the destruction of the old object outside of critical section.
if (cut.num_edges * cut_balance < best.num_edges * best_balance ||
(cut.num_edges == best.num_edges &&
balance_delta(cut.num_nodes_source) < balance_delta(best.num_nodes_source)))
{
best_balance = cut_balance;
std::swap(best, cut);
}
}
// cut gets destroyed here
}
});
// Swap to keep the destruction of the old object outside of
// critical section.
if (cut.num_edges * cut_balance < best.num_edges * best_balance ||
(cut.num_edges == best.num_edges &&
balance_delta(cut.num_nodes_source) <
balance_delta(best.num_nodes_source)))
{
best_balance = cut_balance;
std::swap(best, cut);
}
}
// cut gets destroyed here
}
});
return best;
}
+31 -23
View File
@@ -58,40 +58,48 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_,
std::vector<TreeNode> forest;
forest.reserve(last - first);
std::transform(first, last, std::back_inserter(forest), [this](auto graph) {
return TreeNode{std::move(graph), internal_state.SCCDepth()};
});
std::transform(first,
last,
std::back_inserter(forest),
[this](auto graph) {
return TreeNode{std::move(graph), internal_state.SCCDepth()};
});
using Feeder = tbb::feeder<TreeNode>;
TIMER_START(bisection);
// Bisect graph into two parts. Get partition point and recurse left and right in parallel.
tbb::parallel_for_each(begin(forest), end(forest), [&](const TreeNode &node, Feeder &feeder) {
const auto cut =
computeInertialFlowCut(node.graph, num_optimizing_cuts, balance, boundary_factor);
const auto center = internal_state.ApplyBisection(
node.graph.Begin(), node.graph.End(), node.depth, cut.flags);
tbb::parallel_for_each(
begin(forest),
end(forest),
[&](const TreeNode &node, Feeder &feeder)
{
const auto cut =
computeInertialFlowCut(node.graph, num_optimizing_cuts, balance, boundary_factor);
const auto center = internal_state.ApplyBisection(
node.graph.Begin(), node.graph.End(), node.depth, cut.flags);
const auto terminal = [&](const auto &node) {
const auto maximum_depth = sizeof(BisectionID) * CHAR_BIT;
const auto too_small = node.graph.NumberOfNodes() < maximum_cell_size;
const auto too_deep = node.depth >= maximum_depth;
return too_small || too_deep;
};
const auto terminal = [&](const auto &node)
{
const auto maximum_depth = sizeof(BisectionID) * CHAR_BIT;
const auto too_small = node.graph.NumberOfNodes() < maximum_cell_size;
const auto too_deep = node.depth >= maximum_depth;
return too_small || too_deep;
};
BisectionGraphView left_graph{bisection_graph, node.graph.Begin(), center};
TreeNode left_node{std::move(left_graph), node.depth + 1};
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(left_node);
if (!terminal(left_node))
feeder.add(left_node);
BisectionGraphView right_graph{bisection_graph, center, node.graph.End()};
TreeNode right_node{std::move(right_graph), node.depth + 1};
BisectionGraphView right_graph{bisection_graph, center, node.graph.End()};
TreeNode right_node{std::move(right_graph), node.depth + 1};
if (!terminal(right_node))
feeder.add(right_node);
});
if (!terminal(right_node))
feeder.add(right_node);
});
TIMER_STOP(bisection);
+43 -31
View File
@@ -45,9 +45,8 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin,
}
// Keep items with `0` as partition id to the left, move other to the right
auto by_flag_bit = [this, flag](const auto &node) {
return BisectionID{0} == (bisection_ids[node.original_id] & flag);
};
auto by_flag_bit = [this, flag](const auto &node)
{ return BisectionID{0} == (bisection_ids[node.original_id] & flag); };
auto begin = bisection_graph.Begin() + std::distance(bisection_graph.CBegin(), const_begin);
const auto end = begin + std::distance(const_begin, const_end);
@@ -59,26 +58,34 @@ RecursiveBisectionState::ApplyBisection(const NodeIterator const_begin,
std::transform(const_begin,
const_end,
mapping.begin(),
[by_flag_bit, &lesser_id, &upper_id](const auto &node) {
return by_flag_bit(node) ? lesser_id++ : upper_id++;
});
[by_flag_bit, &lesser_id, &upper_id](const auto &node)
{ return by_flag_bit(node) ? lesser_id++ : upper_id++; });
// erase all edges that point into different partitions
std::for_each(begin, end, [&](auto &node) {
const auto node_flag = by_flag_bit(node);
bisection_graph.RemoveEdges(node, [&](const BisectionGraph::EdgeT &edge) {
const auto target_flag = by_flag_bit(*(const_begin + edge.target));
return (node_flag != target_flag);
});
});
std::for_each(begin,
end,
[&](auto &node)
{
const auto node_flag = by_flag_bit(node);
bisection_graph.RemoveEdges(node,
[&](const BisectionGraph::EdgeT &edge)
{
const auto target_flag =
by_flag_bit(*(const_begin + edge.target));
return (node_flag != target_flag);
});
});
auto center = std::stable_partition(begin, end, by_flag_bit);
// remap all remaining edges
std::for_each(const_begin, const_end, [&](const auto &node) {
for (auto &edge : bisection_graph.Edges(node))
edge.target = mapping[edge.target];
});
std::for_each(const_begin,
const_end,
[&](const auto &node)
{
for (auto &edge : bisection_graph.Edges(node))
edge.target = mapping[edge.target];
});
return const_begin + std::distance(begin, center);
}
@@ -93,13 +100,13 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s
scc_algo.Run();
// Map Edges to Sccs
const auto in_small = [&scc_algo, small_component_size](const NodeID node_id) {
return scc_algo.GetComponentSize(scc_algo.GetComponentID(node_id)) <= small_component_size;
};
const auto in_small = [&scc_algo, small_component_size](const NodeID node_id)
{ return scc_algo.GetComponentSize(scc_algo.GetComponentID(node_id)) <= small_component_size; };
const constexpr std::size_t small_component_id = -1;
std::unordered_map<std::size_t, std::size_t> component_map;
const auto transform_id = [&](const NodeID node_id) -> std::size_t {
const auto transform_id = [&](const NodeID node_id) -> std::size_t
{
if (in_small(node_id))
return small_component_id;
else
@@ -111,16 +118,19 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s
mapping[node.original_id] = component_map[transform_id(node.original_id)]++;
// needs to remove edges, if we should ever switch to directed graphs here
std::stable_sort(
bisection_graph.Begin(), bisection_graph.End(), [&](const auto &lhs, const auto &rhs) {
return transform_id(lhs.original_id) < transform_id(rhs.original_id);
});
std::stable_sort(bisection_graph.Begin(),
bisection_graph.End(),
[&](const auto &lhs, const auto &rhs)
{ return transform_id(lhs.original_id) < transform_id(rhs.original_id); });
// remap all remaining edges
std::for_each(bisection_graph.Begin(), bisection_graph.End(), [&](const auto &node) {
for (auto &edge : bisection_graph.Edges(node))
edge.target = mapping[edge.target];
});
std::for_each(bisection_graph.Begin(),
bisection_graph.End(),
[&](const auto &node)
{
for (auto &edge : bisection_graph.Edges(node))
edge.target = mapping[edge.target];
});
std::vector<BisectionGraphView> views;
auto last = bisection_graph.CBegin();
@@ -139,7 +149,8 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s
}
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)
if (scc_algo.GetComponentSize(i) <= small_component_size)
return true;
@@ -154,7 +165,8 @@ RecursiveBisectionState::PrePartitionWithSCC(const std::size_t small_component_s
// ceil(log_2(components))
scc_levels = ceil(log(views.size()) / log(2.0));
const auto conscutive_component_id = [&](const NodeID nid) {
const auto conscutive_component_id = [&](const NodeID nid)
{
const auto component_id = transform_id(nid);
const auto itr = ordered_component_ids.find(component_id);
BOOST_ASSERT(itr != ordered_component_ids.end());
+8 -8
View File
@@ -46,10 +46,10 @@ std::vector<std::uint32_t> makePermutation(const DynamicEdgeBasedGraph &graph,
// Nodes in the same cell will be sorted by cell ID on the level below
for (const auto &partition : partitions)
{
std::stable_sort(
ordering.begin(), ordering.end(), [&partition](const auto lhs, const auto rhs) {
return partition[lhs] < partition[rhs];
});
std::stable_sort(ordering.begin(),
ordering.end(),
[&partition](const auto lhs, const auto rhs)
{ return partition[lhs] < partition[rhs]; });
}
// Now sort the nodes by the level at which they are a border node, descening.
@@ -57,10 +57,10 @@ std::vector<std::uint32_t> makePermutation(const DynamicEdgeBasedGraph &graph,
// whereas nodes that are nerver border nodes are sorted to the end of the array.
// Note: Since we use a stable sort that preserves the cell sorting within each level
auto border_level = getHighestBorderLevel(graph, partitions);
std::stable_sort(
ordering.begin(), ordering.end(), [&border_level](const auto lhs, const auto rhs) {
return border_level[lhs] > border_level[rhs];
});
std::stable_sort(ordering.begin(),
ordering.end(),
[&border_level](const auto lhs, const auto rhs)
{ return border_level[lhs] > border_level[rhs]; });
return util::orderingToPermutation(ordering);
}