// 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;
}
