Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. int findCoherentGraphs(Graph* g,int *max_size,int* errorFlag){ /* TODO: Speed up */
  2.  
  3. int i=0,number_of_cc=0;
  4. GraphNode* currentGNode = (GraphNode*) NULL;
  5. ResultSet* result_set = (ResultSet*) NULL;
  6. List listOfResultSets;
  7. Pair* currentResult = (Pair*) NULL;
  8.  
  9. *max_size=0;
  10.  
  11. if(g != NULL){
  12. if(g->hashtable.hashmap != NULL){ //H findCoherentGraphs krataei mia lista apo resultSets. Kathe resultSet einai enas upografos me th morfh (ID,apostash) gia kathe kombo tou.
  13. createList(&listOfResultSets, "ResultSetPtr", &allocateResultSetPtr, &destroyResultSetPtr, &compareResultSetPtr, &assignResultSetPtr, &printResultSetPtr);
  14. while ( (currentGNode = pickExcludedNode(listOfResultSets, g, errorFlag) ) != NULL){ //Edw epilegei kombo tou arxikou grafou p dn uparxei mexri stigmhs s kapoio upografo
  15. if(*errorFlag == EXIT_VALUE){ //Wste na ksekinisei kainourgia anazhthsh me reachNodeN gia neo upografo
  16. printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
  17. return EXIT_VALUE;
  18. }
  19.  
  20. if(result_set == NULL){
  21. printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
  22. *errorFlag = EXIT_VALUE;
  23. }
  24. /* New coherent subgraph located! Let's explore it */
  25.  
  26. result_set = reachNodeN(currentGNode->id, g, errorFlag); /* Prepare a 1 to N search starting with new node */ //Neo reachNodeN == Neos upografos
  27. if(*errorFlag == EXIT_VALUE){
  28. printf("findCoherentGraphs: reachNodeN failed! - Exiting!\n");
  29. *errorFlag = EXIT_VALUE;
  30. return EXIT_VALUE;
  31. }
  32. if(addLastList(&listOfResultSets, result_set) == EXIT_VALUE){ /* Add the set of results of this search to a list to keep all the results */
  33. printf("findCoherentGraphs: addLastList failed! - Exiting!\n");
  34. *errorFlag = EXIT_VALUE;
  35. return EXIT_VALUE;
  36. }
  37.  
  38. //Se antistoixeia me to neo reachNodeN esu prepei na dhmiourgeis me createGraph edw pera enan proswrino neo Grafo
  39. //tou stul tempGraph = createGraph();
  40.  
  41. number_of_cc++; /* A new coherent subgraph was located */ //Auto metraei ton arithmo twn upografwn p exoun anakalufthei - Dld ton arithmo twn reachNodeN p eginan
  42.  
  43. while( next(result_set, currentResult, errorFlag) ) continue; /* Explore the latest set as much as possible and create a coherent subgraph by doing so */
  44. //Proxwraei oso borei to to resultSet k anakaluptei ton grafo
  45.  
  46. //Prepei na tropopoihseis to loop apo panw p anakaluptei kainourgia Pairs k na pairneis to currentResult. Na eksageis to ID apo to currentResult.
  47. //Afou to eksageis tha kaneis tempGraphNode = lookUpNode(IdPair,g) gia na fereis ton graphnode apo ton arxiko grafo
  48. //Afou ton fereis prepei na ton kaneis insertNode sto tempGraph p ftiaksame pio panw
  49. //Otan teleiwsei to loop twn while next tote tha prepei na kaneis addLastList(listOfSubGraphs,tempGraph) gia na baleis ton neo upografo sth Lista me tous deiktes s Grafous
  50. //P eipame na ftiaksoume gia uberlist
  51. //Prosekse mia leptomereia: Edw tha kaneis createGraph p kanei malloc mesa kainourgio Graph, tha kaneis insert alla dn tha kaneis destroy. Gia na min exoume polla antigrafa
  52. //kathe grafou. Ousiastika tha kaneis tempGraph = createGraph, tha ton gemizeis k meta tha kaneis addLastList k h uberlist me deiktes s grafous dn tha ftianxei dikia tis
  53. //copia me malloc stin allocateGraphPtr gt tote tha prepei na antigrapsoume apo tin arxh oti exei o grafos! Akolouthise tin logikh tou GraphNodePtr gia to GraphPtr s uberlist
  54.  
  55. if(*errorFlag == EXIT_VALUE){
  56. printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
  57. return EXIT_VALUE;
  58. }
  59.  
  60. if(result_set->set.num_records > *max_size)
  61. *max_size = result_set->set.num_records; /* A subgraph with more nodes has been located! */
  62.  
  63. }
  64.  
  65. if(*errorFlag == EXIT_VALUE){
  66. printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
  67. return EXIT_VALUE;
  68. }
  69.  
  70.  
  71. /* Free all resources allocated by findCoherentGraphs */
  72.  
  73. listOfResultSets.Current = listOfResultSets.Head;
  74. while(listOfResultSets.Current != NULL){
  75. destroyResultSet( (ResultSet**) &(listOfResultSets.Current->data));
  76. listOfResultSets.Current = listOfResultSets.Current->next;
  77. }
  78.  
  79. destroyList(&listOfResultSets);
  80.  
  81. return number_of_cc;
  82.  
  83. }
  84. else{
  85. printf("findCoherentGraphs: HashMap is NULL! - Exiting!\n");
  86. *errorFlag = EXIT_VALUE;
  87. return EXIT_VALUE;
  88. }
  89. }
  90. else{
  91. printf("findCoherentGraphs: Graph Pointer is NULL! - Exiting!\n");
  92. *errorFlag = EXIT_VALUE;
  93. return EXIT_VALUE;
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement