本文整理汇总了C++中Graph::CommunityNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::CommunityNumber方法的具体用法?C++ Graph::CommunityNumber怎么用?C++ Graph::CommunityNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::CommunityNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RunCombo
void RunCombo(Graph& G, int max_comunities)
{
G.CalcModMtrix();
G.SetCommunities(vector<int>(G.Size(), 0));
double currentMod = G.Modularity();
//printf("Initial modularity: %6f\n", currentMod);
vector< vector<double> > moves(2, vector<double>(2, 0)); //results of splitting communities
//vectors of boolean meaning that corresponding vertex should be moved to dest
vector< vector<int> > splits_communities(2, vector<int>(G.Size(), 0)); //best split vectors
int origin, dest;
for(origin = 0; origin < G.CommunityNumber(); ++ origin)
for(dest = 0; dest < G.CommunityNumber() + (G.CommunityNumber() < max_comunities); ++dest)
reCalc(G, moves, splits_communities, origin, dest);
best_gain = BestGain(moves, origin, dest);
while(best_gain > THRESHOLD)
{
bool comunityAdded = dest >= G.CommunityNumber();
G.PerformSplit(origin, dest, splits_communities[dest]);
if(debug_verify)
{
double oldMod = currentMod;
currentMod = G.Modularity();
if(fabs(currentMod - oldMod - best_gain) > THRESHOLD)
printf("ERROR\n");
}
if(comunityAdded && dest < max_comunities - 1)
{
if(dest >= moves.size() - 1)
{
for(int i = 0; i < moves.size(); ++i)
moves[i].push_back(0);
moves.push_back(vector<double>(moves.size() + 1, 0));
splits_communities.push_back(vector<int>(G.Size(), 0));
}
for(int i = 0; i < dest; ++i)
{
moves[i][dest+1] = moves[i][dest];
splits_communities[dest+1] = splits_communities[dest];
}
}
for(int i = 0; i < G.CommunityNumber() + (G.CommunityNumber() < max_comunities); ++i)
{
reCalc(G, moves, splits_communities, origin, i);
reCalc(G, moves, splits_communities, dest, i);
if(i != dest && i < G.CommunityNumber())
reCalc(G, moves, splits_communities, i, origin);
if(i != origin && i < G.CommunityNumber())
reCalc(G, moves, splits_communities, i, dest);
}
DeleteEmptyCommunities(G, moves, splits_communities, origin); //remove origin community if empty
best_gain = BestGain(moves, origin, dest);
}
}
示例2: DeleteEmptyCommunities
void DeleteEmptyCommunities(Graph& G, vector< vector<double> >& moves, vector< vector<int> >& splits_communities, int origin)
{
if(G.DeleteCommunityIfEmpty(origin))
{
int commNumber = G.CommunityNumber();
for(int i = origin; i < commNumber; ++i)
moves[i] = moves[i+1];
moves[commNumber].assign(commNumber+2, 0);
for(int i = 0; i < moves.size(); ++i)
{
for(int j = origin; j < commNumber+1; ++j)
moves[i][j] = moves[i][j+1];
moves[i][commNumber+1] = 0;
}
for(int i = origin; i < commNumber+1; ++i)
splits_communities[i] = splits_communities[i+1];
}
}