0

I'm struggling with finishing my Floyd-Warshall algorithm, I've tried to write my program based on wikipedia pseudocode, but it doesn't work as suposed. I create second matrix to store changes in route so that's my code:

    for (int w = 0; w < wierzcholki; w++)

    {

        for (int i = 0; i < wierzcholki; i++)

        {

            for (int j = 0; j < wierzcholki; j++)

            {

                if (tablica[i][w] + tablica[w][j] < tablica[i][j]) {

                    tablica[i][j] = tablica[i][w]

                    + tablica[w][j];
                    next[i][j] = next[i][w];

                }

            }

        }

    }

This is my method to print shortest path

    List<Double> Path(double i, double j) {

        if (next[(int) i][(int) j] == Double.POSITIVE_INFINITY) {
            return null;
        }
        List<Double> Wynik = new ArrayList<Double>();
        while (i != j) {
            i = next[(int) i][(int) j];
            Wynik.add(i);
            return Path(i, j);

        }
return Wynik;
}

and then I call it out to find a route between all the nodes

Path(0, wierzcholki);

I've posted yesterday similar question (https://stackoverflow.com/questions/34828364/java-floyd-warshall-algorithm), but I think I've gotten closer to the solution so I decided to create new one. I hope it is allowed.

Community
  • 1
  • 1
EyeMaze
  • 143
  • 2
  • 9
  • Please read the FAQ. This question is no better than your first attempt. – duffymo Jan 17 '16 at 14:50
  • You've only shown the 4rd part of the algorithm. Did you do the first three parts? (1) initialize all weights to ∞ , (2) Set all self-to-self weights to 0, (3) set all one hop weights to the given weight. – John Hascall Jan 17 '16 at 14:56
  • Yes, I've done 2, and 3 for sure. But I do not understand what do you mean in first one, I initialaze 2d array with size of the nodes amount, is it not enough? – EyeMaze Jan 17 '16 at 15:10

0 Answers0