-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgenerate_mmodel_graphml.py
149 lines (104 loc) · 5.57 KB
/
generate_mmodel_graphml.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
import networkx
def main():
nonstop = "nonstop.packetmodel.graphml"
generate_default_packetmodel(nonstop)
print_as_c_string(nonstop)
nonstop = "nonstop.streammodel.graphml"
generate_default_streammodel(nonstop)
print_as_c_string(nonstop)
nonstop = "nonstop.flowmodel.graphml"
generate_default_flowmodel(nonstop)
print_as_c_string(nonstop)
# save these files but dont print them
generate_delayed_packetmodel("delayed.packetmodel.graphml")
generate_delayed_streammodel("delayed.streammodel.graphml")
generate_delayed_flowmodel("delayed.flowmodel.graphml")
def generate_default_packetmodel(filename):
G = networkx.DiGraph()
# the "type" and "name" attributes are required on
# all nodes; the ids (eg 's0') can be whatever you want
# 'start' is a special keyword and must exist once
G.add_node('s0', type="state", name='start')
# non-start states can be given any name
G.add_node('s1', type="state", name='nonstop')
# the "type" and "weight" attributes are required on
# all edges; the ids must match the node ids
G.add_edge('s0', 's1', type='transition', weight=1.0)
G.add_edge('s1', 's1', type='transition', weight=1.0)
# for observations, 'name' must be one of these special keywords:
# '+': packet from client to server, or create new stream
# '-': packet from server to client, or create new stream
# 'F': end the generation process
G.add_node('o1', type="observation", name='+')
G.add_node('o2', type="observation", name='-')
# 'distribution' is required
# all parameters should be type double
# if 'uniform', ' then 'param_low' and 'param_high' are required
# if 'normal', ' then 'param_location' and 'param_scale' are required
# if 'exponential', then 'param_rate' is required
# if 'lognormal', ' then 'param_location' and 'param_scale' are required
# if 'pareto', ' then 'param_scale' and 'param_shape' are required
G.add_edge('s1', 'o1', type='emission', weight=0.5, distribution='exponential', param_rate=100.0)
G.add_edge('s1', 'o2', type='emission', weight=0.5, distribution='exponential', param_rate=100.0)
networkx.write_graphml(G, filename)
def generate_default_streammodel(filename):
G = networkx.DiGraph()
G.add_node('s0', type="state", name='start')
G.add_node('s1', type="state", name='default')
G.add_edge('s0', 's1', type='transition', weight=1.0)
G.add_edge('s1', 's1', type='transition', weight=1.0)
G.add_node('o1', type="observation", name='+')
G.add_edge('s1', 'o1', type='emission', weight=1.0, distribution='normal', param_location=10000000.0, param_scale=4000000.0)
networkx.write_graphml(G, filename)
def generate_default_flowmodel(filename):
G = networkx.DiGraph()
G.add_node('s0', type="state", name='start')
G.add_node('s1', type="state", name='default')
G.add_edge('s0', 's1', type='transition', weight=1.0)
G.add_edge('s1', 's1', type='transition', weight=1.0)
G.add_node('o1', type="observation", name='+')
G.add_edge('s1', 'o1', type='emission', weight=1.0, distribution='normal', param_location=60000000.0, param_scale=15000000.0)
networkx.write_graphml(G, filename)
def generate_delayed_packetmodel(filename):
G = networkx.DiGraph()
G.add_node('s0', type="state", name='start')
G.add_node('s1', type="state", name='default')
G.add_edge('s0', 's1', type='transition', weight=1.0)
G.add_edge('s1', 's1', type='transition', weight=1.0)
G.add_node('o1', type="observation", name='+')
G.add_node('o2', type="observation", name='-')
G.add_node('o3', type="observation", name='F')
G.add_edge('s1', 'o1', type='emission', weight=0.4999, distribution='exponential', param_rate=0.00035)
G.add_edge('s1', 'o2', type='emission', weight=0.4999, distribution='exponential', param_rate=0.00035)
G.add_edge('s1', 'o3', type='emission', weight=0.0002, distribution='normal', param_location=1000000.0, param_scale=1.0)
networkx.write_graphml(G, filename)
def generate_delayed_streammodel(filename):
G = networkx.DiGraph()
G.add_node('s0', type="state", name='start')
G.add_node('s1', type="state", name='default')
G.add_edge('s0', 's1', type='transition', weight=1.0)
G.add_edge('s1', 's1', type='transition', weight=1.0)
G.add_node('o1', type="observation", name='+')
G.add_node('o2', type="observation", name='F')
G.add_edge('s1', 'o1', type='emission', weight=0.9, distribution='normal', param_location=10000000.0, param_scale=4000000.0)
G.add_edge('s1', 'o2', type='emission', weight=0.1, distribution='normal', param_location=1000000.0, param_scale=1.0)
networkx.write_graphml(G, filename)
def generate_delayed_flowmodel(filename):
G = networkx.DiGraph()
G.add_node('s0', type="state", name='start')
G.add_node('s1', type="state", name='default')
G.add_edge('s0', 's1', type='transition', weight=1.0)
G.add_edge('s1', 's1', type='transition', weight=1.0)
G.add_node('o1', type="observation", name='+')
G.add_node('o2', type="observation", name='F')
G.add_edge('s1', 'o1', type='emission', weight=0.6, distribution='normal', param_location=30000000.0, param_scale=10000000.0)
G.add_edge('s1', 'o2', type='emission', weight=0.4, distribution='normal', param_location=1000000.0, param_scale=1.0)
networkx.write_graphml(G, filename)
def print_as_c_string(filename):
with open(filename, 'r') as inf:
for line in inf:
escaped = line.replace('"', '\\"')
print('"{}"'.format(escaped.rstrip()))
if __name__ == "__main__":
main()