forked from scoutsaachi/poxStartup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopogen.py
38 lines (31 loc) · 936 Bytes
/
topogen.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
import networkx
numNodes = 14
degree = 3
routing = {}
neighbors = {}
graph = networkx.random_regular_graph(degree, numNodes)
for i in range(numNodes):
neighbors[i] = list(graph[i].keys())
neighbors[i].sort()
print "Node " + str(i) + " connects to " + str(neighbors[i])
print "Routing Table:\n"
for source in range(numNodes):
routing[source] = {}
string = str(source) + ":\t"
for target in range (numNodes):
path = networkx.shortest_path(graph, source, target)
if len(path) == 1:
string += 'x\t'
routing[source][target] = -1
else:
string = string + str(path[1]) + '\t'
routing[source][target] = path[1]
print string
print """"
routing = {}
for source in range(14):
routing[source] = {}
"""
for source in range(14):
for target in range(14):
print "\trouting[" + str(source) + "][" + str(target) + "] = " + str(routing[source][target])