Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int findCoherentGraphs(Graph* g,int *max_size,int* errorFlag){ /* TODO: Speed up */
- int i=0,number_of_cc=0;
- GraphNode* currentGNode = (GraphNode*) NULL;
- ResultSet* result_set = (ResultSet*) NULL;
- List listOfResultSets;
- Pair* currentResult = (Pair*) NULL;
- *max_size=0;
- if(g != NULL){
- 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.
- createList(&listOfResultSets, "ResultSetPtr", &allocateResultSetPtr, &destroyResultSetPtr, &compareResultSetPtr, &assignResultSetPtr, &printResultSetPtr);
- while ( (currentGNode = pickExcludedNode(listOfResultSets, g, errorFlag) ) != NULL){ //Edw epilegei kombo tou arxikou grafou p dn uparxei mexri stigmhs s kapoio upografo
- if(*errorFlag == EXIT_VALUE){ //Wste na ksekinisei kainourgia anazhthsh me reachNodeN gia neo upografo
- printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
- return EXIT_VALUE;
- }
- if(result_set == NULL){
- printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
- *errorFlag = EXIT_VALUE;
- }
- /* New coherent subgraph located! Let's explore it */
- result_set = reachNodeN(currentGNode->id, g, errorFlag); /* Prepare a 1 to N search starting with new node */ //Neo reachNodeN == Neos upografos
- if(*errorFlag == EXIT_VALUE){
- printf("findCoherentGraphs: reachNodeN failed! - Exiting!\n");
- *errorFlag = EXIT_VALUE;
- return EXIT_VALUE;
- }
- if(addLastList(&listOfResultSets, result_set) == EXIT_VALUE){ /* Add the set of results of this search to a list to keep all the results */
- printf("findCoherentGraphs: addLastList failed! - Exiting!\n");
- *errorFlag = EXIT_VALUE;
- return EXIT_VALUE;
- }
- //Se antistoixeia me to neo reachNodeN esu prepei na dhmiourgeis me createGraph edw pera enan proswrino neo Grafo
- //tou stul tempGraph = createGraph();
- 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
- while( next(result_set, currentResult, errorFlag) ) continue; /* Explore the latest set as much as possible and create a coherent subgraph by doing so */
- //Proxwraei oso borei to to resultSet k anakaluptei ton grafo
- //Prepei na tropopoihseis to loop apo panw p anakaluptei kainourgia Pairs k na pairneis to currentResult. Na eksageis to ID apo to currentResult.
- //Afou to eksageis tha kaneis tempGraphNode = lookUpNode(IdPair,g) gia na fereis ton graphnode apo ton arxiko grafo
- //Afou ton fereis prepei na ton kaneis insertNode sto tempGraph p ftiaksame pio panw
- //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
- //P eipame na ftiaksoume gia uberlist
- //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
- //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
- //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
- if(*errorFlag == EXIT_VALUE){
- printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
- return EXIT_VALUE;
- }
- if(result_set->set.num_records > *max_size)
- *max_size = result_set->set.num_records; /* A subgraph with more nodes has been located! */
- }
- if(*errorFlag == EXIT_VALUE){
- printf("findCoherentGraphs: Could not allocate ResultSet! - Exiting!\n");
- return EXIT_VALUE;
- }
- /* Free all resources allocated by findCoherentGraphs */
- listOfResultSets.Current = listOfResultSets.Head;
- while(listOfResultSets.Current != NULL){
- destroyResultSet( (ResultSet**) &(listOfResultSets.Current->data));
- listOfResultSets.Current = listOfResultSets.Current->next;
- }
- destroyList(&listOfResultSets);
- return number_of_cc;
- }
- else{
- printf("findCoherentGraphs: HashMap is NULL! - Exiting!\n");
- *errorFlag = EXIT_VALUE;
- return EXIT_VALUE;
- }
- }
- else{
- printf("findCoherentGraphs: Graph Pointer is NULL! - Exiting!\n");
- *errorFlag = EXIT_VALUE;
- return EXIT_VALUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement