/* * Created on 10/06/2003 */ package graph.spath; import graph.*; import heap.*; /** * @author André Santanchè */ public class TestDijkstra { public static void main(String[] args) { Vertex s = new Vertex("s"), t = new Vertex("t"), x = new Vertex("x"), y = new Vertex("y"), z = new Vertex("z"); Edge[] es = {new Edge(s, t, 10), new Edge(s, y, 5)}, et = {new Edge(t, x, 1), new Edge(t, y, 2)}, ex = {new Edge(x, z, 4)}, ey = {new Edge(y, t, 3), new Edge(y, x, 9), new Edge(y, z, 2)}, ez = {new Edge(z, s, 7), new Edge(z, x, 6)}; s.setEdges(es); t.setEdges(et); x.setEdges(ex); y.setEdges(ey); z.setEdges(ez); Graph g = new Graph(); g.addVertex(s); g.addVertex(t); g.addVertex(x); g.addVertex(y); g.addVertex(z); MinimumHeap h = null; if (args.length == 0) System.out.println("Escolha o tipo de heap: (B)inario ou (W) ou (M)ix"); else switch (args[0].charAt(0)) { case 'B' : h = new BinaryHeap(); break; case 'W' : h = new WHeap(16); break; case 'M' : h = new WBinaryHeap(16); } if (h != null) { Dijkstra dj = new Dijkstra(g, s, h); Graph gs = dj.shortestPath(); System.out.println("Resultado:"); Vertex v[] = gs.getVertexList(); for (int i = 0; i < v.length; i++) System.out.println("vertice: " + v[i] + ", d(" + v[i].getD() + "), pi(" + v[i].getPi() + ")"); } } }