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

Nodal efficiency measures #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 37 additions & 0 deletions snap-exp/efficiency.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "efficiency.hpp"
#include <vector>

namespace TSnap {

/////////////////////////////////////////////////
// Node efficiency measures
/////////////////////////////////////////////////
float getAvgEfficiency(const PUNGraph& Graph) {
float efficiency = 0.0;
float num = 1.0;
float num_nodes = Graph->GetNodes();
vector<int> node_ids;
for (typename PUNGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
node_ids.push_back(NI.GetId());
}
for (int i = 0; i < node_ids.size(); i++) {
for (int j = 0; j < node_ids.size(); j++) {
if (i != j) {
efficiency += (num / (float) GetShortPath(Graph, i, j, true));
}
}
}
float ans = num / (num_nodes * (num_nodes-1)) * efficiency;
return ans;
}

float getGlobalEfficiency(const PUNGraph& Graph) {
float E_G = getAvgEfficiency(Graph);
int num_nodes = Graph->GetNodes();
PUNGraph G_ideal = GenFull<PUNGraph>(num_nodes)
float E_G_ideal = getAvgEfficiency(G_ideal);
return E_G / E_G_ideal;
}


}; // namespace TSnap
6 changes: 6 additions & 0 deletions snap-exp/efficiency.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TSnap {

float getAvgEfficiency(const PUNGraph& Graph);
float getGlobalEfficiency(const PUNGraph& Graph);

}