/* Projet d'algorithmique et programmation 2013-2014 (cours de C.Matthieu et J.Stern) Alex AUVOLAT, Mendes OULAMARA Sujet : Algorithme de Bron-Kerbosch pour Maximum-Clique (cf maxclique.pdf) */ #include #include "sets.h" #include "graph.h" #include "algos.h" // Driver void usage(char *pname) { printf("\nUsage:\n\t%s [options] []\n\n", pname); printf("Available options:\n"); printf("\n -x\n\tRead input in custom format instead of DIMACS format\n"); printf("\n -a\n\tUse algorithm A\n"); printf("\n -b\n\tUse algorithm B\n"); printf("\n -c\n\tUse algorithm C\n"); printf("\n -cc\n\tUse algorithm C with coloring\n"); printf("\n -o \n\tDump graph in graphwiz .dot format\n"); printf("\n -h, --help\n\tShow this help page\n"); exit(1); } int main(int argc, char **argv) { int i; int dimacs = 1; char *filename = "-"; char *dump = NULL; int algo = 0; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-x")) { dimacs = 0; } else if (!strcmp(argv[i], "-o")) { if (++i == argc) usage(argv[0]); dump = argv[i]; } else if (!strcmp(argv[i], "-a")) { algo = 0; } else if (!strcmp(argv[i], "-b")) { algo = 1; } else if (!strcmp(argv[i], "-c")) { algo = 2; } else if (!strcmp(argv[i], "-cc")) { algo = 3; } else if (argv[i][0] == '-') { usage(argv[0]); } else { filename = argv[i]; } } FILE *f = stdin; if (strcmp(filename, "-")) { f = fopen(filename, "r"); if (f == NULL) { fprintf(stderr, "Error: could not open file %s\n", filename); return 1; } } graph g = (dimacs ? load_graph_dimacs(f) : load_graph(f)); if (g == NULL) { fprintf(stderr, "Error loading file %s\n", filename); return 1; } fclose(f); if (dump != NULL) { f = fopen(dump, "w"); if (f == NULL) { fprintf(stderr, "Error: could not open file %s for writing\n", dump); return 1; } dump_graphviz(g, f); fclose(f); } // do stuff with graph set max_clique = empty_set(g->N); if (algo == 0) { set init_s = full_set(g->N); set init_k = empty_set(g->N); max_clique_a(g, init_k, init_s, &max_clique); } else if (algo == 1) { set init_c = full_set(g->N); set init_a = full_set(g->N); set init_k = empty_set(g->N); max_clique_b(g, init_k, init_c, init_a, &max_clique); } else if (algo == 2) { set init_c = full_set(g->N); set init_a = full_set(g->N); set init_k = empty_set(g->N); max_clique_c(g, init_k, init_c, init_a, &max_clique); } else if (algo == 3) { set k = full_set(g->N); int clique_upper_bound = color_subgraph(g, k, 0); delete_set(k); printf("Upper bound on max clique size: %d\n", clique_upper_bound); set init_c = full_set(g->N); set init_a = full_set(g->N); set init_k = empty_set(g->N); max_clique_c_color(g, init_k, init_c, init_a, &max_clique, g->N); } printf("Max clique: "); dump_set(max_clique); return 0; }