added --vector option

This commit is contained in:
Ämin Baumeler 2024-11-15 16:01:11 +01:00
parent 19119a5adf
commit a8b52a581f

View File

@ -32,6 +32,30 @@ void dumpgraph(int n, const int *children, const int *childrenlen) {
printf("}\n");
}
/***
* Print the graph's adjacency vector.
* The entries are (0<-1, 0<-2, ...1, 1<-0, 1<-2, ...)
***/
void dumpgraphvector(int n, const int *parents, const int *parentslen) {
int edge = 0;
for (int a = 0; a < n; a++) {
for (int b = 0; b < n; b++) {
if (a==b) continue;
edge = 0;
for (int i = 0; i < parentslen[a] && !edge; i++) {
const int v = parents[a*n+i];
if (b==v) {
printf("1");
edge = 1;
}
}
if (!edge)
printf("0");
}
}
printf("\n");
}
/***
* Print the graph as graphviz command
***/
@ -460,6 +484,7 @@ int main(int argc, char *argv[]) {
int NOSOURCE = 0;
int RANDOM = 0;
int GRAPHVIZ = 0;
int VECTOR = 0;
int UNKOPTION = 0;
int ALL = 0;
for (int i = 1; i < argc; i++) {
@ -479,6 +504,8 @@ int main(int argc, char *argv[]) {
GRAPHVIZ = 1;
} else if (strcmp(argv[i], "--all") == 0) {
ALL = 1;
} else if (strcmp(argv[i], "--vector") == 0) {
VECTOR = 1;
} else {
UNKOPTION = 1;
break;
@ -489,6 +516,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, " -n <order> Generate SOCs with `order' connected nodes\n");
fprintf(stderr, " -r <num> Pick directed graphs at random, and exit after having found `num' SOCs\n");
fprintf(stderr, " --graphviz Output SOCs in Graphviz format, arcs of common parents are highlighted\n");
fprintf(stderr, " --vector Output SOCs adjacency vectors in the order (0<-1, 0<-2, ..., 1<-0, 1<-2, ...)\n");
fprintf(stderr, " --all Allow for disconnected SOCs and disable the degree-order filter (see below)\n");
fprintf(stderr, "\n");
fprintf(stderr, "[FILTER] Consider only simple directed graphs ...\n");
@ -605,6 +633,8 @@ int main(int argc, char *argv[]) {
len++;
if (GRAPHVIZ)
dumpgv(n, graphnumber, children, childrenlen);
else if (VECTOR)
dumpgraphvector(n, parents, parentslen);
else
dumpgraph(n, children, childrenlen);
}