/* [[file:nauty.note::8adb819f][8adb819f]] */ /* Adopted from nautyex6.c */ #include #include "lib/nauty.h" /* n: number of nodes nedges: number of edges lab: labels ptn: partitions */ int dwim(int n, int nedges, int *edges_i, int *edges_j, int *lab, int *ptn) { /* DYNALLSTAT declares a pointer variable (to hold an array when it is allocated) and a size variable to remember how big the array is. Nothing is allocated yet. */ DYNALLSTAT(graph, g, g_sz); DYNALLSTAT(int, orbits, orbits_sz); /* Default options for undirected graphs in dense nauty */ DEFAULTOPTIONS_GRAPH(options); statsblk stats; /* Select option for canonical labelling */ /* options.getcanon = TRUE; */ /* We want to set node colours using `lab` and `ptn` */ options.defaultptn = FALSE; if (n > 0) { /* The nauty parameter m is a value such that an array of m setwords is sufficient to hold n bits. The type setword is defined in nauty.h. The number of bits in a setword is WORDSIZE, which is 16, 32 or 64. Here we calculate m = ceiling(n/WORDSIZE). */ int 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); /* Now that we know how big the graph will be, we allocate space for the * graph and the other arrays we need. */ DYNALLOC1(int, orbits, orbits_sz, n, "malloc"); DYNALLOC2(graph, g, g_sz, n, m, "malloc"); /* start with no edges */ EMPTYGRAPH(g, m, n); /* add edges from edges_i, edges_j arrays */ for (int i = 0; i < nedges; ++i) { int e1 = edges_i[i]; int e2 = edges_j[i]; if (e1 < e2) { ADDONEEDGE(g, e1, e2, m); } else { return -2; } } /* Create canonical graphs */ densenauty(g, lab, ptn, orbits, &options, &stats, m, n, NULL); assert(stats.errstatus == 0); /* frees any allocated array */ DYNFREE(orbits, orbits_sz); DYNFREE(g, g_sz); return 0; } else { return -1; } } /* 8adb819f ends here */