/* dimacs2g.c version 1.1; B D McKay, October 2022. */
#define USAGE "dimacs2g [-n#:#] [infile...]"
#define HELPTEXT \ " Read files of graphs in Dimacs format and write them to stdout.\n\
\n\
-d Use dreadnaut format (default is sparse6)\n\
-n#:# Specify a range of n values for output\n\
-a\"string\" A string to write before each graph.\n\
-b\"string\" A string to write after eacg graph.\n\
-a and -b only operate for dreadnaut output;\n\ and should be given in separate arguments.\n\
-c Don't copy \"c\" comments from the input.\n\
\n\
Input files with name *.gz are ungzipped.\n"
if (fscanf(f,"%1s",s) != 1) return EOF; elsereturn s[0];
}
static boolean
readdimacsgraph(FILE *f, sparsegraph *g) /* Reads a graph from Bliss format into a sparse graph */
{ int n,c; unsignedlong ne,j; int haven; int i,v,w; int haveptn;
DYNALLSTAT(vpair,elist,elist_sz);
case'p': if (haven)
{
fprintf(stderr,"Duplicate p line\n"); exit(1);
} if (fscanf(f," edge %d %lu",&n,&ne) != 2)
{
fprintf(stderr,"Bad p line\n"); returnFALSE;
}
haven = 1;
DYNALLOC1(vpair,elist,elist_sz,ne,"Alloc vpair"); break;
case'n': if (!haven)
{
fprintf(stderr,"Missing p line\n"); returnFALSE;
} if (fscanf(f,"%d%d",&w,&v) != 2 || w < 1 || w > n)
{
fprintf(stderr,"Bad n line\n"); returnFALSE;
} break;
case'e': if (!haven || j == ne)
{
fprintf(stderr,"Missing p line or too many e lines\n"); returnFALSE;
} if (fscanf(f,"%d%d",&v,&w) != 2 || v < 1 || w < 1 || v > n || w > n)
{
fprintf(stderr,"Bad e line\n"); returnFALSE;
}
elist[j].v = v-1; elist[j].w = w-1;
++j; break;
default:
fprintf(stderr,"Unknown line %c\n",c); returnFALSE;
}
}
if (j != ne)
{
fprintf(stderr,"Wrong number of e lines\n"); exit(1);
}
for (i = 0; i < n; ++i) g->d[i] = 0; for (j = 0; j < ne; ++j)
{
++(g->d[elist[j].v]);
++(g->d[elist[j].w]);
}
g->v[0] = 0; for (i = 1; i < n; ++i) g->v[i] = g->v[i-1] + g->d[i-1]; for (i = 0; i < n; ++i) g->d[i] = 0;
for (j = 0; j < ne; ++j)
{
v = elist[j].v;
w = elist[j].w;
g->e[g->v[v]+(g->d[v])++] = w;
g->e[g->v[w]+(g->d[w])++] = v;
}
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.