1 /* This program prints the entire automorphism group of an n-vertex
2    polygon, where n is a number supplied by the user.
3 */
4 
5 #include "nauty.h"    /* which includes <stdio.h> */
6 #include "naugroup.h"
7 
8 /**************************************************************************/
9 
10 void
writeautom(int * p,int n)11 writeautom(int *p, int n)
12 /* Called by allgroup.  Just writes the permutation p. */
13 {
14     int i;
15 
16     for (i = 0; i < n; ++i) printf(" %2d",p[i]); printf("\n");
17 }
18 
19 /**************************************************************************/
20 
21 int
main(int argc,char * argv[])22 main(int argc, char *argv[])
23 {
24     DYNALLSTAT(graph,g,g_sz);
25     DYNALLSTAT(int,lab,lab_sz);
26     DYNALLSTAT(int,ptn,ptn_sz);
27     DYNALLSTAT(int,orbits,orbits_sz);
28     static DEFAULTOPTIONS_GRAPH(options);
29     statsblk stats;
30 
31     int n,m,v;
32     grouprec *group;
33 
34  /* The following cause nauty to call two procedures which
35         store the group information as nauty runs. */
36 
37     options.userautomproc = groupautomproc;
38     options.userlevelproc = grouplevelproc;
39 
40     while (1)
41     {
42         printf("\nenter n : ");
43         if (scanf("%d",&n) == 1 && n > 0)
44         {
45             m = SETWORDSNEEDED(n);
46             nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
47 
48             DYNALLOC2(graph,g,g_sz,m,n,"malloc");
49             DYNALLOC1(int,lab,lab_sz,n,"malloc");
50             DYNALLOC1(int,ptn,ptn_sz,n,"malloc");
51             DYNALLOC1(int,orbits,orbits_sz,n,"malloc");
52 
53             EMPTYGRAPH(g,m,n);
54             for (v = 0; v < n; ++v) ADDONEEDGE(g,v,(v+1)%n,m);
55 
56             printf("Automorphisms of C[%d]:\n",n);
57             densenauty(g,lab,ptn,orbits,&options,&stats,m,n,NULL);
58 
59          /* Get a pointer to the structure in which the group information
60             has been stored.  If you use TRUE as an argument, the
61             structure will be "cut loose" so that it won't be used
62             again the next time nauty() is called.  Otherwise, as
63             here, the same structure is used repeatedly. */
64 
65             group = groupptr(FALSE);
66 
67          /* Expand the group structure to include a full set of coset
68             representatives at every level.  This step is necessary
69             if allgroup() is to be called. */
70 
71             makecosetreps(group);
72 
73          /* Call the procedure writeautom() for every element of the group.
74             The first call is always for the identity. */
75 
76             allgroup(group,writeautom);
77         }
78         else
79             break;
80     }
81     exit(0);
82 }
83