/* gentourng.c version 1.4; B D McKay, Jan 20, 2016 */
#define USAGE \ "gentourng [-cd#D#] [-ugsz] [-lq] n [res/mod] [file]"
#define HELPTEXT \ " Generate all tournaments of a specified class.\n\
\n\
n : the number of vertices\n\
res/mod : only generate subset res out of subsets 0..mod-1\n\
\n\
-c : only write strongly-connected tournaments\n\
-d# : a lower bound for the minimum out-degree\n\
-D# : a upper bound for the maximum out-degree\n\
-l : canonically label output graphs\n\
\n\
-u : donot output any graphs, just generate and count them\n\
-g : use graph6 output (lower triangle)\n\
-s : use sparse6 output (lower triangle)\n\
-z : use digraph6 output\n\
-h : write a header (only with -g or -s)\n\ Default output is upper triangle row-by-row in ascii\n\
\n\
-q : suppress auxiliary output\n\
\n\
See program text for much more information.\n"
/* Parameters:
n = the number of vertices (1..min(32,WORDSIZE)) 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.
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 -d<int> : specify an upper bound for the maximum out-degree. The value of the upper bound must be adjacent to the "d". Example: -d6 -l : canonically label output graphs
-u : do not output any graphs, just generate and count them -z : use digraph6 output -g : use graph6 output -s : use sparse6 output For -g and -s, the lower triangle of the adjacency matrix is written as if it is an undirected graph. Nauty tools like labelg do not know this format. To read it you can read it as an undirected graph then complement the upper triangle. -h : for graph6 or sparse6 format, write a header too
-q : suppress auxiliary output (except from -v)
Output formats.
The output format is determined by the mutually exclusive switches -u, -z, -g and -s. The default is ascii format.
-u suppresses output of graphs completely. -z uses digraph6 output.
-s and -g specify sparse6 and graph6 format, defined elsewhere. In this case a header is also written if -h is present.
OUTPROC feature.
By defining the C preprocessor variable OUTPROC at compile time (for Unix the syntax is -DOUTPROC=procname on the cc command), gentourng 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 gentourng. The global variables nooutput, and canonise (all type boolean) can be used to test for the presence of the flags -u 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, gentourng 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 gentourng)
gentourng 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 or instead. It has the same meaning but is applied earlier and more often.
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 gentourng 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.
Author: B. D. McKay, Nov 2008. Copyright B. McKay (2008-2022). All rights reserved. This software is subject to the conditions and waivers detailed in the file COPYRIGHT.
typedefstruct
{
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 */
} leveldata;
static TLS_ATTR leveldata data[MAXN]; /* data[n] is data for n -> n+1 */ static TLS_ATTR nauty_counter nodes[MAXN]; /* nodes at each level */ static TLS_ATTR nauty_counter nout;
void
write_ascii(FILE *f, graph *g, int n) /* write tournament g (n vertices) to file f in ascii format */
{ char s[MAXN*(MAXN-1)/2+2]; int i,j;
size_t k;
k = 0; for (i = 0; i < n-1; ++i) for (j = i+1; j < n; ++j) if ((g[i] & bit[j])) s[k++] = '1'; else s[k++] = '0';
s[k++] = '\n';
s[k] = '\0';
if (fwrite(s,1,k,f) != k || ferror(f))
gt_abort(">E write_ascii : error on writing\n");
}
static boolean
isstrong(graph *g, int n) /* test if tournament g is strongly-connected * This code is strictly for tournaments only.
*/
{
setword seen,expanded,toexpand,allbits; int i;
allbits = ALLMASK(n);
seen = bit[0] | g[0];
expanded = bit[0];
while (seen != allbits && (toexpand = (seen & ~expanded))) /* not == */
{
i = FIRSTBITNZ(toexpand);
expanded |= bit[i];
seen |= g[i];
}
if (seen != allbits) returnFALSE;
seen = (allbits ^ g[0]);
expanded = bit[0];
while (seen != allbits && (toexpand = (seen & ~expanded))) /* not == */
{
i = FIRSTBITNZ(toexpand);
expanded |= bit[i];
seen |= (g[i] ^ allbits);
}
staticvoid
makeleveldata(void) /* make the level data for each level */
{ long h; int n,dmax,dmin; long ncj;
leveldata *d;
xword *xcard,*xinv;
xword *xset,xw,tttn,nxsets;
xword cw;
xword i,j;
staticvoid
userautomproc(int count, int *p, int *orbits, int numorbits, int stabvertex, int n) /* form orbits on powerset of VG
called by nauty; operates on data[n] */
{
xword i,j1,j2,moved,pi,pxi;
xword lo,hi;
xword *xorb,*xinv,*xset,w;
xorb = data[n].xorb;
xset = data[n].xset;
xinv = data[n].xinv;
lo = data[n].lo;
hi = data[n].hi;
if (count == 1) /* first automorphism */ for (i = lo; i < hi; ++i) xorb[i] = i;
moved = 0; for (i = 0; i < n; ++i) if (p[i] != i) moved |= xbit[i];
for (i = lo; i < hi; ++i)
{ if ((w = xset[i] & moved) == 0) continue;
pxi = xset[i] & ~moved; while (w)
{
j1 = XNEXTBIT(w);
w ^= xbit[j1];
pxi |= xbit[p[j1]];
}
pi = xinv[pxi];
j1 = xorb[i]; while (xorb[j1] != j1) j1 = xorb[j1];
j2 = xorb[pi]; while (xorb[j2] != j2) j2 = xorb[j2];
/***************************************************************************** * * * refinex(g,lab,ptn,level,numcells,count,active,goodret,code,m,n) is a * * custom version of refine() which can exit quickly if required. * * * * Only use at level==0. * * goodret : whether to do an early return for code 1 * * code := -1 for n-1 not max, 0 for maybe, 1 for definite * * *
*****************************************************************************/
staticvoid
refinex(graph *g, int *lab, int *ptn, int level, int *numcells, int *count, set *active, boolean goodret, int *code, int m, int n)
{ int i,c1,c2,labc1;
setword x,lact; int split1,split2,cell1,cell2; int cnt,bmin,bmax;
set *gptr;
setword workset; int workperm[MAXN]; int bucket[MAXN+2];
if (n == 1)
{
*code = 1; return;
}
*code = 0;
lact = *active;
split1 = -1; while (*numcells < n && lact)
{
TAKEBIT(split1,lact);
for (split2 = split1; ptn[split2] > 0; ++split2) {} if (split1 == split2) /* trivial splitting cell */
{
gptr = GRAPHROW(g,lab[split1],1); for (cell1 = 0; cell1 < n; cell1 = cell2 + 1)
{ for (cell2 = cell1; ptn[cell2] > 0; ++cell2) {} if (cell1 == cell2) continue;
static boolean
accept1(graph *g, int n, xword x, graph *gx, int *deg, boolean *rigid) /* decide if n in theta(g+x) - version for n+1 < maxn */
{ int i; int lab[MAXN],ptn[MAXN],orbits[MAXN]; int count[MAXN];
graph h[MAXN]; int nx,numcells,code; int i0,i1,degn;
set active[MAXM];
statsblk stats; static TLS_ATTR DEFAULTOPTIONS_GRAPH(options);
setword workspace[200];
#ifdef INSTRUMENT
++a1calls; #endif
nx = n + 1; for (i = 0; i < n; ++i) gx[i] = g[i];
gx[n] = 0;
deg[n] = degn = XPOPCOUNT(x);
for (i = 0; i < n; ++i)
{ if ((xbit[i] & x))
gx[n] |= bit[i]; else
{
gx[i] |= bit[n];
++deg[i];
}
}
#ifdef PREPRUNE if (PREPRUNE(gx,n+1,maxn)) returnFALSE; #endif
static boolean
hitinvar(graph *g, int *invar, int n) /* make hitting invariant
* return FALSE if n-1 not maximal else return TRUE */
{
setword x,y,z; int inv,i,v,d;
for (v = n-1; v >= 0; --v)
{
inv = 0;
x = y = g[v]; while (y)
{
TAKEBIT(i,y);
z = x & g[i];
d = POPCOUNT(z); if (d > inv) inv = d;
}
invar[v] = inv; if (v < n-1 && inv > invar[n-1]) returnFALSE;
} returnTRUE;
}
static boolean
accept2(graph *g, int n, xword x, graph *gx, int *deg, boolean nuniq) /* decide if n in theta(g+x) -- version for n+1 == maxn */
{ int i; int lab[MAXN],ptn[MAXN],orbits[MAXN]; int degx[MAXN],invar[MAXN];
setword vmax,gv,gxn; int qn,qv; int count[MAXN]; int nx,numcells,code; int degn,i0,i1,j,j0,j1;
set active[MAXM];
statsblk stats; static TLS_ATTR DEFAULTOPTIONS_GRAPH(options);
setword workspace[200];
boolean cheapacc;
#ifdef INSTRUMENT
++a2calls; if (nuniq) ++a2uniq; #endif
nx = n + 1;
gxn = 0;
staticvoid
genextend(graph *g, int n, int *deg, boolean rigid) /* extend from n to n+1. Note that, differently from
geng, the last vertex has minimum out-degree */
{
xword x,dlow,dhigh,dcrit;
xword *xset,*xcard,*xorb;
xword i,imin,imax; int nx,xc,j,dmax; int xlb,xub,xlbx,xubx;
graph gx[MAXN]; int degx[MAXN];
boolean rigidx;
boolean subconnec;
#ifdef INSTRUMENT
boolean haschild;
haschild = FALSE; if (rigid) ++rigidnodes[n]; #endif
nx = n + 1;
++nodes[n];
if (regular && nx == maxn)
{
x = 0; for (i = 0; i < n; ++i) if (deg[i] == maxdeg) x |= xbit[i];
if (argnum == 0)
badargs = TRUE; elseif (maxn < 1 || maxn > MAXN)
{
fprintf(stderr,">E gentourng: n must be in the range 1..%d\n",MAXN);
badargs = TRUE;
}
if (!gotmr)
{
mod = 1;
res = 0;
}
if (connec1) connec = 1; else connec = 0;
if (maxdeg >= maxn) maxdeg = maxn - 1; if (mindeg < 0) mindeg = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.