Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve calculateQ efficiency #614

Merged
merged 4 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion analytical_engine/apps/pregel/louvain/louvain.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ANALYTICAL_ENGINE_APPS_PREGEL_LOUVAIN_LOUVAIN_H_

#include <map>
#include <set>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -336,11 +337,13 @@ class PregelLouvain
const grape::IteratorPair<md_t*>& messages) {
auto& state = vertex.state();
edata_t k_i_in = state.internal_weight;
std::set<vid_t> source_ids;
for (auto& m : messages) {
if (m.community_id == state.community) {
k_i_in += vertex.get_edge_value(m.source_id);
source_ids.insert(m.source_id);
}
}
k_i_in += vertex.get_edge_values(source_ids);
edata_t sigma_tot = state.community_sigma_total;
edata_t m2 = getTotalEdgeWeight(context, vertex);
edata_t k_i = state.node_weight + state.internal_weight;
Expand Down
22 changes: 22 additions & 0 deletions analytical_engine/apps/pregel/louvain/louvain_vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#define ANALYTICAL_ENGINE_APPS_PREGEL_LOUVAIN_LOUVAIN_VERTEX_H_

#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -99,6 +100,27 @@ class LouvainVertex : public PregelVertex<FRAG_T, VD_T, MD_T> {
return edata_t();
}

edata_t get_edge_values(const std::set<vid_t>& dst_ids) {
edata_t ret = 0;
if (!this->use_fake_edges()) {
for (auto& edge : this->incoming_edges()) {
if (dst_ids.find(edge.get_neighbor()) == dst_ids.end()) {
ret += edge.get_data();
}
}
for (auto& edge : this->outgoing_edges()) {
if (dst_ids.find(edge.get_neighbor()) == dst_ids.end()) {
ret += edge.get_data();
}
}
} else {
for (auto gid : dst_ids) {
ret += this->fake_edges().at(gid);
}
}
return ret;
}

void set_fake_edges(std::map<vid_t, edata_t>&& edges) {
state_t& ref_state = this->state();
ref_state.fake_edges = std::move(edges);
Expand Down