• Nem Talált Eredményt

12 The dynamic program for traversing a vortex in a planar graph

12.1 The dynamic program

12.1.4 Updating the dynamic programming table

For allP ∈ P containing m >1 edges, and for all P1, P2 ∈ P withE(P1)6=∅, E(P2)6=∅, E(P1)∩E(P2) = ∅ and P1P2 = P, and for all φ1 ∈ IP1 andφ2 ∈ IP2 we proceed as follows. Suppose that for all pathsP0 containingm0 < medges and allφ0 ∈ IP0 we have computed the partial solutions in the dynamic programming table at (P0, φ0). If there exist partial solutionsS1 andS2 at (P1, φ1) and (P2, φ2) respectively, we call the merging process to merge S1andS2. Suppose that the merging process returns a partial solutionS at (P, φ) for someφ∈ IP. If there is no partial solution stored currently at (P, φ) then we storeS at that location. Otherwise if there there exists a partial solutionS0 stored at (P, φ) and the cost ofS is smaller than the cost ofS0 then we replaceS0 with S.

12.2 Analysis

LetW be the collection of walks given by Lemma 56. LetW0 be the shadow ofW. LetF be the forest obtained by Lemma 57. For every connected componentT of F pick some vTV(T) and considerT to be rooted atvT.

Let G~0 be the planar piece ofG, that is~ G~0=G~\(V(H~)\(F~)). Fix some planar drawing ψofG0. LetDbe the disk with∂D=ψ(F) withψ(G)~ ⊂ D.

Let P∈ P with endpointsu,v, and letT be a subtree of some tree inF. We say thatP coversT if for allDV(T) we haveV(D)∩V(F)⊆V(P). We say thatP avoids T if for allDV(T) we haveV(D)∩V(P)⊆ {u, v}.

IDefinition 60(Basic path). LetP ∈ P. Letu, vV(P) be the endpoints ofP. We say thatP isbasic(w.r.t.W) if eitherP\ {u, v} does not intersect any of the walks inW (in this case we callP empty basic) or the following holds. There exists some treeT inF and someDV(T), with childrenD1, . . . , Dk, intersectingD in this order along a traversal of D, such that the following conditions are satisfied (see Figure 1):

1. For anyi∈ {1, . . . , k}, letTDi be the subtree ofT rooted atDiand letTD be the subtree ofT rooted at D. Then at least one of the following two conditions is satisfied:

1.1. P coversTD and avoidsT \ TD.

1.2. There exists j ∈ {1, . . . , k} such that for all lj, P covers TDl and P avoids TD\Sj

m=1TDm.

2. LetT0 be a tree in F withT06=T. Then eitherP coversT0 or P avoids T0.

IDefinition 61(Facial restriction). LetP ∈ P be basic. LetW0 be the collection of walks obtained by restricting everyW ∈ W onHP. IfP is empty, we say thatW0 is theP-facial restriction ofW. Suppose thatP is not empty. LetT,D,TD,kandj be as in Definition 60.

Figure 2Part of the collection of walks inW(left) and the correspondingP-facial restriction of Wdepicted in bold (right).

LetF0 ={T0 ∈ F :P coversT0} and let R=S

T0∈F0V(T0). IfP covers TD and avoids T \ TD, we say thatR ∪ W0V(TD) is theP-facial restriction ofW. Otherwise, we say that R ∪ W0∪ {D} ∪Sj

i=1V(TDi) is the P-facial restriction ofW. Figure 2 depicts an example of aP-facial restriction.

IDefinition 62 (Important walk). Let P ∈ P be a basic path. Let W0 be the P-facial restriction ofW. LetW00 be the shadow ofW0. LetQbe a walk inG[W00]. We say thatQ isP-important (w.r.to.W) if the following conditions hold:

1. Both endpoints ofQare in V(P).

