def path_map(): g = Graph() print(type(g)) a = g.add_vertex('a') b = g.add_vertex("b") c = g.add_vertex("c") d = g.add_vertex("d") e = g.add_vertex("e") f = g.add_vertex("f") g.add_edge(a, c, 1) g.add_edge(c, a, 1) g.add_edge(b, c, 2) g.add_edge(c, b, 2) g.add_edge(b, e, 3) g.add_edge(e, b, 3) g.add_edge(c, d, 5) g.add_edge(d, c, 5) g.add_edge(d, e, 4) g.add_edge(e, d, 4) return g
def graph(self): graph = Graph() # Create nodes vertex_1 = graph.add_vertex(1) vertex_2 = graph.add_vertex(2) vertex_3 = graph.add_vertex(3) vertex_4 = graph.add_vertex(4) vertex_5 = graph.add_vertex(5) vertex_6 = graph.add_vertex(6) # Create edges graph.add_edge(vertex_1, vertex_2, 150) graph.add_edge(vertex_2, vertex_1, 150) graph.add_edge(vertex_1, vertex_3, 82) graph.add_edge(vertex_3, vertex_1, 82) graph.add_edge(vertex_2, vertex_3, 99) graph.add_edge(vertex_3, vertex_2, 99) graph.add_edge(vertex_2, vertex_4, 42) graph.add_edge(vertex_4, vertex_2, 42) graph.add_edge(vertex_3, vertex_4, 105) graph.add_edge(vertex_4, vertex_3, 105) graph.add_edge(vertex_3, vertex_5, 37) graph.add_edge(vertex_5, vertex_3, 37) graph.add_edge(vertex_3, vertex_6, 26) graph.add_edge(vertex_6, vertex_3, 26) graph.add_edge(vertex_5, vertex_6, 250) graph.add_edge(vertex_6, vertex_5, 250) graph.add_edge(vertex_4, vertex_6, 73) graph.add_edge(vertex_6, vertex_4, 73) return graph
def test_graph(): graph = Graph() for num in range(6): graph.add_vertex(num) print(graph.vertices) graph.add_edge(0, 1, 5) graph.add_edge(0, 5, 2) graph.add_edge(1, 2, 4) graph.add_edge(2, 3, 9) graph.add_edge(3, 4, 7) graph.add_edge(3, 5, 3) graph.add_edge(4, 0, 1) graph.add_edge(5, 4, 8) graph.add_edge(5, 2, 1) for vertex in graph: for connection in vertex.get_connections(): print(f"{vertex.get_id()} connected to {connection.get_id()}")