Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void computeShortestPath(int[][] c) { int n = c.length; // Number of nodes
- int M = 1000000;
- int min = M;
- int[] v = new int[n]; // Contain optimal costs to node 0
- v[0] = 0; // Initialization of the optimal costs to node 0
- for (int i=1; i<n; i++) // Initialize the optimal costs to node 0
- v[i] = M;
- for (int t=0; t<n; t++) { // Iterations
- for (int i=1; i<n; i++) { // Loop on the nodes
- // Computation of the minimum when passing // through each intermediary node j
- min = M;
- for (int j=0; j < n; j++) {
- if ((c[i][j] + v[j]) < min) { min = c[i][j] + v[j];
- } }
- v[i] = min; // Update optimal costs }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement