-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_graph.py
68 lines (58 loc) · 2.32 KB
/
generate_graph.py
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
62
63
64
65
66
67
68
from random import randrange, choice
from uuid import uuid4
from argparse import ArgumentParser
import sys
import numpy as np
def main(fname, size, dist, lam):
with open(fname, 'w') as fout:
#Each graph have the same amount of nodes
size = int(size) - 1
#Title of each test file
fout.write("parity " + str(size+1) + ";\n")
#Loop to create each node
for i in range(size+1):
#node_name
fout.write(str(i) + ' ')
#color
priority = randrange(1, 100)
fout.write(str(priority) + ' ')
#player
owner = randrange(0, 2)
fout.write(str(owner) + ' ')
#Neighbours
#Number of edges of the this node
if dist == "unif":
number_of_edges = randrange(1, size+1)
elif dist == "poisson":
number_of_edges = np.random.poisson(int(lam)) + 1
if number_of_edges > size:
number_of_edges = size
elif dist == "heavy":
number_of_edges = 10
#Defining connected nodes to node i
sequence = list(range(size+1))
#No self-loops allowed
sequence.remove(i)
for j in range(number_of_edges):
t = choice(sequence)
fout.write(str(t))
sequence.remove(t)
if j == number_of_edges - 1:
fout.write(" ")
else:
fout.write(",")
#Create a uuid for each node
uuid = uuid4()
fout.write("\"" + str(uuid) + "\";\n")
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("--fname", help="name of the file to be created", nargs=1, required=True)
parser.add_argument("--size", help="size of each graph. Default = 30", nargs=1, required=True)
parser.add_argument("--dist", help="unif/poisson/heavy -> probability distribution of the degree of each node", nargs=1, required=True)
parser.add_argument("--lam", help="value of lambda for poisson distribuitions", nargs=1, required=True)
try:
args = parser.parse_args()
except:
parser.print_help(sys.stderr)
exit(1)
main(args.fname[0], args.size[0], args.dist[0], args.lam[0])