65,211
社区成员
发帖
与我相关
我的任务
分享
void CwebBlogDlg::proExpansion2(Graph &g,int iTblNum)
{
srand(time(NULL));
typedef std::set<int>::iterator IntIter;
typedef std::pair<IntIter,bool> PairIntIterBool;
IntIter iIter;
PairIntIterBool prIIterBool;
while (boost::num_edges(g)!=0)
{
int iGraphEdgeNum=boost::num_edges(g);
bool bCanJoinInSociety=true;
int iRandNum=rand()%iGraphEdgeNum;
PtrVtxVtr vtrVtxSourceAdj(new std::vector<VertexDescriptor>);
PtrVtxVtr vtrVtxTargetAdj(new std::vector<VertexDescriptor>);
PtrVtxVtr vtrVtxIntersect(new std::vector<VertexDescriptor>);
PtrVtxVtr vtrSociety(new std::vector<VertexDescriptor>);
mt19937 gen(time(0));
EdgeDescriptor eDescriptor;
//选用随机边或者最多邻接点边
if (this->m_enumActModeSel==randomEdge)
{
eDescriptor=this->getEdgeWithRandom(g);
m_strModeRandMax="self random edge";
}
else
{
eDescriptor=this->getEdgeWithMostAdj(g);
m_strModeRandMax="most Adj Edge";
}
VertexDescriptor vtxSource=boost::source(eDescriptor,*m_gphSglEdge);
VertexDescriptor vtxTarget=boost::target(eDescriptor,*m_gphSglEdge);
vtrSociety->push_back(vtxSource);
vtrSociety->push_back(vtxTarget);
std::pair<AdjIter,AdjIter> prAdjIter;
for (prAdjIter=boost::adjacent_vertices(vtxSource,*m_gphSglEdge);prAdjIter.first!=prAdjIter.second;prAdjIter.first++)
{
vtrVtxSourceAdj->push_back(*prAdjIter.first);
}
for (prAdjIter=boost::adjacent_vertices(vtxTarget,*m_gphSglEdge);prAdjIter.first!=prAdjIter.second;prAdjIter.first++)
{
vtrVtxTargetAdj->push_back(*prAdjIter.first);
}
vtrVtxIntersect=CGlbFunc::getVectorIntersect(vtrVtxSourceAdj,vtrVtxTargetAdj);
int iIntersectSetSize=vtrVtxIntersect->size();
if (iIntersectSetSize>0)//四个三角形连接在一个四边形的四个顶点上的情况,此时有可能不产生任何社区
{
int iRandIntersectSetNum=rand()%iIntersectSetSize;
this->bJoinTheSosiety((*vtrVtxIntersect)[iRandIntersectSetNum],vtrSociety,*m_gphSglEdge);
if (vtrSociety->size()<boost::num_edges(*m_gphSglEdge))
{
bCanJoinInSociety=true;
}
else
{
bCanJoinInSociety=false;
}
while (bCanJoinInSociety==true)
{
VertexDescriptor vtxToJoin=this->getVtxToJoinSociety(vtrSociety,*m_gphSglEdge);
bCanJoinInSociety=this->bJoinTheSosiety(vtxToJoin,vtrSociety,*m_gphSglEdge);
}
for (int i=0;i<vtrSociety->size();i++)
{
boost::clear_vertex((*vtrSociety)[i],*m_gphSglEdge);
}
this->m_vtrCommunities.push_back(vtrSociety);
}
else
{
if (vtrSociety->size()>=3)
{
this->m_vtrCommunities.push_back(vtrSociety);
}
for (int i=0;i<vtrSociety->size();i++)
{
boost::remove_edge(vtxSource,vtxTarget,g);
//boost::clear_vertex(vtrSociety[i],m_gphSglEdge);//此处不能清除顶点,而只能清除边
}
}
}
this->m_dwProcTime=GetTickCount()-this->m_dwProcTime;
this->m_dwProExpansionTime=this->m_dwProExpansionTime+(GetTickCount()-dwProExpStart);
this->outputToFile(this->m_vtrCommunities,iTblNum);
}