I having problem getting jgrapht or jgraph or applet to visualize this graph correctly? Can I use this graph library to visualize similarly to the picture beneath? U would be x and V would be Y in the code for example. I'm using the demo versions that used directed graphs to do same in this example. Not sure if I should use a jgAdapter or jgxAdapter? Currently getting blank applet for either.
public class GraphDemo extends JApplet{
private static final long serialVersionUID = 2202072534703043194L;
private static final Dimension DEFAULT_SIZE = new Dimension(530, 320);
private JGraphXAdapter<String, DefaultEdge> jgxAdapter;
public static void main(String[] args) {
JGraphAdapterDemo applet = new JGraphAdapterDemo();
applet.init();
JFrame frame = new JFrame();
frame.getContentPane().add(applet);
frame.setTitle("JGraphT Adapter to JGraph Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void init()
{
UndirectedGraph<String, DefaultEdge> g =
new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
jgxAdapter = new JGraphXAdapter<String, DefaultEdge>(g);
getContentPane().add(new mxGraphComponent(jgxAdapter));
resize(DEFAULT_SIZE);
String x1 = "x1";
String x2 = "x2";
String x3 = "x3";
String y1 = "y1";
String y2 = "y2";
String y3 = "y3";
String y4 = "y5";
g.addVertex(x1);
g.addVertex(x2);
g.addVertex(x3);
g.addVertex(y1);
g.addVertex(y2);
g.addVertex(y3);
g.addVertex(y4);
g.addEdge(x1, y1);
g.addEdge(x1, y2);
g.addEdge(x2, y1);
g.addEdge(x2, y4);
g.addEdge(x3, y2);
g.addEdge(x3, y3);
Set<String> p1 = new HashSet<String>(Arrays.asList(x1, x2, x3));
Set<String> p2 = new HashSet<String>(Arrays.asList(y1, y2, y3, y4));
HopcroftKarpBipartiteMatching<String, DefaultEdge> alg =
new HopcroftKarpBipartiteMatching<String, DefaultEdge>(g, p1, p2);
Set<DefaultEdge> match = alg.getMatching();
mxCircleLayout layout = new mxCircleLayout(jgxAdapter);
layout.execute(jgxAdapter.getDefaultParent());
System.out.println(g.toString());
System.out.println(match);
}
}