Commit 546ef4a9 by Bertrand NÉRON

### 🎨 improve output by printing graph ascii art

parent 540cc43a
 ... ... @@ -4,14 +4,17 @@ from graph.traversing import BFS, DFS print("=============== UnDirected weight Graph =============") # We want to create a toy graph (not directed) to check our algos graph_schema = """ # no # / \ # 1/ \\3 # n1 n3 # | / | # 2| 15/|4 # n2 n4 # \ / # 5\ /6 # n5 """ print(graph_schema) nodes = [Node() for _ in range(6)] g = UnDirectedGraph() ... ... @@ -28,13 +31,18 @@ for n, p in BFS(g, nodes[0]): print(n, [str(e) for e in p]) print(f"distance = {sum([e.weight for e in p])}") print("=" * 20, "UnDirected weight Graph 2", "=" * 20) graph_schema = """ # no # / \ # 1/ \\3 # n1 n3 # | X | # 2| X |4 (3-2 15) (1-4 20) # n2 n4 # \ / # 5\ /6 # n5 """ print(graph_schema) g.add_edge(nodes[1], nodes[4], weight=20) ... ... @@ -52,6 +60,22 @@ for n, p in DFS(g, nodes[0]): print(f"distance = {sum([e.weight for e in p])}") print("=============== Directed weighted Graph =============") graph_schema = """ # n6 # 1/ \\6 # v V # n7 n9 # 2|^ ^|7 # | X | (10 -> 7 10) (8 -> 9 8) # v vv # n8 n10 # 5\ ^ # v/4 # n11 """ print(graph_schema) nodes += [Node() for _ in range(6)] g = DirectedGraph() ... ... @@ -65,17 +89,6 @@ g.add_edge(nodes[8], nodes[9], weight=8) g.add_edge(nodes[7], nodes[10], weight=9) g.add_edge(nodes[10], nodes[7], weight=10) # n6 # / \ # v V # n7 n9 # |^ ^| # | X | # v vv # n8 n10 # \ ^ # v/ # n11 print("Order", g.order()) print("Size", g.size()) ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!