|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +--- |
| 4 | + |
| 5 | +# Java Graph Algorithms Visualizer |
| 6 | +*[Ray Jasson](mailto:holmesqueen2070@yahoo.com)*<br> |
| 7 | +*26/07/2020*<br> |
| 8 | + |
| 9 | +<br> |
| 10 | + |
| 11 | +## Background |
| 12 | + |
| 13 | +This is a dynamic and interactive graph algorithm visualizer written in Java that demonstrates the solution of the following problems: |
| 14 | + |
| 15 | +- Strong Connectivity |
| 16 | +- Cycle Detection |
| 17 | +- Shortest Path |
| 18 | + |
| 19 | +This visualizer is developed using [JavaFX SmartGraph library](https://github.com/brunomnsilva/JavaFXSmartGraph) written by [Bruno Silva](https://github.com/brunomnsilva). |
| 20 | + |
| 21 | +***The visualizer was implemented in Java 8 which includes JavaFX as bundle.*** |
| 22 | + |
| 23 | +<br> |
| 24 | + |
| 25 | +## Graph Representation in Java |
| 26 | + |
| 27 | +The data structure for graph is represented using an adjacency map. The adjacency map has a primary and a secondary structure. In the primary structure represented by the hash-based map, the names or IDs of vertices serve as keys and the associated vertices as values. The secondary structure maintains the incidence collection of the edges using two different map references: an *Outgoing Edges* hash-based map and an *Incoming Edges* hash-based map. In both hash-based maps, the opposite end vertices serve as the keys and the edges serve as the values. |
| 28 | + |
| 29 | +<p align="center"><img src="./pics/AdjacencyMap.png" width=85% height=85%></p> |
| 30 | +<p align="center"><i>Schematic Representation of an Adjacency Map</i></p> |
| 31 | + |
| 32 | +Refer to [AdjacencyMapDigraph.java](/src/graphvisualizer/graph/AdjacencyMapDigraph.java) for more details. |
| 33 | + |
| 34 | +<br> |
| 35 | + |
| 36 | +## Program Execution |
| 37 | + |
| 38 | +The visualizer has 5 functions: |
| 39 | + |
| 40 | +- Strong Connectivity |
| 41 | +- Cycle Detection |
| 42 | +- Shortest Path |
| 43 | +- Add Vertex |
| 44 | +- Reset Graph |
| 45 | + |
| 46 | +<p align="center"><img src="./pics/interface.png"></p> |
| 47 | +<p align="center"><i>User Interface of the Graph Algorithms Visualizer</i></p> |
| 48 | + |
| 49 | +<br> |
| 50 | + |
| 51 | +### Strong Connectivity |
| 52 | + |
| 53 | +[Tarjan's algorithm](https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm) is used to determine whether the directed graph is strongly connected by finding the strongly connected components (SCCs) of the graph. The implementation of Tarjan's algorithm is as follows: |
| 54 | + |
| 55 | +- **If the graph is strongly connected**<br> |
| 56 | +Print the resulting strongly-connected graph |
| 57 | +- **Else**<br> |
| 58 | +Generate random edges between vertices until the graph is strongly connected |
| 59 | + |
| 60 | +<p align="center"><img src="./gifs/StrongConnectivity.gif"></p> |
| 61 | +<p align="center"><i>Random edges are generated until the graph is strongly connected</i></p> |
| 62 | + |
| 63 | +Refer to [StrongConnectivity.java](/src/graphvisualizer/graphalgorithms/StrongConnectivity.java) for more details. |
| 64 | + |
| 65 | +<br> |
| 66 | + |
| 67 | +### Cycle Detection |
| 68 | + |
| 69 | +[Depth-First Search (DFS)](https://en.wikipedia.org/wiki/Depth-first_search) is used to detect the presence of a cycle in the graph. The implementation of DFS cycle detection algorithm is as follows: |
| 70 | + |
| 71 | +- **If the graph has a cycle**<br> |
| 72 | +Print the resulting cycle and its length |
| 73 | +- **Else**<br> |
| 74 | +Generate random edges between vertices until the graph has a cycle |
| 75 | + |
| 76 | +<p align="center"><img src="./gifs/CycleDetection.gif"></p> |
| 77 | +<p align="center"><i>Random edges are generated until the graph has a cycle</i></p> |
| 78 | + |
| 79 | +Refer to [CycleDetection.java](/src/graphvisualizer/graphalgorithms/CycleDetection.java) for more details. |
| 80 | + |
| 81 | +<br> |
| 82 | + |
| 83 | +### Shortest Path |
| 84 | + |
| 85 | +[Dijkstra's algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) is used to determine the shortest path between two end vertices in the graph. You can select a start vertex and an end vertex of the shortest path by double-clicking the vertices. The selected end vertices are shown in yellow. The implementation of Dijkstra's algorithm is as follows: |
| 86 | + |
| 87 | +- **If there is a path between the start vertex and the end vertex**<br> |
| 88 | +Print the shortest path between the end vertices and the path cost |
| 89 | +- **Else**<br> |
| 90 | +Generate random edges between vertices until a path is formed between the end vertices |
| 91 | + |
| 92 | +<p align="center"><img src="./gifs/ShortestPath.gif"></p> |
| 93 | +<p align="center"><i>Random edges are generated until the graph has a path between two end vertices</i></p> |
| 94 | + |
| 95 | +Refer to [ShortestPath.java](/src/graphvisualizer/graphalgorithms/ShortestPath.java) for more details. |
| 96 | + |
| 97 | +<br> |
| 98 | + |
| 99 | +### Add Vertex and Reset Graph |
| 100 | + |
| 101 | +- You can add up to maximum 5 additional vertices to the graph for testing and viewing the solution of the algorithms. |
| 102 | + |
| 103 | +<p align="center"><img src="./gifs/Add.gif"></p> |
| 104 | +<p align="center"><i>An example of adding 2 additional vertices to the graph, and performing strong connectivity algorithm</i></p> |
| 105 | + |
| 106 | +- You can reset the graph to its default state. |
| 107 | + |
| 108 | +Refer to [Main.java](/src/graphvisualizer/graphalgorithms/Main.java) for more details. |
| 109 | + |
| 110 | +<br> |
| 111 | + |
| 112 | +## References |
| 113 | + |
| 114 | +- Cormen, T. H., Leiserson, C., Rivest, R., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). Cambridge, Massachusetts, United States of America: MIT Press. |
| 115 | +- Goodrich, M. T., & Tamassia, R. (2014). Data Structures and Algorithms in Java (6th ed.). New Jersey: John Wiley. |
| 116 | +- [A generic (Java FX) graph visualization library](https://github.com/brunomnsilva/JavaFXSmartGraph) |
0 commit comments