From c433eb2b47ae21ca765be12c8abd7df143721b46 Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 12 Oct 2008 22:29:51 +0000 Subject: [PATCH] added src dir with gen_adj_matrix.c code git-svn-id: svn://anubis/gvsu@189 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs677/hw7/src/gen_adj_matrix.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cs677/hw7/src/gen_adj_matrix.c diff --git a/cs677/hw7/src/gen_adj_matrix.c b/cs677/hw7/src/gen_adj_matrix.c new file mode 100644 index 0000000..7e09739 --- /dev/null +++ b/cs677/hw7/src/gen_adj_matrix.c @@ -0,0 +1,39 @@ +// gen_adj_matrix.c +// generates random adjacency matrix of desired size and connectivity +// gw + +#include +#include + +int main(int argc, char *argv[]) +{ + int i, j; + FILE *fp; + int numVertices, avgConnectivity; + + // get parameters + if (argc != 3) { + printf ("usage: progName numVertices avgConnectivity\n"); + exit(-1); + } + else { + numVertices = atoi(argv[1]); + avgConnectivity = atoi(argv[2]); + } + + // open/create output file + if ((fp = fopen ("adjacency.dat", "w")) == NULL) { + printf ("coulnd not create file\n"); + exit(-1); + } + + // generate random graph/matrix + for (i=0; i < numVertices; i++) + for (j=0; j < numVertices; j++) + if (((rand() % numVertices) < avgConnectivity) && i!=j) + fprintf (fp, "%d ", 1 + (rand() % 20)); + else + fprintf (fp, "%d ", 0); + fclose (fp); + return 0; +}