-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
63 lines (54 loc) · 1.16 KB
/
gen.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
import sys
import random
from graph import Graph
import matplotlib.pyplot as plt
##########
# Inputs #
##########
N = int(sys.argv[1])
M = int(sys.argv[2])
P = 10
I = 33
random.seed(sys.argv[-1])
##############
# Processing #
##############
# Graph gen
graph = Graph(N)
graph.connect_tree()
graph.connect_tree()
temp = [i for i in range(N)]
random.shuffle(temp)
for i in temp:
friends = int(random.normalvariate(4,2))
while(friends > 0):
graph.connect_grandchild(i)
friends -= 1
# Vaccinate
candidates = {i for i in range(N)}
vaccinated = random.sample(candidates,M)
##########
# Prints #
##########
def adj_print():
# Variables
print(graph.nodes, graph.edges, M)
print(P,I)
# Vaccinated
print(' '.join(map(str,vaccinated)))
# Edges
graph.print_adj()
adj_print()
#print('Source,Target')
#graph.print_edges()
#############################
# Optional degree histogram #
#############################
if sys.argv[3] == "hist":
import numpy as np
meow = np.array(graph.deg)
plt.xlabel("Outdegree")
plt.ylabel("Nodes")
plt.title(f"Mean: {meow.mean()} Std:{meow.std()}")
plt.hist(graph.deg)
plt.show()