I'm trying to find a simple Java API for creating graph relationships. It should have some functionality like addEdge()
, addNode()
, isConnected(node1, node2)
, findPaths(node1, node2)
, etc. I need no UI, just logic.
I found a bunch of academic projects, but none seems to be "The Definitive Graph API".
Does anyone know about such an API?
Usually, we implement graphs in Java using HashMap collection. HashMap elements are in the form of key-value pairs. We can represent the graph adjacency list in a HashMap. A most common way to create a graph is by using one of the representations of graphs like adjacency matrix or adjacency list.
JGraph is an interactive Java-based diagramming and graph visualization library. The maintainers of JGraph have a product family that includes a Java Swing library (open-source), a JavaScript library (proprietary commercial), as well as other technologies.
The Graph class is implemented using HashMap in Java. As we know HashMap contains a key and a value, we represent nodes as keys and their adjacency list in values in the graph. Illustration: An undirected and unweighted graph with 5 vertices.
JGraphT sounds like what you're after.
JGraphT is a free Java graph library that provides mathematical graph-theory objects and algorithms. JGraphT supports various types of graphs.
Their API can create graphs from various input and also supports creating graphs using addVertex
, addEdge
. They support finding shortest paths using various well know algorithms such as Bellman-Ford and Dijkstra They also have a complete javadoc available online.
JDLS is a great library for Graphs and Datastructures in general. You could also use the Grappa library. Its advantage is that it can use the graphViz libraries for graph layouting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With