Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public static void computeShortestPath(int[][] c) { int n = c.length; // Number of nodes
  2. int M = 1000000;
  3. int min = M;
  4. int[] v = new int[n]; // Contain optimal costs to node 0
  5. v[0] = 0; // Initialization of the optimal costs to node 0
  6. for (int i=1; i<n; i++) // Initialize the optimal costs to node 0
  7. v[i] = M;
  8. for (int t=0; t<n; t++) { // Iterations
  9. for (int i=1; i<n; i++) { // Loop on the nodes
  10. // Computation of the minimum when passing // through each intermediary node j
  11. min = M;
  12. for (int j=0; j < n; j++) {
  13. if ((c[i][j] + v[j]) < min) { min = c[i][j] + v[j];
  14. } }
  15. v[i] = min; // Update optimal costs }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement