Tuesday, 17 September 2013

shortest distance between two vertex

shortest distance between two vertex

Am new on using mxGraph on Java and i have created the next code :

public class Graphx extends JFrame {
public Graphx(){
super("JGrapghX");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, "1", "Reference", 20, 10, 80,30);
Object v2 = graph.insertVertex(parent, "2", "Book!", 340, 10,80, 30);
graph.insertEdge(parent, "1.2", "0.5", v1, v2);
Object v3 = graph.insertVertex(parent, "3", "Hello", 20, 100, 80,30);
Object v4 = graph.insertVertex(parent, "4", "World!", 360, 80,80, 30);
graph.insertEdge(parent, "3.4", "1.0", v3, v4);
Object v5 = graph.insertVertex(parent, "5", "Academic", 20, 140, 80,30);
Object v6 = graph.insertVertex(parent, "6", "Proceedings!", 340,
140,80, 30);
graph.insertEdge(parent, "5.6", "5.0", v5, v6);
Object v7 = graph.insertVertex(parent, "7", "communications", 20, 240,
80,30);
Object v8 = graph.insertVertex(parent, "8", "Conference!", 400,
230,80, 30);
graph.insertEdge(parent, "7.8", "2.0", v7, v8);
graph.insertEdge(parent, "1.4", "1.0", v1, v4);
graph.insertEdge(parent, "5.2", "3.0", v5, v2);
graph.insertEdge(parent, "4.7", "3.0", v4, v7);
graph.insertEdge(parent, "8.6", "3.0", v8, v6);
}
finally
{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
And i added the main class :

public static void main(String[] args) {
// TODO code application logic here
Graphx frame = new Graphx();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setVisible(true);
}
Now, i want to create a method or to include the public Object[]
getShortestPath(mxGraph graph, Object from, Object to,mxICostFunction cf,
int steps, boolean directed)that gives me the shortest distance or path if
i give it two Vertex there is the DijkstraShortestPath . Any help please ?

No comments:

Post a Comment