Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findTrends(int k, Graph *g, Graph *tagg, char **womenTrends, char **menTrends) {
- Graph *subGraph;
- tagHolder *holder=NULL, tempHolder;
- int errorFlag=0, num, i=0, op=0, *trends, size=0, commonInterests=0, gender=0, start=0, graphSize=0;
- int spot=0, j=0, *t=NULL, tagId=0, counter=0, lastPos=0, menFlag=0, womenFlag=0;
- char result[64];
- // ----------- Create list of sub-coherent graphs ------------
- List listOfSubGraphs;
- createList(&listOfSubGraphs, "GraphPtr", &allocateGraphPtr, &destroyGraphPtr, &compareGraphPtr, &assignGraphPtr, &printGraphPtr);
- findAllCoherentGraphs(g, &listOfSubGraphs, &errorFlag);
- if(errorFlag == EXIT_VALUE){
- printf("findAllCoherentSubGraphs: failed!\n");
- }
- // --------------- Initialise tag data holder ----------------
- holder = malloc(listOfSubGraphs.items * sizeof(tagHolder));
- for (i=0 ; i<listOfSubGraphs.items ; i++) {
- holder[i].gender = -1;
- holder[i].tags = NULL;
- holder[i].size = -1;
- }
- // ------ for each subgraph check its common interests -------
- listOfSubGraphs.Current = listOfSubGraphs.Head;
- for (i=0 ; i<listOfSubGraphs.items ; i++) {
- // initialise trends data
- trends = malloc(5 * sizeof(int)); assert(trends != NULL);
- trends[0] = 5; // holds trends array size
- trends[1] = 2; // holds first available spot
- for (j=2 ; j<5 ; j++)
- trends[j] = -1;
- subGraph = (Graph*) listOfSubGraphs.Current->data;
- // receive tags of subgraph
- commonInterests = graphTrends(subGraph, trends, &start, &errorFlag);
- if (! commonInterests) { // array needs to be realloced
- size = trends[0];
- trends = (int*) realloc(trends, (size+1) * sizeof(int)); // increase the size of array by one
- graphTrends(subGraph, trends, &start, &errorFlag); // call again function to continue search
- }
- // receive gender of subgraph
- gender = checkGender(subGraph, &errorFlag); // receive gender of this coherent subgraph
- if (gender == 0) // report that the group is of one gender only
- if (commonInterests != -1) // but only if this group has a common interest
- printf("Mixed genders problem\n");
- // receive size of subgraph
- graphSize = getNumberOfGraphNodes(subGraph, &errorFlag);
- /*printf("gender: %d\n", gender);
- printf("Gender %d with size %d has these interests\n", gender, graphSize);
- for (op=0 ; op<trends[0] ; op++)
- printf("%d-", trends[op]); printf("\n");
- printf("Size: %d\n", graphSize);*/
- // insert tag data to appropriate place
- tempHolder.gender = gender;
- tempHolder.tags = trends;
- tempHolder.size = graphSize;
- insertHolder(holder, tempHolder, listOfSubGraphs.items);
- listOfSubGraphs.Current = listOfSubGraphs.Current->next;
- if (trends != NULL) free(trends);
- }
- counter = 0;
- lastPos = 0;
- // men first ( ! savoir vivre )
- for (j=0 ; j<listOfSubGraphs.items ; j++) {
- if (holder[j].gender != 1) continue;
- t = holder[j].tags;
- for (i=2 ; i<t[0] ; i++) {
- tagId = t[i];
- whatTagIsThis(tagId, tagg, result, &errorFlag);
- assert (result != NULL); // NULL means that no tag with such id exists
- if (tagId == -1)
- strcpy(menTrends[lastPos], "n/a");
- else
- strcpy(menTrends[lastPos], result);
- lastPos ++;
- counter ++;
- if (counter >= k) break;
- }
- if (counter >= k) break;
- }
- printf("\nΤOP MEN TRENDS\n---------------\n");
- for (i=0 ; i<k ; i++)
- printf("\t%s\n", menTrends[i]); printf("\n");
- // women now
- counter = 0;
- lastPos = 0;
- for (j=0 ; j<listOfSubGraphs.items ; j++) {
- if (holder[j].gender != 2) continue;
- t = holder[j].tags;
- for (i=2 ; i<t[0] ; i++) {
- tagId = t[i];
- whatTagIsThis(tagId, tagg, result, &errorFlag);
- assert (result != NULL); // NULL means that no tag with such id exists
- if (tagId == -1)
- strcpy(womenTrends[lastPos], "n/a");
- else
- strcpy(womenTrends[lastPos], result);
- lastPos ++;
- counter ++;
- if (counter >= k) break;
- }
- if (counter >= k) break;
- }
- printf("\nΤOP WOMEN TRENDS\n---------------\n");
- for (i=0 ; i<k ; i++)
- printf("\t%s\n", womenTrends[i]); printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement