Skip to main content
. 2019 May 29;19(11):2461. doi: 10.3390/s19112461
Algorithm 3 Primal-dual heuristic for finding an HDSF
1: Initialization
2: Fk, Ck{{v}:vVk} for k=1,2
3: All the vertices are unmarked.
4: All the 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,C2 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(j)activek(Cj)
11: end for
12:  Let the corresponding CjCk be Sk, while S={S1,S2} satisfies S1S2 and S1,S2 are active.
13: Fk{ek}Fk
14:  Increase the dual variables of Sk by εk.
15: ifek forms a new strongly connected component and the component is not reachable from dk then
16:   Let the strongly connected component be an active component.
17: else if ek makes any vertex vSk reachable from dk then
18:   Let the depot and all vertices that are reachable from the depot be an inactive component.
19:   if ek=e1 then
20:    Deactivate all subsets of this component in C2.
21:   else
22:    Mark all vertices in the supersets of this component in C1. Deactivate it if the corresponding component consists of all marked vertices.
23:   end if
24: else
25:   Deactivate Sk.
26: end if
27: if there exists no S={S1,S2} that can be chosen that satisfies the given conditions and there exists any inactive set without an incoming edge that is not connected to the depot then
28:   Pick an inactive component for each k that consists of marked vertices that have incoming or outgoing edges. Combine those connected components until the new component does not have any incoming edges.
29: end if
30: end while
31: Pruning
32: Pkallverticesthatareonlyreachablefromdkfork=1,2
33: Pctheverticesthatarereachablefrombothd1andd2
34: Let Tk be the minimum directed spanning tree of Pkfork=1,2.
35: Let C(Tk) be the sum of the edge costs present in Tk.
36: whilePc is not empty do
37:  Find the shortest edge ek that makes a vertex in Pc reachable from the vertices in Pk for each k.
38: if C(T1)C(T2) then
39:   Add e1 to T1, remove the corresponding vertex from Pc, and add it to P1.
40: else
41:   Add e2 to T2, remove the corresponding vertex from Pc, and add it to P2.
42: end if
43: end while