Ejemplo n.º 1
0
//------------------------------------------------------------------------------
void NiceGraph::getPageRank(map<int,float> &pageRank, int iterations, float damping)
{
	int total = getNumVertices();

	// set initial page ranks
	for (map<int,Vertex*>::iterator vIter = vertexList.begin(); vIter != vertexList.end(); vIter++)
	{
		pageRank[vIter->first] = 1.0/(float)total;
	}

	// run arbitrary number of iterations
	for (int i = 0; i < iterations; i++)
	{
		for (map<int,Vertex*>::iterator vIter = vertexList.begin(); vIter != vertexList.end(); vIter++)
		{	
			float votes = 0;
			int id = vIter->first;
			
			vector<int> inList = getInNeighborList(id);

			for (vector<int>::iterator nIter = inList.begin(); nIter != inList.end(); nIter++)
			{
				votes+=pageRank[(*nIter)]/(float)getOutDegree(*nIter);
			}

			pageRank[id] = (1.0-damping) + damping * votes;
		}
	}
}
Ejemplo n.º 2
0
long Network::getOutDegree(const std::string& vertex_name) const  {
	return getOutDegree(getVertexId(vertex_name));
}
Ejemplo n.º 3
0
long Network::getDegree(vertex_id vid) const  {
	long tmp_degree = getInDegree(vid);
	if (isDirected()) tmp_degree += getOutDegree(vid);
	return tmp_degree;
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------------
int NiceGraph::getDegree (int vertexID) 
{
	return getInDegree(vertexID) + getOutDegree(vertexID);
}