1 #ifndef THIRD_PARTY_ALL_DISTANCE_SKETCH_ALL_DISTANCE_SKETCH_SKETCH_RANK_CALCULATOR_H_
2 #define THIRD_PARTY_ALL_DISTANCE_SKETCH_ALL_DISTANCE_SKETCH_SKETCH_RANK_CALCULATOR_H_
3 #include "../graph/graph.h"
9 class RankCalculatorInterface {
11 virtual ~RankCalculatorInterface() {};
12 virtual double CalculateNodeRank(
int node_id) = 0;
14 virtual double GetNodeInsertProb(
int node_id,
double threshold_prob) = 0;
18 class DegreeRankCalculator :
public RankCalculatorInterface {
20 void InitDegreeRankCalculator(
const graph::Graph<T>* graph) {
23 m_gen.reset(
new boost::random::mt19937());
24 m_dis.reset(
new boost::random::uniform_real_distribution<>(0, 1));
27 double CalculateNodeRank(
int node_id) {
28 int node_degree = m_graph->GetNI(node_id).GetDeg();
29 double degree_param = node_degree == 0 ? degree_param = 1 : (1 /
static_cast<double>(node_degree));
30 m_dis.reset(
new boost::random::uniform_real_distribution<>(0, degree_param));
31 return m_dis((*m_gen));
34 double GetNodeInsertProb(
int node_id,
double threshold_prob) {
35 int node_degree = m_graph->GetNI(node_id).GetDeg();
36 double degree_param = node_degree == 0 ? degree_param = 1 : (1 /
static_cast<double>(node_degree));
37 if (degree_param < threshold_prob) {
41 return threshold_prob / degree_param;
44 const graph::Graph<T>* m_graph;
46 std::unique_ptr<boost::random::mt19937 > m_gen;
47 std::unique_ptr<boost::random::uniform_real_distribution<> > m_dis;
50 typedef boost::minstd_rand base_generator_type;
51 class UniformRankCalculator :
public RankCalculatorInterface {
53 void InitUniformRankCalculator(
double start_range = 0,
double end_range = 1) {
54 m_generator.reset(
new base_generator_type(42u));
55 m_uni_dist.reset(
new boost::uniform_real<>(start_range, end_range));
56 m_dis.reset(
new boost::variate_generator<base_generator_type&, boost::uniform_real<> >((*m_generator), (*m_uni_dist)) );
59 double CalculateNodeRank(
int node_id) {
63 double GetNodeInsertProb(
int node_id,
double threshold_prob) {
64 return threshold_prob;
68 std::unique_ptr<base_generator_type> m_generator;
69 std::unique_ptr<boost::uniform_real<> > m_uni_dist;
70 std::unique_ptr<boost::variate_generator<base_generator_type&, boost::uniform_real<> > > m_dis;
74 #endif // THIRD_PARTY_ALL_DISTANCE_SKETCH_ALL_DISTANCE_SKETCH_SKETCH_RANK_CALCULATOR_H_