From a8b52a581fcef7dcbd8da050717fdcea431092b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Fri, 15 Nov 2024 16:01:11 +0100 Subject: [PATCH] added --vector option --- src/SOCgen.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/SOCgen.c b/src/SOCgen.c index 730fc7d..fe9398b 100644 --- a/src/SOCgen.c +++ b/src/SOCgen.c @@ -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 Generate SOCs with `order' connected nodes\n"); fprintf(stderr, " -r 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); }