-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeGraph.c
62 lines (47 loc) · 1.18 KB
/
makeGraph.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*Dong-Son Nguyen-Huu - 40014054
COMP 428
November 29, 2017
Assignment 3 - Floyd All-Pairs Shortest Path Algorithm - Graph Generator
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[]) {
//Create a random seed
srand(time(NULL));
//Take 4 parameters from the command line
int graphSize = strtol(argv[1], NULL, 10);
int connectionPercent = strtol(argv[2], NULL, 10);
int maxWeight = strtol(argv[3], NULL, 10);
int minWeight = strtol(argv[4], NULL, 10);
//Create a file that will be written into
FILE *file;
file = fopen("input.txt", "w");
//int values that will map the x and y coordinate
int x, y;
//iterate through the graph based on supplied size
for (x = 0; x < graphSize; x++) {
for (y = 0; y < graphSize; y++) {
if (x == y) {
fprintf(file, "%d\t", 0);
continue;
}
//determines the connect percentage
int connected;
if (connectionPercent > (rand() % 101)) {
connected = 1;
}
else {
connected = 0;
}
if (connected == 1) {
fprintf(file, "%d\t", rand() % (maxWeight - minWeight) + minWeight);
}
else {
fprintf(file, "N\t");
}
}
fprintf(file, "\n");
}
fclose(file);
}