Guest User

Untitled

a guest
May 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. (**
  2. Spanning Tree Algorithm: the sync breadth-first search
  3.  
  4. (local variables)
  5. int visited, depth <- 0
  6. int parent <- _|_
  7. set of int Neighbors <- set of neighbors
  8.  
  9. (message types)
  10. QUERY
  11.  
  12. 1) if i = root then
  13. 2) visited <- 1;
  14. 3) depth <- 0;
  15. 4) send QUERY to Neighbors;
  16. 5) for round = 1 to diameter do
  17. 6) if visited = 0 then
  18. 7) if any QUERY messages arrive then
  19. 8) parent <- randomly select a node from which
  20. QUERY was received;
  21. 9) visited <- 1;
  22. 10) depth <- round;
  23. 11) send QUERY to Neighbors \ {senders of QUERYs received
  24. in this round};
  25. 12) delete any QUERY messages that arrive in this round;
  26. **)
  27.  
  28. (** Data Structure **)
  29. { { 1 <- value, {} <- parents , {2,3} <- childrens }
  30. , { 2 <- value, {1} <- parents , {4,3} <- childrens }
  31. , { 3 <- value, {4, 2} <- parents , {5,6} <- childrens }
  32. , { 4 <- value, {1,2,3} <- parents , {5} <- childrens }
  33. , { 5 <- value, {4,3} <- parents , {6} <- childrens }
  34. , { 6 <- value ,{3,5} <- parents , {} <- childrens } }
  35.  
  36. VARIABLES nodes
  37. CONSTANT Val
  38.  
  39. (** Data Structure Input **)
  40. (** { value, parents, children } **)
  41. Val <-
  42. { { 1 , {} , {2,3} }
  43. , { 2 , {1} , {4,3} }
  44. , { 3 , {4, 2} , {5,6} }
  45. , { 4 , {1,2,3} , {5} }
  46. , { 5 , {4,3} , {6} }
  47. , { 6 , {3,5} , {} } }
  48.  
  49. TypeInvariant == /\
  50. \A node \in nodes
  51. : node \in [ value \in Nat
  52. , parents \in Nat
  53. , childrens \in Nat
  54. , visited : {0,1}
  55. , depth : {0,1} ]
  56.  
  57. Init == /\ nodes = {}
  58.  
  59. Insert(v) ==
  60. /\ \A node \in nodes : node.value = v[0] == {}
  61. /\ nodes' = nodes \union
  62. { value : v[0]
  63. , parents : v[1]
  64. , childrens : v[2]
  65. , visited : 0
  66. , depth : 0 }
  67.  
  68. Next ==
  69. /\ \E node \in Val : Insert(v)
  70.  
  71. Spec == Init \/ [][Next]_<<nodes>> \/ TRUE
Add Comment
Please, Sign In to add comment