public static void main(String args[]) {

    Grafo teste = new Grafo();

    teste.setVertices(lerGrafo(args[0]));
    Vertice i1 = new Vertice();
    Vertice i2 = new Vertice();
    i1 = teste.encontrarVertice(args[1]);
    i2 = teste.encontrarVertice(args[2]);

    List<Vertice> resultado = new ArrayList<Vertice>();
    Dijkstra algoritmo = new Dijkstra();
    resultado = algoritmo.encontrarMenorCaminhoDijkstra(teste, i1, i2);

    System.out.println("Esse é o menor caminho feito pelo algoritmo:" + resultado);
  }
 private double[][] getMinDistances() {
   double[][] minDistances = new double[clients.length][clients.length];
   for (int i = 0; i < clients.length; i++) {
     double[] result = Dijkstra.getMinDistance(i, clients);
     minDistances[i] = result;
   }
   return minDistances;
 }
예제 #3
0
 public static void main(String[] unused) {
   //        Dijkstra dijkstra = new Dijkstra(5);
   //        dijkstra.setWeightMatrix(0, 2, 6);
   //        dijkstra.setWeightMatrix(2, 0, 6);
   //        dijkstra.setWeightMatrix(0, 3, 2);
   //        dijkstra.setWeightMatrix(3, 0, 2);
   //        dijkstra.setWeightMatrix(0, 1, 2);
   //        dijkstra.setWeightMatrix(1, 0, 2);
   //        dijkstra.setWeightMatrix(1, 3, 5);
   //        dijkstra.setWeightMatrix(3, 1, 5);
   //        dijkstra.setWeightMatrix(3, 4, 4);
   //        dijkstra.setWeightMatrix(4, 3, 4);
   //        dijkstra.setWeightMatrix(2, 4, 1);
   //        dijkstra.setWeightMatrix(4, 2, 1);
   double weight1[][] = {
     /* HNL    SFO     LAX     ORD     DFW     LGA     PVD     MIA */
     {0, INF, 2555, INF, INF, INF, INF, INF}, // HNL
     {INF, 0, 337, 1843, INF, INF, INF, INF}, // SFO
     {2555, 337, 0, 1743, 1233, INF, INF, INF}, // LAX
     {INF, 1843, 1742, 0, 802, INF, 849, INF}, // ORD
     {INF, INF, 1233, 802, 0, 1387, INF, 1120}, // DFW
     {INF, INF, INF, INF, 1387, 0, 142, 1099}, // LGA
     {INF, INF, INF, 849, INF, 142, 0, 1205}, // PVD
     {INF, INF, INF, INF, 1120, 1099, 1205, 0}, // MIA
   };
   Dijkstra dijkstra = new Dijkstra(weight1);
   //  int source = 3;
   for (int source = 0; source < weight1.length; source++) {
     dijkstra.dijkstra(source);
     for (int i = 0; i < weight1.length; i++) {
       if (i != source) {
         dijkstra.printShortestPath(source, i);
       }
       //   dijkstra.
     }
   }
 }