|
Algorithm 2. The spanning tree algorithm |
-
1.
Input: an OCRG;
-
2.
Output: a spanning tree with the mobile sink as the root node;
-
3.
Add into set K;
-
4.
Add the remaining nodes in the OCRG into set U;
-
5.
for each node in set U do // initialization
-
6.
if ( is directly connected to )
-
7.
= ; //
is the PC of the path from
to
-
8.
= {,}; //
is used to store the nodes on the path from
to
-
9.
else
-
10.
= 0;
-
11.
= ∅;
-
12.
end if
-
13.
end for
-
14.
= 1; // set the PC of the path from
to
is 1
-
15.
while (set U is not empty)
-
16.
Select the node with max from set U;
-
17.
Transfer from set U to set K;
-
18.
for each neighbor of
do //
is still in set U
-
19.
temp ←×;
-
20.
if (temp > )
-
21.
← temp; // update the PC of the path from
to
-
22.
← + ; // update the nodes on the path from
to
-
23.
end if
-
24.
end for
-
25.
end while
|