#define HELPTEXT \ " Apply a heuristic for finding hamiltonian cycles.\n\
Output those which are unsuccessful.\n\
\n\
-s force output to sparse6 format\n\
-g force output to graph6 format\n\
If neither -s or -g are given, the output format is\n\
determined by the header or, if there is none, by the\n\
format of the first input graph.\n\
-u Suppress output to outfile, give statistics instead.\n\
\n\
The output file will have a header if and only if the input file does.\n\
\n\
-p Be content with a hamiltonian path\n\
-v Give a cycle or path if one is found.\n\
-L# Limit number of sideways steps (default1000+5*n)\n\
-t# Try# times (default1)\n\
\n\
-q suppress auxiliary information\n"
static int
hamheur(sparsegraph *sg, boolean pathok, unsigned long limit, int *cyc) /* Try up to limit, fill cyc if YES and cyc!=NULL */ /* For pathok = TRUE, return when a hamiltonian path is found */
{
DYNALLSTAT(int,path,path_sz);
DYNALLSTAT(int,work,work_sz);
DYNALLSTAT(int,pos,pos_sz); /* position on path or -1 */
int end0,end1,v0,v1;
size_t *v;
int n,*e,*d,len,d0,*e0,d1,*e1,dx,*ex;
int i,ix,x,j,w,vext,exts; unsigned long count;
boolean left,cycle;
long ran;
SG_VDE(sg,v,d,e);
n = sg->nv;
if (n < 3) return NO;
if (cycle)
{
if (len == n)
{
if (cyc)
{
j = 0;
for (i = pos[0]; i <= end1; ++i) cyc[j++] = path[i];
for (i = end0; i < pos[0]; ++i) cyc[j++] = path[i];
} return YES;
}
ix = end0 + KRAN(len);
for (i = 0; i < len; ++i)
{
x = path[ix];
exts = 0;
dx = d[x];
ex = e + v[x];
ran = NEXTRAN;
for (j = 0; j < dx; ++j)
{
w = ex[j];
if (pos[w] < 0)
{
++exts;
if (ran%exts == 0) vext = w;
}
}
if (exts > 0) break;
if (ix == end1) ix = end0; else ++ix;
}
if (i == len) return NO; /* isolated component */
work[0] = vext;
j = 1;
for (i = ix; i <= end1; ++i) work[j++] = path[i];
for (i = end0; i < ix; ++i) work[j++] = path[i];
for (i = 0; i < j; ++i)
{
path[end0+i] = work[i];
pos[work[i]] = end0+i;
}
++end1;
++len; continue;
}
/* In the last resort, do a sideways move. */
exts = 0;
d0 = d[v0];
e0 = e + v[v0];
ran = NEXTRAN;
for (i = 0; i < d0; ++i)
{
w = e0[i];
if (pos[w] >= 0 && w != path[end0+1])
{
++exts;
if (ran%exts == 0) {left = TRUE; vext = w;}
}
}
d1 = d[v1];
e1 = e + v[v1];
ran = NEXTRAN;
for (i = 0; i < d1; ++i)
{
w = e1[i];
if (pos[w] >= 0 && w != path[end1-1])
{
++exts;
if (ran%exts == 0) {left = FALSE; vext = w;}
}
}
if (left)
{
i = end0;
j = pos[vext]-1;
} else
{
i = pos[vext]+1;
j = end1;
}
for (; i < j; ++i, --j)
{
w = path[i];
path[i] = path[j];
path[j] = w;
pos[path[i]] = i;
pos[path[j]] = j;
}
if (!qswitch)
{
fprintf(stderr,">A hamheuristic");
if (pswitch || sswitch || gswitch || vswitch || tswitch || Lswitch)
fprintf(stderr," -");
if (sswitch) fprintf(stderr,"s");
if (gswitch) fprintf(stderr,"g");
if (uswitch) fprintf(stderr,"u");
if (vswitch) fprintf(stderr,"v");
if (pswitch) fprintf(stderr,"p");
if (Lswitch) fprintf(stderr,"L%ld",Lvalue);
if (tswitch) fprintf(stderr,"t%d",tvalue);
if (argnum > 0) fprintf(stderr," %s",infilename);
if (argnum > 1) fprintf(stderr," %s",outfilename);
fprintf(stderr,"\n");
fflush(stderr);
}
if (infilename && infilename[0] == '-') infilename = NULL;
infile = opengraphfile(infilename,&codetype,FALSE,1);
if (!infile) exit(1);
if (!infilename) infilename = "stdin";
NODIGRAPHSYET(codetype);
if (!uswitch)
{
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);
}
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.