mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
MinCutAGaT.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <tuple>
7#include <vector>
8
9
10namespace m {
11
13{
15
16 template<typename Callback>
17 void min_cut_advanced_generate_and_test(const AdjacencyMatrix &M, Callback &&callback, const Subproblem S,
18 const Subproblem C, const Subproblem X, const Subproblem T) const
19 {
20 M_insist(not S.empty());
21 M_insist(not S.is_singleton());
23 M_insist(T.is_subset(C));
24 M_insist(C.is_subset(S));
25 M_insist((C & X).empty());
26
27 using queue_entry = std::tuple<Subproblem, Subproblem, Subproblem>;
28 std::vector<queue_entry> worklist;
29 worklist.emplace_back(C, X, T);
30
31 while (not worklist.empty()) {
32 auto [C, X, T] = worklist.back();
33 worklist.pop_back();
34
35 M_insist(C.is_subset(S));
37 M_insist(T.is_subset(C));
38
39 /*----- IsConnectedImp() check. -----*/
40 const Subproblem N_T = (M.neighbors(T) & S) - C; // sufficient to check if neighbors of T are connected
41 bool is_connected;
42 if (N_T.size() <= 1) {
43 is_connected = true; // trivial
44 } else {
45 const Subproblem n = N_T.begin().as_set(); // single, random vertex from the neighborhood of T
46 const Subproblem reachable = M.reachable(n, S - C); // compute vertices reachable from n in S - C
47 is_connected = N_T.is_subset(reachable); // if reachable vertices contain N_T, then S - C is connected
48 }
49
50 Subproblem T_tmp;
51 if (is_connected) { // found ccp (C, S\C)
52 M_insist(M.is_connected(S - C));
53 M_insist(M.is_connected(C, S - C));
54 callback(C, S - C);
55 } else {
56 M_insist(not M.is_connected(S - C) or not M.is_connected(C, S - C));
57 T_tmp = C;
58 }
59
60 if (C.size() + 1 >= S.size()) continue;
61
62 Subproblem X_tmp = X;
63 const Subproblem N_C = (M.neighbors(C) & S) - X;
64 for (auto it = N_C.begin(); it != N_C.end(); ++it) {
65 const Subproblem v = it.as_set();
66 worklist.emplace_back(C | v, X_tmp, T_tmp | v);
67 X_tmp = X_tmp | v;
68 }
69 }
70 }
71
72 template<typename Callback>
73 void partition(const AdjacencyMatrix &M, Callback &&callback, const Subproblem S) const {
74 M_insist(not S.empty());
75 M_insist(not S.is_singleton());
76 const Subproblem C = S.begin().as_set();
77 M_insist(not C.empty());
79 /* Matrix= */ M,
80 /* Callback= */ std::forward<Callback>(callback),
81 /* S= */ S,
82 /* C= */ C,
83 /* X= */ Subproblem(),
84 /* T= */ C
85 );
86 }
87};
88
89}
#define M_insist(...)
Definition: macro.hpp:129
‍mutable namespace
Definition: Backend.hpp:10
T(x)
An adjacency matrix for a given query graph.
SmallBitset reachable(SmallBitset src) const
Computes the set of nodes reachable from src, i.e. the set of nodes reachable from any node in src.
bool is_connected(SmallBitset S) const
Returns true iff the subproblem S is connected.
SmallBitset neighbors(SmallBitset S) const
Computes the neighbors of S.
void min_cut_advanced_generate_and_test(const AdjacencyMatrix &M, Callback &&callback, const Subproblem S, const Subproblem C, const Subproblem X, const Subproblem T) const
Definition: MinCutAGaT.hpp:17
SmallBitset Subproblem
Definition: MinCutAGaT.hpp:14
void partition(const AdjacencyMatrix &M, Callback &&callback, const Subproblem S) const
Definition: MinCutAGaT.hpp:73
Implements a small and efficient set over integers in the range of 0 to 63 (including).
Definition: ADT.hpp:26
bool is_singleton() const
Definition: ADT.hpp:165
std::size_t size() const
Returns the number of elements in this SmallBitset.
Definition: ADT.hpp:161
bool empty() const
Returns true if there are no elements in this SmallBitset.
Definition: ADT.hpp:163
auto end() const
Definition: ADT.hpp:175
auto begin() const
Definition: ADT.hpp:173
bool is_subset(SmallBitset other) const
Returns true if the set represented by this is a subset of other, i.e. this ⊆ other.
Definition: ADT.hpp:194