1 /* This program prints generators for the automorphism group of an
2    n-vertex polygon, where n is a number supplied by the user.
3 
4    This version uses a fixed limit for MAXN.
5 */
6 
7 #define MAXN 1000    /* Define this before including nauty.h */
8 #include "nauty.h"   /* which includes <stdio.h> and other system files */
9 
10 int
main(int argc,char * argv[])11 main(int argc, char *argv[])
12 {
13     graph g[MAXN*MAXM];
14     int lab[MAXN],ptn[MAXN],orbits[MAXN];
15     static DEFAULTOPTIONS_GRAPH(options);
16     statsblk stats;
17 
18     int n,m,v;
19 
20  /* Default options are set by the DEFAULTOPTIONS_GRAPH macro above.
21     Here we change those options that we want to be different from the
22     defaults.  writeautoms=TRUE causes automorphisms to be written.     */
23 
24     options.writeautoms = TRUE;
25 
26     while (1)
27     {
28         printf("\nenter n : ");
29         if (scanf("%d",&n) != 1 || n <= 0)    /* Exit if EOF or bad number */
30             break;
31 
32         if (n > MAXN)
33         {
34             printf("n must be in the range 1..%d\n",MAXN);
35             exit(1);
36         }
37 
38      /* The nauty parameter m is a value such that an array of
39         m setwords is sufficient to hold n bits.  The type setword
40         is defined in nauty.h.  The number of bits in a setword is
41         WORDSIZE, which is 16, 32 or 64.  Here we calculate
42         m = ceiling(n/WORDSIZE).                                  */
43 
44         m = SETWORDSNEEDED(n);
45 
46      /* The following optional call verifies that we are linking
47         to compatible versions of the nauty routines.            */
48 
49         nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
50 
51      /* Now we create the cycle.  First we zero the graph, than for
52         each v, we add the edge (v,v+1), where values are mod n. */
53 
54         EMPTYGRAPH(g,m,n);
55         for (v = 0; v < n; ++v)  ADDONEEDGE(g,v,(v+1)%n,m);
56 
57         printf("Generators for Aut(C[%d]):\n",n);
58 
59      /* Since we are not requiring a canonical labelling, the last
60         parameter to densenauty() is not required and can be NULL. */
61 
62         densenauty(g,lab,ptn,orbits,&options,&stats,m,n,NULL);
63 
64      /* The size of the group is returned in stats.grpsize1 and
65         stats.grpsize2. */
66 
67         printf("Automorphism group size = ");
68         writegroupsize(stdout,stats.grpsize1,stats.grpsize2);
69         printf("\n");
70     }
71 
72     exit(0);
73 }
74