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.