Skip to main content
. 2019 May 29;19(11):2461. doi: 10.3390/s19112461
Algorithm 2 Primal-dual heuristic for finding an HSF
1: Initialization
2: Fk, Ck{{v}:vVk} for k=1,2
3: All vertices are unmarked.
4: All dual variables are set to zero.
5: activek({v})1, vVk, for k=1,2
6: activek({dk})0, for k=1,2
7: Main loop
8: while there exists any active component in C1 do
9: for k=1,2 do
10:   Find an edge ek=(i,j)Ek with iCi,jCj where Ci,CjCk,CiCj that minimizes εk={Wk×costijkdualk(i)dualk(j)}activek(Ci)+activek(Cj).
11: end for
12:  Let :={R:activek(R)=1,OneofsubsetsofRcontainsd2,RC1}.
13:  Find R¯ that minimizes ε3=bound(R¯)Y1(R¯)
14: εmin=min(ε1,ε2,ε3)
15: for k=1,2 do
16:   for CCk do
17:    Yk(C)Yk(C)+εmin×activek(C)
18:    dualk(v)dualk(v)+εmin×activek(C),vC
19:    if k=1 then
20:     bound(C)bound(C)+εmin|Children(C)|
21:    end if
22:   end for
23: end for
24: if εmin=εk for k=1 or 2 then
25:   Fk{ek}Fk
26:   CkCk{CiCj}CiCj
27:   Yk({CiCj})=Yk(Ci)+Yk(Cj)
28:   if k=1 then
29:    Bound(CiCj)bound(Ci)+bound(Cj)
30:   end if
31:   if dk{CiCj} then
32:    activek(CiCj)0
33:    if k=1 then
34:     active2(C)0CChildren(CiCj)
35:    end if
36:   else
37:    activek(CiCj)1
38:   end if
39: else
40:   active1(C¯)0
41:   Mark all of the vertices of C¯ with the label C¯.
42: end if
43: end while
44: Pruning
45: Pkallverticesthatareonlyconnectedtodkfork=1,2
46: Pctheverticesthatareconnectedtobothd1andd2
47: Let Tk be the minimum spanning tree of Pkfork=1,2.
48: Let C(Tk) be the sum of edge costs present in Tk
49: whilePc is not empty do
50:  Find the shortest edge ek that connects a vertex in Pc and a vertex in Pk for each k.
51: if C(T1)C(T2) then
52:   Add e1 to T1, remove the corresponding vertex from Pc, and add it to P1.
53: else
54:   Add e2 to T2, remove the corresponding vertex from Pc and add it to P2.
55: end if
56: end while