Skip to content

Commit

Permalink
Fixed nodes printing, Issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
levnikmyskin committed Oct 23, 2021
1 parent 016153e commit 2fd41b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
26 changes: 21 additions & 5 deletions enumerable/clique.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ class CliqueEnumeration
using node_t = typename Graph::node_t;
using NodeCallback = typename Enumerable<CliqueEnumerationNode<node_t>,
Clique<node_t>>::NodeCallback;
explicit CliqueEnumeration(Graph* graph)
:graph_(

explicit CliqueEnumeration(Graph* graph) : graph_() {
#ifndef DEGENERACY
graph->Clone()
graph_ = graph->Clone();
#else
graph->Permute(DegeneracyOrder(*graph))
auto degen = DegeneracyOrder(*graph);
inverse_perm = degen;
for (int i = 0; i < degen.size(); i++) {
inverse_perm[i] = degen[i];
}
graph_ = graph->Permute(degen);
#endif
){}
}

void SetUp() override {
candidates_bitset_.resize(graph_->size());
Expand Down Expand Up @@ -112,7 +117,15 @@ class CliqueEnumeration

Clique<node_t> NodeToItem(
const CliqueEnumerationNode<node_t>& node) override {
#ifdef DEGENERACY
Clique<node_t> inv_permuted(node.first.size());
for (int i = 0; i < node.first.size(); i++) {
inv_permuted[i] = inverse_perm[node.first[i]];
}
return inv_permuted;
#else
return node.first;
#endif
}

private:
Expand Down Expand Up @@ -179,6 +192,9 @@ class CliqueEnumeration
static thread_local std::vector<bool> bad_bitset_;
static thread_local std::vector<node_t> bad_;
std::unique_ptr<Graph> graph_;
#ifdef DEGENERACY
std::vector<node_t> inverse_perm;
#endif
};

template <typename Graph>
Expand Down
54 changes: 34 additions & 20 deletions enumerable/diam2kplex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,18 +489,20 @@ class Diam2KplexEnumeration
using NodeCallback =
typename Enumerable<Diam2KplexNode<Graph>,
Kplex<typename Graph::node_t>>::NodeCallback;

explicit Diam2KplexEnumeration(Graph* graph, size_t k, size_t q,
bool enable_pivoting)
: graph_(
#ifndef DEGENERACY
graph->Clone()
: graph_(), k_(k), q_(q), enable_pivoting_(enable_pivoting) {
#ifdef DEGENERACY
auto degen = DegeneracyOrder(*graph);
inverse_perm = degen;
for (int i = 0; i < degen.size(); i++) {
inverse_perm[i] = degen[i];
}
graph_ = graph->Permute(degen);
#else
graph->Permute(DegeneracyOrder(*graph))
graph_ = graph->Clone();
#endif
),
k_(k),
q_(q),
enable_pivoting_(enable_pivoting) {
}

void SetUp() override {}
Expand All @@ -510,7 +512,16 @@ class Diam2KplexEnumeration
size_t MaxRoots() override { return graph_->size(); }

Kplex<node_t> NodeToItem(const Diam2KplexNode<Graph>& node) override {
#ifdef DEGENERACY
auto kp = ((const Diam2KplexEnumeration*)this)->NodeToItem(node);
Kplex<node_t> inv_permuted(kp.size());
for (int i = 0; i < kp.size(); i++) {
inv_permuted[i] = inverse_perm[kp[i]];
}
return inv_permuted;
#else
return ((const Diam2KplexEnumeration*)this)->NodeToItem(node);
#endif
}

Kplex<node_t> NodeToItem(const Diam2KplexNode<Graph>& node) const {
Expand All @@ -537,25 +548,25 @@ class Diam2KplexEnumeration
subgraph_added[v] = true;
node.AddToSubgraph(v);
std::vector<node_t> sg;
for (node_t n: graph_->fwd_neighs(v)) {
for (node_t n : graph_->fwd_neighs(v)) {
sg.push_back(n);
subgraph_added[n] = true;
}
auto filter_sg = [&](const std::vector<node_t>& sg) {
std::vector<node_t> filtered;
for (size_t i=0; i<sg.size(); i++) {
size_t count = 0;
for (size_t j=0; j<sg.size(); j++) {
if (graph_->are_neighs(sg[i], sg[j]))count++;
}
if (count +2*k_>= q_) filtered.push_back(sg[i]);
std::vector<node_t> filtered;
for (size_t i = 0; i < sg.size(); i++) {
size_t count = 0;
for (size_t j = 0; j < sg.size(); j++) {
if (graph_->are_neighs(sg[i], sg[j])) count++;
}
return filtered;
if (count + 2 * k_ >= q_) filtered.push_back(sg[i]);
}
return filtered;
};
size_t sz;
do {
sz = sg.size();
sg = filter_sg(sg);
sz = sg.size();
sg = filter_sg(sg);
} while (sg.size() != sz);
for (node_t n : sg) {
node.AddToSubgraph(n);
Expand All @@ -580,7 +591,7 @@ class Diam2KplexEnumeration
subgraph_candidates.clear();
}
for (node_t n : node.Subgraph()) subgraph_added[n] = false;
for (node_t n: graph_->fwd_neighs(v)) subgraph_added[n] = false;
for (node_t n : graph_->fwd_neighs(v)) subgraph_added[n] = false;
node.Init(graph_.get(), k_);
cb(node);
}
Expand All @@ -597,6 +608,9 @@ class Diam2KplexEnumeration
const size_t k_;
const size_t q_;
const bool enable_pivoting_;
#ifdef DEGENERACY
std::vector<node_t> inverse_perm;
#endif
};

extern template class Diam2KplexEnumeration<fast_graph_t<uint32_t, void>>;
Expand Down

0 comments on commit 2fd41b7

Please sign in to comment.