Int Graph
A graph data structure specialized for integer nodes ranging from 0 to size-1.
The IntGraph class behaves a lot like the Graph class when used with integers like the example above. However, * it's more performant, because it does not need to maintain an internal mapping between the nodes and their indexes in the adjacency list. The obvious drawback being it only supports integer nodes.
Example usage:
val intGraph = IntGraph(3) // Creates a graph with nodes 0, 1 and 2
graph.addEdge(0, 1, 5.0)
graph.addEdge(0, 2, 2.0)
graph.addEdge(2, 1, 1.0)
graph.dijkstra(0, 1)
// 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
The number of nodes in the graph. Nodes are represented as integers from 0 to size-1. This cannot be altered later
Indicates whether the graph uses weighted or unweighted 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.