#define HELPTEXT \ " Read graphs or digraphs and colour their vertices in\n\
all possible ways with colours 0,1,2,... .\n\
Isomorphic graphs derived from the same input are suppressed.\n\
If the input graphs are non-isomorphic then the output graphs are also.\n\
\n\
-e# | -e#:# specify a value or range of the total value of the colours\n\
-m# number of available colours (default2 if -c not given)\n\
-c#,..,# specify the maximum number of vertices of each colour\n\
The total must at least equal the number of vertices in the input.\n\
-d#,..,# minimum vertex degree for each colour (out-degree for digraphs)\n\
-D#,..,# maximum vertex degree for each colour (out-degree for digraphs)\n\
-d and -D can have fewer colours than -m/-c but not more\n\
-f# Use the group that fixes the first # vertices setwise\n\
-T Use a simple text output format (nv ne {col} {v1 v2})\n\
-o Use sparse6 (undirected) or digraph6 (directed) for output,\n\
provided m=2and the inputs have no loops.\n\
-u no output, just count them\n\
-q suppress auxiliary information\n"
static int col[MAXNV]; static boolean first; static int lastreject[MAXNV]; static boolean lastrejok; staticunsigned long groupsize; staticunsigned long newgroupsize; static boolean Tswitch,oswitch;
static int fail_level;
#define GROUPTEST_NOT #ifdef GROUPTEST static long long totallab; #endif
/* If OUTPROC is defined at compile time, and -u is not used, the *procedureOUTPROCiscalledforeachgraph.Thismustbelinked *bythecompiler.Theargumentsare *f=openoutputfile *g=theinputgraph *col[0..n-1]=thecolours *m,n=usualnautymeanings
*/
staticvoid
writeone(FILE *outfile, graph *g, int *col, boolean digraph, int m, int n)
{
int i;
set *gi;
for (i = 0, gi = g; i < n; ++i, gi += m)
if (col[i] == 1) ADDELEMENT(gi,i);
if (digraph)
writed6(outfile,g,m,n); else
writes6(outfile,g,m,n);
for (i = 0, gi = g; i < n; ++i, gi += m)
if (col[i] == 1) DELELEMENT(gi,i);
}
static int
trythisone(grouprec *group, graph *g, boolean digraph, int m, int n) /* Try one solution, accept if maximal. */ /* Return value is level to return to. */
{
int i,j;
boolean accept;
graph *gi;
size_t ne;
char s[20],*p;
DYNALLSTAT(char,line,line_sz);
newgroupsize = 1;
if (!group || groupsize == 1)
accept = TRUE; else if (lastrejok && !ismax(lastreject,n))
accept = FALSE; else if (lastrejok && groupsize == 2)
accept = TRUE; else
{
newgroupsize = 1;
first = TRUE;
static int
scan(int level, graph *g, boolean digraph, int *prev, long mincols,
long maxcols, long sofar, long *colcount, long *mindeg,
long *maxdeg, long *deg, int numcols, grouprec *group, int m, int n) /* Recursive scan for default case */ /* Returned value is level to return to. */
{
int left;
long min,max,k,ret;
if (level == n) return trythisone(group,g,digraph,m,n);
left = n - level - 1;
min = mincols - sofar - numcols*left;
if (min < 0) min = 0;
max = maxcols - sofar;
if (max >= numcols) max = numcols - 1;
if (prev[level] >= 0 && col[prev[level]] < max)
max = col[prev[level]];
for (k = min; k <= max; ++k)
{
if (colcount[k] <= 0) continue;
if (mindeg[k] > deg[level] || maxdeg[k] < deg[level]) continue;
--colcount[k];
col[level] = k;
ret = scan(level+1,g,digraph,prev,mincols,maxcols,
sofar+k,colcount,mindeg,maxdeg,deg,numcols,group,m,n);
++colcount[k];
if (ret < level) return ret;
}
staticvoid
colourgraph(graph *g, int nfixed, long mincols, long maxcols,
long *colcount, long *mindeg, long *maxdeg, long *deg,
int numcols, int m, int n)
{ static DEFAULTOPTIONS_GRAPH(options);
statsblk stats;
setword workspace[8*MAXNV];
grouprec *group;
int i,j,k,nloops;
set *gi,*gj;
int lab[MAXNV],ptn[MAXNV],orbits[MAXNV];
boolean loop[MAXNV];
int prev[MAXNV]; /* If >= 0, earlier point that must have greater colour */
int weight[MAXNV];
int region,start,stop;
if (n > MAXNV) gt_abort(">E vcolg: MAXNV exceeded\n");
nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
nloops = 0;
for (i = 0, gi = g; i < n; ++i, gi += m)
if (ISELEMENT(gi,i))
{
DELELEMENT(gi,i);
loop[i] = TRUE;
++nloops;
} else
loop[i] = FALSE;
for (region = 0; region < 2; ++region)
{
if (region == 0)
{
if (nfixed == 0) continue;
start = 0;
stop = nfixed;
if (stop > n) stop = n;
} else
{
if (nfixed >= n) continue;
start = nfixed;
stop = n;
}
for (i = start, gi = g + m*(size_t)start; i < stop; ++i, gi += m)
{ /* Find most recent equivalent j. */
for (j = i-1, gj = gi-m; j >= start; --j, gj -= m)
{
if (loop[j] != loop[i]) continue;
for (k = 0; k < m; ++k) if (gi[k] != gj[k]) break;
if (k < m)
{
FLIPELEMENT(gi,i); FLIPELEMENT(gj,j);
for (k = 0; k < m; ++k) if (gi[k] != gj[k]) break;
FLIPELEMENT(gi,i); FLIPELEMENT(gj,j);
}
if (k == m) break;
}
if (j >= start)
{
prev[i] = j;
weight[i] = weight[j] + 1;
} else
{
prev[i] = -1;
weight[i] = 0;
}
}
}
if (n == 0)
{
scan(0,g,FALSE,prev,mincols,maxcols,0,colcount,
NULL,NULL,NULL,numcols,FALSE,m,n); return;
}
for (i = nfixed; i < n; ++i) weight[i] += nfixed;
if (maxcols == NOLIMIT || maxcols > n*numcols) maxcols = n*numcols;
if (n*numcols < mincols) return;
staticvoid
colourdigraph(graph *g, int nfixed, long mincols, long maxcols,
long *colcount, long *mindeg, long *maxdeg, long *deg,
int numcols, int m, int n)
{ static DEFAULTOPTIONS_GRAPH(options);
statsblk stats;
setword workspace[8*MAXNV];
grouprec *group;
int i,j,k,nloops;
size_t ii;
set *gi,*gj,*gci,*gcj;
int lab[MAXNV],ptn[MAXNV],orbits[MAXNV];
boolean loop[MAXNV];
int prev[MAXNV]; /* If >= 0, earlier point that must have greater colour */
int weight[MAXNV];
int region,start,stop;
DYNALLSTAT(graph,gconv,gconv_sz);
if (n > MAXNV) gt_abort(">E vcolg: MAXNV exceeded\n");
nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
int
main(int argc, char *argv[])
{
graph *g,*gi;
int m,n,codetype;
int argnum,i,j,nfixed;
char *arg,sw;
boolean badargs,digraph,cswitch,dswitch,Dswitch;
boolean fswitch,uswitch,eswitch,qswitch,mswitch;
long mincols,maxcols,totcols;
int numcols; double t;
char *infilename,*outfilename;
FILE *infile;
char msg[201];
int msglen,collen,dlen,Dlen;
long colcount[MAXNV],mindeg[MAXNV],maxdeg[MAXNV],deg[MAXNV];
if ((Tswitch!=0) + (oswitch!=0) + (uswitch!=0) >= 2)
gt_abort(">E vcolg: -T, -o and -u are incompatible\n");
#ifndef OUTPROC
if (!Tswitch && !oswitch && !uswitch)
gt_abort(">E vcolg: must use -T, -o or -u\n"); #endif
if (!mswitch) numcols = 2;
if (oswitch && numcols != 2)
gt_abort(">E vcolg: -o is only allowed for 2 colours\n");
if (!eswitch)
{
mincols = 0;
maxcols = NOLIMIT;
}
if (!fswitch) nfixed = 0;
if (cswitch && mswitch && numcols != collen)
gt_abort(">E vcolg: -m and -c disagree on number of colours\n");
if (cswitch)
{
numcols = collen;
totcols = 0;
for (i = 0; i < numcols; ++i)
if (colcount[i] < 0)
gt_abort(">E vcolg: negative counts not allowed for -c\n"); else
{
totcols += colcount[i];
if (totcols < 0) { totcols = NOLIMIT; break; } /* catch overflow */
}
} else
for (i = 0; i < numcols; ++i) colcount[i] = NOLIMIT;
if (dswitch && dlen > numcols)
gt_abort(">E vcolg: -d has too many colours\n");
if (Dswitch && Dlen > numcols)
gt_abort(">E vcolg: -D has too many colours\n");
for (i = (dswitch ? dlen : 0); i < numcols; ++i)
mindeg[i] = 0;
for (i = (Dswitch ? Dlen : 0); i < numcols; ++i)
maxdeg[i] = NOLIMIT;
for (i = 0; i < numcols; ++i)
if (mindeg[i] > maxdeg[i])
gt_abort(">E vcolg : contradictory bound from -d/-D\n");
if (cswitch && !qswitch)
{
fprintf(stderr,">c"); for (i = 0; i < numcols; ++i)
fprintf(stderr," %ld",colcount[i]);
fprintf(stderr,"\n");
}
if (dswitch && !qswitch)
{
fprintf(stderr,">d");
for (i = 0; i < numcols; ++i)
fprintf(stderr," %ld",mindeg[i]);
fprintf(stderr,"\n");
}
if (Dswitch && !qswitch)
{
fprintf(stderr,">D");
for (i = 0; i < numcols; ++i)
if (maxdeg[i] == NOLIMIT) fprintf(stderr," -"); else fprintf(stderr," %ld",maxdeg[i]);
fprintf(stderr,"\n");
}
if (!qswitch)
{
msg[0] = '\0';
CATMSG0(">A vcolg");
if (eswitch || mswitch || uswitch || (fswitch && nfixed > 0)
|| Tswitch || oswitch)
CATMSG0(" -");
if (mswitch) CATMSG1("m%d",numcols);
if (uswitch) CATMSG0("u");
if (Tswitch) CATMSG0("T");
if (oswitch) CATMSG0("o");
if (fswitch) CATMSG1("f%d",nfixed);
if (eswitch) CATMSG2("e%ld:%ld",mincols,maxcols);
msglen = strlen(msg);
if (argnum > 0) msglen += strlen(infilename);
if (argnum > 1) msglen += strlen(outfilename);
if (msglen >= 196)
{
fputs(msg,stderr);
if (argnum > 0) fprintf(stderr," %s",infilename);
if (argnum > 1) fprintf(stderr," %s",outfilename);
fprintf(stderr,"\n");
} else
{
if (argnum > 0) CATMSG1(" %s",infilename);
if (argnum > 1) CATMSG1(" %s",outfilename);
CATMSG0("\n");
fputs(msg,stderr);
}
fflush(stderr);
}
if (infilename && infilename[0] == '-') infilename = NULL;
infile = opengraphfile(infilename,&codetype,FALSE,1);
if (!infile) exit(1);
if (!infilename) infilename = "stdin";
if (uswitch)
outfile = NULL; else
{
if (!outfilename || outfilename[0] == '-')
{
outfilename = "stdout";
outfile = stdout;
} else if ((outfile = fopen(outfilename,"w")) == NULL)
{
fprintf(stderr,"Can't open output file %s\n",outfilename);
gt_abort(NULL);
}
}
vc_nin = vc_nout = 0;
t = CPUTIME; while (TRUE)
{
if ((g = readgg(infile,NULL,0,&m,&n,&digraph)) == NULL) break;
++vc_nin;
if (cswitch && n > totcols)
gt_abort(">E vcolg: not enough colours for input\n");
if (oswitch && loopcount(g,m,n) > 0)
gt_abort(">E vcolg: loops in input are not allowed for -o\n");
for (i = 0, gi = g; i < n; ++i, gi += m)
{
deg[i] = 0;
for (j = 0; j < m; ++j) deg[i] += POPCOUNT(gi[j]);
}
if (!digraph)
colourgraph(g,nfixed,mincols,maxcols,colcount,
mindeg,maxdeg,deg,numcols,m,n); else
colourdigraph(g,nfixed,mincols,maxcols,colcount,
mindeg,maxdeg,deg,numcols,m,n);
if (!uswitch && ferror(outfile)) gt_abort(">E vcolg output error\n");
FREES(g);
}
t = CPUTIME - t;
#ifdef SUMMARY
SUMMARY(); #endif
if (!qswitch)
{
fprintf(stderr,">Z ");
PRINT_COUNTER(stderr,vc_nin);
fprintf(stderr," graphs read from %s",infilename);
fprintf(stderr,"; ");
PRINT_COUNTER(stderr,vc_nout);
if (!uswitch)
fprintf(stderr," coloured graphs written to %s",outfilename); else
fprintf(stderr," coloured graphs generated");
fprintf(stderr,"; %.2f sec\n",t);
}
#ifdef GROUPTEST
fprintf(stderr,"Group test = %lld\n",totallab); #endif
exit(0);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-09-04)
¤
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.