Hi!
As in the subject: I'm looking for the *simplest* working code, demonstrating graph visualization and based on JUNG 2 library.
I reviewed jung2 samples but there is a lot of sophisticated details that make it unclear to me.
Can anyone help me?
Adam
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Adam, I put together a JUNG2 tutorial and its referenced in the Wiki and can be found at: http://www.grotto-networking.com/JUNG/ Here is one example from the tutorial of visualization but no interactivity. The examples add more interactivity as they progress. Also illustrated are non-visual examples. The PDF file (or OpenOffice file) contains explanations. Note that I just tried this against the latest (as of 12/17/07) JUNG2 CVS repository. BTW does anyone out there have a graph coloring algorithm compatible with JUNG2? Or if somebody can point me to a strongly recommended algorithm I'll implement it.
/**
*
* @author Dr. Greg M. Bernstein
*/
public class SimpleGraphView {
Graph<Integer, String> g;
/** Creates a new instance of SimpleGraphView */
public SimpleGraphView() {
// Graph<V, E> where V is the type of the vertices and E is the type of the edges
g = new SparseMultigraph<Integer, String>();
// Add some vertices. From above we defined these to be type Integer.
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)3);
// Note that the default is for undirected edges, our Edges are Strings.
g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
g.addEdge("Edge-B", 2, 3);
}
public static void main(String[] args) {
SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here
// The Layout<V, E> is parameterized by the vertex and edge types
Layout<Integer, String> layout = new CircleLayout(sgv.g);
layout.setSize(new Dimension(300,300)); // sets the initial size of the layout space
// The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size
As for your request: you know that graph coloring's NP-hard, right? :)
(That is: I don't have an algorithm for that...and while, given time, I might be able to put something together that would work most of the time, in general no known approach is guaranteed to be better than a BFI (Brute Force and Ignorance) approach.)
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There's a JUNG 1.x sample that does precisely what you want (SimpleGraphDraw) that we apparently haven't migrated over to JUNG 2.0 that you can find here:
Looks like porting it should be trivial; I believe that the only change that you'd have to make is that you'd have to either supply vertex and edge Factories (and a Graph instance or Factory) to the PajekNetReader.load() call, or you could build a graph "by hand" as in Greg's example.
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Gregbern and Joshua,
Thanks for the help. It seems to be what I needed. Anyway there has arised yet another problem that I can't resolve: When I added to my code following lines (copied from Joshua sample http://tiny.pl/pmfs\):...
...the editor (I use NetBeans 6.0 IDE) generated following error messages:
"cannot find symbol, symbol: class PluggableRenderer, location: package edu.uci.ics.jung.visualization"
and
"cannot find symbol, symbol: class SpringLayout, location: package edu.uci.ics.jung.visualization"
respectively. I added all jung2 jars to the project libraries so I don't know what's wrong.
Sorry if I ask you the trivial questions (and being slightly off topic) but it stops me.
BTW: Do you intend to build a library (package) providing the possibility of graph decomposition?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The import specifications are incorrect: that's not where PluggableRenderer and SpringLayout live. I assume that NetBeans has a tool to automatically find the necessary imports (Eclipse does); if not you may have to break down and read the online Javadocs. :)
In general, when porting from JUNG 1.x to JUNG 2.0, do not assume that the packages are the same. The JUNG 1.x packages are rather a mess in places, and we're trying to clean things up in JUNG 2.0.
(Also, auto-adding imports is your friend in Java in general, if your IDE supports it.)
Graph decompositions: if you mean "identifying weak components", that's already there: check out WeakComponentClusterer. If you don't...please be more specific: on what basis are you decomposing the graph?
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yeah, I migrated to Eclipse and then tried to use quick fix to remove the error "PluggableRenderer cannot be resolved to a type". The hints are to change the class to either PluggableRendererDemo or PluggableRenderContext (I could also create my own class :P). At last I changed it to BasicRenderer (I'm hardly experienced in Java so it looks like playing dice).
Last problem is the error "Cannot instantiate the type VisualizationViewer<V,E>".
What is the problem?
Adam
The state of my code (after all above changes) is:
[CODE]
JFrame jf = new JFrame();
VisualizationViewer<V,E> vv = new VisualizationViewer<V,E>(new SpringLayout<V,E>(this.G), new BasicRenderer<V,E>());
jf.getContentPane().add((Component) vv);
Make sure that the SWT visualization jar is not in your classpath; you're probably picking that up, and some of the class names (VisualizationViewer in particular) conflict with the AWT/Swing visualization jar classes.
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Whoops, I should have worded that as a favorite heuristic or approximate algorithm for graph coloring. I was trolling the ACM digital library a quite a few approximate algorithms come up. Just wondering if anyone out there had a favorite.
Regards
Greg
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
[code]
JFrame jf = new JFrame();
SpringLayout<V,E> sl = new SpringLayout<V,E>(this.G);
VisualizationViewer<V,E> vv =new VisualizationViewer<V,E>(sl, new Dimension(300,300));
jf.getContentPane().add((Component) vv);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
[/code]
I removed jung SWT visualization jar as you adviced me, but it didn't help. So, instead of VisualizationViewer(Layer,Renderer) I used VisualizationViewer(Layer,Dimension).
Does it mean that Renderer object is not always nedded to paint the graph?
You need to read the documentation. I apologize if I led you astray by pointing you to a JUNG 1.x demo and saying that the porting to 2.0 should be easy...but I can't walk you through everything. Please see the docs for VisualizationViewer to see what arguments you can give its constructor.
By default VisualizationViewer creates the Renderer object for you.
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi!
As in the subject: I'm looking for the *simplest* working code, demonstrating graph visualization and based on JUNG 2 library.
I reviewed jung2 samples but there is a lot of sophisticated details that make it unclear to me.
Can anyone help me?
Adam
Hi Adam, I put together a JUNG2 tutorial and its referenced in the Wiki and can be found at: http://www.grotto-networking.com/JUNG/ Here is one example from the tutorial of visualization but no interactivity. The examples add more interactivity as they progress. Also illustrated are non-visual examples. The PDF file (or OpenOffice file) contains explanations. Note that I just tried this against the latest (as of 12/17/07) JUNG2 CVS repository. BTW does anyone out there have a graph coloring algorithm compatible with JUNG2? Or if somebody can point me to a strongly recommended algorithm I'll implement it.
Regards
Greg B.
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import java.awt.Dimension;
import javax.swing.JFrame;
/**
*
* @author Dr. Greg M. Bernstein
*/
public class SimpleGraphView {
Graph<Integer, String> g;
/** Creates a new instance of SimpleGraphView */
public SimpleGraphView() {
// Graph<V, E> where V is the type of the vertices and E is the type of the edges
g = new SparseMultigraph<Integer, String>();
// Add some vertices. From above we defined these to be type Integer.
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)3);
// Note that the default is for undirected edges, our Edges are Strings.
g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
g.addEdge("Edge-B", 2, 3);
}
public static void main(String[] args) {
SimpleGraphView sgv = new SimpleGraphView(); //We create our graph in here
// The Layout<V, E> is parameterized by the vertex and edge types
Layout<Integer, String> layout = new CircleLayout(sgv.g);
layout.setSize(new Dimension(300,300)); // sets the initial size of the layout space
// The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size
JFrame frame = new JFrame("Simple Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
}
Greg:
Thanks for your response to Adam.
As for your request: you know that graph coloring's NP-hard, right? :)
(That is: I don't have an algorithm for that...and while, given time, I might be able to put something together that would work most of the time, in general no known approach is guaranteed to be better than a BFI (Brute Force and Ignorance) approach.)
Joshua
Adam:
There's a JUNG 1.x sample that does precisely what you want (SimpleGraphDraw) that we apparently haven't migrated over to JUNG 2.0 that you can find here:
http://jung.cvs.sourceforge.net/jung/jung/src/samples/graph/SimpleGraphDraw.java?revision=1.9&view=markup
Looks like porting it should be trivial; I believe that the only change that you'd have to make is that you'd have to either supply vertex and edge Factories (and a Graph instance or Factory) to the PajekNetReader.load() call, or you could build a graph "by hand" as in Greg's example.
Joshua
Gregbern and Joshua,
Thanks for the help. It seems to be what I needed. Anyway there has arised yet another problem that I can't resolve: When I added to my code following lines (copied from Joshua sample http://tiny.pl/pmfs\):...
import edu.uci.ics.jung.visualization.PluggableRenderer;
import edu.uci.ics.jung.visualization.SpringLayout;
...the editor (I use NetBeans 6.0 IDE) generated following error messages:
"cannot find symbol, symbol: class PluggableRenderer, location: package edu.uci.ics.jung.visualization"
and
"cannot find symbol, symbol: class SpringLayout, location: package edu.uci.ics.jung.visualization"
respectively. I added all jung2 jars to the project libraries so I don't know what's wrong.
Sorry if I ask you the trivial questions (and being slightly off topic) but it stops me.
BTW: Do you intend to build a library (package) providing the possibility of graph decomposition?
Adam:
The import specifications are incorrect: that's not where PluggableRenderer and SpringLayout live. I assume that NetBeans has a tool to automatically find the necessary imports (Eclipse does); if not you may have to break down and read the online Javadocs. :)
In general, when porting from JUNG 1.x to JUNG 2.0, do not assume that the packages are the same. The JUNG 1.x packages are rather a mess in places, and we're trying to clean things up in JUNG 2.0.
(Also, auto-adding imports is your friend in Java in general, if your IDE supports it.)
Graph decompositions: if you mean "identifying weak components", that's already there: check out WeakComponentClusterer. If you don't...please be more specific: on what basis are you decomposing the graph?
Joshua
Yeah, I migrated to Eclipse and then tried to use quick fix to remove the error "PluggableRenderer cannot be resolved to a type". The hints are to change the class to either PluggableRendererDemo or PluggableRenderContext (I could also create my own class :P). At last I changed it to BasicRenderer (I'm hardly experienced in Java so it looks like playing dice).
Last problem is the error "Cannot instantiate the type VisualizationViewer<V,E>".
What is the problem?
Adam
The state of my code (after all above changes) is:
[CODE]
JFrame jf = new JFrame();
VisualizationViewer<V,E> vv = new VisualizationViewer<V,E>(new SpringLayout<V,E>(this.G), new BasicRenderer<V,E>());
jf.getContentPane().add((Component) vv);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
[/CODE]
Adam:
Make sure that the SWT visualization jar is not in your classpath; you're probably picking that up, and some of the class names (VisualizationViewer in particular) conflict with the AWT/Swing visualization jar classes.
Joshua
Whoops, I should have worded that as a favorite heuristic or approximate algorithm for graph coloring. I was trolling the ACM digital library a quite a few approximate algorithms come up. Just wondering if anyone out there had a favorite.
Regards
Greg
I got the picture with following code:
[code]
JFrame jf = new JFrame();
SpringLayout<V,E> sl = new SpringLayout<V,E>(this.G);
VisualizationViewer<V,E> vv =new VisualizationViewer<V,E>(sl, new Dimension(300,300));
jf.getContentPane().add((Component) vv);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
[/code]
I removed jung SWT visualization jar as you adviced me, but it didn't help. So, instead of VisualizationViewer(Layer,Renderer) I used VisualizationViewer(Layer,Dimension).
Does it mean that Renderer object is not always nedded to paint the graph?
Related
Code: code
Adam:
You need to read the documentation. I apologize if I led you astray by pointing you to a JUNG 1.x demo and saying that the porting to 2.0 should be easy...but I can't walk you through everything. Please see the docs for VisualizationViewer to see what arguments you can give its constructor.
By default VisualizationViewer creates the Renderer object for you.
Joshua