darksantos

Pseudo TSP

Jul 11th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. void travel (int n,
  2. const number W [] [],
  3. index P [] [],
  4. number & minlength)
  5. {
  6. index i, j, k;
  7. number D [1 .. n] [subset of V - {v1}];
  8.  
  9. for (i = 2; i <= n; i++)
  10. D [i] [⊘] = W[i] [1];
  11. for (k = 1; k <= n - 2; k++)
  12. for (all subsets A ⊆ V - {v1} containing k vertices)
  13. for (i such that i ≠ 1 and vi is not in A){
  14. D [i] [A] = minimum (W [i] [j] + D [j] [A - {vj}]);
  15. j: [vj ∊ A
  16. P[i] [A] = value of j that gave the minimum;
  17. }
  18. D [1] [V - {v1}] = minimum (W[1] [j] + D[j] [V - {v1, vj}]);
  19. 2 ≤ j ≤ n
  20. P[1] [V - {v1}] = value of j that gave the minimum;
  21. minlength = D[1] [V - {v1}];
  22. }
Advertisement
Add Comment
Please, Sign In to add comment