MembershipInitializer.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "MembershipInitializer.h"
  2. MembershipInitializer ::MembershipInitializer()
  3. {
  4. }
  5. void MembershipInitializer::initializeMembers(SubGraph& gMainGraphRef)
  6. {
  7. // Assigns clusterId's and VertexIds in subgraph
  8. //int iTotalClusters = 0;
  9. BoostGraphWrapper bGraphWrap;
  10. VertexIterPair viPair;
  11. QQueue<SubGraph*> qSubgraphs; //a queue of subgraphs
  12. int iClusterIDGenerator = 0;
  13. m_MapSubgraphsId.insert(999,&(gMainGraphRef)); //map of ids and subgraphs
  14. qSubgraphs.enqueue(&gMainGraphRef);
  15. SubGraph* gSubgraph1 = NULL;
  16. while(qSubgraphs.isEmpty() == false) //iterating subgraphs till they exist
  17. {
  18. gSubgraph1 = qSubgraphs.dequeue();
  19. ChildrenIterator iterChild , iterChildEnd;
  20. //for each of its child
  21. for(boost::tie(iterChild , iterChildEnd) = gSubgraph1->children(); iterChild != iterChildEnd;iterChild++)
  22. {
  23. //iTotalClusters++;
  24. //cout<<" Cluster No : "<<iTotalClusters;
  25. iClusterIDGenerator++;
  26. SubGraph* gChildGraph = &(*iterChild);
  27. qSubgraphs.enqueue(gChildGraph);
  28. //assign ClusterID to child
  29. bGraphWrap.setGraphClusterID(iClusterIDGenerator,*gChildGraph);
  30. m_MapSubgraphsId.insert(iClusterIDGenerator,gChildGraph);
  31. //for each of its vertex
  32. for(tie(viPair.first,viPair.second)=vertices(*gChildGraph); viPair.first!= viPair.second; ++viPair.first)
  33. //assign ClusterID to vertex
  34. bGraphWrap.setVertexClusterID(iClusterIDGenerator,*viPair.first,*gChildGraph);
  35. }
  36. }
  37. }
  38. QMap<int,SubGraph*> MembershipInitializer::getIdToSubgraphMap()
  39. {
  40. // returns map ids and subgraphs
  41. return m_MapSubgraphsId;
  42. }