Good Java graph algorithm library? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
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.

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.

Summary:
JGraphT if you are more interested in data structures and algorithms.
JGraph if your primary focus is visualization.
Jung, yWorks, and BFG are other things people tried using.
Prefuse is a no no since one has to rewrite most of it.
Google Guava if you need good datastructures only.
Apache Commons Graph. Currently dormant, but provides implementations for many algorithms. See https://issues.apache.org/jira/browse/SANDBOX-458 for a list of implemented algorithms, also compared with Jung, GraphT, Prefuse, jBPT

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);

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.

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).

http://neo4j.org/ is a graph database that contains many of graph algorithms and scales better than most in-memory libraries.

In a university project I toyed around with yFiles by yWorks and found it had pretty good API.

check out Blueprints:
Blueprints is a collection of interfaces, implementations, ouplementations, and test suites for the property graph data model. Blueprints is analogous to the JDBC, but for graph databases. Within the TinkerPop open source software stack, Blueprints serves as the foundational technology for:
Pipes: A lazy, data flow framework
Gremlin: A graph traversal language
Frames: An object-to-graph mapper
Furnace: A graph algorithms package
Rexster: A graph server

http://incubator.apache.org/hama/ is a distributed scientific package on Hadoop for massive matrix and graph data.

JDSL (Data Structures Library in Java) should be good enough if you're into graph algorithms - http://www.cs.brown.edu/cgc/jdsl/

For visualization our group had some success with prefuse. We extended it to handle architectural floorplates and bubble diagraming, and it didn't complain too much. They have a new Flex toolkit out too called Flare that uses a very similar API.
UPDATE:
I'd have to agree with the comment, we ended up writing a lot of custom functionality/working around prefuse limitations. I can't say that starting from scratch would have been better though as we were able to demonstrate progress from day 1 by using prefuse. On the other hand if we were doing a second implementation of the same stuff, I might skip prefuse since we'd understand the requirements a lot better.

Try Annas its an open source graph package which is easy to get to grips with
http://annas.googlecode.com

It's also good to be convinced that a Graph can be represented as simply as :
class Node {
int value;
List<Node> adj;
}
and implement most the algorithms you find interesting by yourself. If you fall on this question in the middle of some practice/learning session on graphs, that's the best lib to consider. ;)
You can also prefer adjacency matrix for most common algorithms :
class SparseGraph {
int[] nodeValues;
List<Integer>[] edges;
}
or a matrix for some operations :
class DenseGraph {
int[] nodeValues;
int[][] edges;
}

I don't know if I'd call it production-ready, but there's jGABL.

If you need performance, you might take a look at Grph. The library is developed in the French University and CNRS/Inria.
http://www.i3s.unice.fr/~hogie/grph/
The project is active and reactive support is provided!

Instructional graph algorithm implementations in java could be found here (by prof. Sedgewick et al.):
http://algs4.cs.princeton.edu/code/
I was introduced to them while attending these exceptional algorithm courses on coursera (also taught by prof. Sedgewick):
https://www.coursera.org/course/algs4partI
https://www.coursera.org/course/algs4partII

If you are actually looking for Charting libraries and not for Node/Edge Graph libraries I would suggest splurging on Big Faceless Graph library (BFG). It's way easier to use than JFreeChart, looks nicer, runs faster, has more output options, really no comparison.

JGraph from http://mmengineer.blogspot.com/2009/10/java-graph-floyd-class.html
Provides a powerfull software to work with graphs (direct or undirect). Also generates Graphivz code, you can see graphics representations. You can put your own code algorithms into pakage, for example: backtracking code. The package provide some algorithms: Dijkstra, backtracking minimun path cost, ect..

Related

data structure for Graph in java

i am looking to implement a algorithm for the Travel Salesman Problem. I want to model the solution using the graph , in this a vertex will represent a city and edge will represent the cost from one city to another.
At any point i have to compute cost from one city to another like
(cityA, cityB)--->cost
What data structure in java should i use for graph?
And what kind of GUI tool or library can i use to represent a graph ?
If you are free to use external libraries, JGraphT is easy to use.
Why a graph, of course. Take a look at JUNG.
depending on the size of your problem and your hardware, you might want to take a look at nosql graph databases like: http://neo4j.org/
most of them are easy to handle and some (like neo4j) provide a graph visualization which is nice for debugging purpose.
if you want to develop with as much performance as possible, you might have to create your own simple graph format. Most of the told ones are slow due to a lot of overhead (generics etc.)

Java Graph Visualisation Library: Nodes with multiple connect points

