↰ Return to documentation for file (include/networkit/centrality/TopCloseness.hpp
)
/*
* TopCloseness.hpp
*
* Created on: 03.10.2014
* Author: ebergamini, michele borassi
*/
#ifndef NETWORKIT_CENTRALITY_TOP_CLOSENESS_HPP_
#define NETWORKIT_CENTRALITY_TOP_CLOSENESS_HPP_
#include <memory>
#include <networkit/base/Algorithm.hpp>
#include <networkit/components/StronglyConnectedComponents.hpp>
#include <networkit/graph/Graph.hpp>
namespace NetworKit {
class TopCloseness final : public Algorithm {
public:
TopCloseness(const Graph &G, count k = 1, bool first_heu = true, bool sec_heu = true);
void run() override;
std::vector<node> topkNodesList(bool includeTrail = false);
std::vector<edgeweight> topkScoresList(bool includeTrail = false);
void restrictTopKComputationToNodes(const std::vector<node> &nodeList) {
nodeListPtr = &nodeList;
};
private:
const Graph &G;
count n;
count k;
bool first_heu, sec_heu;
std::vector<node> topk;
const std::vector<node> *nodeListPtr;
count visEdges;
count n_op;
count trail;
double maxFarness = -1.0;
count nMaxFarness;
std::vector<std::vector<count>> nodesPerLevs, sumLevels;
std::vector<edgeweight> topkScores;
std::vector<double> farness;
std::shared_ptr<std::vector<count>> reachLPtr, reachUPtr;
std::unique_ptr<StronglyConnectedComponents> sccsPtr;
void init();
double BFScut(node v, double x, std::vector<bool> &visited, std::vector<count> &distances,
std::vector<node> &pred, count &visEdges);
void computelBound1(std::vector<double> &S);
void BFSbound(node x, std::vector<double> &S, count &visEdges,
const std::vector<bool> &toAnalyze);
void computeReachable();
};
inline std::vector<node> TopCloseness::topkNodesList(bool includeTrail) {
assureFinished();
if (!includeTrail) {
auto begin = topk.begin();
std::vector<node> topkNoTrail(begin, begin + k);
return topkNoTrail;
}
return topk;
}
inline std::vector<edgeweight> TopCloseness::topkScoresList(bool includeTrail) {
assureFinished();
if (!includeTrail) {
auto begin = topkScores.begin();
std::vector<double> topkScoresNoTrail(begin, begin + k);
return topkScoresNoTrail;
}
return topkScores;
}
} /* namespace NetworKit */
#endif // NETWORKIT_CENTRALITY_TOP_CLOSENESS_HPP_