forked from lonnen/nauty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgtnauty.c
792 lines (699 loc) · 20.9 KB
/
gtnauty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/* gtnauty.c : nauty-related routines for gtools.
Jan 15, 2001 : Increased graph order limit from 2^16-1 to 2^22-1.
Aug 9, 2001 : Added fgroup_inv() and fcanonise_inv()
Sep 15, 2004 : Completed prototypes
Oct 16, 2004 : DEAFULTOPTIONS_GRAPH
Nov 17, 2005 : Added fcanonise_inv_sg()
May 11, 2010 : use sorttemplates.c
Sep 5, 2013 : Unify format processing and remove 2^22 limit
Oct 14, 2017 : Include code for n=0
**************************************************************************/
#include "gtools.h" /* which includes naututil.h, nausparse.h, stdio.h */
static booleann issymm;
static set *g0;
static int gm;
static int fuzz2[] = {006532,070236,035523,062437};
#define FUZZ2(x) ((x) ^ fuzz2[(x)&3])
int gt_numorbits;
#ifdef REFINE
void REFINE(graph*,int*,int*,int,int*,int*,set*,int*,int,int);
#endif
#define MIN_SCHREIER 33 /* If n is this large, schreier will be
turned on. */
/**************************************************************************/
#define SORT_OF_SORT 3
#define SORT_NAME sortwt
#define SORT_TYPE1 int
#define SORT_TYPE2 int
#include "sorttemplates.c"
/* Creates static void sortwt(int *lab, int *wt, int n) */
void
setlabptn(int *weight, int *lab, int *ptn, int n)
/* Define (lab,ptn) with cells in increasing order of weight. */
{
int i;
if (n == 0) return;
for (i = 0; i < n; ++i) lab[i] = i;
if (weight)
{
sortwt(lab,weight,n);
for (i = 0; i < n-1; ++i)
{
if (weight[lab[i]] != weight[lab[i+1]])
ptn[i] = 0;
else
ptn[i] = 1;
}
ptn[n-1] = 0;
}
else
{
for (i = 0; i < n-1; ++i) ptn[i] = 1;
ptn[n-1] = 0;
}
}
static int
setlabptnfmt(char *fmt, int *lab, int *ptn, set *active, int m, int n)
/* Define (lab,ptn,active) according to format string.
Return number of cells */
{
int i,nc;
#if MAXN
int wt[MAXN];
#else
DYNALLSTAT(int,wt,wt_sz);
DYNALLOC1(int,wt,wt_sz,n,"setlabptnfmt");
#endif
if (n == 0) return 0;
EMPTYSET(active,m);
ADDELEMENT(active,0);
nc = 1;
if (fmt != NULL && fmt[0] != '\0')
{
#if !MAXN
DYNALLOC1(int,wt,wt_sz,n,"fcanonise");
#endif
for (i = 0; i < n && fmt[i] != '\0'; ++i)
wt[i] = (unsigned char)fmt[i];
for ( ; i < n; ++i)
wt[i] = 'z';
setlabptn(wt,lab,ptn,n);
for (i = 0; i < n-1; ++i)
if (ptn[i] == 0)
{
++nc;
ADDELEMENT(active,i+1);
}
}
else
{
for (i = 0; i < n; ++i)
{
lab[i] = i;
ptn[i] = 1;
}
ptn[n-1] = 0;
}
return nc;
}
/**************************************************************************/
static booleann
hasloops(graph *g, int m, int n)
/* Test for loops */
{
int i;
set *gi;
for (i = 0, gi = g; i < n; ++i, gi += m)
if (ISELEMENT(gi,i)) return TRUE;
return FALSE;
}
static booleann
hasloops_sg(sparsegraph *sg)
{
size_t *v,vi,j;
int *d,*e,n,i;
n = sg->nv;
SG_VDE(sg,v,d,e);
for (i = 0; i < n; ++i)
{
vi = v[i];
for (j = vi; j < vi + d[i]; ++j)
if (e[vi] == i) return TRUE;
}
return FALSE;
}
void
fcanonise(graph *g, int m, int n, graph *h, char *fmt, booleann digraph)
/* canonise g under format fmt; result in h.
fmt is either NULL (for no vertex classification) or is a string
with char-valued colours for the vertices. If it ends early, it
is assumed to continue with the colour 'z' indefinitely. */
{
#if MAXN
int lab[MAXN],ptn[MAXN],orbits[MAXN];
int count[MAXN];
set active[MAXM];
setword workspace[24*MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,orbits,orbits_sz);
DYNALLSTAT(int,count,count_sz);
DYNALLSTAT(set,active,active_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
#endif
int i;
int numcells,code;
statsblk stats;
static DEFAULTOPTIONS_GRAPH(options);
if (n == 0) return;
#if MAXN
if (n > MAXN || m > MAXM)
{
fprintf(stderr,">E fcanonise: m or n too large\n");
ABORT(">E fcanonise");
}
#else
DYNALLOC1(int,lab,lab_sz,n,"fcanonise");
DYNALLOC1(int,ptn,ptn_sz,n,"fcanonise");
DYNALLOC1(int,orbits,orbits_sz,n,"fcanonise");
DYNALLOC1(int,count,count_sz,n,"fcanonise");
DYNALLOC1(set,active,active_sz,m,"fcanonise");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"fcanonise");
#endif
digraph = digraph || hasloops(g,m,n);
numcells = setlabptnfmt(fmt,lab,ptn,active,m,n);
if (m == 1)
refine1(g,lab,ptn,0,&numcells,count,active,&code,1,n);
else
refine(g,lab,ptn,0,&numcells,count,active,&code,m,n);
if (numcells == n || (numcells == n-1 && !digraph))
{
for (i = 0; i < n; ++i) count[i] = lab[i];
updatecan(g,h,count,0,m,n);
gt_numorbits = numcells;
}
else
{
options.getcanon = TRUE;
options.defaultptn = FALSE;
options.digraph = digraph;
#ifdef REFINE
options.userrefproc = REFINE;
#endif
if (n >= MIN_SCHREIER) options.schreier = TRUE;
EMPTYSET(active,m);
nauty(g,lab,ptn,active,orbits,&options,&stats,
workspace,24*m,m,n,h);
gt_numorbits = stats.numorbits;
}
}
/**************************************************************************/
void
fcanonise_inv(graph *g, int m, int n, graph *h, char *fmt,
void (*invarproc)(graph*,int*,int*,int,int,int,int*,int,
booleann,int,int), int mininvarlevel, int maxinvarlevel,
int invararg, booleann digraph)
/* Canonise g under format fmt; result in h.
fmt is either NULL (for no vertex classification) or is a string
with char-valued colours for the vertices. If it ends early, it
is assumed to continue with the colour 'z' indefinitely.
This is like fcanonise() except that a invariant and its arguments
can be specified. */
{
#if MAXN
int lab[MAXN],ptn[MAXN],orbits[MAXN];
int count[MAXN];
set active[MAXM];
setword workspace[24*MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,orbits,orbits_sz);
DYNALLSTAT(int,count,count_sz);
DYNALLSTAT(set,active,active_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
#endif
int i;
int numcells,code;
statsblk stats;
static DEFAULTOPTIONS_GRAPH(options);
if (n == 0) return;
#if MAXN
if (n > MAXN || m > MAXM)
{
fprintf(stderr,">E fcanonise: m or n too large\n");
ABORT(">E fcanonise");
}
#else
DYNALLOC1(int,lab,lab_sz,n,"fcanonise");
DYNALLOC1(int,ptn,ptn_sz,n,"fcanonise");
DYNALLOC1(int,orbits,orbits_sz,n,"fcanonise");
DYNALLOC1(int,count,count_sz,n,"fcanonise");
DYNALLOC1(set,active,active_sz,m,"fcanonise");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"fcanonise");
#endif
numcells = setlabptnfmt(fmt,lab,ptn,active,m,n);
digraph = digraph || hasloops(g,m,n);
if (m == 1)
refine1(g,lab,ptn,0,&numcells,count,active,&code,1,n);
else
refine(g,lab,ptn,0,&numcells,count,active,&code,m,n);
if (numcells == n || (!digraph && numcells >= n-1))
{
for (i = 0; i < n; ++i) count[i] = lab[i];
updatecan(g,h,count,0,m,n);
gt_numorbits = numcells;
}
else
{
options.getcanon = TRUE;
options.digraph = digraph;
options.defaultptn = FALSE;
if (invarproc)
{
options.invarproc = invarproc;
options.mininvarlevel = mininvarlevel;
options.maxinvarlevel = maxinvarlevel;
options.invararg = invararg;
}
#ifdef REFINE
options.userrefproc = REFINE;
#endif
if (n >= MIN_SCHREIER) options.schreier = TRUE;
EMPTYSET(active,m);
nauty(g,lab,ptn,active,orbits,&options,&stats,workspace,24*m,m,n,h);
gt_numorbits = stats.numorbits;
}
}
/**************************************************************************/
void
fcanonise_inv_sg(sparsegraph *g, int m, int n, sparsegraph *h, char *fmt,
void (*invarproc)(graph*,int*,int*,int,int,int,int*,int,
booleann,int,int), int mininvarlevel, int maxinvarlevel,
int invararg, booleann digraph)
/* canonise g under format fmt; result in h.
fmt is either NULL (for no vertex classification) or is a string
with char-valued colours for the vertices. If it ends early, it
is assumed to continue with the colour 'z' indefinitely.
This is like fcanonise() except that a invariant and its arguments
can be specified. Version for sparse graphs. */
{
#if MAXN
int lab[MAXN],ptn[MAXN],orbits[MAXN];
int count[MAXN];
set active[MAXM];
setword workspace[24*MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,orbits,orbits_sz);
DYNALLSTAT(int,count,count_sz);
DYNALLSTAT(set,active,active_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
#endif
int i;
int numcells,code;
statsblk stats;
static DEFAULTOPTIONS_SPARSEGRAPH(options);
if (n == 0)
{
h->nv = 0;
h->nde = 0;
return;
}
#if MAXN
if (n > MAXN || m > MAXM)
{
fprintf(stderr,">E fcanonise: m or n too large\n");
ABORT(">E fcanonise");
}
#else
DYNALLOC1(int,lab,lab_sz,n,"fcanonise");
DYNALLOC1(int,ptn,ptn_sz,n,"fcanonise");
DYNALLOC1(int,orbits,orbits_sz,n,"fcanonise");
DYNALLOC1(int,count,count_sz,n,"fcanonise");
DYNALLOC1(set,active,active_sz,m,"fcanonise");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"fcanonise");
#endif
numcells = setlabptnfmt(fmt,lab,ptn,active,m,n);
digraph = digraph || hasloops_sg(g);
refine_sg((graph*)g,lab,ptn,0,&numcells,count,active,&code,1,n);
if (numcells == n || (!digraph && numcells == n-1))
{
for (i = 0; i < n; ++i) count[i] = lab[i];
updatecan_sg((graph*)g,(graph*)h,count,0,m,n);
gt_numorbits = numcells;
}
else
{
options.getcanon = TRUE;
options.digraph = digraph;
options.defaultptn = FALSE;
if (invarproc)
{
options.invarproc = invarproc;
options.mininvarlevel = mininvarlevel;
options.maxinvarlevel = maxinvarlevel;
options.invararg = invararg;
}
#ifdef REFINE
options.userrefproc = REFINE;
#endif
if (n >= MIN_SCHREIER) options.schreier = TRUE;
EMPTYSET(active,m);
nauty((graph*)g,lab,ptn,active,orbits,&options,&stats,
workspace,24*m,m,n,(graph*)h);
gt_numorbits = stats.numorbits;
}
}
/**************************************************************************/
void
fgroup(graph *g, int m, int n, char *fmt, int *orbits, int *numorbits)
/* Find the orbits of undirected graph g stabilised by format fmt.
The orbits are put into orbits[] and the number of them into *numorbits
fmt is either NULL (for no vertex classification) or is a string
with char-valued colours for the vertices. If it ends early, it
is assumed to continue with the colour 'z' indefinitely. */
{
#if MAXN
int lab[MAXN],ptn[MAXN];
int count[MAXN];
set active[MAXM];
setword workspace[24*MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,count,count_sz);
DYNALLSTAT(set,active,active_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
#endif
int i,j;
int orbrep;
int numcells,code;
booleann digraph;
statsblk stats;
static DEFAULTOPTIONS_GRAPH(options);
if (n == 0)
{
*numorbits = 0;
return;
}
#if MAXN
if (n > MAXN || m > MAXM)
{
fprintf(stderr,">E fcanonise: m or n too large\n");
ABORT(">E fcanonise");
}
#else
DYNALLOC1(int,lab,lab_sz,n,"fcanonise");
DYNALLOC1(int,ptn,ptn_sz,n,"fcanonise");
DYNALLOC1(int,count,count_sz,n,"fcanonise");
DYNALLOC1(set,active,active_sz,m,"fcanonise");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"fcanonise");
#endif
numcells = setlabptnfmt(fmt,lab,ptn,active,m,n);
digraph = hasloops(g,m,n);
if (m == 1)
refine1(g,lab,ptn,0,&numcells,count,active,&code,1,n);
else
refine(g,lab,ptn,0,&numcells,count,active,&code,m,n);
if (cheapautom(ptn,0,digraph,n))
{
for (i = 0; i < n; )
{
if (ptn[i] == 0)
{
orbits[lab[i]] = lab[i];
++i;
}
else
{
orbrep = n;
j = i;
do
{
if (lab[j] < orbrep) orbrep = lab[j];
} while (ptn[j++] != 0);
for (; i < j; ++i) orbits[lab[i]] = orbrep;
}
}
*numorbits = gt_numorbits = numcells;
}
else
{
options.getcanon = FALSE;
options.defaultptn = FALSE;
options.digraph = digraph;
#ifdef REFINE
options.userrefproc = REFINE;
#endif
if (n >= MIN_SCHREIER) options.schreier = TRUE;
EMPTYSET(active,m);
nauty(g,lab,ptn,active,orbits,&options,&stats,workspace,24*m,m,n,NULL);
*numorbits = gt_numorbits = stats.numorbits;
}
}
/**************************************************************************/
void
fgroup_inv(graph *g, int m, int n, char *fmt, int *orbits, int *numorbits,
void (*invarproc)(graph*,int*,int*,int,int,int,int*,int,
booleann,int,int), int mininvarlevel, int maxinvarlevel, int invararg)
/* Find the orbits of undirected graph g stabilised by format fmt.
The orbits are put into orbits[] and the number of them into *numorbits
fmt is either NULL (for no vertex classification) or is a string
with char-valued colours for the vertices. If it ends early, it
is assumed to continue with the colour 'z' indefinitely.
This is like fgroup() except that a invariant and its arguments
can be specified. */
{
#if MAXN
int lab[MAXN],ptn[MAXN];
int count[MAXN];
set active[MAXM];
setword workspace[24*MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,count,count_sz);
DYNALLSTAT(set,active,active_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
#endif
int i,j;
int orbrep;
booleann digraph;
int numcells,code;
statsblk stats;
static DEFAULTOPTIONS_GRAPH(options);
if (n == 0)
{
*numorbits = 0;
return;
}
#if MAXN
if (n > MAXN || m > MAXM)
{
fprintf(stderr,">E fcanonise: m or n too large\n");
ABORT(">E fcanonise");
}
#else
DYNALLOC1(int,lab,lab_sz,n,"fcanonise");
DYNALLOC1(int,ptn,ptn_sz,n,"fcanonise");
DYNALLOC1(int,count,count_sz,n,"fcanonise");
DYNALLOC1(set,active,active_sz,m,"fcanonise");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"fcanonise");
#endif
numcells = setlabptnfmt(fmt,lab,ptn,active,m,n);
digraph = hasloops(g,m,n);
if (m == 1)
refine1(g,lab,ptn,0,&numcells,count,active,&code,1,n);
else
refine(g,lab,ptn,0,&numcells,count,active,&code,m,n);
if (cheapautom(ptn,0,digraph,n))
{
for (i = 0; i < n; )
{
if (ptn[i] == 0)
{
orbits[lab[i]] = lab[i];
++i;
}
else
{
orbrep = n;
j = i;
do
{
if (lab[j] < orbrep) orbrep = lab[j];
} while (ptn[j++] != 0);
for (; i < j; ++i) orbits[lab[i]] = orbrep;
}
}
*numorbits = gt_numorbits = numcells;
}
else
{
options.getcanon = FALSE;
options.defaultptn = FALSE;
options.digraph = digraph;
if (invarproc)
{
options.invarproc = invarproc;
options.mininvarlevel = mininvarlevel;
options.maxinvarlevel = maxinvarlevel;
options.invararg = invararg;
}
#ifdef REFINE
options.userrefproc = REFINE;
#endif
if (n >= MIN_SCHREIER) options.schreier = TRUE;
EMPTYSET(active,m);
nauty(g,lab,ptn,active,orbits,&options,&stats,workspace,24*m,m,n,NULL);
*numorbits = gt_numorbits = stats.numorbits;
}
}
/**************************************************************************/
static void
userlevel(int *lab, int *ptn, int level, int *orbits, statsblk *stats,
int tv, int index, int tcellsize, int numcells, int cc, int n)
{
int i0,i;
if (level != 2) return;
issymm = TRUE;
i0 = nextelement(g0,gm,-1);
if (i0 >= 0)
for (i = i0; (i = nextelement(g0,gm,i)) >= 0;)
if (orbits[i] != i0)
{
issymm = FALSE;
return;
}
}
/*******************************************************************/
/* istransitive(g,m,n,h)
g is an input undirected graph without loops
m,n of standard meaning.
h is a place to put an output graph.
If g is transitive, return 1 or 2 and put a canonically labelled
version of g into h. The value is 2 for symmetric graphs,
and 1 for other transitive graphs.
If g is not transitive, return 0. In that case h may or
may not have something in it.
*/
int
istransitive(graph *g, int m, int n, graph *h)
{
int i,inv;
set *gw;
short wt;
int d,inv0,v,w;
statsblk stats;
static DEFAULTOPTIONS_GRAPH(options);
#if MAXN
int lab[MAXN],ptn[MAXN],orbits[MAXN];
long x[MAXN];
int count[MAXN];
setword workspace[24*MAXM];
set workset[MAXM];
set sofar[MAXM],frontier[MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,orbits,orbits_sz);
DYNALLSTAT(int,count,count_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
DYNALLSTAT(set,workset,workset_sz);
DYNALLSTAT(set,sofar,sofar_sz);
DYNALLSTAT(set,frontier,frontier_sz);
#endif
if (n == 0) return 2;
#if MAXN
if (m > MAXM || n > MAXN)
{
fprintf(stderr,
">E istransitive: bad input parameters (n=%d m=%d)\n",n,m);
exit(1);
}
#else
DYNALLOC1(int,lab,lab_sz,n,"istransitive");
DYNALLOC1(int,ptn,ptn_sz,n,"istransitive");
DYNALLOC1(int,orbits,orbits_sz,n,"istransitive");
DYNALLOC1(int,count,count_sz,n,"istransitive");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"istransitive");
DYNALLOC1(set,workset,workset_sz,m,"istransitive");
DYNALLOC1(set,sofar,sofar_sz,m,"istransitive");
DYNALLOC1(set,frontier,frontier_sz,m,"istransitive");
#endif
for (v = 0; v < n; ++v)
{
inv = 0;
EMPTYSET(sofar,m);
ADDELEMENT(sofar,v);
EMPTYSET(frontier,m);
ADDELEMENT(frontier,v);
for (d = 1; d < n; ++d)
{
EMPTYSET(workset,m);
wt = 0;
for (w = -1; (w = nextelement(frontier,m,w)) >= 0;)
{
++wt;
gw = GRAPHROW(g,w,m);
for (i = m; --i >= 0;) workset[i] |= gw[i];
}
if (wt == 0) break;
wt += (short)(0x73 ^ d);
wt = (short)FUZZ2(wt);
inv += wt;
for (i = m; --i >= 0;)
{
frontier[i] = workset[i] & ~sofar[i];
sofar[i] |= frontier[i];
}
}
if (v == 0) inv0 = inv;
else if (inv != inv0) return 0;
}
options.getcanon = TRUE;
options.userlevelproc = userlevel;
#ifdef REFINE
options.userrefproc = REFINE;
#endif
if (n >= MIN_SCHREIER) options.schreier = TRUE;
issymm = TRUE;
g0 = (set*) g;
gm = m;
nauty(g,lab,ptn,NULL,orbits,&options,&stats,workspace,24*m,m,n,h);
if (stats.numorbits != 1) return 0;
else if (!issymm) return 1;
else return 2;
}
/**************************************************************************/
void
tg_canonise(graph *g, graph *h, int m, int n)
/* Canonise vertex-transitive graph */
{
int i;
#if MAXN
int lab[MAXN],ptn[MAXN],orbits[MAXN];
set active[MAXM];
setword workspace[24*MAXM];
#else
DYNALLSTAT(int,lab,lab_sz);
DYNALLSTAT(int,ptn,ptn_sz);
DYNALLSTAT(int,orbits,orbits_sz);
DYNALLSTAT(set,active,active_sz);
DYNALLSTAT(setword,workspace,workspace_sz);
#endif
statsblk stats;
static DEFAULTOPTIONS_GRAPH(options);
#if MAXN
if (n > MAXN || m > MAXM)
{
fprintf(stderr,">E tg_canonise: m or n too large\n");
ABORT(">E tg_canonise");
}
#else
DYNALLOC1(int,lab,lab_sz,n,"tg_canonise");
DYNALLOC1(int,ptn,ptn_sz,n,"tg_canonise");
DYNALLOC1(int,orbits,orbits_sz,n,"tg_canonise");
DYNALLOC1(set,active,active_sz,m,"tg_canonise");
DYNALLOC1(setword,workspace,workspace_sz,24*m,"tg_canonise");
#endif
if (n == 0) return;
options.getcanon = TRUE;
options.defaultptn = FALSE;
#ifdef REFINE
options.userrefproc = REFINE;
#endif
for (i = 0; i < n; ++i)
{
lab[i] = i;
ptn[i] = 1;
}
ptn[0] = ptn[n-1] = 0;
EMPTYSET(active,m);
ADDELEMENT(active,0);
if (n >= MIN_SCHREIER) options.schreier = TRUE;
nauty(g,lab,ptn,active,orbits,&options,&stats,workspace,24*m,m,n,h);
}