Transformer fundamentals
 
Loading...
Searching...
No Matches
main.py
Go to the documentation of this file.
1import os
2
3from graph_utils import Graph
4
5
6def main():
7
8 print("\n=== Test 1: Creating graph ===")
9 g1 = Graph()
10
11 # adding nodes
12 g1.add_node("A", label="Start", shape="box")
13 g1.add_node("B", label="Process", shape="ellipse")
14 g1.add_node("C", label="Decision", shape="diamond")
15 g1.add_node("D", label="End", shape="box")
16
17 # adding edges
18 g1.add_edge("A", "B", label="next")
19 g1.add_edge("B", "C", label="evaluate")
20 g1.add_edge("C", "D", label="yes")
21 g1.add_edge("C", "B", label="no", style="dashed")
22
23 # save to .dot file
24 g1.save_to_dot("test1_graph.dot")
25
26 # display the graph
27 print("Displaying graph with GraphViz (dot layout):")
28 g1.display_with_graphviz(layout="dot")
29
30 print("\nDisplaying graph with Matplotlib:")
31 g1.display_with_matplotlib()
32
33 print("\n=== Test 2: Loading graph from .dot file ===")
34 if os.path.exists("example_graph.dot"):
35 g2 = Graph()
36 if g2.load_from_dot("example_graph.dot"):
37 print(f"Number of nodes: {g2.get_node_count()}")
38 print(f"Number of edges: {g2.get_edge_count()}")
39 print(f"Nodes: {g2.get_nodes()}")
40 print(f"Edges: {g2.get_edges()}")
41
42 # Display with a different layout
43 print("\nDisplaying graph with GraphViz (neato layout):")
44 g2.display_with_graphviz(layout="neato")
45
46 print("\n=== Test 3: Creating a more complex graph ===")
47 g3 = Graph()
48
49 # Add nodes
50 for i in range(1, 11):
51 g3.add_node(f"Node{i}")
52
53 # Add edges to create a circular structure with some cross connections
54 for i in range(1, 10):
55 g3.add_edge(f"Node{i}", f"Node{i+1}")
56 g3.add_edge("Node10", "Node1") # Complete the circle
57
58 # Add some cross connections
59 g3.add_edge("Node1", "Node5")
60 g3.add_edge("Node3", "Node8")
61 g3.add_edge("Node7", "Node2")
62
63 # Display the graph with different layouts
64 print("\nDisplaying complex graph with GraphViz (dot layout):")
65 g3.display_with_graphviz(layout="dot")
66
67 print("\nDisplaying complex graph with GraphViz (circo layout):")
68 g3.display_with_graphviz(layout="circo")
69
70 print("\nDisplaying complex graph with GraphViz (fdp layout):")
71 g3.display_with_graphviz(layout="fdp")
72
73 print("\nDisplaying complex graph with Matplotlib:")
74 g3.display_with_matplotlib()
75
76
77if __name__ == "__main__":
78 main()
Attempting to create a custom Graph class that can load, manipulate, and visualize graphs from ....
Definition main.py:1
main()
Definition main.py:6