java - Implementation of Distance Vector not finding new paths -


i trying implement distance vector routing protocol text file, , have hit roadblock, in algorithm not finding new connections between nodes. node structure

public class node {      int name;      public int[][] connections, via;       node(int iname, int size) {         name = iname;         connections = new int[size][size];         via = new int[size][size];     }  } 

and search algorithm is

for(int = 0; < size; i++){     for(int j = 0; j<size; j++){          if(node.connections[i][j]!=max){              for(int k = 0; k < size; k++){                 if((node.connections[i][j]+node.connections[j][k])<node.connections[i][k]&&(node.connections[i][j]+node.connections[j][k])>0){                      node.connections[i][k] = node.connections[i][j] + node.connections[j][k];                      node.via[i][k] = j;                      node.via[k][i] = j;                 }             }         }     } } 

if play around parameters, can track connections between nodes, have defined connections.

see link floyd-warshall algorithm. order should pseudocode website:

for k 1 |v|     1 |v|       j 1 |v|          if dist[i][k] + dist[k][j] < dist[i][j]          dist[i][j] ← dist[i][k] + dist[k][j] 

edit: based on above pseudocode, code should this:

for(int k = 0; k < size; i++){     for(int = 0; j<size; j++){         for(int j = 0; j < size; j++){             if((node.connections[i][k]+node.connections[k][j])<node.connections[i][j]                 &&(node.connections[i][k]+node.connections[k][j])>0){                 node.connections[i][j] = node.connections[i][k] + node.connections[k][j];                 node.via[i][j] = k;             }         }     } } 

the order of loops matters because body of loop behave differently. first step choose size of path (k + 1 size of path optimizing, starting path of size 1). second step choose start node. third step choose end node. then, algorithm finds shortest path of size 1 start node node. second loop goes through of start nodes find of best paths of size 1. afterwards, size increased find best paths of size 2, building best paths of size 1. goes on until paths use of nodes in graph considered.


Comments