1 #ifndef SRC_ALGORITHMS_T_SKIM_REVERSE_RANK_H_
2 #define SRC_ALGORITHMS_T_SKIM_REVERSE_RANK_H_
15 class TSkimReverseRankCallBacks {
17 void SetWantedNodes(
const std::unordered_map<int, bool>& nodes) {
18 wanted_nodes_ = nodes;
20 void InitTSkimReverseRankCallBacks(
int T) {
22 num_nodes_visited_ = 0;
23 wanted_nodes_.clear();
25 visited_nodes_including_self_.clear();
28 void PrepareForIteration() {
29 num_nodes_visited_ = 0;
30 visited_nodes_including_self_.clear();
34 LOG_M(DEBUG3,
"Source node id=" << source_node_id);
35 source_node_id_ = source_node_id;
39 inline void NodePopedFromHeap(
int poped_node_id,
const RankData& heap_value) {
40 if (wanted_nodes_.size() != 0 && wanted_nodes_.count(poped_node_id) == 0) {
43 LOG_M(DEBUG3,
"poped node=" << poped_node_id);
44 if (T_ >= heap_value.rank) {
45 LOG_M(DEBUG3,
"Inserted node to visited nodes");
46 visited_nodes_including_self_.push_back(poped_node_id);
52 inline bool ShouldPrune(
int visited_node_id,
const RankData& rank_data) {
53 LOG_M(DEBUG3,
" node id=" << visited_node_id <<
54 " Should prune? " << (rank_data.rank >= T_) <<
55 " current rank =" << rank_data.rank <<
56 " Distance =" << rank_data.distance <<
58 " Deg= " << graph_->GetNI(visited_node_id).GetOutDeg());
60 if (rank_data.rank > T_) {
64 if (delta_.count(visited_node_id) == 0 || delta_[visited_node_id] > rank_data.rank ) {
65 delta_[visited_node_id] = rank_data.rank;
68 if (delta_[visited_node_id] < rank_data.rank) {
75 inline bool ShouldStop() {
79 inline void RelaxedPath(
int node_id) { }
81 inline std::vector<int>& get_visited_nodes() {
82 return visited_nodes_including_self_;
85 std::unordered_map<int, bool> wanted_nodes_;
86 std::unordered_map<int, double> delta_;
89 std::vector<int> visited_nodes_including_self_;
90 int num_nodes_visited_;
113 int K_all_distance_sketch,
114 int min_influence_for_seed,
117 K_all_distance_sketch_ = K_all_distance_sketch;
118 graph_sketch_ = NULL;
119 TSkimBase<Z>::InitTSkimBase(T, min_influence_for_seed, cover, graph);
126 graph_sketch_ = graph_sketch;
131 int AddSeed(
int seed, std::unordered_map<int, int>* influence_change) {
132 LOG_M(DEBUG3,
"seed node = " << seed);
133 std::vector<int> ranking;
134 reverse_rank_call_backs_.PrepareForIteration();
135 CalculateReverseRank<Z, TSkimReverseRankCallBacks<Z> > (seed,
139 &reverse_rank_call_backs_);
140 LOG_M(DEBUG3,
"Adding seed node= " << seed <<
" Cover size=" << reverse_rank_call_backs_.get_visited_nodes().size() <<
141 " Cover size=" << this->cover_->Size());
142 return TSkimBase<Z>::UpdateCover(seed, influence_change, reverse_rank_call_backs_.get_visited_nodes());
145 const std::vector<int>& CalculateVisitedNodes(
int source_node_id) {
146 NodeIdRandomIdData source_node_details(source_node_id, graph_sketch_->GetNodeRandomId(source_node_id));
147 NodeSketch * source_sketch = graph_sketch_->GetNodeSketch(source_node_details);
148 double distance = source_sketch->GetDistanceCoverNeighborhood(this->T_);
149 typename Z::TNode source(source_node_id);
150 LOG_M(DEBUG3,
"Running from node=" << source_node_id <<
" T=" << this->T_ <<
" Distance=" << distance);
151 call_backs_.InitTSkimDijkstraCallBacksDistancePrune(distance);
152 PrunedDijkstra< Z, TSkimDijkstraCallBacksDistancePrune<Z> > (source,
153 TSkimBase<Z>::graph_,
156 return call_backs_.get_visited_nodes();
161 TSkimBase<Z>::PreRunInit();
163 this->graph_->Transpose(&graph_transpose_);
164 if (graph_sketch_ == NULL) {
165 graph_sketch_ = &local_graph_sketch;
166 graph_sketch_->
InitGraphSketch(K_all_distance_sketch_, this->graph_->GetMxNId());
167 CalculateGraphSketch<Z>(&graph_transpose_, graph_sketch_);
169 reverse_rank_call_backs_.InitTSkimReverseRankCallBacks(this->T_);
170 reverse_rank_call_backs_.SetWantedNodes(this->wanted_nodes_);
171 call_backs_.SetWantedNodes(this->rankees_nodes_);
172 return TSkimBase<Z>::Run(
false);
176 int K_all_distance_sketch_;
179 TSkimReverseRankCallBacks<Z> reverse_rank_call_backs_;
180 DijkstraParams param_;
181 TSkimDijkstraCallBacksDistancePrune<Z> call_backs_;
186 #endif // SRC_ALGORITHMS_T_SKIM_REVERSE_RANK_H_
void InitGraphSketch(unsigned int K, int max_node_id, const std::vector< int > *nodes_id=NULL)
Init the class.
Definition: graph_sketch.h:28
Single node sketch.
Definition: node_sketch.h:204
Infuelnce maximization based on reverse ranks.
Definition: t_skim_reverse_rank.h:100
void set_graph_sketch(GraphSketch *graph_sketch)
Sets the graph sketch and prevents the algorithm from performing the calculation Calculating the grap...
Definition: t_skim_reverse_rank.h:125
Contains all TSkim influence maximization algorithms.
void InitTSkim(int T, int K_all_distance_sketch, int min_influence_for_seed, Cover *cover, graph::Graph< Z > *graph)
Initialize the class.
Definition: t_skim_reverse_rank.h:112
Data structure for the graph sketch.
Definition: graph_sketch.h:17
Cover extracted by the influence maximization algorithms.
Definition: t_skim.h:34