Can anyone recommend a Java Graph Visualisation library in which graph nodes can be rendered with multiple connect points?
For example, supposing a graph node represents a processor that takes input from two sources and produces output. This would be visualised as 3 vertices. However, clearly each vertex has a defined role in the workflow and therefore ideally my node would appear with 3 distinct connection points that the user could attach vertices to.
I've taken a look at JUNG but I don't think it will suit my needs.
Any recommendations welcome; either on specific libraries or alternative approaches I can take.
You could try JGraph's java library
JGRAPH
It has a good amount of functionality and I have used it with success before. The only thing is that the documentation is a bit lacking, but if you read through some examples and code its pretty good when you get the hang of it.
Take a look at JGraph (http://www.jgraph.com/). I used jgraph-5.14.0.0 for a similar project before. Here are the graphs that I made for another project: https://github.com/eamocanu/spellcheck.graph/tree/master/graph%20photos

java library for high-performance graph/network data structure

Well, is there a high-performance graph library for working with primitivies, without those generics/autoboxing overheads? For double lists you may use trove, for linear algebra you may use netlib-java (examples for you to better understand the point of my interest in this question).
As for Graphs/Networks: all the libs I've found use generics and should be not that performant. I may as well do some tests for that, but I believe that heap-managed network link weights would be inferior to double[] with some bit offsets to get the index for i and j. The usage scenario: there're hundreds of such networks (most of them sparse) of size 4k*4k, there's some genetic optimization running over that set of networks, which do some flow/min route estimations for each specimen.
So, there're: JGraphT, JUNG, ANNAS, JDSL (the links lead to the APIs/code samples which expose the miserable Java Generics/Object wrappers in all of them). Are there any Trove-ish alternatives? I'd already created some simplistic implementation, but just decided to look around to avoid inventing the proper bicycle...
Any opinions, suggestions?
Thanks,
Anton
PS: Please don't start on performance of generics-laden Java code, at least without linking to some decent benchmark, ok? ;)
You may use some sparse matrix with row compression. Not best and not specialized, but you may build upon it.
Well, there're some generic sparse matrix implementations which do not mess with generics and one rather solid performance benchmark:
java-matrix-benchmark on google code
ujmp related overview
The most convincing is MTJ's sparse matrix.
Please add answers to the question if you have any suggestions or updates. I'll accept any better ideas. Thanks.
If you need performant data structures, you should check the fastutil project, which is an efficient both in time and memory implementation of the Java Collection Framework. Performance is achieved also avoiding boxing and unboxing primitive types.
Fastutil are very efficient data structure. If you need a graph ADT implementation, you could check this, which is an efficient in memory graph implementation, based on the fastutil.
The project was part of my MS thesis, which was about community detection in big graphs.
Hope it helps!

Geometry library for Java [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Is there any geometry library available for Java? I'm looking for solution to get an intersection point(s) between two geometry objects.
JTS is your best free open source option. The method you are looking for in JTS is here
As far as commercial options, you have ESRI's Java JNI version of their ArcObjects library which has a very robust Geometry Library. The interface on ESRI's library is called ITopologicalOperator
If all you are trying to do is Geometric operations, JTS is your best option - it is an excellent library which has many ports to different languages. If, on the other hand, you are looking for an entire GIS system that does complex symbology, supports GIS workflows and multiuser editing, printing, etc etc, then I would start looking at the ESRI libraries.
The package you should look at it java.awt.geom, which is part of the JDK.
In particular check out the java.awt.geom.Area class, which allows you to perform intersection operations between two Shapes.
EDIT
Finding the intersection points is non-trivial as far as I know, as you need to apply a different algorithm depending on the shapes you're analysing. For example, the algorithm for the intersection between two circles is given here, whereas the algorithm for calculating the intrsection between two Bezier curves is completely different (here).
EDIT 2
One suggestion: You could look into the PathIterator class, which returns a description of a shape's path as a sequence of segments. In particular check out FlatteningPathIterator, which will collapse any curves into multiple straight lines. Once your path has been reduced to straight lines, calculating the intersection points will be simple ... although obviously this is an approximation in cases where your shape contains curves.
For non-GIS purposes I may suggest javaGeom library. It uses the Euclidean abstraction of geometry which most of the people know from school. There's no recent activity on this project, but I find it well structured and easy to use. They say it supports boolean operations, but never tested how well they work. There is a pretty feature-rich testing application named Euclid, which is developed from the same author.
You can try to use it, but only if you are sure it's gonna work for you.
http://sourceforge.net/projects/geom-java/
I found that JTS has changed hands, or changed home sites, or something. A newer version can be found here: http://maven.geotoolkit.org/com/vividsolutions/jts/1.10/
Edit: This might be its new home page: http://tsusiatsoftware.net/jts/main.html
Edit: Moved again! https://locationtech.github.io/jts/
JTS - Java Topology Suite - is the best.
http://www.vividsolutions.com/jts/jtshome.htm
It is free, fast, robust, and can handle degenerate intersections.

Image Classification Algorithms Using Java

My goal is to implements different image classification methods to show how they function and the advantages and disadvantages behind such methods. The ones I want to try and implement using Java include;
Minimum distance classifier
k-nearest neighbour classifier.
I was wondering what can be used to accomplish my task that already exists in Java so that I can alter the way the algorithms operates.
Although not entirely sure this is what you are looking for (sorry, your question is a bit unclear), if what you want is a library / system to help you with the classification part of the work, then you may want to look at Weka (http://www.cs.waikato.ac.nz/ml/weka/), in my opinion the best Java library for data mining experimentation.
If, instead, you are looking for algorithms that would allow you to analyze images in order to extract features that can, in turn, be used to perform the classification, you may want to start with targeted descriptions of such algorithms in Java, such as those found in the nice on-line book Java Image Processing Cookbook by Rafael Santos; here's a direct link to the section "A Brief Tutorial on Supervised Image Classification".
You can also use RapidMiner with IMMI (IMage MIning) extension:
http://www.burgsys.com/mumi-image-mining-community.php
For image classification you can use for example global feature extraction and then use some classification algorithm (e.g. Artificial Neural Networks).

Categories

Resources