testgraphmlwriter.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #include "testgraphmlwriter.h"
  2. //#include "graphmlgenerator.h"
  3. TestGraphmlWriter::TestGraphmlWriter()
  4. {
  5. }
  6. void TestGraphmlWriter::test(int iExtraVertices)
  7. {
  8. //select file
  9. m_sFileName = "boostGraph.graphml";
  10. QFile file(m_sFileName);
  11. if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
  12. cout<<"File could not be open. Exiting.";
  13. return;
  14. }
  15. //provide boost graph
  16. cout << "Generating graph.." << endl;
  17. generateMainGraph2(iExtraVertices);
  18. int iTotalNodes = num_vertices(m_gMainGraph);
  19. int iTotalEdges = num_edges(m_gMainGraph);
  20. cout<< "Graph,\nTotal Nodes: " << iTotalNodes <<
  21. " Total Edges: " << iTotalEdges << endl;
  22. QTime t;
  23. t.currentTime();
  24. t.start();
  25. //write graphml
  26. //GraphMLGenerator graphmlGenerator;
  27. //graphmlGenerator.writeGraphml(m_gMainGraph, &file);
  28. cout<<"Graphml generation time duration: "<<t.elapsed() <<" ms."<<endl;
  29. }
  30. void TestGraphmlWriter::generateMainGraph1()
  31. {
  32. Graph& subGraph1 = m_gMainGraph.create_subgraph();
  33. Graph& subGraph2 = subGraph1.create_subgraph();
  34. Graph::vertex_descriptor v0 = add_vertex(m_gMainGraph);
  35. Graph::vertex_descriptor v1 = add_vertex(m_gMainGraph);
  36. Graph::vertex_descriptor v2 = add_vertex(m_gMainGraph);
  37. Graph::vertex_descriptor v3 = add_vertex(m_gMainGraph);
  38. Graph::vertex_descriptor v4 = add_vertex(m_gMainGraph);
  39. Graph::vertex_descriptor v5 = add_vertex(m_gMainGraph);
  40. Graph::vertex_descriptor v6 = add_vertex(m_gMainGraph);
  41. Graph::vertex_descriptor v7 = add_vertex(m_gMainGraph);
  42. m_gMainGraph[v0].sId = "S_1";
  43. m_gMainGraph[v1].sId = "S_2";
  44. m_gMainGraph[v2].sId = "S_3";
  45. m_gMainGraph[v3].sId = "S_4";
  46. m_gMainGraph[v4].sId = "S_5";
  47. m_gMainGraph[v5].sId = "S_6";
  48. m_gMainGraph[v6].sId = "S_7";
  49. m_gMainGraph[v7].sId = "S_8";
  50. Graph::vertex_descriptor v8 = add_vertex(subGraph1);
  51. Graph::vertex_descriptor v9 = add_vertex(subGraph1);
  52. Graph::vertex_descriptor v10 = add_vertex(subGraph1);
  53. Graph::vertex_descriptor v11 = add_vertex(subGraph1);
  54. Graph::vertex_descriptor v12 = add_vertex(subGraph1);
  55. Graph::vertex_descriptor v13 = add_vertex(subGraph1);
  56. subGraph1[v8].sId = "S_9";
  57. subGraph1[v9].sId = "S_10";
  58. subGraph1[v10].sId = "S_11";
  59. subGraph1[v11].sId = "S_12";
  60. subGraph1[v12].sId = "S_13";
  61. subGraph1[v13].sId = "S_14";
  62. // add edge returns pair< edge_descriptor , bool >
  63. auto e0 = add_edge(v0,v1,m_gMainGraph);
  64. auto e1 = add_edge(v0,v2,m_gMainGraph);
  65. auto e2 = add_edge(v1,v3,m_gMainGraph);
  66. auto e3 = add_edge(v1,v4,m_gMainGraph);
  67. auto e4 = add_edge(v3,v5,m_gMainGraph);
  68. auto e5 = add_edge(v3,v6,m_gMainGraph);
  69. auto e6 = add_edge(v4,v7,m_gMainGraph);
  70. auto e7 = add_edge(v2,subGraph1.local_to_global(v8),m_gMainGraph); //intergraph edge
  71. m_gMainGraph[e0.first].sId = "E_1";
  72. m_gMainGraph[e1.first].sId = "E_2";
  73. m_gMainGraph[e2.first].sId = "E_3";
  74. m_gMainGraph[e3.first].sId = "E_4";
  75. m_gMainGraph[e4.first].sId = "E_5";
  76. m_gMainGraph[e5.first].sId = "E_6";
  77. m_gMainGraph[e6.first].sId = "E_7";
  78. m_gMainGraph[e7.first].sId = "E_8";
  79. auto e8 = add_edge(v8,v9,subGraph1);
  80. auto e9 = add_edge(v8,v10,subGraph1);
  81. auto e10 = add_edge(v9,v11,subGraph1);
  82. auto e11 = add_edge(v9,v12,subGraph1);
  83. auto e12 = add_edge(v10,v13,subGraph1);
  84. subGraph1[e8.first].sId = "E_9";
  85. subGraph1[e9.first].sId = "E_10";
  86. subGraph1[e10.first].sId = "E_11";
  87. subGraph1[e11.first].sId = "E_12";
  88. subGraph1[e12.first].sId = "E_13";
  89. Graph::vertex_descriptor v14 = add_vertex(subGraph2);
  90. Graph::vertex_descriptor v15 = add_vertex(subGraph2);
  91. Graph::vertex_descriptor v16 = add_vertex(subGraph2);
  92. subGraph2[v14].sId = "S_15";
  93. subGraph2[v15].sId = "S_16";
  94. subGraph2[v16].sId = "S_17";
  95. auto e13 = add_edge(v0, subGraph2.local_to_global(v15), m_gMainGraph);
  96. m_gMainGraph[e13.first].sId ="E14 intergraph";
  97. auto e14 = add_edge(subGraph1.local_to_global(v11),
  98. subGraph2.local_to_global(v15),
  99. m_gMainGraph);
  100. m_gMainGraph[e14.first].sId = "E_15 intergraph global edge";
  101. }
  102. void TestGraphmlWriter::generateMainGraph2(int iGenerateExtraVertice)
  103. {
  104. const int generateVertexIdFrom = 100;
  105. Graph& G1 = m_gMainGraph.create_subgraph();
  106. Graph& G2 = m_gMainGraph.create_subgraph();
  107. Graph& G4 = G2.create_subgraph();
  108. Graph& G3 = m_gMainGraph.create_subgraph();
  109. Graph::vertex_descriptor n3 = add_vertex(G1);
  110. Graph::vertex_descriptor n4 = add_vertex(G1);
  111. Graph::vertex_descriptor n5 = add_vertex(G1);
  112. G1[n3].sId = "n3";
  113. G1[n4].sId = "n4";
  114. G1[n5].sId = "n5";
  115. int iMaxVertexCount = iGenerateExtraVertice;
  116. iMaxVertexCount /=5; // Because we have 5 graphs in subgraph tree,
  117. //and in each iteration we insert one vertex to every graph
  118. //Adding extra vertices and edges to the graph
  119. iMaxVertexCount += generateVertexIdFrom;
  120. int iVertexId;
  121. string sVertexIdMaingraph, sVertexIdG1, sVertexIdG2, sVertexIdG3, sVertexIdG4 ;
  122. for(int vertexCounter = generateVertexIdFrom ; vertexCounter < iMaxVertexCount ; vertexCounter++)
  123. {
  124. Graph::vertex_descriptor vMainGraph = add_vertex(m_gMainGraph);
  125. iVertexId = vertexCounter;
  126. sVertexIdMaingraph = lexical_cast<string>(iVertexId);
  127. m_gMainGraph[vMainGraph].sId = "n" + sVertexIdMaingraph;
  128. Graph::vertex_descriptor vG1= add_vertex(G1);
  129. iVertexId = vertexCounter + iMaxVertexCount;
  130. sVertexIdG1 = lexical_cast<string>(iVertexId);
  131. G1[vG1].sId = "n"+ sVertexIdG1;
  132. Graph::vertex_descriptor vG2 = add_vertex(G2);
  133. iVertexId = vertexCounter + iMaxVertexCount * 2;
  134. sVertexIdG2 = lexical_cast<string>(iVertexId);
  135. G2[vG2].sId = "n" + sVertexIdG2;
  136. Graph::vertex_descriptor vG3 = add_vertex(G3);
  137. iVertexId = vertexCounter + iMaxVertexCount * 3;
  138. sVertexIdG3 = lexical_cast<string>(iVertexId);
  139. G3[vG3].sId = "n" + sVertexIdG3;
  140. Graph::vertex_descriptor vG4 = add_vertex(G4);
  141. iVertexId = vertexCounter + iMaxVertexCount * 4;
  142. sVertexIdG4 = lexical_cast<string>(iVertexId);
  143. G4[vG4].sId = "n" + sVertexIdG4;
  144. auto eMainGraphG1 = add_edge(vMainGraph , G1.local_to_global(vG1), m_gMainGraph);
  145. m_gMainGraph[eMainGraphG1.first].sId = "e" + sVertexIdMaingraph;
  146. m_gMainGraph[eMainGraphG1.first].bBidirectional = true;
  147. auto eMainGraphG2 = add_edge(vMainGraph , G2.local_to_global(vG2), m_gMainGraph);
  148. m_gMainGraph[eMainGraphG2.first].sId = "e" + sVertexIdG1;
  149. auto eG2G3 = add_edge(G2.local_to_global(vG2), G3.local_to_global(vG3), m_gMainGraph);
  150. m_gMainGraph[eG2G3.first].sId = "e" + sVertexIdG2;
  151. auto eG2G4 = add_edge(G2.local_to_global(vG2), G4.local_to_global(vG4), m_gMainGraph);
  152. m_gMainGraph[eG2G4.first].sId = "e" + sVertexIdG3;
  153. }
  154. auto e0 = add_edge(n3, n4, G1);
  155. auto e1 = add_edge(n4, n5, G1);
  156. G1[e0.first].sId = "e0";
  157. G1[e1.first].sId = "e1";
  158. Graph::vertex_descriptor n6 = add_vertex(G2);
  159. Graph::vertex_descriptor n7 = add_vertex(G2);
  160. G2[n6].sId = "n6";
  161. G2[n7].sId = "n7";
  162. Graph::vertex_descriptor n12 = add_vertex(G4);
  163. Graph::vertex_descriptor n13 = add_vertex(G4);
  164. G4[n12].sId = "n12";
  165. G4[n13].sId = "n13";
  166. auto e3 = add_edge(n12, n13, G4);
  167. G4[e3.first].sId = "e3";
  168. Graph::vertex_descriptor n9 = add_vertex(G3);
  169. Graph::vertex_descriptor n10 = add_vertex(G3);
  170. G3[n9].sId = "n9";
  171. G3[n10].sId = "n10";
  172. auto e4 = add_edge(G1.local_to_global(n3),G2.local_to_global(n6),m_gMainGraph);
  173. auto e5 = add_edge(G1.local_to_global(n4),G2.local_to_global(n7),m_gMainGraph);
  174. auto e6 = add_edge(G1.local_to_global(n5),G3.local_to_global(n10),m_gMainGraph);
  175. m_gMainGraph[e4.first].sId = "e4";
  176. m_gMainGraph[e5.first].sId = "e5";
  177. m_gMainGraph[e6.first].sId = "e6";
  178. }