Skip to content

Update Dijkstra.java

Povodna implementacia nefunguje.

Na priklade nizsie nekorektne vyrata ds (a v mojom pripade aj p - predchodcov). Dovod je ten, ze v pripade neorientovaneho grafu bude platit prave jedna z podmienok

  • vv == v,
  • uu == v.

Tym padom mame asi tak 50-50 sancu, ze ds.put bude robeny opacne ako by mal byt.

Example na ktorom to vrati nespravny vysledok:

        Graph graf = new Graph();

   
        /*
         * A --- C     E
         * | \         | 
         * |  \        |  G
         * |   \       | /
         * B     D --- F
         * 
         */

        Vertex a = graf.addVertex("A");
        Vertex b = graf.addVertex("B");
        Vertex c = graf.addVertex("C");
        Vertex d = graf.addVertex("D");
        Vertex e = graf.addVertex("E");
        Vertex f = graf.addVertex("F");
        Vertex g = graf.addVertex("G");

        graf.addEdge(a, b).setWeight(8);
        graf.addEdge(a, c).setWeight(2);
        graf.addEdge(a, d).setWeight(14);

        graf.addEdge(d, f).setWeight(13);

        graf.addEdge(e, f).setWeight(5);

        graf.addEdge(f, g).setWeight(1);

        dijsktra(b, g)  

Merge request reports