I have implemented this function but have not gotten the correct output. The task is to compute the neighbour Matrix for all pairs of vertices for every undirected path from one vertex to all other vertices and update that path which has minimum cost. what am I doing wrong here?
static COMP108A2Output neighbourhood(int[][] adjMatrix, int gSize) {
COMP108A2Output output = new COMP108A2Output(1, gSize);
for(int i=0;i<gSize;i++)
{
for(int j=0;j<gSize;j++)
{
if(i == j){
output.neighbourMatrix[i][j]=0;
}
else{
if(adjMatrix[i][j]==1){
output.neighbourMatrix[i][j]=1;
}
else{
for(int k=0;k<gSize;k++){
if(k == j || k == i){
continue;
}
else{
if(adjMatrix[k][j]==1){
output.neighbourMatrix[i][j]+=1;
}
}
}
}
}
}
}
return output;
}
Input:
0 1 1 0 0 0
1 0 0 1 0 0
1 0 0 1 1 0
0 1 1 0 0 1
0 0 1 0 0 1
0 0 0 1 1 0
My output:
0 1 1 3 2 2
1 0 3 1 2 2
1 2 0 1 1 2
2 1 1 0 2 1
2 2 1 3 0 1
2 2 3 1 1 0
Actual output:
0 1 1 2 2 3
1 0 2 1 3 2
1 2 0 1 1 2
2 1 1 0 2 1
2 3 1 2 0 1
3 2 2 1 1 0