Graph
A graph data structure that supports nodes of any datatype.
Any new node is given an ID upon creation, which is used to build an adjacency list. The class maintains internal maps between ID's and nodes and vice versa.
Example usage:
val graph = Graph()
graph.addEdge("A", "B", 5.0)
graph.addEdge("A", "C", 2.0)
graph.addEdge("C", "B", 1.0)
graph.dijkstra("A", "B")
// NOTE: visualizeGraph() requires the smartgraph.css and smartgraph.properties files to be added to the root of your project.
graph.visualizeGraph() // Find the needed files here: https://github.com/Norskeaksel/GraphMateKTParameters
Indicates whether it uses weighted or unweighted edges. Traversal algorithms like BFS and DFS operate on unweighted graphs, while minimum cost algorithms like Dijkstra, Floyd Warshall and Prims are based on weighted edges
Functions
Overload of fun bfs(startNodes: List
Performs a Breadth-First Search, which finds the shortest path from the starting node to all other nodes, assuming the graph is unweighted (all edges have a weight of 1.0) It stores results that can be retrieved with the following functions:
Retrieves a list of all visited nodes on the order they were visited during the last search operation (DFS, BFS, Dijkstra).
Retrieves the shortest distance between two nodes in the graph.
Retrieves the distance to the specified node from the starting node of the most recent search operation (BFS, Dijkstra).
Executes the Floyd-Warshall algorithm on the graph to compute the shortest paths between all pairs of nodes.
Checks if the target node was found during the most recent search operation (BFS, Dijkstra).
Retrieves the node that is the farthest from the starting node in the most recent search operation (BFS, Dijkstra).
Retrieves the maximum distance from the starting node to any other node of the most recent search operation (BFS, Dijkstra).
Computes the Minimum Spanning Tree (MST) of the graph using Prim's algorithm.
Retrieves a list the neighboring nodes of the specified node.
Removes the edge(s) between two nodes in the graph.
Clears the search results stored in the graph.
Identifies groups where each node is reachable from every other node in the group.
Builds an order of nodes so that the first nodes has no outgoing edges, then nodes with edges pointing to these and so on, assuming the graph is a Directed Acyclic Graph (DAG). This is done by running a DFS from each node and ordering the nodes by descending depth (post-order).
Retrieves a (unordered) list of all visited nodes during any non-reset search operation (DFS, BFS, Dijkstra).
Visualizes the graph with Bruno Silva's JavaFXSmartGraph library.