Ejemplo n.º 1
0
void pageRank(myset<WebPage*>& pages, int steps, char* configFile) {
	
	for (set<WebPage*>::iterator it = pages.begin(); it != pages.end(); ++it) {
		(*it)->setPR(1.0/pages.size());
	}
	//pageRankHelper(pages, steps);
}
Ejemplo n.º 2
0
void search() {
    if(!vis[v[0]][v[1]][v[2]][v[3]]) {
        vis[v[0]][v[1]][v[2]][v[3]] = true;
        maxans = max(maxans, ans);
        if(s.size() == 5)
            return;
        for(int i = 0; i < 4; ++i) {
            if(v[i] < n) {
                if(!s.find(bd[v[i]][i])) {
                    s.insert(bd[v[i]][i]);
                }
                else {
                    s.erase(bd[v[i]][i]);
                    ++ans;
                }
                ++v[i];
                search();
                --v[i];
                if(!s.find(bd[v[i]][i])) {
                    s.insert(bd[v[i]][i]);
                    --ans;
                }
                else {
                    s.erase(bd[v[i]][i]);
                }
            }
        }
    }
}
Ejemplo n.º 3
0
void pageRankHelper(myset<WebPage*>& pages, int steps) {
	// for each step
	for (int i=0; i<steps; i++) {
		cout << "STEP " << i+1 << endl;
		// create temp map to store PR for current step
		map<string,double> temp;
		for (set<WebPage*>::iterator it = pages.begin(); it != pages.end(); ++it) {
			double sum = 0;
			set<WebPage*> in = (*it)->incoming_links();
			for (set<WebPage*>::iterator it2 = in.begin(); it2 != in.end(); ++it2) {
				sum += (*it2)->PR()/((*it2)->outgoing_links().size() + 1); // all nodes have a self loop
			}
			// add itself as an incoming AND outgoing link 
			sum += (*it)->PR()/((*it)->outgoing_links().size() + 1);
			temp.insert(pair<string,double>((*it)->filename(), sum));
			//cout << "  insert:" << (*it)->filename() << " " << sum << endl;
		}

		// update PR for each page
		double total = 0;
		for (set<WebPage*>::iterator it = pages.begin(); it != pages.end(); ++it) {
			if (temp.find((*it)->filename()) == temp.end()) cout << "CANNOT FIND" << endl;
			
			// update its PR value ----------------------------------make e a variable in config -------
			double e = 0.15;
			double pr = (1-e)*temp.find((*it)->filename())->second + e/pages.size();
			(*it)->setPR(pr);
			cout << "  " << (*it)->filename() << " " << pr << endl;
			total += pr;
		}
		cout << "  " << total << endl;
	}
}