void calculatePageRank(int& iterationNumber, long& totalURLs, unordered_map<long,WebURL>& webURLs,float& dampingFactor) { #ifdef _TRACE cout<<"\nIteration : "<<iterationNumber - 1<<" Dangling Factor = "<<danglingFactor<<endl; #endif double tmpDanglingFactor = 0; unordered_map<long,WebURL>::iterator it; // Iterating through each Key (Representing Page) in the Map and calculating the Page Rank of the pages associated with it. for(it = webURLs.begin(); it != webURLs.end(); it++) { WebURL *masterURL = &(it->second); list<WebURL *> listofOutboundURLs = masterURL->getOutboundWebURLs(); list<WebURL *>::iterator listite; double val; // First time call the evaluate function for the master url to change the iteration number and // calculate the pagerank of the previous iteration masterURL->evaluate(iterationNumber,dampingFactor,totalURLs); #ifdef _TRACE cout<<"src_url: "<<masterURL->getId()<<" cur_val:["<<masterURL->getOldPageRank()<<"]"<<endl; #endif if(!listofOutboundURLs.empty()) { for(listite = listofOutboundURLs.begin(); listite != listofOutboundURLs.end(); listite++) { WebURL *url = *listite; url->evaluate(iterationNumber,dampingFactor,totalURLs); val = (masterURL->getOldPageRank() / (double)(listofOutboundURLs.size())); url->setNewPageRank(val + url->getNewPageRank()); #ifdef _TRACE cout<<" ->tar_url:"<<url->getId()<<" cur_val:"<<url->getOldPageRank()<<" added_val:"<<val<<endl; #endif } } else { tmpDanglingFactor += masterURL->getOldPageRank(); } } // Saving the dangling factor to use it in the next cycle danglingFactor = tmpDanglingFactor; }
void verify(unordered_map<long,WebURL>& webURLs) { unordered_map<long,WebURL>::iterator it; cout<<"\nVERIFYING THE UNORDERED MAP :"<<endl; cout<<"The size of unordered_map = "<<webURLs.size()<<endl; for(it = webURLs.begin(); it != webURLs.end(); it++) { cout<<"Web URL = "<<it->first<<":"<<endl; WebURL myurl = it->second; cout<<"id = "<<myurl.getId()<<"\t"<<"Page Rank = "<<setprecision(15)<<myurl.getNewPageRank()<<"\tOutbound WebURL ids : "; list<WebURL *> listofurls = myurl.getOutboundWebURLs(); list<WebURL *>::iterator listite; for(listite = listofurls.begin(); listite != listofurls.end(); listite++) { WebURL *url = *listite; cout<<url->getId()<<" "; } cout<<endl<<endl; } }