New Algorithmic Approaches for Computing Optimal Network Paths with Several Types of QoS Constraints

The problem of efficiently delivering data within networks is very important nowadays, especially in the context of the large volumes of data which are being produced each year and of the increased data access needs of the users. Efficient data deliv…

Authors: Mugurel Ionut Andreica, Nicolae Tapus

New Algorithm ic Approaches for Computin g Optimal Networ k Paths with Sev eral Types of QoS Constraints Mugurel Ionu ţ Andreica, Nicolae Ţă pu ş Compu ter Science and Engineerin g Department Politeh nica Universit y of Bucharest Bucharest , Romania e-mail: {mugurel.and reica, nicolae.tapus }@cs.pub.ro Abstract —The problem of efficiently deliver ing data within networks is very i mportant nowadays, especially in t he context of the large v olumes of data which are being produced each year and of the increased data access needs of the users . Efficient data delivery strategies must sati sfy several types of Quality of S ervice (QoS) constraints w hich a re imposed b y the data consumers. One p ossibili ty of achieving th is go al (particularly in th e case of in-order da ta transf ers) is to cho ose a satisf actory netwo rk delivery pa th. In this pap er we present novel algorithmic approaches fo r computing optimal network paths which satisfy sever al types of (QoS) constraints. Keywords-optimal constrained network path; QoS I. I NTRODU CTION Effic ient delivery of data is an important issue nowaday s, particu larly i n the context in which large amounts of data are produced, accessed and consumed every year. Moreover, data consumer s impose stringent QoS constraint s on the data delivery mechanism in order to consider it of a goo d enough quality . In the c ase of in-order data delivery , on e possibilit y of satisfy ing the constrain ts is to choose an adequate ne twork delivery path. In this p aper w e consider multiple constrained network path o ptimiza tion problems, for which we present novel a lgorit hmic solution s. In Sec tion II we con sider an approximate bicriteria optimal path problem. I n Section III we present sensitivity analysis algorithms for several optimal path problems (and more). In Section IV we present novel solution s for seve ral Hamilt onian and constra ined c olor- alternat ing paths and cycles in gra phs. In Section V we discuss r elated work and i n Sec tion VI we c onclude. II. A PPROXIMATE B ICRITERIA O PTIMAL P ATH We c onsider a direc ted graph G with n vertices and m edges. Each directed edg e e from u(e) to v (e) has t wo non- negative integer weights w 1 (e) and w 2 (e) . W e want to f ind a path from a source vertex s to a destina tion vertex t which minimizes the sum of the w 1 weights of the edges on the path, under the constrai nt that the sum of the w 2 edges of th e path is a t mo st B (at least B ). A standar d but i neffic ient solution to this problem con sists of cons tructing a graph G’ of pairs (i,j) , where i is a vertex of G and j i s an integer value between 0 and Bmax =the sum of all the w 2 weights of the edges of G . For every edge e from u to v we add Bmax - w 2 (e)+1 edges, from a vertex (u,j) to t he vertex (u, j+w 2 (e)) ( 0 ≤ j ≤ Bmax -w 2 (e) ); e ach such edge has a w eight equa l to w 1 (e) . We now only need to compute the shorte st paths (using the weights of the edges of G’ ) from (s,0) to all the other vertice s. The answer to our problem is the minimum length of the sho rtest path from ( s,0) to some ( t,j) , with j ≤ B (or j ≥ B ). A much more eff icient approach, albeit a heuris tic one, is the following. We assig n t o every edge e of G a cost function c(e,x)=w 1 (e)+x·w 2 (e) , where x is a parameter. We compute t he shortest path from s to t using t he newly assigned cost func tions of the edges, for x=0 and we compute w 2 sum(0) =the sum of the w 2 weights of the edges on the path. If w 2 sum(0) ≤ B (a nd we ar e in the “at mo st B” case) or w 2 sum(0) ≥ B (a nd we a re in the “ at least B” case), then the shortest path at x=0 is the one we are looking for (because it minimizes the sum of the w 1 weights di sregarding the w 2 weights; howeve r, th e sum of the w 2 weights of the edges on the p ath satisf ies the constra ints). Let’s assume now that w 2 sum(0)>B and w e are loo king f or the path from s to t minimizing the sum o f the w 1 weights wi th the constrain t that the sum of the w 2 weights is at most B . We n otice that as th e parameter x increases from 0 to + ∞ , the t otal sum of the w 2 weights on the shortest path from s to t (using the cost function s c(*,x) ) decrea ses (although not s trictly ). In fact, we have that w 2 sum(x’) ≥ w 2 sum(x’’) if x’ ≤ x’’ . At x=+ ∞ , the influence of the w 1 weights is negligible. Thus, at x=+ ∞ , we can cons ider c(e,x =+ ∞ )=w 2 (e) for eve ry edge e . Let w 2 sum(+ ∞ ) be the sum of the w 2 weights of the shortest p ath from s to t when x=+ ∞ . If w 2 sum(+ ∞ )>B then we have no solution. Otherwise, we will bin ary s earch the smallest value of x (between 0 and + ∞ ) f or w hich w 2 sum(x) ≤ B . The sum of the w 1 weights on the e dges of the shortest p ath f rom s to t for the value of x we found in the binary search is the minimum possible sum of the w 1 w eight s on a path from s to t which s atisfi es the c onstrain ts and w hich can b e fou nd by this algor ithm. Note that w 2 sum(x) is computed as follows. We compute the shortest path from s to t using the costs c(e,x) on t he edg es. Then, we fi nd the edges composing th e actual path and we let w 2 sum(x) be the sum of the w 2 weights of these edges. T he time complexity is O ((m+n· log(n))· log(x)) for arbitrary d irected graphs and O((m+n)· log(x)) for directed acy clic graphs. In the second case, when we want the sum of the w 2 weights t o be a t least B and w 2 sum(0)1 (i.e. we set xm=c·xm ; e.g. c=2 ). Then, we binary search xmin on the interva l [xm,0] . After this, we compute w 2 sum(xmin) . If w 2 sum(xmin)B (for the case “at most B” ), we have th e property that w 2 sum(x’) ≤ w 2 sum(x’’) fo r x’ ≤ x’’ . Thus, we will find a value xmin<0 s uch that w 2 sum(xmin) ≤ B (the same way we found the value xmin previously ). Then, we will binary search the largest value of x in the interval [xmin,0] such t hat w 2 sum(x) ≤ B . The longest path corre sponding to this value of x is a near- optima l path for our p roblem. If, initially , we have w 2 sum(0) 0 such that w 2 sum(xm ax) ≥ B (we start with xmax=1 and we multiply it by c>1 until t he condition is met). Then, we binary search the smallest value of x in the interval [ 0,xmax ] f or which w 2 sum(x) ≥ B . The longest path corr espondi ng to this valu e of x is a (near) o ptimal pat h for our origina l proble m. An optimal path (with respect to the aggregation function aggf ) from every vertex u to t in a directed acyclic graph in which every edge e and vertex v have a weight we(e) and wv(v) can be computed recursively, usin g memoization. We initializ e the values computed(u) =false for every vertex u . We have popt(t)=wv(t) and computed(t)=true . Then, we consider every vertex u and we call Comp ute(u) which ta kes the following steps: (1) if comp uted(u)=fals e then: { (1.1) popt(u)= aggf(wv( u), opt{aggf(we(e ), Compute(v)) | e is an edge directed fr om u to v}) ; (1.2) computed(u) =true ; } (2) return pop t(u) . o pt can be , for instance, max or min . III. S ENSITIVITY A NALYSIS A LGORI THMS A. Classif ying Graph Edg es and Verti ces We consi der a directed graph G , in whic h every directed edge (u,v) ( from vertex u to vertex v ) has a weight w (u,v ) . We would like to class ify the vertices and edges o f this gr aph into 3 categories, relative to the shortest path (i.e. the p ath of minimum total we ight) between two given vertic es s and t : 1) belonging to every shortest path from s to t ; 2) belonging to a t le ast one shortest path from s to t ; 3) belong ing to no shortest path f rom s to t . We will start b y computing the shortest path tree rooted at s (i.e. the shortest p aths from s to every other vertex of t he g raph). W e can achieve t his i n O(m+n·log( n)) time, where m is t he number of e dges of the graph and n is the nu mber of ver tices. Let ds(u) be the distance from s to u in the graph (if u is not reachab le from s , then ds( u)=+ ∞ ). I f ds (t)=+ ∞ then t is no t reach able f rom s and all the edges and vertices belong to c ategory 3 (as there is no pa th from s to t ) . If ds(t)< + ∞ then we compute the shortest path distances from t to every vertex of the graph, consider ing the transposed graph ( i. e. the graph in which the direc t ion of each edge i s rever s ed). Le t dt(u) b e the dist ance fro m t to u in the transposed graph. We will mark the vertices u for which ds(u)+dt ( u)=ds(t) ( = dt(s) ); the other verti c es wil l be left unmarked. Note that s and t are also mar ked (as ds(s)=dt( t)=0 and ds(t)=dt(s) ). T hen, we construct th e graph G’ containing all the marked vertices and all the edges between them (an edge (u,v) is included in G’ onl y if both u and v were marked). Every edge th at was not included in G’ and ev ery vertex that wa s not marked be long to c ateg o ry 3 . After this, we will i gnore the direction of the edges of G’ , thus turning G’ into an undirec t ed graph G’’ . In G’’ we will compute the bridges a nd cut vertice s , in O(m+n) time. Every directed edge (u,v) from G’ correspondi n g to a bridge in G’’ belongs to category 1 ; every vertex from G’ corre sponding to a c ut vertex in G’’ also belongs to ca t egory 1 . All the other edges an d vertice s from G’ b elong t o catego ry 2 . When the edge weights are all 1 (or a ll equal, in which case we c an replace th em by 1 ), we can improve the time complexity to O(m+n) . The distances from s to every vertex of G and from t to every vert ex of the t ranspose of G can be computed with a simple BF S traversal. Afterwards, we construct G’ like before (again , all the edges and vert i ces outside of G’ belong to category 3 ). After constructing G’ , we do not n eed to construct G’’ any m ore and co m pute its edges and cut vertice s . Instead, we will initialize an array cnt (with indices from 0 to n-1 ) to 0 . Th en, for every vertex u o f G’ we increase cnt(ds(u)) by 1 . cnt(d) will be equal to the number of vertice s u of G ’ such th at ds(u)=d . A ve rtex u of G’ bel o ngs to category 1 only if cnt(d s (u))=1 (otherwise, if cnt(ds(u) )> 1 , then u belongs to category 2 ). A directed edge (u,v) of G’ belongs t o category 1 only if both u and v belong to categ o ry 1 ; otherwise, (u,v) b elong s to categ or y 2 . The algorithms described in this section can also be used for und i rected graphs. If we have an undirected graph UG , we w ill construct a directed graph G with th e same ver tices as UG , by adding to G t wo directed ed ges (u,v) and ( v,u) for every undirect ed edge (u,v) of UG ; both e dges will have the same weig ht w(u,v) . The n, we run on e of t he al gorithm s described above. A vertex of U G belongs to the same category as the correspondi n g v ertex of G . An edge (u,v) of UG belongs to categ o ry 1 ( 2 ) if at least one of the edges (u,v) or (v,u) belongs to catego r y 1 ( 2 ). N ote that if one of the edges (u,v) and (v,u) belongs to category 1 or 2 , then the other edge b elongs to category 3 . An edge (u,v) of UG belongs to category 3 if b oth e d ges ( u, v) and (v ,u) of G belong to c at egory 3 . B. Classif ying Items Relati ve to Knapsa ck Solutions We have n items. Eac h item i ( 1 ≤ i ≤ n ) has a wei ght w(i) ≥ 0 . We want to find a subset of items whose sum of weights is exactly S (the knapsa ck problem) . We would l ike to cla ssify the n items into 3 categ ories: 1) belonging to every knapsack solution; 2) belonging to at least one knapsack solution; 3) belonging to no solution. W e will assume that we can afford O(n·S) time and memory . We will compute ok 1 (i,j)= t rue , if we can obtain the s um j using some of the items 1, …, i , or fal se , otherwise ( 0 ≤ i ≤ n; 0 ≤ j ≤ S ). Moreover, we also compute cnt 1 (i,j) =th e number of solutions for obtaining the sum j from the it ems 1, … , i (bounded from above at any val ue Q ≥ 2 , even Q=+ ∞ ; 0 ≤ i ≤ n; 0 ≤ j ≤ S ). W e have ok 1 (0,0)=tru e , cnt 1 (0,0) =1 , ok 1 (0,1 ≤ j ≤ S)=false and cnt 1 (0, 1 ≤ j ≤ S) =0 . For 1 ≤ i ≤ n (in this order) we have: ok 1 (i,0 ≤ j< min{w(i),S +1})=ok 1 (i-1,j) , cnt 1 (i,0 ≤ j< min{w( i), S+1})=cn t 1 (i-1,j) ) , ok 1 (i,w(i) ≤ j ≤ S)=ok 1 (i-1,j) or ok 1 (i-1, j - w(i)) ( th e first ca se consider s th at ite m i is not used f or obtaining the sum j , while the second case consider s that item i is u sed for obtaining the sum j ) and c nt 1 (i,w(i) ≤ j ≤ S)= min{Q, cnt 1 (i-1,j) +cnt 1 (i-1,j- w(i))} . Then, in a s imilar manner, we compute ok 2 (i,j)=t rue , if we can obtain the sum j using some of the items i, i+1, …, n , or false , otherwise, and cnt 2 (i,j) ( 1 ≤ i ≤ n+1 ; 0 ≤ j ≤ S ) . We have ok 2 (n+1,0)=tru e , cnt 2 (n+1 ,0)=1 , ok 2 (n+1,1 ≤ j ≤ S )=false and cnt 2 (n+1,1 ≤ j ≤ S )= 0 . For 1 ≤ i ≤ n (i n decrea sing order) we hav e: ok 2 (i,0 ≤ j< min{w(i), S+1 })=o k 2 (i+1, j ), cnt 2 (i,0 ≤ j< min{w( i), S+1})=cn t 2 (i+1, j ), ok 2 (i,w(i) ≤ j ≤ S )=ok 2 (i+1,j) or ok 2 (i+1, j - w(i)) and cnt 2 (i,w(i) ≤ j ≤ S)=min{Q, cnt 2 (i+1, j)+cnt 2 (i+1, j- w(i))} . With these tables, we can decide for each item i in O(S) time to which categ or y it belongs . We will compu te c(i) =the sum of th e values cnt 1 (i-1,j) ·cnt 2 (i+1, S -j) ( 0 ≤ j ≤ S ), and d(i) =the logical OR of the values ( ok 1 (i-1,j) and ok 2 (i+1,S-j -w(i)) ) ( 0 ≤ j ≤ S-w(i) ; d(i)=false if w( i )>S ). If d(i)=false then item i belongs to category 3 ; otherwise, if c(i)>0 then item i belongs to category 2 (there is at least one solution without item i ) and if c(i)=0 then item i be longs to category 1 (there is no solution without item i , meaning that item i b elong s to every knapsack solution). Note how this so lution is m u ch better than the triv i al solution w hi ch would r e move every item i one at a time, would recompu t e the knapsack problem’s dy n amic programming tables every time (obtaining an O(n 2 ·S) time complexity ), and would c ompute a(i)=true ( false ) if the sum S-w(i) can (cannot) be obtained and b(i)=true ( false ) if the sum S can ( canno t ) be obtained. If a(i)=false then item i is in category 3 ; if a(i)=true and b(i)=true ( b(i)=fa lse ) then item i is in cat egory 2 ( 1 ). We will no w also assign a cost cost(i) to ever y item i and we want to find a subset of items whos e sum of weights i s equal to S and whose sum of cost s is minimum. As b efore, we want to cl assify the items into the same 3 categori es , relative to an o ptimal solution for this p roblem : 1 ) belonging to every o ptimal solution; 2 ) belong i ng to at least one optimal solution ; 3) belonging to no optimal solution. We will compute c min 1 (i,j) ( cmin 2 (i,j) ) = th e minimum cost of a subset of the items 1, …, i ( i, …, n ) such that their sum of weights is j ( 0 ≤ j ≤ S ); we also compute cnt 1 (i,j) ( c nt 2 (i,j) ) = the number of subsets, bounded from above by any value Q ≥ 2 (even Q=+ ∞ ), of the items 1, …, i ( i, …, n ) whose sum of weights is j and whose sum of cos ts i s cmin 1 (i,j) ( cmin 2 (i,j) ) ( 0 ≤ j ≤ S ). We have cmin 1 (0,0)=cm in 2 (n+1,0)=0 , cnt 1 (0,0)= cnt 2 (n+1 ,0)=1 , cmin 1 (0,1 ≤ j ≤ S)=cmin 2 (n+1, 1 ≤ j ≤ S)=+ ∞ , and cnt 1 (0, 1 ≤ j ≤ S) =cnt 2 (n+1,1 ≤ j ≤ S)=0 . For 1 ≤ i ≤ n (in increasing order) we have: cmin 1 (i, 0 ≤ jS then d(i)=+ ∞ ). If d(i)>cmin 1 (n,S) then the item i belongs to category 3 . Otherwise ( if d(i) = cmin 1 (n,S) ) then: if c(i)>0 then item i be l ongs to category 2 , ot h erwise (if c(i)=0 ) then item i b elong s to catego r y 1 . IV. H AMILTONIA N AND C OLOR -A LTERNATING P ATHS AN D C YCLES A. Hamilto nian Path in a Tournament Graph We consider a tournament graph G (a di rected graph in which t here is exactl y on e direc ted edge b etween an y t wo vertic es i and j : either t he edge i->j , o r j ->i ) with n vertices. We w ant to find a H amiltonian path in this graph . Th e graph is not given e xplicitl y . It s structure can be disco vered by asking questions: Ask(u,v) ( u ≠ v ) ret urns 1 , if the edge u->v exists in th e graph, o r -1 , if the edge v-> u exists in G . A tourn ament graphs always c ontains at least on e Hamilto nian path. We can cons truct such a path incr ementally. We will start wit h a p ath of length 1 , consisting of th e vertex 1 . Then, we will traverse the other vertic es i=2 ,…,n . W hen we reach t he vert ex i , we w ill alrea dy have a pat h v(1 ), …, v(i-1) com posed of t he vertices 1, …, i-1 (in so me order) , such th at w e h ave t he dir ected edges v(j)-> v(j+1) ( 1 ≤ j ≤ i-2 ) . I f t he edge i->v( 1) exis ts in G , then we can add the vert ex i before v (1) and ob tain a p ath with i vertic es. If , instead , t he edge v(i-1)->i exists in G , then we can add i a fter v(i-1) and o btain a path with i vertic es. If none of the edges i->v(1) and v(i-1)->i exist in G , then we will tr averse the vert ices v(j) on t he path found so far ( j=2,…,i-1 ) , until we find t he first vert ex for w hich the edge i->v(j) exists in G . We will i nsert the vertex i betwe en v(j-1) an d v(j) , obtaining a new path: v(1), …, v(j- 1), i, v(j), …, v (i-1) . The time compl exity of t his approach is O(n 2 ) . Anoth er O(n 2 ) solution is t he fol lowing. We consi der the vertices in t he order p(1)=1, ..., p(i)=i , ..., p (N)=N . Then, we will repeatedl y t ravers e th ese vert ices. When we find tw o adjacent vertices p(i) an d p(i+1) su ch t hat th e edge betwe en th em is oriented from p(i+1) t o p(i) , t hen we s wap the two vertices in the p ordering. Wh en n o more sw aps can be performed, we s top. This algorithm is ver y sim ilar t o bubble -sort. The pr evious al gorithm was very s im ilar to the insertion so rt m ethod. T he O (n 2 ) soluti ons presented earli er can be improved to O(n·log (n)) . We will start by im proving the first presented s olution, as follows. Let’s assume that we arrived at vertex i a nd we cur rently ha ve a pat h v(1 ), … , v(i- 1) (co ntaining th e vertices 1, …, i -1 ). W e w ill find in O(log(n )) tim e the place where th e vertex i w i ll be i nserted in t he path. If we h ave th e edge i->v(1) , then we add the vertex i before v(1) ; otherwise, if we h ave th e e dge v(i- 1)->i then we add vertex i after v(i-1) . Ot herwise, w e kn ow that we have t he e dges v(1)->i and i ->v(i-1) . We will use the binar y search t echnique and, at every step, we will m aintain an i nterval [ a,b] , s uch that we ha ve th e edges v(a)->i and i - >v(b) . Initiall y , a=1 and b=i-1 . Within th e binar y sear ch, we will select c=(a+b) div 2 . If we h ave th e edge v(c)->i , then w e maint ain furth er the i nterval [c,b] ; otherwise, we have t he ed ge i->v(c) and we wil l maint ain further t he interval [a,c] . The b inar y search ends when b=a+1 . Then, we insert vertex i betw een v(a) and v(a+1) in the p ath. Other s olutions with O( n·log(n)) ti me co mplexiti es are based on sorting algorithms l ike merge-sort or quick-sort. Basicall y, we consi der th at every vertex i of the grap h has an associ ated val ue val(i) . W hen running th e sorting algorithms , we will t ry to sort th e vertices in “incre asing” order of thei r val ues. When we need to compare the values of two vertices i and j , we make the following de cision: • if we have t he edge i ->j then val(i)i then val(j)v(i+1 ) ( 1 ≤ i ≤ n-1 ). B. Constr ained Path/Cycl e in a Small G raph We co nsider a dire cted grap h wit h n vertices, where n is not t oo large. Ever y directe d edge e ( directed from u(e) to v(e) ) has a cost cm(e) ≥ 0 and ever y vertex u has a cost cn(u) ≥ 0 . We want t o f ind a path/c y c le co ntaining exactl y Q vertic es for which the agg r egate agg o f the edge an d vertex costs is min i mu m. For Q = 1 we simply choos e the vert ex u with t he minimum value cn (u) . Fo r Q ≥ 2 we will compute the values D min (i, S) =the minimum cost of a p ath ending at the vertex i and p assing t hrough every vert ex from the set S ( S is a subset of {1,...,n} and contains the vertex i ) and through no other vertex; we will a lso compute C min (i,j,S) =t he minimum cost o f a pat h whos e two end- vertic es are i and j (th e path is dire cted from i to j ) and passes t hrough e very vertex of the set S ( S is a subs et o f {1,...,n} and contains the vertices i and j ) and through no other vert ex. We will consider t he s ubsets S in incr easing order of their c ardinality |S| (from 1 t o Q ) . We ha ve D min (i, {i})=cn(i) and C min (i,i,{i})=cn(i) . For | S| ≥ 2 , we will proceed as follows. D min (i,S) (wi th i ∈ S ) is equ al to c n (i) a gg min{D min (j, S\{i})+ cm(e) | e is an edge d irected from a vertex j to the vertex i , 1 ≤ j ≤ n , j ≠ i , j ∈ S\{i} ). C min (i, j, S) is equal to min{U(i,j,S), V(i ,j,S)} , wh ere: U(i, j, S)=cn(j) agg min{C min (i, k, S\{j}) agg cm(e) | e is an edge directed from the v er tex k to the vertex j , 1 ≤ k ≤ n , k ≠ j , k ∈ (S\ {j})} and V(i, j, S)=cn (i) agg min {Cmin(k, j, S\{i}) ag g cm(e)|e is an edge dir ected from the vert ex i to the vertex k , 1 ≤ k ≤ n , k ≠ i , k ∈ (S\ {i})} (actually, V(i ,j,S) may always be co nsidered + ∞ ). The answ er will be min {D min (i,S)|1 ≤ i ≤ N, |S|=Q} (for the path c ase), r espectivel y min {C min (i,j,S) agg cm(e) | e i s an edge d irected from j to i , 1 ≤ i,j ≤ N, i ≠ j , |S |=Q} . Th e time complexit y of the algorithm is O(n 2 ·T(n,Q)) for the path case and O(n 3 ·T(n,Q)) for the cy cle case, w h ere T(n,Q)= C(n,0)+ C(n,1)+...+C(n ,Q) ( C(i ,j) =combin ations o f i eleme nts t aken as j ) . When Q=n , T(n,n)=2 n . Note th at t he algorithm can be generaliz ed as follows: on l y s ome s ubsets S of verti ces are allowed to f orm t he path/cycle; in t his case, we simply i terat e when co mputing the answer over the valid subsets S only. C. Ha miltonian Path in the Cube of a Grap h The cube graph G 3 o f an u ndirected graph G is t he grap h in which two vertices x and y are di rectly connected by an edge if th eir distance in G is at mo st 3 . In ord er to fi nd a Hamilto nian path in G 3 , we will first find a sp anning t ree T of G and then we will focus on finding a Hamiltonian path in T 3 . We will choose an arbitrar y root vert ex r f or T and we will perform a DFS traversal of T st arting fr om r . We consid er the level o f each node: level(r)=1 an d level(i ≠ r)= level(par ent(i))+1 . While t raversing th e t ree, we will construct the Hamilt onian path HP as fo llows. We start with an empt y path HP . Then, d uring th e traversal, w hen we first enter a vert ex i an d l evel(i) i s odd , we add the vertex i at the end of HP (befor e tr aversing an y of the other vertices in vertex i ’s su btree). Af t er finis hing traversi ng the entire subtr ee of a vertex i , if l evel(i) is even, th en we add i at t he end of HP . It is easy to notice that t he dis tance in T bet ween any two co nsecuti ve nodes in HP is at m ost 3 : if the y have the same level parit y , the distance between them is 2 (they are either tw o so ns of t he s ame vertex or one of them is the grand-parent of the other ); th e di stance bet ween t wo conse cutive ver tices x a nd y from H P ca n also be 3 , by consid ering t he foll owing scenario – level( x) i s even and we exit the subtre e of the vertex x , we return to vertex x ’s grand-parent z and t hen we e n ter the vertex y which i s one of z ’s s ons; of course , the distance ma y also be 1 . D. Optimal Color Alt ernating Path We consider a graph with n vertices and m dir ected edges. Each e dge e i s directed from u(e) t o v(e) , h as a cost cost(e ) ≥ 0 a nd a color col(e) (e.g. label). T he colors are numbe red from 1 to C . Every verte x u also h as a cost cn(u) . We want t o find a path from the vertex s to th e vert ex t whose aggregate cos t is minimum (us ing t he aggregatio n functio n a gg ) and such that an y two co nsecutive ed ges on the path have different colors. The first solution consists o f constructin g a color-expand ed grap h, in which ever y nod e is a pair (i,k) , meaning that we rea ched nod e i of th e i nitial graph and the last use d edge h ad color k . Normall y , 1 ≤ k ≤ C , but we wi ll also c onsider the cas e k= 0 for the vert ex i=s . For every d ire cted ed ge e o f th e o riginal grap h we add an edge from (u(e),k) to (v(e) ,col(e)) with the cost cost(e)+ cn(v(e) ) ( 1 ≤ k ≤ C ; k ma y als o be 0 when u(e)=s ; k ≠ col(e) ) . We will n ow compute t he tre e of minim um aggregate paths st arting from (s,0) in th e color-expanded graph (consid ering costs only on t he graph’s edges). Th e minimum cost of a color-alter nating p ath from s t o t is cn(s) agg the minimum of t he costs o f reaching a ver tex (t,k) ( 0 ≤ k ≤ C ). Th e col or- expanded graph h as O(n·C) vert ices and O(m ·C) edges. Another pos sibility i s t he following. We will comput e th e minimum cost of a path from s to ever y ot her verte x i o f t he graph (let this value be C min (i) ). We will also maintain Col min (i) =the color of the l ast edge on the opti mal path f rom s to i . We also compute C min,2 (i) =the mi nimum cost of a path from s to i such th at the color o f its last e dge is differ ent from Col min (i) ; let the color of the la s t edge of the pat h denoted by C min,2 (i) be Col min,2 (i) . If th e graph is directed and acycli c, t hen we wi ll first compute a t opological sort. T hen, we t raverse th e vertices i i n the o rder of t his sort . For a vertex i we will consid er as candidat e (Cost, Color ) pairs the following val ues: ( C min (u(e)) ag g c ost(e) agg cn(i), col(e)) (where v(e)=i and col( e) ≠ Col min (u(e)) ) and (C min,2 (u(e)) agg cost(e ) agg cn(i), col(e)) (where v(e)=i and col( e) ≠ Col min,2 (u(e)) ). If i= s t hen C min (s)=cn(s) , Col min (s)=0 , C min,2 (s)=+ ∞ and Col min,2 (s)=0 . For i ≠ s we initi alize C min (i)= C min,2 (i)=+ ∞ and Co l min (i)= Col min,2 (i)=0 . Fo r each candidate p air (Cost, Color) : (1) if Cost

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment