added src dir with gen_adj_matrix.c code
git-svn-id: svn://anubis/gvsu@189 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
ee58c58087
commit
c433eb2b47
39
cs677/hw7/src/gen_adj_matrix.c
Normal file
39
cs677/hw7/src/gen_adj_matrix.c
Normal file
@ -0,0 +1,39 @@
|
||||
// gen_adj_matrix.c
|
||||
// generates random adjacency matrix of desired size and connectivity
|
||||
// gw
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user