Good Java graph algorithm library?

212,789

Solution 1

If you were using JGraph, you should give a try to JGraphT which is designed for algorithms. One of its features is visualization using the JGraph library. It's still developed, but pretty stable. I analyzed the complexity of JGraphT algorithms some time ago. Some of them aren't the quickest, but if you're going to implement them on your own and need to display your graph, then it might be the best choice. I really liked using its API, when I quickly had to write an app that was working on graph and displaying it later.

Solution 2

Summary:

Solution 3

Check out JGraphT for a very simple and powerful Java graph library that is pretty well done and, to allay any confusion, is different than JGraph. Some sample code:

UndirectedGraph<String, DefaultEdge> g =
        new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);

    String v1 = "v1";
    String v2 = "v2";
    String v3 = "v3";
    String v4 = "v4";

    // add the vertices
    g.addVertex(v1);
    g.addVertex(v2);
    g.addVertex(v3);
    g.addVertex(v4);

    // add edges to create a circuit
    g.addEdge(v1, v2);
    g.addEdge(v2, v3);
    g.addEdge(v3, v4);
    g.addEdge(v4, v1);

Solution 4

JUNG is a good option for visualisation, and also has a fairly good set of available graph algorithms, including several different mechanisms for random graph creation, rewiring, etc. I've also found it to be generally fairly easy to extend and adapt where necessary.

Solution 5

Apache Commons offers commons-graph. Under http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/ one can inspect the source. Sample API usage is in the SVN, too. See https://issues.apache.org/jira/browse/SANDBOX-458 for a list of implemented algorithms, also compared with Jung, GraphT, Prefuse, jBPT

Google Guava if you need good datastructures only.

JGraphT is a graph library with many Algorithms implemented and having (in my oppinion) a good graph model. Helloworld Example. License: LGPL+EPL.

JUNG2 is also a BSD-licensed library with the data structure similar to JGraphT. It offers layouting algorithms, which are currently missing in JGraphT. The most recent commit is from 2010 and packages hep.aida.* are LGPL (via the colt library, which is imported by JUNG). This prevents JUNG from being used in projects under the umbrella of ASF and ESF. Maybe one should use the github fork and remove that dependency. Commit f4ca0cd is mirroring the last CVS commit. The current commits seem to remove visualization functionality. Commit d0fb491c adds a .gitignore.

Prefuse stores the graphs using a matrix structure, which is not memory efficient for sparse graphs. License: BSD

Eclipse Zest has built in graph layout algorithms, which can be used independently of SWT. See org.eclipse.zest.layouts.algorithms. The graph structure used is the one of Eclipse Draw2d, where Nodes are explicit objects and not injected via Generics (as it happens in Apache Commons Graph, JGraphT, and JUNG2).

Share:
212,789

Related videos on Youtube

Nick Fortescue
Author by

Nick Fortescue

Software developer

Updated on July 27, 2020

Comments

  • Nick Fortescue
    Nick Fortescue almost 4 years

    Has anyone had good experiences with any Java libraries for Graph algorithms. I've tried JGraph and found it ok, and there are a lot of different ones in google. Are there any that people are actually using successfully in production code or would recommend?

    To clarify, I'm not looking for a library that produces graphs/charts, I'm looking for one that helps with Graph algorithms, eg minimum spanning tree, Kruskal's algorithm Nodes, Edges, etc. Ideally one with some good algorithms/data structures in a nice Java OO API.

  • Thomas Owens
    Thomas Owens over 15 years
    What were your personal thoughts with prefuse? At my last job, a project started to use it, but ended up with a 90%+ rewritten (and optimized, with additions of new features) version of prefuse.
  • Jonik
    Jonik over 15 years
    I've used yFiles for visualisation of interdependencies between data items (as part of a commercial software platform). I didn't really use any graph analysis algorithms, but check if the y.algo package has what you need: yworks.com/products/yfiles/doc/api
  • Nick Fortescue
    Nick Fortescue about 15 years
    Thanks for this, I'd never come across it. Are you using it?
  • mr.sverrir
    mr.sverrir about 15 years
    Yes, I am using it. I started using it maybe 4 years ago. So far so good, I just wish there was a port of that for .NET, too.
  • T9b
    T9b over 12 years
    You misunderstood the question: it is about the kind of graphs that have nodes and edges, not the kind that has pies and bars.
  • Ross Judson
    Ross Judson over 12 years
    Sadly, the jdsl.org page seems to be a spam page now.
  • mr.sverrir
    mr.sverrir over 12 years
    I have updated the link in the original post. Thanks.
  • SoftwareSavant
    SoftwareSavant over 11 years
    Alot of those are extremely complicated... Using factory Methods and so forth. I just need something simple to prep for an interview. Any ideas?
  • Frodo Baggins
    Frodo Baggins about 11 years
    JGraph does have an analysis package now that includes a range of analysis functions, jgraph.github.com/mxgraph/java/docs/index.html.
  • koppor
    koppor almost 11 years
    yFiles is not opensource, but offers commercial licenses
  • koppor
    koppor almost 11 years
    Packages hep.aida.* are LGPL (acs.lbl.gov/software/colt/license.html). This is imported via colt (jung.sourceforge.net/download.html). This prevents JUNG from being used in projects under the umbrella of ASF and ESF. Maybe one should use the github fork github.com/rortian/jung2 and remove that dependency. github.com/rortian/jung2/commit/… is mirroring the last CVS commit. The current commits seem to remove visualization functionality.
  • Someone Somewhere
    Someone Somewhere about 8 years
  • Maytham Fahmi
    Maytham Fahmi about 7 years
    If these are complicated than what kind of job you are looking for
  • Yacino
    Yacino almost 7 years
    There is no released since 2010, I think that this project is abandoned
  • mosh
    mosh almost 7 years
    Graph algorithms are explained here geeksforgeeks.org/graph-data-structure-and-algorithms with simple code
  • Vishrant
    Vishrant over 6 years
    is there any Neo4J client (java client) where you can visualize it?