Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a simple Java API for creating graphs (edges + nodes) [closed]

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?

like image 610
David Koelle Avatar asked Apr 13 '09 19:04

David Koelle


People also ask

How do you represent a graph in Java?

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.

What is JGraph?

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.

Does Java have a graph class?

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.


2 Answers

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.

like image 114
Ben S Avatar answered Oct 22 '22 15:10

Ben S


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.

like image 37
paweloque Avatar answered Oct 22 '22 16:10

paweloque