bool add_graph_to_level(graph_info *new_graph, level *my_level) { unsigned i = new_graph->m - my_level->min_m; if(priority_queue_num_elems(my_level->queues[i]) >= my_level->p && graph_compare_gt(new_graph, priority_queue_peek(my_level->queues[i]))) return false; if(!new_graph->gcan) { int m = (new_graph->n + WORDSIZE - 1) / WORDSIZE; DEFAULTOPTIONS_GRAPH(options); statsblk stats; setword workspace[m * 50]; int lab[new_graph->n], ptn[new_graph->n], orbits[new_graph->n]; new_graph->gcan = malloc(new_graph->n * m * sizeof(setword)); options.getcanon = true; nauty(new_graph->nauty_graph, lab, ptn, NULL, orbits, &options, &stats, workspace, 50 * m, m, new_graph->n, new_graph->gcan); } if(!hash_set_add(my_level->sets[i], new_graph)) { //this graph already exists return false; } _add_graph_to_level(new_graph, my_level); return true; }
static void* runit(void * threadarg) /* Main routine for one thread */ { DYNALLSTAT(graph,g,g_sz); DYNALLSTAT(int,lab,lab_sz); DYNALLSTAT(int,ptn,ptn_sz); DYNALLSTAT(int,orbits,orbits_sz); DEFAULTOPTIONS_GRAPH(options); statsblk stats; set *gv; int n,m,v; n = ((params*)threadarg)->n; /* Default options are set by the DEFAULTOPTIONS_GRAPH macro above. Here we change those options that we want to be different from the defaults. writeautoms=TRUE causes automorphisms to be written. */ options.writeautoms = ((params*)threadarg)->writeautoms; m = SETWORDSNEEDED(n); /* The following optional call verifies that we are linking to compatible versions of the nauty routines. */ nauty_check(WORDSIZE,m,n,NAUTYVERSIONID); DYNALLOC2(graph,g,g_sz,m,n,"malloc"); DYNALLOC1(int,lab,lab_sz,n,"malloc"); DYNALLOC1(int,ptn,ptn_sz,n,"malloc"); DYNALLOC1(int,orbits,orbits_sz,n,"malloc"); /* Now we will make a polygon of n vertices */ EMPTYGRAPH(g,m,n); for (v = 0; v < n; ++v) ADDONEEDGE(g,v,(v+1)%n,m); if (options.writeautoms) printf("Generators for Aut(C[%d]):\n",n); densenauty(g,lab,ptn,orbits,&options,&stats,m,n,NULL); if (options.writeautoms) { printf("order = "); writegroupsize(stdout,stats.grpsize1,stats.grpsize2); printf("\n"); } if (stats.numorbits != 1 || stats.grpsize1 != 2*n) fprintf(stderr,">E group error\n"); /* If we are using multiple threads, we need to free all the dynamic memory we have allocated. We don't have to do this after each call to nauty, just once before the thread finishes. */ DYNFREE(g,g_sz); DYNFREE(lab,lab_sz); DYNFREE(ptn,ptn_sz); DYNFREE(orbits,orbits_sz); nauty_freedyn(); nautil_freedyn(); naugraph_freedyn(); /* Use nausparse_freedyn() instead if sparse format is being used. */ return NULL; }