c# - Floyd-Warshall Algorithm - Also get the name of each point other than shortest distance -
i have created algorithm shortest point between 2 selected points on map.
first filled matrix entirely distance, weight. named example: dist[0,1] refers road between point 0 , point 1. every point has number assigned it.
the matrix filled accordingly , fjord warshall algorithm runs:
for (int k = 0; k < count; ++k) { (int = 0; < count; ++i) { (int j = 0; j < count; ++j) { if (dist[i,j] > (dist[i,k]+dist[k,j])) { dist[i, j] = dist[i, k] + dist[k, j]; } } } }
this derives shortest point between every single path. check path have it's shortest point:
shortest = dist[x, y];
which return correct value , works well. here issue. need set see through points passes. mean if want go point 1 point 5 , shortest route through 3 , 6, display 1,3,6,5.
any ideas? stuck on one.
create array same dimensions dist, lets call vert.
below line:
dist[i, j] = dist[i, k] + dist[k, j];
add,
vert[i, j] = k;
then call recursive function defined as,
void pr(int x, int y) { if(x == y) return; pr(x, vert[x, vert[x, y]]); cout << vert[x, y]; pr(vert[vert[x, y]], y); }
Comments
Post a Comment