-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (54 loc) · 2.31 KB
/
main.py
File metadata and controls
71 lines (54 loc) · 2.31 KB
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
import pandas as pd
#-GESTIONE DELLE ECCEZIONI
#-IMPLEMENTAZIONE PER SCOPRIRE AUTOMATICAMENTE I NEIGHBORS
#-IMPLEMENTAZIONE REALISTICA DEL FUNZIONAMENTO DEL PROTOCOLLO OSFP CON i DR BDR E DROTHERS
#-RISOLVERE MAPPATURA CON I NEIGHBOR
class Graph():
def __init__(self, verteces = []):
self.verteces = verteces
def discoverPaths(self, startingPoint): #iterating over nodes
for index in self.verteces:
for neighbor in index.neighbors:
z=startingPoint.routeTable.at[(index.id), "Cost"]
y=index.routeTable.at[(neighbor.id), "Cost"]
w = startingPoint.routeTable.at[(neighbor.id), "Cost"]
sumCost = z + y
if (sumCost<w):
startingPoint.routeTable.at[(neighbor.id), "Cost"] = sumCost
neighbor.routeTable.at[(startingPoint.id), "Cost"] = sumCost
class Vertex():
'''
define one single vertex of the map
'''
def __init__(self, name, id, file,): #(... , graph)
'''
in a network, id in four-dotted format
'''
#self.obj_graph = Graph(graph)
self.name = name
self.id = id
self.routeTable = pd.read_csv(file)
'''if the cost is not 0 it is not the starting point itself, and if isn't 255
the node is not directly connected and it is not the starting point itself'''
def gen():
for x in range(self.routeTable.shape[0]):
if self.routeTable.at[x, "Cost"] not in (0, 255):
yield globals()[self.routeTable.at[x, "NodeID"]]
self.neighbors = gen()
'''
for bugging reason is useful to sort the neighbors in crescent mode to
iterate the graph. In this case this step is omitted because already sorted,
but must be done everytime
''' #self.neighbors.sort()
#def __lt__(self, other): #used to sort the neighbors
# return self.id < other.id
A = Vertex("A", 0, "atab.csv")
B = Vertex("B", 1, "btab.csv")
C = Vertex("C" ,2, "ctab.csv")
D = Vertex("D", 3, "dtab.csv")
E = Vertex("E", 4, "etab.csv")
F = Vertex("F", 5,"ftab.csv")
G = Vertex("G", 6, "gtab.csv")
grafo = Graph([A,B,C,D,E,F,G])
grafo.discoverPaths(C)
print(C.routeTable)