Skip to content

Commit

Permalink
Fix Bugs in pagerank & idd implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakeerthan committed Dec 24, 2023
1 parent 1a0ebc8 commit 19fc795
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
5 changes: 1 addition & 4 deletions src/localstore/JasmineGraphHashMapLocalStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ map<long, long> JasmineGraphHashMapLocalStore::getInDegreeDistributionHashMap()
long previousValue = distMapItr->second;
distMapItr->second = previousValue + 1;
} else {
std::map<long, unordered_set<long>>::iterator graphItr = localSubGraphMap.find(*itr);
if (graphItr != localSubGraphMap.end()) {
distributionHashMap.insert(std::make_pair(*itr, 1));
}
distributionHashMap.insert(std::make_pair(*itr, 1));
}
}
}
Expand Down
70 changes: 43 additions & 27 deletions src/server/JasmineGraphInstanceService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,8 @@ map<long, long> calculateInDegreeDist(string graphID, string partitionID, int se
if (degreeDistributionLocalItr != degreeDistribution.end()) {
long degreeDistributionValue = degreeDistributionLocalItr->second;
degreeDistribution[degreeDistributionLocalItr->first] = degreeDistributionValue + its->second;
} else {
degreeDistribution.insert(std::make_pair(its->first, its->second));
}
}

Expand Down Expand Up @@ -1689,28 +1691,35 @@ map<long, double> calculateLocalPageRank(string graphID, double alpha, string pa
// calculating local pagerank
map<long, double> rankMap;

map<long, long> inDegreeDistribution;
std::map<long, long> inDegreeDistribution;

std::string aggregatorFilePath = Utils::getJasmineGraphProperty("org.jasminegraph.server.instance.datafolder");
std::string iddFilePath = aggregatorFilePath + "/" + graphID + "_idd_" + partitionID;
ifstream dataFile;
dataFile.open(iddFilePath);

while (!dataFile.eof()) {
std::string str;
std::getline(dataFile, str);
std::stringstream buffer(str);
std::string temp;
std::vector<long> values;

while (getline(buffer, temp, '\t')) {
values.push_back(::strtod(temp.c_str(), nullptr));
}
if (values.size() == 2) {
long nodeID = values[0];
long iddValue = values[1];
inDegreeDistribution.insert(std::make_pair(nodeID, iddValue));

for (int partitionID = 0; partitionID <= 1; ++partitionID) {
std::string iddFilePath = aggregatorFilePath + "/" + graphID + "_idd_" + std::to_string(partitionID);
std::ifstream dataFile;
dataFile.open(iddFilePath);

while (!dataFile.eof()) {
std::string str;
std::getline(dataFile, str);
std::stringstream buffer(str);
std::string temp;
std::vector<long> values;

while (getline(buffer, temp, '\t')) {
values.push_back(::strtod(temp.c_str(), nullptr));
}

if (values.size() == 2) {
long nodeID = values[0];
long iddValue = values[1];

inDegreeDistribution[nodeID] = std::max(inDegreeDistribution[nodeID], iddValue);
}
}

dataFile.close();
}

for (localGraphMapIterator = localGraphMap.begin(); localGraphMapIterator != localGraphMap.end();
Expand Down Expand Up @@ -1767,15 +1776,9 @@ map<long, double> calculateLocalPageRank(string graphID, double alpha, string pa
if (top_k_page_rank_value == -1) {
instance_logger.log("PageRank is not implemented", "info");
} else {
std::string resultTree = "";
for (map<long, double>::iterator rankMapItr = rankMap.begin(); rankMapItr != rankMap.end(); ++rankMapItr) {
rankMapResults.insert(std::make_pair(rankMapItr->second, rankMapItr->first));
}

int count = 0;
for (map<double, long>::iterator rankMapItr = rankMapResults.end(); rankMapItr != rankMapResults.begin();
--rankMapItr) {
finalPageRankResults.insert(std::make_pair(rankMapItr->second, rankMapItr->first));
for (map<long, double>::iterator rankMapItr = rankMap.begin(); rankMapItr != rankMap.end(); ++rankMapItr) {
finalPageRankResults.insert(std::make_pair(rankMapItr->first, rankMapItr->second));
count++;
}
}
Expand Down Expand Up @@ -2965,6 +2968,19 @@ static void page_rank_command(int connFd, int serverPort,
double value = pageRankValue->second;
pageRankLocalstore.insert(std::make_pair(startVid, value));
}

for (auto a = endVidSet.begin(); a != endVidSet.end(); ++a) {
long endVid = *a;
map<long, double>::iterator pageRankValue = pageRankResults.find(endVid);
if (pageRankLocalstore.find(endVid) == pageRankLocalstore.end()) {
if (pageRankValue == pageRankResults.end()) {
pageRankLocalstore.insert(std::make_pair(endVid, 0.0));
} else {
double value = pageRankValue->second;
pageRankLocalstore.insert(std::make_pair(endVid, value));
}
}
}
}

string instanceDataFolderLocation = Utils::getJasmineGraphProperty("org.jasminegraph.server.instance.datafolder");
Expand Down

0 comments on commit 19fc795

Please sign in to comment.