I want implement the Floyd–Warshall algorithm in GAMS . i need to find shortest paths in a weighted graph with positive weight .
Below is the algorithm in C++
void Floyd_Warshal(int graph[MAX][MAX], int D[MAX][MAX], int P[MAX][MAX], int numberOfNodes){
for(int i = 0 ; i < numberOfNodes ; i++)
for(int j = 0 ; j < numberOfNodes ; j++){
D[i][j] = graph[i][j];
P[i][j] = -1;
}
for(int k = 0 ; k < numberOfNodes ; k++)
for(int i = 0 ; i < numberOfNodes ; i++)
for(int j = 0 ; j < numberOfNodes ; j++)
if(D[i][j] > D[i][k] + D[k][j]){
D[i][j] = D[i][k] + D[k][j];
P[i][j] = k;
}
}
}
D
is adjacent matrix of original graph, and p
is path . in fact p
is the result.
Can I change this code to GAMS code , I mean , can we have Floyd–Warshall algorithm in GAMS,according to this code?