Guest User

Untitled

a guest
May 19th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.14 KB | None | 0 0
  1. 11,12d10
  2. < #pragma region Floyd-Warshall
  3. <
  4. 27c25,28
  5. < int min_value(int a, int b)
  6. ---
  7. > /*
  8. >  * Returns whether or not a weight is valid
  9. >  */
  10. > bool valid_weight(int weight)
  11. 29,32c30,48
  12. <     if (a == INFINITY)
  13. <         return b;
  14. <     if (b == INFINITY)
  15. <         return a;
  16. ---
  17. >     // Pre-conditions:
  18. >     assert(true);
  19. >     // Post-conditions: the function returned whether or not the weight was
  20. >     // valid
  21. >
  22. >     return weight >= 0 || weight == INFINITY;
  23. > }
  24. >
  25. > /*
  26. >  * Returns the minimum weight of two weights
  27. >  */
  28. > int min_weight(int a, int b)
  29. > {
  30. >     // Pre-conditions:
  31. >     assert(valid_weight(a) && valid_weight(b));
  32. >     // Post-conditions: the minimum weight has been returned
  33. >
  34. >     if (a == INFINITY || b == INFINITY)
  35. >         return INFINITY;
  36. 59a76,80
  37. >     // Pre-conditions:
  38. >     assert(true);
  39. >     // Post-conditions: the path has been initialized with INFINITY for all
  40. >     // edges
  41. >
  42. 144a166,168
  43. > /*
  44. >  * Adds two weights
  45. >  */
  46. 146a171,174
  47. >     // Pre-conditions:
  48. >     assert(valid_weight(a) && valid_weight(b));
  49. >     // Post-conditions: the sum of the weights was returned
  50. >
  51. 152c180,183
  52. < void distance2(Graph graph, Path path, int n)
  53. ---
  54. > /*
  55. >  * Determines the shortest paths in a graph using iterative Floyd-Warshall
  56. >  */
  57. > void distance(Graph graph, Path path, int n)
  58. 153a185,192
  59. >     // Pre-conditions:
  60. >     assert(n >= 0);
  61. >     // Post-conditions: graph was filled with all shortest distances from the
  62. >     // first node to the second and path was filled with the node that should
  63. >     // be visited first if you want to go from one node to another, with
  64. >     // INFINITY meaning the shortest way of going from the first node to the
  65. >     // other is going directly from the first node to the other
  66. >
  67. 158c197
  68. <                 int new_weight = min_value(graph[i][j],
  69. ---
  70. >                 int new_weight = min_weight(graph[i][j],
  71. 170,173d208
  72. < #pragma endregion
  73. <
  74. < #pragma region Charles
  75. <
  76. 234c269
  77. <  
  78. ---
  79. >
  80. 242c277
  81. <   distance2(graph, path, NODE_COUNT - 1);
  82. ---
  83. >   distance(graph, path, NODE_COUNT - 1);
  84. 288,289d322
  85. <
  86. < #pragma endregion
Add Comment
Please, Sign In to add comment