18 static constexpr bool Is_Const = C;
21 using reference_type = std::conditional_t<Is_Const, const AdjacencyMatrix&, AdjacencyMatrix&>;
34 operator bool()
const {
return M_.m_[i_][j_]; }
36 template<
bool C_ = Is_Const>
38 Proxy &
operator=(
bool val) { M_.m_[i_][j_] = val;
return *
this; }
42 return operator=(
bool(other));
47 return operator=(
bool(other));
52 return operator=(
bool(other));
56 return operator=(
bool(other));
61 std::array<SmallBitset, SmallBitset::CAPACITY>
m_;
62 std::size_t num_vertices_ = 0;
80 if (i >= num_vertices_ or j >= num_vertices_)
82 return operator()(i, j);
86 if (i >= num_vertices_ or j >= num_vertices_)
88 return operator()(i, j);
96 auto R = R_new - R_old;
97 if (R.empty())
goto exit;
112 auto R = R_new - R_old;
113 if (R.empty())
goto exit;
127 return neighbors - S;
139 for (
auto it : right)
140 neighbors = neighbors | m_[it];
143 return not (left & neighbors).
empty();
160 source = source & super;
162 std::deque<std::pair<SmallBitset, SmallBitset>> Q;
163 for (
auto it = source.
begin(); it != source.
end(); ++it) {
168 while (not Q.empty()) {
169 auto [S, X_old] = Q.front();
174 const SmallBitset N = (neighbors(S) & super) - X_old;
177 Q.emplace_back(S | n, X_new);
185 for_each_CSG_undirected(super, super, std::move(callback));
191 auto callback_CSG = [
this, super, &callback](
SmallBitset first) {
192 auto callback_partial = [&callback, first](
SmallBitset second) {
193 callback(first, second);
195 const SmallBitset N_first = neighbors(first) & super;
197 for_each_CSG_undirected(super_second, N_first, callback_partial);
199 for_each_CSG_undirected(super, callback_CSG);
204 AdjacencyMatrix minimum_spanning_forest(std::function<
double(std::size_t, std::size_t)> weight)
const;
212 if (this->num_vertices_ != other.
num_vertices_)
return false;
213 for (std::size_t i = 0; i != num_vertices_; ++i) {
214 if (this->m_[i] != other.
m_[i])
228 std::ostringstream oss;
234 M_insist(length <= SmallBitset::CAPACITY);
235 out <<
"Adjacency Matrix";
236 for (
unsigned i = 0; i != length; ++i) {
238 m_[i].print_fixed_length(out, length);
242 void dump(std::ostream &out)
const;
SmallBitset least_subset(SmallBitset S)
Returns the least subset of a given set, i.e. the set represented by the lowest 1 bit.
SmallBitset next_subset(SmallBitset subset, SmallBitset set)
Returns the next subset of a given subset and `set.
A proxy to access single entries in the AdjacencyMatrix.
Proxy(reference_type M, std::size_t i, std::size_t j)
Proxy & operator=(const Proxy< false > &other)
Proxy & operator=(Proxy< true > &&other)
std::conditional_t< Is_Const, const AdjacencyMatrix &, AdjacencyMatrix & > reference_type
Proxy & operator=(const Proxy< true > &other)
Proxy & operator=(Proxy< false > &&other)
An adjacency matrix for a given query graph.
Proxy< false > operator()(std::size_t i, std::size_t j)
Returns the bit at position (i, j).
friend std::string to_string(const AdjacencyMatrix &M)
bool is_connected(SmallBitset left, SmallBitset right) const
Returns true iff there is at least one edge (join) between left and right.
bool operator!=(const AdjacencyMatrix &other) const
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.
void for_each_CSG_pair_undirected(SmallBitset super, std::function< void(SmallBitset, SmallBitset)> callback) const
Enumerate all pairs of connected subgraphs (CSGs) that are connected by at least one edge.
SmallBitset reachable(SmallBitset src, SmallBitset S) const
Computes the set of nodes in S reachable from src, i.e. the set of nodes in S reachable from any node...
Proxy< true > operator()(std::size_t i, std::size_t j) const
Returns the bit at position (i, j).
std::array< SmallBitset, SmallBitset::CAPACITY > m_
matrix entries
AdjacencyMatrix & operator=(AdjacencyMatrix &&)=default
M_LCOV_EXCL_START friend std::ostream & operator<<(std::ostream &out, const AdjacencyMatrix &M)
AdjacencyMatrix(std::size_t num_vertices)
std::size_t num_vertices_
number of sources of the QueryGraph represented by this matrix
bool is_connected(SmallBitset S) const
Returns true iff the subproblem S is connected.
Proxy< false > at(std::size_t i, std::size_t j)
bool operator==(const AdjacencyMatrix &other) const
Compares two AdjacencyMatrixs element-wise.
Proxy< true > at(std::size_t i, std::size_t j) const
void for_each_CSG_undirected(SmallBitset super, std::function< void(SmallBitset)> callback) const
Enumerate all connected subgraphs (CSGs) of the graph induced by vertex super set super.
AdjacencyMatrix(const AdjacencyMatrix &)=default
SmallBitset neighbors(SmallBitset S) const
Computes the neighbors of S.
AdjacencyMatrix(AdjacencyMatrix &&)=default
void print_fixed_length(std::ostream &out, unsigned length) const
void for_each_CSG_undirected(SmallBitset super, SmallBitset source, std::function< void(SmallBitset)> callback) const
Enumerate all connected subgraphs (CSGs) of the graph induced by vertex super set super,...
Implements a small and efficient set over integers in the range of 0 to 63 (including).
bool is_singleton() const
SmallBitset hi() const
Returns the highest set bit as a SmallBitset.
SmallBitset mask_to_lo() const
Returns a mask up to and including the lowest set bit.
bool empty() const
Returns true if there are no elements in this SmallBitset.
Signals that an index-based or key-based access was out of range.