-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
24 lines (20 loc) · 801 Bytes
/
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
class Graph(object):
def __init__(self, nodes):
"""Constructor for Graph
Arguments:
nodes {list} -- list of nodes of the graph
"""
self.nodes = nodes
self.matrix = [[float("inf") for _ in range(len(self.nodes))] for _ in range(len(self.nodes))]
def __repr__(self):
res = ""
#for node in self.nodes:
# res += "Node {} (index={}) with shift {}\n".format(node["name"], node["index"], node["shift"])
for matrix_line in self.matrix:
for element in matrix_line:
to_add = str(element) + "," + (" " * (5 -len(str(element))))
res += to_add
res += "\n"
return res
def add_edge(self, i, j, dist):
self.matrix[i][j] = dist