2. Qis the concatenation of walksQ1, . . . , Q`such that for eachi∈ {1, . . . , `}there exists someWi ∈ W such thatQi is a sub-walk ofWi, and for eachj∈ {1, . . . , `−1}we have {Wj, Wj+1} ∈E(F).

IProposition 63. For anyu, vV(P), there is at most one P-important walk from uto v.

Proof. It follows immediately by the fact thatF is a forest. J I Lemma 64. Let P ∈ P be basic w.r.t. W with endpoints u, vV(F), where u = v if P is closed. Let WP be the P-facial restriction of W. Let Γ = S

W~∈WP

W~ . Let C be the partition of BuBv that corresponds to the weakly-connected components of Γ.

For any xBuBv let fin(x) =in-degreeW

P(x) and fout(x) =out-degreeW

P(x). Then there exists some a ∈ A ∪(A × A)∪nil and l, r, p ∈(V(G)~ ∪nil) such that the dynamic programming table contains some partial solution S at location (P,(C, fin, fout, a, l, r, p)), such thatcostG~(S)≤costG~(WP).

Proof. Let us first assume thatF contains only one tree. We will deal with the more general case later on. First suppose thatP is an empty basic path. LetP =x1, x2, . . . , xm, where x1=uandxm=v. We will prove the assertion by induction onm. For the base case, suppose thatm= 2, and thusP contains only one edge. Leta=l=r=p=nil. In this case, a partial solutionS at location (P,(C, fin, fout, a, l, r, p)) is computed in the initialization step of the dynamic programming table and clearly we havecostG~(S)≤costG~(WP) and we are done. Now suppose thatm >2 and we have proved the assertion for allm0< m. We first decomposeP into two edge-disjoint pathsP1andP2, such thatV(P1)∩V(P2) =wfor some 1< j < mand w=xj. Fori∈ {1,2} letWPi be thePi-facial restriction of W~OPT and let Γi=S

W~∈WPiW~ . LetC1be the partition ofBu∪Bwthat corresponds to the weakly-connected components of Γ1 and letC2be the partition ofBwBvthat corresponds to the weakly-connected components

of Γ2. For anyxBuBw let f1in(x) =in-degreeWP

1(x) andf1out(x) =out-degreeWP

1(x).

Also for any xBwBv let f2in(x) = in-degreeWP

2(x) and f2out(x) = out-degreeWP

2(x).

By the induction hypothesis, there exists partial solutionsS1 andS2 that are compatible with (P1,(C1, f1in, f1out,nil,nil,nil,nil)) and (P2,(C2, f2in, fout,nil,nil,nil,nil)) respectively, and we have costG~(S1) ≤ costG~(WP1), costG~(S2) ≤ costG~(WP2). The dynamic program will mergeS1 andS2 to get the desired S. Note that by the construction, for everyxBwwe havef1in(x) =f2out(x) andf2in(x) =f1out(x). Therefore, by the first merging phase, we can merge walks in S1andS2. Also, we leta=l=r=p=niland we proceed the second phase of merging. Finally, by the construction and definition ofP-facial restriction, (T5) holds and the merging process returns a partial solutionS compatible with (P,(C, fin, fout, a, l, r, p)) withcostG~(S)≤costG~(WP), as desired.

Now suppose thatP is not empty basic. LetT, D, TD,kandj be as in Definition 60.

We will prove the assertion by induction on T. For the base case, suppose thatDis a leaf of T. Suppose thatP =x1, x2, . . . , xmfor somem >0, wherex1=uandxm=v, andD is a (possibly closed) walk from xiV(P) to xjV(P). We may assume w.l.o.g. thatij.

There are some possible cases here based oniandj. First suppose thati >1,j < mandji≥3. In this case, letP1=x1, . . . , xi,P2=xi, xi+1,P3=xi+1, . . . , xj−1,P4=xj−1, xj and P5=xj, . . . , xm. LetP6=P1∪P2,P7=P6∪P3andP8=P7∪P4. Fori∈ {1,2,3,4,5,6,7,8}

letWPi be thePi-facial restriction of W~OPT and let Γi =S

W~∈WPiW~ . We also define Ci, fiin andfiout as in the previous case. Note that P1,P3 andP5 are empty basic paths. We leta1 =a3=a5=nil, l1 =l3 =l5 =nil, r1=r3=r5 =nil, p1 =p3 =p5 =niland thus we can find partial solutionsS1,S3 andS5 compatible with (P1,(C1, f1in, f1out, a1, l1, r1, p1)), (P3,(C3, f3in, f3out, a3, l3, r3, p3)) and (P5,(C5, f5in, f5out, a5, l5, r5, p5)) respectively. We also have

costG~(S1)≤costG~(WP1), costG~(S3)≤costG~(WP3) andcostG~(S5)≤costG~(WP5). Leta2= a4=a6=a7=a8= (xi, xj). IfDdoes not have a parent inT, then we letl2=l4=l6= l7 =l8 = r2 =r4 =r6 =r7 =r8 =p2 =p4 =p6 =p7 =p8V(D) to be an arbitrary vertex ofD. Otherwise, suppose that Dhas a parentD0 in T. IfD0 does not have a parent inT, then we let l2 =l4=l6=l7 =l8=r2=r4=r6 =r7 =r8 =p2=p4=p6 =p7= p8V(D)∩V(D0). Otherwise, suppose thatD0 has a parentD00 inT. In this case, we letl2 =l4 =l6 =l7 =l8 =r2 =r4 =r6=r7 =r8V(D)∩V(D0) andp2=p4=p6= p7=p8V(D0)∩V(D00). Therefore, by computing the initialization step, we can find a partial solution S2 compatible with (P2,(C2, f2in, f2out, a2, l2, r2, p2)) and a partial solution S4 compatible with (P4,(C4, f4in, f4out, a4, l4, r4, p4)), and we have costG~(S2) ≤costG~(WP2) and costG~(S4) ≤ costG~(WP4). Now by merging S1 and S2, we get a partial solution S6

compatible with (P6,(C6, f6in, f6out, a6, l6, r6, p6)). By merging S6 andS3, we get a partial solutionS7compatible with (P7,(C7, f7in, f7out, a7, l7, r7, p7)). By mergingS7 andS4, we get a partial solutionS8compatible with (P8,(C8, f8in, f8out, a8, l8, r8, p8)), and finally by merging S8 andS5, we get the desired partial solutionS compatible with (P,(C, fin, fout, a, l, r, p)) withcostG~(S)≤costG~(WP). Ifi= 1 or j=m, we will follow a similar approach. The only different is that instead of dividingP into five paths, we divide it into four paths. Finally, the last case is whenji <3. In this case, ifi6=j, we define the same subpathsP1,P2,P4

and P5, and we follow a similar approach. Otherwise, suppose thati=j. In this case, we letP1=x1, . . . , xi andP2=xi, . . . , xm and by following the same approach by mering two partial solutions, we get the desiredS.

Now suppose thatDV(T) is non-leaf. In this case, we prove the assertion by induction on j, wherej comes from Definition 60. Note that we perform a second induction inside the first induction. For the base case, suppose thatj = 1. In this case,D1 is a child ofD andP covers TD1 and avoidsTD\ TD1. Therefore, by using the first induction hypothesis

onD1, there existsa ∈ A ∪(A × A)∪niland l, r, pV(G)~ ∪nil such that the dynamic programming table contains some partial solution S at location (P,(C, fin, fout, a, l, r, p)) withcostG~(S)≤costG~(WP). Now for the samea,l,r,pandS, we have thatS is compatible we can apply the second merging phase. Finally, by the construction (T5) holds and we get a partial solutionS4 compatible with (P4,(C4, f4in, f4out, a4, l4, r4, p4)). Now, we merge

then we have a = a2, l = l2, r = r2 andp = p2, and thus this case is also immediate.

Suppose thata2= (u2, v2)6=nil,a4= (u4, v4)6=nil,l4=r4 andp1=p2, anda= (u, v), whereu∈ {u2, u4} andv∈ {v2, v4}. We may assume w.l.o.g thata= (u2, v4). We have that l = l2, r =r4 and p=p2. For i ∈ {2,4} let Qi be the grip of Si, and letW~i ∈ Si

that contains Qi as a sub-walk. LetY1 be the shortest-path in G~ fromu2 tol2. Let Y2 be the shortest-path in G~ from l2 to l4. Let Y3 be the shortest-path inG~ from l4 tov4. Let R1 be the path inG~ from u2 tov4 obtained by concatenation of Y1, Y2 andY3. Let Y10 be the shortest-path in G~ from u4 to r4. Let Y20 be the shortest-path in G~ from r4

to l2. Let Y30 be the shortest-path in G~ from l2 to v2. Let R2 be the path in G~ from u4 tov2 obtained by concatenation ofY10,Y20 andY30. Now by the construction, we have thatcostG~(S) =costG~(S2) +costG~(S4) +costG~(R1) +costG~(R2)−costG~(Q2)−costG~(Q4).

Note that by the construction, there exists aP-important walk from u2 tov4 (w.r.t.W) and a P-important walk from u4 to v2 (w.r.t. W). By Proposition 63 these walks are unique. Let R01 be the P-important walk from u2 to v4 (w.r.t. W) and let R02 be the P-important walk fromu4 tov2 (w.r.t.W). Also, there exists aP2-important walk from u2 to v2 (w.r.t. W) and a P4-important walk from u4 to v4 (w.r.t. W), and thus by Proposition 63 these walks are unique. Let Q02 be the P2-important walk from u2 to v2 (w.r.t. W) and let Q04 be the P4-important walk from u4 to v4 (w.r.t. W). By the definition of important walks, we have that costG~(R1)≤costG~(R01),costG~(R2)≤costG~(R02), costG~(Q2)≤costG~(Q02) andcostG~(Q4)≤costG~(Q04). Also by the construction, we have that costG~(R01) +costG~(R02) =costG~(Q02) +costG~(Q04). Therefore, we have

costG~(S) =costG~(S2) +costG~(S4) +costG~(R1) +costG~(R2)−costG~(Q2)−costG~(Q4)

≤costG~(S2) +costG~(S4) +costG~(R01) +costG~(R02)−costG~(Q2)−costG~(Q4)

= (costG~(S2)−costG~(Q4)) + (costG~(S4)−costG~(Q2)) +costG~(R01) +costG~(R02)

≤costG~(WP1) +costG~(WP2)

=costG~(WP).

Now suppose that D is an open walk. If a2 =nil anda4 ∈ (A × A), or a4 =nil and a2∈(A × A), then this is immediate. Ifa2= (u2, v2)∈ A,a4= (u4, v4)∈ A,l2=r2,l4=r4 andp2=p4, then we havea= ((u0, v0),(u00, v00)) wherev0∈ {v2, v4}andu00∈ {u2, u4}. We may assume w.l.o.g thatv0 =v2andu00=u4. Then we havel=l2,r=r2andp=p2. LetR1 be the shortest-path inG~ fromu0tol2. LetR2be the shortest-path inG~ froml1tov0. LetR0 be the path fromu0tov0 obtained by the concatenation ofR1andR2. LetY1be the shortest path inG~ fromu00 tol4. LetY2 be the shortest path inG~ froml4tov00. LetY0 be the path fromu00 tov00 obtained by the concatenation ofY1 andY2. LetZ1 be the shortest path inG~ fromu2tol2. LetZ2be the shortest path inG~ froml2tol4. LetZ3be the shortest path inG~ froml4tov4. LetZ0be the path fromu2 tov4 obtained by the concatenation ofZ1,Z2 and Z3. LetQ2 be the grip ofS2and letQ4 be the grip ofS4. By the construction, we have that costG~(S) =costG~(S2)+costG~(S4)+costG~(R0)+costG~(Y0)+costG~(Z0)−costG~(Q2)−costG~(Q4).

By the construction, there exists a P-important walk from u2 tov4, a P-important walk fromu0 tov2, and aP-important walk fromu4tov00. Therefore by Proposition 63, these

important walks are unique. LetR00,Y00 andZ00 be the important walks fromu0 tov0,u00 to v00, andu2 tov4respectively. Therefore, we have that

costG~(S) =costG~(S2) +costG~(S4) +costG~(R0) +costG~(Y0) +costG~(Z0)

−costG~(Q2)−costG~(Q4)

≤costG~(S2) +costG~(S4) +costG~(R00) +costG~(Y00) +costG~(Z00)

−costG~(Q2)−costG~(Q4)

≤costG~(WP1) +costG~(WP2) =costG~(WP).

If a4= ((u4, v4),(u04, v04))∈(A × A), a2 = (u2, v2)∈ A, l2 =r2 andp2 =p4, then we havea= ((u4, v4),(u2, v40)),l=l4,r=r2 andp=p2. Let (Q4, Q∗∗4 ) be the grip of S4, and letQ2 be the grip ofS2. We may assume w.l.o.g thatQ4 is a path fromu4tov4, andQ∗∗4 is a path fromu04 tov04. LetY1 be the shortest path inG~ fromu2tol2. LetY2be the shortest path inG~ froml2 tov40. LetY0 be the path fromu2 tov40 obtained by the concatenation of Y1 andY2. LetZ1 be the shortest path inG~ fromu04 tor4. LetZ2 be the shortest path in G~ fromr4tol2. LetZ3 be the shortest path inG~ froml2tov2. LetZ0 be the path fromu04 tov2 obtained by the concatenation ofZ1,Z2 andZ3. By the construction, we have that costG~(S) =costG~(S2) +costG~(S4) +costG~(Y0) +costG~(Z0)−costG~(Q2)−costG~(Q∗∗4 ). By the construction, there exists aP-important walk fromu04 tov2, and aP-important walk fromu2 tov04. Therefore by Proposition 63, these important walks are unique. LetY00 and Z00be the important walks fromu2to v40, andu04 tov2respectively. Therefore we have

costG~(S) =costG~(S2) +costG~(S4) +costG~(Y0) +costG~(Z0)−costG~(Q2)−costG~(Q∗∗4 )

≤costG~(S2) +costG~(S4) +costG~(Y00) +costG~(Z00)−costG~(Q2)−costG~(Q∗∗4 )

≤costG~(WP1) +costG~(WP2) =costG~(WP).

Now suppose that F contains more than one tree. Let A = {T1, . . . ,Tm} be the set of all trees in F. For every T ∈ A we define the level of T, L(T), as follows. Let D be the root of T. We set L(T) = 0, if there exists a basic path P0 that covers T and avoids allT0 ∈ F \ {T }. We call a minimal such path, acorresponding basic path for T and we denote it byPT; it is immediate that there is a unique such minimal path. Let F0 = {T ∈ F : L(T) = 0}. Now for i≥0, suppose that we have defined trees of level i andFi. Suppose thatL(T)∈ {0, . . . , i}. We set/ L(T) =i+ 1 if there exists a basic path P0 that coversT such that for allT0 ∈Si

j=0Fj, P0 either avoids or coversT0, and for all T00∈(F \ {T })\Si

j=0Fj,P0 avoidsT00. We also call a minimal such path corresponding basic forT and we denote it byPT. LetFi+1={T ∈ F :L(T) =i+ 1}.

We say that some T ∈ F is outer-most if there is noT0 ∈ F withL(T0)> L(T) and PTPT0.

Let us first suppose that there exists only one outer-most treeT ∈ F, such thatPTP. We will deal with the more general case later. Also, suppose thatT ∈ Fmfor somem≥0.

We will prove the assertion by induction onm. We also prove that for this case, we have a=l =r=p=nil. For the base case, ifm= 0, then by the construction,T is the only tree with a corresponding basic pathPTP. For this case, we have already established the assertion and we are done. Now suppose that we have proved the assertion for all m0< m. LetF0=F \ {T }. LetT1, . . . ,Tt∈ F0 be all outer-most trees inF0, such that for j∈ {1, . . . , t} we havePTjP, and they intersectF in this order. By the construction, for everyj∈ {1, . . . , t} we haveL(Tj)< m. For everyj∈ {1, . . . , t} letPTj be a corresponding basic path forTj. By the induction hypothesis, for everyj∈ {1, . . . , t} there exists a partial

solutionSj forPTj. Now, we can apply the same argument when we had only one treeT ∈ F forT. Note that for eachj∈ {1, . . . , t}, we haveaj=lj=rj=pj =nil. The only difference is that the intermediate basic paths here are not necessarily empty basic paths, and eachTj

appears as an intermediate basic path, with a partial solutionSj. Therefore, by following a similar approach to the previous cases and merging appropriately we get a partial solutionS, as desired.

Now, suppose that there exist more than one outer-most treesT ∈ F, wherePTP. Let B={T1, . . . ,Tt} be the set of all such trees, where they intersect consecutive subpaths of P in this order. In this case, we prove the assertion by induction on t. For the base case wheret= 1, we have already proved the assertion. Now suppose that we have proved the assertion for allt0< t. LetB0={T1, . . . ,Tt−1}. LetP0P be the subpath ofP such that B0 is the set of all outer-most trees, withPTjP0 for all 1≤jt−1. By the induction hypothesis, there exists a partial solutionS0 forP0. LetP00=PP0. By the construction, P00is a corresponding basic path forTt, and thus by the induction hypothesis, there exists a partial solutionS00 forP00. Therefore, by mergingS0 andS00 we get a partial solutionS for

P, as desired. J

ITheorem 65. Let G~ be an n-vertex (0,0,1, p)-nearly embeddable graph (that is, planar with a single vortex) and letH~ be the vortex of G. Then there exists an algorithm which~ computes a walkW~ visiting all vertices in V(H)~ of total length OPTG~(V(H~)) in timenO(p). Proof. We have F ∈ P and it is immediate to check that F is basic. Since F is a cycle, both the endpoitns ofF are some vertexv. It follows by Lemma 64 that there exists some φ∈ IF such that the dynamic programming table contains a partial solution S at location (F, φ). Let φ = (C, fin, fout, a, l, r, p). It follows by condition (T4) that for all xBv

we havein-degreeS(x) = out-degreeS(x). Thus by repeatedly merging pairs of walks that respectively terminate to and start from the same vertex, we obtain a collectionS0 of closed walks with costG~(S0) = costG~(S) that visit all vertices inV(H~). By Lemma 57 we can assume thatC is the trivial partition containing only one cluster, that isC={{Bv}}. Since C is trivial, it follows by (T5) that all vertices inV(H~) are in the same weakly-connected component of S

W∈SW. Thus all vertices in V(H~) are in the same strongly-connected component of S

W∈S0W. Since all walks in S0 are closed, by repeatedly shortcutting pairs of intersecting walks, we obtain a walk W~ with that visits all vertices inV(H~) with costG~(W~ ) =costG~(S0) =costG~(S)≤costG~(W~OPT) =OPTG~.

The running time is polynomial in the size of the dynamic programming table, which is at most|P| ·maxP∈P|IP|=O(n2pO(p)·nO(p)·O(n2) =nO(p). J

13 The dynamic program for traversing a vortex in a bounded genus