#ifndef NK_SCD_H #define NK_SCD_H #include "rust/cxx.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace NetworKit { using namespace std; inline unique_ptr NewApproximatePageRank(const Graph &g, double alpha, double epsilon = 1e-12) { return make_unique(g, alpha, epsilon); } inline void ApproximatePageRankRun(ApproximatePageRank &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline unique_ptr NewCliqueDetect(const Graph &g) { return make_unique(g); } inline void CliqueDetectRun(CliqueDetect &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void CliqueDetectExpandOneCommunity(CliqueDetect &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr CliqueDetectAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewCombinedSCD(const Graph &g, SelectiveCommunityDetector &first, SelectiveCommunityDetector &second) { return make_unique(g, first, second); } inline void CombinedSCDRun(CombinedSCD &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void CombinedSCDExpandOneCommunity(CombinedSCD &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr CombinedSCDAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewGCE(const Graph &g, rust::Str Q) { string q(Q); return make_unique(g, q); } inline void GCERun(GCE &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void GCEExpandOneCommunity(GCE &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr GCEAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewLFMLocal(const Graph &g, double alpha = 1.0) { return make_unique(g, alpha); } inline void LFMLocalRun(LFMLocal &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void LFMLocalExpandOneCommunity(LFMLocal &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr LFMLocalAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewLocalT(const Graph &g) { return make_unique(g); } inline void LocalTRun(LocalT &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void LocalTExpandOneCommunity(LocalT &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr LocalTAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewLocalTightnessExpansion(const Graph &g, double alpha = 1.0) { return make_unique(g, alpha); } inline void LocalTightnessExpansionRun(LocalTightnessExpansion &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void LocalTightnessExpansionExpandOneCommunity(LocalTightnessExpansion &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr LocalTightnessExpansionAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewPageRankNibble(const Graph &g, double alpha, double epsilon) { return make_unique(g, alpha, epsilon); } inline void PageRankNibbleRun(PageRankNibble &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void PageRankNibbleExpandOneCommunity(PageRankNibble &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr PageRankNibbleAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewRandomBFS(const Graph &g, const Cover &c) { return make_unique(g, c); } inline void RandomBFSRun(RandomBFS &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void RandomBFSExpandOneCommunity(RandomBFS &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr RandomBFSAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewSCDGroundTruthComparison(const Graph &g, const Cover &groundTruth, rust::Slice ks, rust::Slice vs, bool ignoreSeeds = false) { map> found; for (size_t i = 0; i < ks.length(); ++i) { auto k = ks[i]; auto v = vs[i]; if (found.find(k) == found.end()) { set s; s.insert(v); found[k] = s; } else { found[k].insert(v); } } return make_unique(g, groundTruth, found, ignoreSeeds); } inline void SCDGroundTruthComparisonGetIndividualJaccard(const SCDGroundTruthComparison &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getIndividualJaccard()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void SCDGroundTruthComparisonGetIndividualPrecision(const SCDGroundTruthComparison &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getIndividualPrecision()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void SCDGroundTruthComparisonGetIndividualRecall(const SCDGroundTruthComparison &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getIndividualRecall()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline void SCDGroundTruthComparisonGetIndividualF1(const SCDGroundTruthComparison &algo, rust::Vec &ks, rust::Vec &vs) { for (auto &&pair : algo.getIndividualF1()) { ks.push_back(pair.first); vs.push_back(pair.second); } } inline unique_ptr NewSetConductance(const Graph &g, rust::Slice community) { set c(community.begin(), community.end()); return make_unique(g, c); } inline unique_ptr NewTCE(const Graph &g, bool refine, bool useJaccard) { return make_unique(g, refine, useJaccard); } inline void TCERun(TCE &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void TCEExpandOneCommunity(TCE &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr TCEAsBase(unique_ptr algo) { return algo; } inline unique_ptr NewTwoPhaseL(const Graph &g) { return make_unique(g); } inline void TwoPhaseLRun(TwoPhaseL &algo, rust::Slice nodes, rust::Vec &ks, rust::Vec &vs) { set s(nodes.begin(), nodes.end()); for (auto &&pair : algo.run(s)) { for (auto &&val : pair.second) { ks.push_back(pair.first); vs.push_back(val); } } } inline void TwoPhaseLExpandOneCommunity(TwoPhaseL &algo, rust::Slice seeds, rust::Vec &rs) { set s(seeds.begin(), seeds.end()); for (auto &&v : algo.expandOneCommunity(s)) { rs.push_back(v); } } inline unique_ptr TwoPhaseLAsBase(unique_ptr algo) { return algo; } } #endif // NK_SCD_H