-
Notifications
You must be signed in to change notification settings - Fork 0
/
geng.c
2455 lines (2150 loc) · 70.3 KB
/
geng.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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* TODO: insert new timings
* add chordal graphs
* add perfect graphs
* add complements for ordinary graphs */
/* geng.c version 3.1; B D McKay, Jan 2019. */
#define USAGE \
"geng [-cCmtfbd#D#] [-uygsnh] [-lvq] \n\
[-x#X#] n [mine[:maxe]] [res/mod] [file]"
#define HELPTEXT \
" Generate all graphs of a specified class.\n\
\n\
n : the number of vertices\n\
mine:maxe : a range for the number of edges\n\
#:0 means '# or more' except in the case 0:0\n\
res/mod : only generate subset res out of subsets 0..mod-1\n\
\n\
-c : only write connected graphs\n\
-C : only write biconnected graphs\n\
-t : only generate triangle-free graphs\n\
-f : only generate 4-cycle-free graphs\n\
-b : only generate bipartite graphs\n\
(-t, -f and -b can be used in any combination)\n\
-m : save memory at the expense of time (only makes a\n\
difference in the absence of -b, -t, -f and n <= 28).\n\
-d# : a lower bound for the minimum degree\n\
-D# : an upper bound for the maximum degree\n\
-v : display counts by number of edges\n\
-l : canonically label output graphs\n\
\n\
-u : do not output any graphs, just generate and count them\n\
-g : use graph6 output (default)\n\
-s : use sparse6 output\n\
-h : for graph6 or sparse6 format, write a header too\n\
\n\
-q : suppress auxiliary output (except from -v)\n\
\n\
See program text for much more information.\n"
/* Parameters:
n = the number of vertices (1..MAXN)
Note that MAXN is limited to WORDSIZE
mine = the minimum number of edges (no bounds if missing)
maxe = the maximum number of edges (same as mine if missing)
0 means "infinity" except in the case "0-0"
mod, res = a way to restrict the output to a subset.
All the graphs in G(n,mine..maxe) are divided into
disjoint classes C(0,mod),C(1,mod),...,C(mod-1,mod),
of very approximately equal size.
Only the class C(res,mod) is written.
If the -x or -X switch is used, they must have the
same value for different values of res; otherwise
the partitioning may not be valid. In this case
(-x,-X with constant value), the usual relationships
between modulo classes are obeyed; for example
C(3,4) = C(3,8) union C(7,8). This is not true
if 3/8 and 7/8 are done with -x or -X values
different from those used for 3/4.
file = a name for the output file (stdout if missing or "-")
All switches can be concatenated or separate. However, the
value of -d must be attached to the "d", and similarly for "x".
-c : only write connected graphs
-C : only write biconnected graphs
-t : only generate triangle-free graphs
-f : only generate 4-cycle-free graphs
-b : only generate bipartite graphs
(-t, -f and -b can be used in any combination)
-m : save memory at expense of time (only makes a
difference in the absence of -b, -t, -f and n <= 30).
-D<int> : specify an upper bound for the maximum degree.
The value of the upper bound must be adjacent to
the "D". Example: -D6
-d<int> : specify a lower bound for the minimum degree.
The value of the upper bound must be adjacent to
the "d". Example: -d6
-v : display counts by number of edges
-l : canonically label output graphs
-u : do not output any graphs, just generate and count them
-g : use graph6 output (default)
-s : use sparse6 output
-n : use nauty format instead of graph6 format for output
-y : use the obsolete y-format for output
-h : for graph6 or sparse6 format, write a header too
-q : suppress auxiliary output (except from -v)
-x<int> : specify a parameter that determines how evenly
the res/mod facility splits the graphs into subsets.
High values mean more even splitting at slight cost
to the total time. The default is 20*mod, and the
the legal minimum is 3*mod. More information is given
under "res/mod" above.
-X<lev> : move the initial splitting level higher by <lev>,
in order to force more even splitting at the cost
of speed. Default is -X0. More information is given
under "res/mod" above.
Output formats.
The output format is determined by the mutually exclusive switches
-u, -n, -y, -g and -s. The default is -g.
-u suppresses output of graphs completely.
-s and -g specify sparse6 and graph6 format, defined elsewhere.
In this case a header is also written if -h is present.
If -y is present, graphs will be written in y-format.
y-format is obsolete and only provided for backwards compatibility.
Each graph occupies one line with a terminating newline.
Except for the newline, each byte has the format 01xxxxxx, where
each "x" represents one bit of data.
First byte: xxxxxx is the number of vertices n
Other ceiling(n(n-1)/12) bytes: These contain the upper triangle of
the adjacency matrix in column major order. That is, the entries
appear in the order (0,1),(0,2),(1,2),(0,3),(1,3),(2,3),(0,4),... .
The bits are used in left to right order within each byte.
Any unused bits on the end are set to zero.
If -n is present, any output graphs are written in nauty format.
For a graph of n vertices, the output consists of one int giving
the number of vertices, and n setwords containing the adjacency
matrix. Note that this is system dependent (i.e. don't use it).
It will not work properly if the output is to stdout and your
system distinguishes binary and text files.
OUTPROC feature.
By defining the C preprocessor variable OUTPROC at compile time
(for Unix the syntax is -DOUTPROC=procname on the cc command),
geng can be made to call a procedure of your manufacture with
each output graph instead of writing anything. Your procedure
needs to have type void and the argument list (FILE *f, graph
*g, int n). f is a stream open for writing, g is the graph in
nauty format, and n is the number of vertices. Your procedure
can be in a separate file so long as it is linked with geng. The
global variables sparse6, graph6, quiet, nooutput, nautyformat,
yformat and canonise (all type boolean) can be used to test
for the presence of the flags -s, -g, -q, -u, -n, -y and -l,
respectively. If -l is present, the group size and similar
details can be found in the global variable nauty_stats.
PRUNE feature.
By defining the C preprocessor variable PRUNE at compile time, geng
can be made to call
int PRUNE(graph *g,int n,int maxn)
for each intermediate (and final) graph, and reject it if
the value returned is nonzero. The arguments are:
g = the graph in nauty format (m=1)
n = the number of vertices in g
maxn = the number of vertices for output
(the value you gave on the command line to geng)
geng constructs the graph starting with vertex 0, then adding
vertices 1,2,3,... in that order. Each graph in the sequence is
an induced subgraph of all later graphs in the sequence.
A call is made for all orders from 1 to maxn. In testing for
a uniform property (such as a forbidden subgraph or forbidden
induced subgraph) it might save time to notice that a call to
PRUNE for n implies that the call for n-1 already passed.
For very fast tests, it might be worthwhile using PREPRUNE as
well. It has the same meaning but is applied earlier and more
often.
Some parameters are available in global variables:
geng_mindeg, geng_maxdeg, geng_mine, geng_maxe;
SUMMARY
If the C preprocessor variable SUMMARY is defined at compile time, the
procedure SUMMARY(nauty_counter nout, double cpu) is called just before
the program exits. The purpose is to allow reporting of statistics
collected by PRUNE or OUTPROC. The values nout and cpu are the output
count and cpu time reported on the >Z line.
Output should be written to stderr.
INSTRUMENT feature.
If the C preprocessor variable INSTRUMENT is defined at compile time,
extra code is inserted to collect statistics during execution, and
more information is written to stderr at termination.
CALLING FROM A PROGRAM
It is possible to call geng from another program instead of using it
as a stand-alone program. The main requirement is to change the name
of the main program to be other than "main". This is done by defining
the preprocessor variable GENG_MAIN. You might also like to define
OUTPROC to be the name of a procedure to receive the graphs. To call
the program you need to define an argument list argv[] consistent with
the usual one; don't forget that argv[0] is the command name and not
the first argument. The value of argc is the number of strings in
argv[]; that is, one more than the number of arguments. See the
sample program callgeng.c.
**************************************************************************
Counts and sample performance statistics.
Here we give some graph counts and approximate execution times
on a Linux computer with Intel Core i7-4790 nominally 3.6GHz,
compiled with gcc 6.2.0.
Times are with the -u option (generate but don't write); add
0.2-0.3 microseconds per graph for output to a file.
General Graphs C3-free Graphs (-t)
1 1 1 1
2 2 2 2
3 4 3 3
4 11 4 7
5 34 5 14
6 156 6 38
7 1044 7 107
8 12346 8 410
9 274668 0.08 sec 9 1897
10 12005168 2.7 sec 10 12172
11 1018997864 207 sec 11 105071 0.09 sec
12 165091172592 9 hr 12 1262180 0.8 sec
13 50502031367952 108 days 13 20797002 11 sec
These can be done in about half 14 467871369 220 sec
the time by setting the edge limit 15 14232552452 1.7 hr
half way then adding complements. 16 581460254001 65 hr
17 31720840164950 145 days
C4-free Graphs (-f) (C3,C4)-free Graphs (-tf)
1 1 1 1
2 2 2 2
3 4 3 3
4 8 4 6
5 18 5 11
6 44 6 23
7 117 7 48
8 351 8 114
9 1230 9 293
10 5069 10 869
11 25181 0.04 sec 11 2963
12 152045 0.17 sec 12 12066 0.03 sec
13 1116403 1.0 sec 13 58933 0.10 sec
14 9899865 7.5 sec 14 347498 0.5 sec
15 104980369 71 sec 15 2455693 2.7 sec
16 1318017549 14 min 16 20592932 19 sec
17 19427531763 3.4 hr 17 202724920 170 sec
18 333964672216 56 hr 18 2322206466 32 min
19 6660282066936 45 days 19 30743624324 7 hr
20 468026657815 4 days
21 8161170076257 106 days
Old value was wrong: 18 2142368552 (The program was
ok, but somehow we tabulated the answer incorrectly.)
Bipartite Graphs (-b) C4-free Bipartite Graphs (-bf)
1 1 1 1
2 2 2 2
3 3 3 3
4 7 4 6
5 13 5 10
6 35 6 21
7 88 7 39
8 303 8 86
9 1119 9 182
10 5479 10 440
11 32303 0.03 sec 11 1074
12 251135 2.3 sec 12 2941
13 2527712 1.7 sec 13 8424 0.04 sec
14 33985853 19 sec 14 26720 0.11 sec
15 611846940 4.9 min 15 90883 0.33 sec
16 14864650924 1.8 hr 16 340253 1.1 sec
17 488222721992 2.4 days 17 1384567 3.7 sec
18 21712049275198 105 days 18 6186907 14 sec
19 30219769 59 sec
20 161763233 280 sec
21 946742190 24 min
22 6054606722 2.5 hr
23 42229136988 17 hr
24 320741332093 125 hr
25 2648348712904 58 days
If you know any more of these counts, please tell me.
**************************************************************************
Hints:
To make all the graphs of order n, without restriction on type,
it is fastest to make them up to binomial(n,2)/2 edges and append
the complement of those with strictly less than binomial(n,2)/2 edges.
If it is necessary to split the computation into pieces, it is more
efficient to use the res/mod feature than to split by numbers of edges.
**************************************************************************
Author: B. D. McKay, Sep 1991 and many later dates.
Copyright B. McKay (1991-2018). All rights reserved.
This software is subject to the conditions and waivers
detailed in the file nauty.h.
Changes: Nov 18, 1991 : added -d switch
fixed operation for n=16
Nov 26, 1991 : added OUTPROC feature
Nov 29, 1991 : -c implies mine >= n-1
Jan 8, 1992 : make writeny() not static
Jan 10, 1992 : added -n switch
Feb 9, 1992 : fixed case of n=1
Feb 16, 1992 : changed mine,maxe,maxdeg testing
Feb 19, 1992 : added -b, -t and -u options
documented OUTPROC and added external
declaration for it.
Feb 20, 1992 : added -v option
Feb 22, 1992 : added INSTRUMENT compile-time option
Feb 23, 1992 : added xbnds() for more effective pruning
Feb 24, 1992 : added -l option
Feb 25, 1992 : changed writenauty() to use fwrite()
Mar 11, 1992 : completely revised many parts, incl
new refinement procedure for fast rejection,
distance invariant for regular graphs
May 19, 1992 : modified userautomproc slightly. xorb[]
is no longer idempotent but it doesn't matter.
Speed-up of 2-5% achieved.
June 5, 1993 : removed ";" after "CPUDEFS" to avoid illegal
empty declaration.
Nov 24, 1994 : tested for 0 <= res < mod
Apr 13, 1996 : Major overhaul. Renamed "geng".
Changed argument syntax.
Removed 16-vertex limit.
Added -s, -m, -x. Allowed combinations.
Replaced code for non-general graphs.
Very many small changes.
Jul 12, 1996 : Changed semantics of -x and res/mod.
Changed >A line and added fflush()/
All switches can be concatenated or not.
Aug 16, 1996 : Added -X switch and PRUNE() feature.
Fixed case of argument 0-0.
Sep 22, 1996 : Improved 1-2% by tweaking refinex().
Jan 21, 1997 : Renamed to geng.
Changed -s to -f, and added -sghq.
Sep 7, 1997 : Fixed WORDSIZE=16 problems.
Sep 22, 1997 : Use "wb" open for nautyformat.
Jan 26, 1998 : Added SUMMARY feature.
Mar 4, 1998 : Added -C.
Mar 12, 1998 : Moved stats to nauty_stats.
Jan 1, 2000 : Changed -d to -D and added -d.
Feb 24, 2000 : Raised limit to 32 vertices.
Mar 3, 2000 : Made some counts into unsigned long.
(Includes first arg to SUMMARY.)
Mar 12, 2000 : Used bigint for counts that may exceed 2^32.
Now all counts from very long runs are ok.
Oct 12, 2000 : Changed maxef[32] to 92 after confirmation
from Yang Yuansheng. The old value of 93 was
valid but 92 is slightly more efficient.
Nov 16, 2000 : Used fuction prototypes.
Jul 31, 2001 : Added PREPRUNE
May 7, 2004 : Complete all function prototypes
Nov 24, 2004 : Force -m for very large sizes
Add -bf automatically if generating trees
Apr 1, 2007 : Write >A in one fputs() to try to reduce
mixing of outputs in multi-process pipes.
Sep 19, 2007 : Force -m for n > 28 regardless of word size.
Nov 29, 2008 : Slightly improved connectivity testing.
Mar 3, 2015 : Improve maxdeg tweaking.
Jan 18, 2016 : Replace bigint by nauty_counter.
Mar 8, 2018 : Can now compile for MAXN up to WORDSIZE.
Use setword instead of unsigned for xword.
Revised splitting level.
Updated sample execution times.
Mar 10, 2018 : Fix overflow at impossibly large n, maxdeg.
Jan 14, 2019 : Define geng_mindeg, geng_maxdeg, geng_mine, geng_maxe.
**************************************************************************/
#define NAUTY_PGM 1 /* 1 = geng, 2 = genbg, 3 = gentourng */
#ifndef MAXN
#define MAXN WORDSIZE /* not more than WORDSIZE */
#endif
#if MAXN > WORDSIZE
#error "Can't have MAXN greater than WORDSIZE"
#endif
#define ONE_WORD_SETS
#include "gtools.h" /* which includes nauty.h and stdio.h */
typedef setword xword;
static void (*outproc)(FILE*,graph*,int);
static FILE *outfile; /* file for output graphs */
static int connec; /* 1 for -c, 2 for -C, 0 for neither */
static boolean bipartite; /* presence of -b */
static boolean trianglefree; /* presence of -t */
static boolean squarefree; /* presence of -f */
static boolean savemem; /* presence of -m */
static boolean verbose; /* presence of -v */
boolean nautyformat; /* presence of -n */
boolean yformat; /* presence of -y */
boolean graph6; /* presence of -g */
boolean sparse6; /* presence of -s */
boolean nooutput; /* presence of -u */
boolean canonise; /* presence of -l */
boolean quiet; /* presence of -q */
boolean header; /* presence of -h */
statsblk nauty_stats;
static int mindeg,maxdeg,maxn,mine,maxe,mod,res;
#define PRUNEMULT 50 /* bigger -> more even split at greater cost */
static int min_splitlevel,odometer,splitlevel,multiplicity;
static graph gcan[MAXN];
#define XBIT(i) ((xword)1 << (i))
#define XPOPCOUNT(x) POPCOUNT(x)
#define XNEXTBIT(x) (WORDSIZE-1-FIRSTBITNZ(x)) /* Assumes non-zero */
typedef struct
{
int ne,dmax; /* values used for xlb,xub calculation */
int xlb,xub; /* saved bounds on extension degree */
xword lo,hi; /* work purposes for orbit calculation */
xword xstart[MAXN+1]; /* index into xset[] for each cardinality */
xword *xset; /* array of all x-sets in card order */
xword *xcard; /* cardinalities of all x-sets */
xword *xinv; /* map from x-set to index in xset */
xword *xorb; /* min orbit representative */
xword *xx; /* (-b, -t, -s, -m) candidate x-sets */
/* note: can be the same as xcard */
xword xlim; /* number of x-sets in xx[] */
} leveldata;
static leveldata data[MAXN]; /* data[n] is data for n -> n+1 */
static nauty_counter ecount[1+MAXN*(MAXN-1)/2]; /* counts by number of edges */
static nauty_counter nodes[MAXN]; /* nodes at each level */
#ifdef INSTRUMENT
static nauty_counter rigidnodes[MAXN],fertilenodes[MAXN];
static nauty_counter a1calls,a1nauty,a1succs;
static nauty_counter a2calls,a2nauty,a2uniq,a2succs;
#endif
/* The numbers below are actual maximum edge counts.
geng works correctly with any upper bounds.
To extend known upper bounds upwards:
(n-1, E) -> (n, E + floor(2*E/(n-2))),
which is done by the procedure findmaxe().
*/
static int maxeb[65] = /* max edges for -b */
{0,0,1,2,4, -1};
static int maxet[65] = /* max edges for -t */
{0,0,1,2,4, -1};
static int maxef[65] = /* max edges for -f */
{0,0,1,3,4, 6,7,9,11,13,
16,18,21,24,27, 30,33,36,39,42,
46,50,52,56,59, 63,67,71,76,80,
85,90,92,96,102, 106,110,113,117,122, -1};
static int maxeft[65] = /* max edges for -ft */
{0,0,1,2,3, 5,6,8,10,12,
15,16,18,21,23, 26,28,31,34,38,
41,44,47,50,54, 57,61,65,68,72,
76,80,85,87,90, 95,99,104,109,114,
120,124,129,134,139, 145,150,156,162,168,
175,176,178, -1};
static int maxebf[65] = /* max edges for -bf */
{0,0,1,2,3, 4,6,7,9,10,
12,14,16,18,21, 22,24,26,29,31,
34,36,39,42,45, 48,52,53,56,58,
61,64,67,70,74, 77,81,84,88,92,
96,100,105,106,108, 110,115,118,122,126,
130,134,138,142,147, 151,156,160,165,170,
175,180,186,187, -1};
#ifdef PLUGIN
#include PLUGIN
#endif
#ifdef OUTPROC
extern void OUTPROC(FILE*,graph*,int);
#endif
#ifdef PRUNE
extern int PRUNE(graph*,int,int);
#endif
#ifdef PREPRUNE
extern int PREPRUNE(graph*,int,int);
#endif
#ifdef SUMMARY
extern void SUMMARY(nauty_counter,double);
#endif
#if defined(PRUNE) || defined(PREPRUNE)
int geng_mindeg, geng_maxdeg, geng_mine, geng_maxe;
#endif
/************************************************************************/
#define EXTEND(table,n) ((n) <= 1 ? 0 : (n) == 2 ? 1 : \
table[(n)-1] + (2*table[(n)-1]/((n)-2)))
static int
findmaxe(int *table, int n)
/* Return the n-th entry of a maxe table, extending existing values
if necessary. */
{
int i;
for (i = 0; i <= n && table[i] >= 0; ++i) {}
for ( ; i <= n; ++i) table[i] = EXTEND(table,i);
return table[n];
}
/************************************************************************/
void
writeny(FILE *f, graph *g, int n)
/* write graph g (n vertices) to file f in y format */
{
static char ybit[] = {32,16,8,4,2,1};
char s[(MAXN*(MAXN-1)/2 + 5)/6 + 4];
int i,j,k;
char y,*sp;
sp = s;
*(sp++) = 0x40 | n;
y = 0x40;
k = -1;
for (j = 1; j < n; ++j)
for (i = 0; i < j; ++i)
{
if (++k == 6)
{
*(sp++) = y;
y = 0x40;
k = 0;
}
if (g[i] & bit[j]) y |= ybit[k];
}
if (n >= 2) *(sp++) = y;
*(sp++) = '\n';
*sp = '\0';
if (fputs(s,f) == EOF || ferror(f))
{
fprintf(stderr,">E writeny : error on writing file\n");
exit(2);
}
}
/************************************************************************/
void
writeg6x(FILE *f, graph *g, int n)
/* write graph g (n vertices) to file f in graph6 format */
{
writeg6(f,g,1,n);
}
/************************************************************************/
void
writes6x(FILE *f, graph *g, int n)
/* write graph g (n vertices) to file f in sparse6 format */
{
writes6(f,g,1,n);
}
/***********************************************************************/
static void
nullwrite(FILE *f, graph *g, int n)
/* don't write graph g (n vertices) to file f */
{
}
/***********************************************************************/
void
writenauty(FILE *f, graph *g, int n)
/* write graph g (n vertices) to file f in nauty format */
{
int nn;
nn = n;
if (fwrite((char *)&nn,sizeof(int),(size_t)1,f) != 1 ||
fwrite((char*)g,sizeof(setword),(size_t)n,f) != n)
{
fprintf(stderr,">E writenauty : error on writing file\n");
exit(2);
}
}
/*********************************************************************/
static boolean
isconnected(graph *g, int n)
/* test if g is connected */
{
setword seen,expanded,toexpand,allbits;
int i;
allbits = ALLMASK(n);
expanded = bit[n-1];
seen = expanded | g[n-1];
while (seen != allbits && (toexpand = (seen & ~expanded))) /* not == */
{
i = FIRSTBITNZ(toexpand);
expanded |= bit[i];
seen |= g[i];
}
return seen == allbits;
}
/**********************************************************************/
static boolean
isbiconnected(graph *g, int n)
/* test if g is biconnected */
{
int sp,v,w;
setword sw;
setword visited;
int numvis,num[MAXN],lp[MAXN],stack[MAXN];
if (n <= 2) return FALSE;
visited = bit[0];
stack[0] = 0;
num[0] = 0;
lp[0] = 0;
numvis = 1;
sp = 0;
v = 0;
for (;;)
{
if ((sw = g[v] & ~visited)) /* not "==" */
{
w = v;
v = FIRSTBITNZ(sw); /* visit next child */
stack[++sp] = v;
visited |= bit[v];
lp[v] = num[v] = numvis++;
sw = g[v] & visited & ~bit[w];
while (sw)
{
w = FIRSTBITNZ(sw);
sw &= ~bit[w];
if (num[w] < lp[v]) lp[v] = num[w];
}
}
else
{
w = v; /* back up to parent */
if (sp <= 1) return numvis == n;
v = stack[--sp];
if (lp[w] >= num[v]) return FALSE;
if (lp[w] < lp[v]) lp[v] = lp[w];
}
}
}
/**********************************************************************/
static void
gcomplement(graph *g, graph *gc, int n)
/* Take the complement of g and put it in gc */
{
int i;
setword all;
all = ~(setword)BITMASK(n-1);
for (i = 0; i < n; ++i)
gc[i] = g[i] ^ all ^ bit[i];
}
/**********************************************************************/
static boolean
distinvar(graph *g, int *invar, int n)
/* make distance invariant
return FALSE if n-1 not maximal else return TRUE */
{
int w;
setword workset,frontier;
setword sofar;
int inv,d,v;
for (v = n-1; v >= 0; --v)
{
inv = 0;
sofar = frontier = bit[v];
for (d = 1; frontier != 0; ++d)
{
workset = 0;
inv += POPCOUNT(frontier) ^ (0x57 + d);
while (frontier)
{
w = FIRSTBITNZ(frontier);
frontier ^= bit[w];
workset |= g[w];
}
frontier = workset & ~sofar;
sofar |= frontier;
}
invar[v] = inv;
if (v < n-1 && inv > invar[n-1]) return FALSE;
}
return TRUE;
}
/**************************************************************************/
static void
makexgraph(graph *g, xword *h, int n)
/* make x-format graph from nauty format graph */
{
setword gi;
int i,j;
xword hi;
for (i = 0; i < n; ++i)
{
hi = 0;
gi = g[i];
while (gi)
{
j = FIRSTBITNZ(gi);
gi ^= bit[j];
hi |= XBIT(j);
}
h[i] = hi;
}
}
/**************************************************************************/
static void
make0graph(graph *g, xword *h, int n)
/* make x-format graph without edges */
{
int i;
for (i = 0; i < n; ++i) h[i] = 0;
}
/**************************************************************************/
static void
makebgraph(graph *g, xword *h, int n)
/* make x-format graph of different colour graph */
{
setword seen1,seen2,expanded,w;
setword restv;
xword xseen1,xseen2;
int i;
restv = 0;
for (i = 0; i < n; ++i) restv |= bit[i];
seen1 = seen2 = 0;
expanded = 0;
while (TRUE)
{
if ((w = ((seen1 | seen2) & ~expanded)) == 0)
{
xseen1 = 0;
w = seen1;
while (w)
{
i = FIRSTBITNZ(w);
w ^= bit[i];
xseen1 |= XBIT(i);
}
xseen2 = 0;
w = seen2;
while (w)
{
i = FIRSTBITNZ(w);
w ^= bit[i];
xseen2 |= XBIT(i);
}
w = seen1;
while (w)
{
i = FIRSTBITNZ(w);
w ^= bit[i];
h[i] = xseen2;
}
w = seen2;
while (w)
{
i = FIRSTBITNZ(w);
w ^= bit[i];
h[i] = xseen1;
}
restv &= ~(seen1 | seen2);
if (restv == 0) return;
i = FIRSTBITNZ(restv);
seen1 = bit[i];
seen2 = 0;
}
else
i = FIRSTBITNZ(w);
expanded |= bit[i];
if (bit[i] & seen1) seen2 |= g[i];
else seen1 |= g[i];
}
}
/**************************************************************************/
static void
makeb6graph(graph *g, xword *h, int n)
/* make x-format bipartite girth 6 graph */
{
setword w,x;
xword hi;
int i,j;
makebgraph(g,h,n);
for (i = 0; i < n; ++i)
{
w = g[i];
x = 0;
while (w)
{
j = FIRSTBITNZ(w);
w ^= bit[j];
x |= g[j];
}
x &= ~bit[i];
hi = h[i];
while (x)
{
j = FIRSTBITNZ(x);
x ^= bit[j];
hi |= XBIT(j);
}
h[i] = hi;
}
}
/**************************************************************************/
static void
makesgraph(graph *g, xword *h, int n)
/* make x-format square graph */
{
setword w,x;
xword hi;
int i,j;
for (i = 0; i < n; ++i)
{
w = g[i];
x = 0;
while (w)
{
j = FIRSTBITNZ(w);
w ^= bit[j];
x |= g[j];
}
x &= ~bit[i];
hi = 0;
while (x)
{
j = FIRSTBITNZ(x);
x ^= bit[j];
hi |= XBIT(j);
}
h[i] = hi;
}
}
/**************************************************************************/
static void
makeg5graph(graph *g, xword *h, int n)
/* make x-format girth-5 graph */
{
setword w,x;
xword hi;
int i,j;
for (i = 0; i < n; ++i)
{
w = g[i];
x = g[i];
while (w)
{
j = FIRSTBITNZ(w);
w ^= bit[j];
x |= g[j];
}
x &= ~bit[i];
hi = 0;
while (x)
{
j = FIRSTBITNZ(x);
x ^= bit[j];
hi |= XBIT(j);
}
h[i] = hi;
}
}
/**************************************************************************/
static xword
arith(xword a, xword b, xword c)
/* Calculate a*b/c, assuming a*b/c and (c-1)*b are representable integers */
{
return (a/c)*b + ((a%c)*b)/c;
}
/**************************************************************************/
static void
makeleveldata(boolean restricted)
/* make the level data for each level */
{
long h;
int n,nn;
xword ncj;
leveldata *d;
xword *xcard,*xinv;
xword *xset,xw,nxsets;
xword cw;
xword i,ilast,j;
size_t tttn;
for (n = 1; n < maxn; ++n)
{
nn = maxdeg <= n ? maxdeg : n;
ncj = nxsets = 1;
for (j = 1; j <= nn; ++j)
{
ncj = arith(ncj,n-j+1,j);
nxsets += ncj;
}
d = &data[n];
d->ne = d->dmax = d->xlb = d->xub = -1;
if (restricted)
{
d->xorb = (xword*) calloc(nxsets,sizeof(xword));
d->xx = (xword*) calloc(nxsets,sizeof(xword));
if (d->xorb == NULL || d->xx == NULL)
{
fprintf(stderr,
">E geng: calloc failed in makeleveldata()\n");
exit(2);
}
continue; /* <--- NOTE THIS! */
}
tttn = (size_t)1 << n;
d->xset = xset = (xword*) calloc(nxsets,sizeof(xword));
d->xcard = xcard = (xword*) calloc(nxsets,sizeof(xword));
d->xinv = xinv = (xword*) calloc(tttn,sizeof(xword));
d->xorb = (xword*) calloc(nxsets,sizeof(xword));
d->xx = d->xcard;
if (xset==NULL || xcard==NULL || xinv==NULL || d->xorb==NULL)
{
fprintf(stderr,">E geng: calloc failed in makeleveldata()\n");
exit(2);
}
j = 0;