|
Algorithm 2 Primal-dual heuristic for finding an HSF |
| 1: |
Initialization |
| 2: |
, for
|
| 3: |
All vertices are unmarked. |
| 4: |
All dual variables are set to zero. |
| 5: |
, , for
|
| 6: |
, for
|
| 7: |
Main loop |
| 8: |
while there exists any active component in
do
|
| 9: |
for
do
|
| 10: |
Find an edge with where that minimizes . |
| 11: |
end for
|
| 12: |
Let . |
| 13: |
Find that minimizes
|
| 14: |
|
| 15: |
for
do
|
| 16: |
for
do
|
| 17: |
|
| 18: |
|
| 19: |
if
then
|
| 20: |
|
| 21: |
end if
|
| 22: |
end for
|
| 23: |
end for
|
| 24: |
if
for or 2 then
|
| 25: |
|
| 26: |
|
| 27: |
|
| 28: |
if
then
|
| 29: |
|
| 30: |
end if
|
| 31: |
if
then
|
| 32: |
|
| 33: |
if
then
|
| 34: |
|
| 35: |
end if
|
| 36: |
else
|
| 37: |
|
| 38: |
end if
|
| 39: |
else
|
| 40: |
|
| 41: |
Mark all of the vertices of with the label . |
| 42: |
end if
|
| 43: |
end while
|
| 44: |
Pruning |
| 45: |
|
| 46: |
|
| 47: |
Let be the minimum spanning tree of . |
| 48: |
Let be the sum of edge costs present in
|
| 49: |
while is not empty do
|
| 50: |
Find the shortest edge that connects a vertex in and a vertex in for each k. |
| 51: |
if
then
|
| 52: |
Add to , remove the corresponding vertex from , and add it to . |
| 53: |
else
|
| 54: |
Add to , remove the corresponding vertex from and add it to . |
| 55: |
end if
|
| 56: |
end while
|