void basicHopcroft(int N, int d, int runForever) { srandom(time(NULL)); int *right_sides, *matching, unmatched; struct Graph *originalGraph; if (runForever) { while (true) { right_sides = createRightSides(N,d); originalGraph = createRandomRegBipartite(N,d,false,right_sides); int steps = hopcroft(originalGraph, &matching); printf("Missed %i of %i Matches\n", validateMatching(matching, originalGraph),N); printf("steps: %i\n", steps); freeGraph(originalGraph); free(right_sides); free(matching); } } else { right_sides = createRightSides(N,d); originalGraph = createRandomRegBipartite(N,d,false,right_sides); START_TIMER int steps = hopcroft(originalGraph, &matching); STOP_TIMER printf("Missed %i of %i Matches\n", validateMatching(matching, originalGraph),N); printf("%f seconds\n", seconds); freeGraph(originalGraph); free(right_sides); free(matching); } }
int main() { int a[100][100]; memset(a,0,sizeof(a)); hopcroft(); return 0; }
int hopcroftTest(int N, int d, char *file_name) { /* hopcroft_steps, hopcroft_time, quickmatchHopcroft_steps, quickmatchHopcroft_time, quickmatchHopcroft_unmatched */ FILE *file; file = fopen(file_name,"a+"); // append file (add text to a file or // create a file if it does not exist. assert(file != NULL); srandom(SEED); int hopcroft_steps=0; int quickmatchHopcroft_steps=0; float hopcroft_time=0.0; float quickmatchHopcroft_time=0.0; int i; while (true) { int *right_sides; int *matching1, *matching2; int unmatched = 0; struct Graph *graph; right_sides = createRightSides(N,d); graph = createRandomRegBipartite(N,d,1,right_sides); START_TIMER hopcroft_steps = hopcroft(graph, &matching1); STOP_TIMER hopcroft_time = seconds; resetGraph(graph); START_TIMER quickmatchHopcroft_steps = quickmatch_hopcroft(graph, &matching2); STOP_TIMER quickmatchHopcroft_time = seconds; // Validate assert(0 == validateMatching(matching1, graph)); int quickmatchHopcroft_unmatched = validateMatching(matching2, graph); printf("printing to file\n"); fprintf(file,"%i,%f,%i,%f,%i\n", hopcroft_steps, hopcroft_time, quickmatchHopcroft_steps, quickmatchHopcroft_time, quickmatchHopcroft_unmatched); // Free fflush(file); freeGraph(graph); free(right_sides); free(matching1); free(matching2); //free(visited); //free(targets); } fclose(file); }