To Fll or not to Fll: The Gas Staton Problem Samr Khuller Azarakhsh Malekan Julán Mestre Abstract In ths paper we study several routng problems that generalze shortest paths and the Travelng Salesman Problem. We consder a more general model that ncorporates the actual cost n terms of gas prces. We have a vehcle wth a gven tank capacty. We assume that at each vertex gas may be purchased at a certan prce. The objectve s to fnd the cheapest route to go from s to t, or the cheapest tour vstng a gven set of locatons. Surprsngly, the problem of fnd the cheapest way to go from s to t can be solved n polynomal tme and s not NP-complete. For most other versons however, the problem s NP-complete and we develop polynomal tme approxmaton algorthms for these versons. 1 Introducton Optmzaton problems related to computng the shortest (or cheapest) tour vstng a set of locatons, or that of computng the shortest path between a par of locatons are pervasve n Computer Scence and Operatons Research. Typcally, the measures that we optmze are n terms of dstance traveled, or tme spent (or n some cases, a combnaton of the two). There are lterally thousands of papers dealng wth problems related to shortest-path and tour problems. In ths paper, we consder a more general model that ncorporates the actual cost n terms of gas prces. We have a vehcle wth a gven tank capacty of U. In fact, we wll assume that U s the dstance the vehcle may travel on a full tank of gas (ths can easly be obtaned by takng the product of the tank sze and the mleage per gas unt of the vehcle). Moreover, we may assume that we start wth some gven amount of gas µ ( U) n the tank. We assume that at each vertex v gas may be purchased at a prce of c(v). Ths prce s the cost of gas per mle. For example f gas costs $3.40 per gallon and the vehcle can travel for 17 mles per gallon, then the cost per mle s 20 cents. At each gas staton we may fll up some amount of gas to extend the range of the vehcle by a certan amount. Moreover, snce gas prces vary, the cost depends on where we purchase gas from. In addton to fluctuatng gas prces, there s sgnfcant varance n the prce of gas between gas statons n dfferent areas. For example, n the Washngton DC area alone, the varance n gas prces between gas statons n dfferent areas (on the same day) can be by as much as 20%. Due to dfferent state taxes, gas prces n adjacent states also vary. Fnally, one may ask: why do we expect such nformaton to be avalable? In fact, there are a collecton of web stes [2, 1] that currently lst gas prces n an area specfed by zp code. So t s reasonable to assume that nformaton about Research supported by NSF grant CCF-0430650. Insttute for Advanced Computer Studes. Unversty of Maryland, College Park, MD 20742, USA. Department of Computer Scence. Unversty of Maryland, College Park, MD 20742, USA. Emal: {samr,malekan,jmestre}@cs.umd.edu 1
gas prces s avalable. What we are nterested n are algorthms that wll let us compute solutons to some basc problems, gven ths nformaton. In ths general framework, we are nterested n a collecton of basc questons. 1. (The gas staton problem) Gven a start node s and a target node t, how do we go from s to t n the cheapest possble way f we start at s wth µ s amount of gas? In addton we consder the varaton n whch we are wllng to stop to get gas at most tmes 1. Another generalzaton we study s the sequence gas staton problem. Here, we want to fnd the cheapest route that vsts a set of p locatons n a specfed order (for example by a delvery vehcle). 2. (The fxed-path gas staton problem) An nterestng specal case s when we fx the path along whch we would lke to travel, and only want the cheapest soluton wth ths restrcton. For ths verson we develop a faster algorthm. 3. (The unform cost tour gas staton problem) Gven a collecton of ctes T, and a set of gas statons S at whch we are wllng to purchase gas, fnd the shortest tour that vsts T. We have to ensure that we never run out of gas. Clearly ths problem generalzes the Travelng Salesman Problem. The problem gets more nterestng when S T, and we address ths case. Ths models the stuaton when a large transportaton company has a deal wth a certan gas company, and ther vehcles may fll up gas at any staton of ths company at a pre-negotated prce. Here we assume that gas prces are the same at each gas staton. Ths could also model a stuaton where some gas statons wth very hgh prces are smply dropped from consderaton, and the set S s smply the set of gas statons that we are wllng to use. 4. (The tour gas staton problem) Ths s the same as the prevous problem, except that the prces at dfferent statons can vary. Of all the above problems, only the tour problems are NP-hard. For the frst two we develop polynomal tme algorthms, and for the tour problems we develop approxmaton algorthms. We now gve a short summary of the results n the paper: 1. (The gas staton problem) For the basc gas staton problem, our algorthm runs n tme O( n 2 log n) and computes an optmal soluton. If we want to vst a sequence of p ctes we can fnd an optmal soluton n tme O( (np) 2 log(np)). In addton, we develop a second algorthm for the all-pars verson that runs n tme O(n 3 2 ). Ths method s better than repeatng the fxed-destnaton algorthm n tmes when < log n. 2. (The fxed-path gas staton problem) For the fxed-path verson wth an unbounded number of stops, we develop a faster algorthm that takes O(n log n) tme. See Appendx B. 3. (The unform cost tour gas staton problem) Snce ths problem s NP-hard, we focus on polynomal tme approxmaton algorthms. We assume that every cty has a gas staton wthn a dstance of α U 2 for some α < 1. Ths assumpton s reasonable snce n any case, every cty has to have a gas staton wthn dstance U 2, otherwse there s no way to vst t. A smlar assumpton s made n the work on dstance constraned vehcle routng problem [14]. We develop an approxmaton algorthm wth an approxmaton factor of 3 2 (1+α 1 α ). We also consder a specal case, namely when there s only one gas staton. Ths s the same 1 Ths restrcton makes sense, because n some stuatons where the gas prces are decreasng as we approach our destnaton, the cheapest soluton may nvolve an arbtrarly large number of stops, snce we only fll up enough gas to make t to a cheaper staton further down the path. 2
as havng a central depot, and requrng the vehcle to return to the depot after travelng a maxmum dstance of U. For ths specal case, we develop an algorthm wth factor O(ln 1 1 α ) 3 and ths mproves the bound of 2(1 α) gven by L et al. [14] for the dstance constraned vehcle routng problem. 4. (The tour gas staton problem) For the tour problem wth arbtrary prces, we can use the followng scheme: sort all the gas prces n non-decreasng order c 1 c 2...c n. Now guess a range of prces [c...c j ] one s wllng to pay, and let β j = c j c. Let S j nclude all the gas statons v such that c c(v) c j. We can run the algorthm for the unform cost tour gas staton problem wth set S j and ctes T. Ths wll yeld a tour Tour j. We observe that the cost of the tour Tour j s at most O( β j 1 α ) tmes the cost of an optmal soluton, snce ts possble that we always pay a factor β j more than the optmal soluton, at each staton where we fll gas. Takng the best soluton over all O(n 2 ) possble choces gves a vald soluton to the tour gas staton problem. 1.1 Related Work The problems of computng shortest paths and the shortest TSP tour are clearly the most relevant ones here and are wdely studed, and dscussed n several books [13, 18]. One closely related problem s the Orenteerng problem [3, 5, 11, 7]. In ths problem the goal s to compute a path of a fxed length L that vsts as many locatons as possble, startng from a specfed vertex. For ths problem, a factor 3 approxmaton has been gven recently by Bansal et al. [6]. (In fact, they can fx the startng and endng vertces.) Ths algorthm s used as subroutne for developng a bcrtera bound for Deadlne TSP. By usng the 3 approxmaton for the Orenteerng problem, we develop an O(log T ) approxmaton for the sngle gas staton tour problem. Ths s not surprsng, snce we would lke to cover all the locatons by fndng walks of length at most U. There has been some recent work by Nagarajan and Rav [17] on mnmum vehcle routng that s closely related to the sngle gas staton tour problem. In ths problem, a desgnated root vertex (depot) and a deadlne D are gven and the goal s to use the mnmum number of vehcles from the root so that each locaton s met by at least one of the vehcles, and each vehcle traverses length at most D. (In ther defnton, vehcles do not have to go back to the root.) They gve a 4-approxmaton for the case where locatons are n a tree and an O(log D) approxmaton for graphs wth nteger weghts. Another closely related pece of work s by Arkn et al. [4] where tree and tour covers of bounded length are computed. What makes ther problem easer s that there s no specfed root node, or a set of gas statons one of whch should be ncluded n any bounded length tree or tour. Several peces of work deal wth vehcle routng problems [15, 16, 10] wth multple vehcles, where the objectve s to bound the total cost of the soluton, or to mnmze the longest tour. However these problems are sgnfcantly easer to develop approxmaton algorthms for. 2 The gas staton problem The nput to our problem conssts of a complete graph G = (V, E) wth edge lengths d : E R +, gas costs c : V R + and a tank capacty U. (Equvalently, f we are not gven a complete graph we can defne d(u, v) to be the dstance between u and v n G.) Our goal s to go from a source s to a destnaton t n the cheapest possble way usng at most stops to fll gas. For ease of exposton we concentrate on the case where we start from s wth an empty tank. The case n whch we start wth µ s unts of gas can be reduced to the former as follows. Add a new node s 3
such that d(s, s) = U µ s and c(s ) = 0. The problem of startng from s wth µ s unts of gas and that of startng from s wth an empty tank usng one addtonal stop are equvalent. We would also lke to note that our strategy yelds a soluton where the gas tank wll be empty when one reaches a locaton where gas can be flled cheaply. In practce, ths s not safe and one mght run out of gas (for example f one gets stuck n traffc). For that reason we suggest defnng U to be smaller than the actual tank capacty so that we always have some reserve capacty. In ths secton we develop an O( n 2 log n) tme algorthm for the gas staton problem. In addton, when = n we show how to solve the problem n O(n 3 ) tme for general graphs, and O(n log n) tme for the case where G s a fxed path. One nterestng generalzaton of the problem s the sequence gas staton problem where we are gven a sequence s 1, s 2,...,s p of vertces that we must vst n the specfed order. Ths varant can be reduced to the s-t verson n an approprately defned graph (see Appendx A). 2.1 The gas staton problem usng stops We wll solve the gas staton problem usng the followng dynamc program (DP) formulaton 2 : C[u, q, g] = Mnmum cost of gong from u to t usng q refll stops, startng wth g unts of gas. We consder u to be one of the q stops. The man dffculty n dealng wth the problem stems from the fact that, n prncple, we need to consder every value of g [0, U]. One way to avod ths s to dscretze the values g can take. Unfortunately ths only yelds a pseudo-polynomal tme algorthm. To get around ths we need to take a closer look at the structure of the optmal soluton. Lemma 1. Let s = u 1, u 2,...,u l be the refll stops of an optmal soluton usng at most stops. The followng s an optmal strategy for decdng how much gas to fll at each stop: At u l fll just enough to reach t wth an empty tank; for j < l ) If c(u j ) < c(u j+1 ), then at u j fll up the tank. ) If c(u j ) c(u j+1 ), then at u j fll just enough gas to reach u j+1. Consder a refll stop u s n the optmal soluton, and let w be the stop rght before u. Lemma 1 mples that f c(w) > c(u), we reach u wth an empty tank, otherwse we reach u wth U d(w, u) gas. Therefore, n our DP formulaton we need to keep track of at most n dfferent values of gas for u. Let GV (u) be the set of such values, namely GV (u) = {U d(w, u) w V and c(w) < c(u) and d(w, u) U} {0} The followng recurrence allows us to compute C[u, q, g] for any g GV (u): { (d(u, t) g)c(u) f g d(u, t) U C[u, 1, g] = otherwse { C[v, q 1, 0] + (d(u, v) g)c(u) f c(v) c(u) g d(u, v) C[u, q, g] = C[v, q 1, U d(u, v)] + (U g)c(u) f c(v) > c(u) mn v s.t. d(u,v) U The optmal soluton can be found as mn 1 l C[s, l, 0]. The nave way of fllng the table takes O( n 3 ) tme. However, ths can be done more effcently. 2 Whle farly elementary, the soluton presented n ths secton s the dstlled verson of sgnfcantly more complex schemes. In order to fully apprecate t, the reader s encouraged to try to solve the problem before readng on. 4
Theorem 1. There s an O( n 2 log n) tme algorthm for the gas staton problem wth stops. Instead of spendng O(n) tme computng a sngle entry of the table, we spend O(log n) amortzed tme per entry. More precsely, for fxed u V and 1 < q we show how to compute all entres of the form C[u, q, ] n O(n log n) tme usng entres of the form C[, q 1, ]. Theorem 1 follows mmedately from ths. The DP recurson for C[u, q, g] fnds the mnmum, over all v such that d(u, v) U, of terms that corresponds to the cost of gong from u to t through v. Splt each of these terms nto two parts based on whether they depend on g or not. Thus we have an ndependent part, whch s ether C[v, q 1, 0] + d(u, v)c(u) or C[v, q 1, U d(u, v)] + Uc(u); and a dependent part, g c(u). Our procedure begns by sortng the ndependent part of every term. Note that the mnmum of these corresponds to the entry for g = 0. As we ncrease g, the terms decrease unformly. Thus, to compute the table entry for g > 0 just subtract g c(u) from the smallest ndependent part avalable. The only caveat s that the term correspondng to a vertex v such that c(v) c(u) should not be consdered any more once g > d(u, v), we say such a term expres after g > d(u, v). Snce the ndependent terms are sorted, once the smallest ndependent term expres we can walk down the sorted lst to fnd the next vertex whch has not yet expred. The procedure s domnated by the tme spent sortng the ndependent terms whch takes O(n log n) tme. Theorem 2. When = n the problem can be solved n O(n 3 ) tme. We can reduce the problem to a shortest path queston on a new graph H. The vertces of H are pars (u, g), where u V and g GV (u). The edges of H and ther weght w( ) are defned by the DP recurrence: For every u, v V and g GV (u) such that d(u, v) U we have { w ( (u, q), (v,0) ) = (d(u, v) g)c(u) f c(v) c(u) g d(u, v), w ( (u, q), (v, U d(u, v) ) (1) = (U g)c(u) f c(v) > c(u). Our objectve s to fnd a shortest path from (s,0) to (t, 0). Note that H has at most n 2 vertces and at most n 3 edges. Usng Djkstra s algorthm [9] the theorem follows. 2.2 Faster algorthm for the all-pars verson Consder the case n whch we wsh to solve the problem for all startng nodes, wth µ amount of gas n the tank ntally. Usng the method descrbed n the prevous secton, we get a runnng tme of O(n 3 log n) snce we run the algorthm for each possble destnaton. We wll show that for < log n we can mprove ths and get a bound of O(n 3 2 ). Add new nodes such that d(, ) = U µ and c( ) = 0. If we start at wth µ unts of gas, t s the same as startng from where gas s free. We fll up the tank to capacty U, and then by the tme we reach we wll have exactly µ unts of gas n the tank. (Snce gas s free at any node n any optmal soluton we fll up the tank to capacty U). Ths wll use one extra stop. We defne D[, l, p] as the mnmum cost soluton to go from to l (destnaton), wth p stops to get gas, gven that we start wth an empty tank at. Snce we start wth an empty tank, we have to fll up gas at the startng pont (and ths s ncluded as one of the stops). Clearly, we wll also reach l (destnaton) wth an empty tank, assumng that there s no trval soluton, such as one that arrves at the destnaton wth no fll-ups on the way. Our goal s to compute D[, l, + 1] whch s a mnmum cost soluton to go from to l wth at most stops n-between. Note that the frst fll-up s the one that takes place at node, after that we stop at most tmes. We wll now show how to compute D[, l, p]. There are two optons: 5
Cost of gas 4 Reach wth empty tank Start wth empty tank = 1 2 3 k = 5 Refll stop Fgure 1: Example to show Cost(, k, q) for q = 4. If the gas prce at the frst stop after (e.g. k) s cheaper than c() then we wll reach that staton wth an empty tank after fllng d(, k) unts of gas at (as long as d(, k) U): D[, l, p] = D[k, l, p 1] + d(, k)c() If the frst place where the cost of gas decreases from the prevous stop s the q + 1 st stop and the prce s n ncreasng order n the frst q stops then D[, l, p] = Cost(, k, q) + D[k, l, p q] We defne Cost(, k, q) as the mnmum cost way of gong from to k wth at most q stops to get gas, such that we start at wth an empty tank (and get gas at, whch counts as a stop) and fnally reach k wth an empty tank. In addton, the prce of gas n ntermedate statons s n ncreasng order except for the last stop. We defne D[l, l, p] = 0 and for l we have D[, l,1] = c()d(, l) f d(, l) U), otherwse D[, l,1] =. In general: { } D[, l, p] = mn mn Cost(, k, q) + D[k, l, p q], mn D[k, l, p 1] + d(, k)c() 1 k n 1 k n 1<q p s.t.d(,k) U If we are able to compute Cost(, k, q) effcently, then D[, l, p] can be computed. There are n 2 states n the dynamc program, and each one can be computed n tme O(n ). Ths yelds a runnng tme of O(n 3 2 ). We wll see that the tme requred to compute Cost(, k, q) s O(n 3 ) for all relevant choces of, k, q. Suppose that n gong from to k we stop at 1 =,..., q, q+1 = k (see Fg. 1). Note that c( 1 ) c( 2 )... c( q ), however c( q ) > c( q+1 ). In fact, at 1 we wll get U amount of gas. When we reach j for 1 < j < q, we wll get d( j 1, j ) unts of gas (the amount that we consumed snce the prevous fll-up) at a cost of c( j ) per unt of gas. The amount of gas we wll get at q s just enough to reach k wth an empty tank. Now we can see that the total cost s equal to Uc( 1 )+d( 1, 2 )c( 2 )+...+d( q 2, q 1 )c( q 1 )+(d( q 1, q )+d( q, k) U)c( q ). Note that the last term s not negatve, snce we could not reach k from q 1 even wth a full tank at q 1, wthout stoppng to get a small amount of gas. We compute Cost(, k, q) as follows. Frst note that f d(, k) U then the answer s d(, k)c(). Otherwse we buld a drected graph G = (V V D, E E D ), where V s the set of vertces, and V D = { V }. 6
We defne E: add a drected edge from V to j for each vertex j V \ {} such that d(, j) U and c() c(j). The weght of ths edge s d(, j)c(j). We defne E D as follows: add a drected edge from each j V to k for each vertex k V D \{j } such that U < d(j, k) 2U. The weght of ths edge s mn { (d(j, z) + d(z, k) U)c(z) c(j), c(k) < c(z) and d(j, z), d(z, k) U } Now we can express Cost(, k, q) as Sp(, k, q) + Uc() where Sp(, k, q) s the shortest path from to k n the graph G usng at most q edges. To see why t s true, we can see that for any gven order of stops between and k (where the gas prce s n ncreasng order n consecutve stops), the mnmum cost s equal to the weght of the path n G that starts from, goes to the second stop n the gven order (e.g., 2 ) and then traverses the vertces of V n the same order and from the second last stop goes to k. It s also possble that q = 2 and the path goes drectly from = 1 to k n ths case, and 2 s the choce for z that acheves the mnmum cost for the edge (, k ). For any gven path P n G between and k, f the weght of the path s W P we can fnd a feasble plan for fllng the tank at the statons so that the cost s equal to W P + Uc(). It s enough to fll up the tank at the statons that are n the path, except the last one n whch the tank s flled to only the requred level to reach k. We can conclude that Cost(, k, q) s equal to Sp(, k, q) + Uc(). The runnng tme for fndng the shortest path between all pars of nodes wth dfferent number of stops (at most ) can be computed n O(n 3 ) by dynamc programmng [12]. If we precompute Cost(, k, q) the runnng tme for computng D[, l, + 1] s O(n 3 2 ) assumng we start at wth µ amount of gas. So n general the runnng tme s O(n 3 2 ). 3 The unform cost tour gas staton problem In ths secton we study a varant of the gas staton problem where we must vst a set of ctes T n arbtrary order. We consder the case where gas costs the same at every gas staton, but some ctes may not have a gas staton. More formally, the nput to our problem conssts of an undrected graph G = (V, E) wth edge lengths d : E R +, a set of ctes T V, a set of gas statons S V, and tank capacty U for our vehcle. The objectve s to fnd a mnmum length tour that vsts all ctes n T, and possbly some gas statons n S. We are allowed to vst a locaton multple tmes f necessary. We requre any segment of the tour of length U to contan at least one gas staton, ths ensures we never run out of gas. We call ths the unform cost tour gas staton problem. We assume that we start wth an empty tank at a gas-staton. The problem s NP-hard as t generalzes the well-known travelng salesman problem: just set the tank capacty to the largest dstance between any two ctes and let T = S. In fact, there s a closer connecton between the two problems: If every cty has a gas staton,.e., T S, we can reduce the gas staton problem to TSP. Consder a TSP nstance on T under metrc l : T T R +, where l(x, y) s the mnmum cost of gong between ctes x and y startng wth an empty tank (ths can be computed by standard technques). Snce the cost of gas s the same everywhere, a TSP tour can be turned nto a drvng plan that vsts all ctes wth the same cost and vce-versa. Let OPT denote an optmal soluton, and c(opt) ts cost. As mentoned earler, we can use the algorthm for the unform cost case to derve an approxmaton algorthm for the general case by payng a factor β n the approxmaton rato. Here β 7
s the rato of the maxmum prce that an optmal soluton pays for buyng a unt of gas, to the mnmum prce t pays for buyng a unt of gas (n practce ths ranges from 1 to 1.2). Unfortunately ths reducton to TSP breaks down when ctes are not guaranteed to have a gas staton. Consder gong from x to y, where x does not have a gas staton. The dstance between x and y wll depend on how much gas we have at x, whch n turn depends on whch cty was vsted before x and what route we took to get there. An nterestng case of the tour gas staton problem s that of an nstance wth a sngle gas staton. Ths s also known as the dstance constraned vehcle routng problem and was studed by 3 L et al. [14] who gave a 2(1 α) to the most dstant cty s α U 2 approxmaton algorthm, where the dstance from the gas staton, for some α < 1. We mprove ths by provdng an O(log 1 1 α ) approxmaton algorthm (see Appendx C). Wthout makng any assumptons on α we show that a greedy algorthm that fnds bounded length tours vstng the most ctes at a tme s a O(log T )- factor approxmaton (see Appendx D). For the general case we make the assumpton that every cty has a gas staton at dstance at most α U 2. Ths assumpton s reasonable, because f a cty has no gas staton wthn dstance U 2, there s no way to vst t. We show a 3(1+α) 2(1 α) approxmaton for ths problem. Note that when α = 0, ths gves the same bound as the Chrstofdes method for TSP. 3.1 The tour gas staton problem We assume that every cty x has a gas staton g(x) at dstance at most α U 2. We wll defne the dstance from x to g(x) as d x. Recall that t s assumed that the prce of the gas s the same at all the gas statons. We defne a new dstance functon for the dstance between each par of ctes. The dstance l s defned as follows: For each par of ctes x and y, l(x, y) s the length of the shortest traversal to go from x to y startng wth U d x amount of gas and reachng y wth d y amount of gas. If d(x, y) U d x d y then we can go drectly from x to y, and l(x, y) = d(x, y). Otherwse, we can compute ths as follows. Create a graph whose vertex set s S, the set of gas statons. To ths graph add x and y. We now add edges from x to all gas statons wthn dstance U d x from x. Smlarly we add edges from y to all gas statons wthn dstance U d y to y. Between all pars of gas statons, we add an edge f the dstance between the par of gas statons s at most U. All edges have length equal to the dstance between ther end ponts. The length of the shortest path n ths graph from x to y wll be l(x, y). Note that the shortest path (n general) wll start at x and then go through a seres of gas statons before reachng y. Ths path yelds a vald plan to drve from x to y wthout runnng out of gas, once we reach x wth U d x unts of gas. When we reach y, we have enough gas to go to g y. Also note that l(x, y) = l(y, x) snce the path s essentally reversble. In Fg. 2 we llustrate the defnton of functon l(x, y). We assume here that all dstances are Eucldean. Note that from x, we can only go to B and not A snce we start from x wth U d x unts of gas. From B, we cannot go to D snce the dstance between B and D s more than U, even though the path through D to y would be shorter. From C we go to E snce gong through F wll gve a longer path, snce from F we cannot go to y drectly. Note that the functon l may not satsfy trangle nequalty. To see ths, suppose we have three ctes x, y, z. Let d(x, y) = d(y, z) = U 2. Let d x = d y = d z = U 4 and d(x, z) = U. We frst observe that l(x, y) = l(y, z) = U 2. However, f we compute l(x, z), we cannot go from x to z drectly snce we only have 3 4 U unts of gas when we start at x and need to reach z wth U 4 unts of gas. So we have to vst g y along the way, and thus l(x, z) = 3 2 U. The algorthm s as follows: 8
g y g x d x x U d x A C D F E U d y y d y B Fgure 2: Functon l(x, y). The path shown s the shortest vald path from x to y. Create a new graph G, wth a vertex for each cty. For each par of ctes x, y compute l(x, y) as shown earler. Fnd the mnmum spannng tree n G. Also fnd a mnmum weght perfect matchng M on the odd degree vertces n the MST. Combne the MST and M to fnd an Euler tour T. Start traversng the Euleran tour. Add trps to the close gas statons whenever they are needed. (Detals on ths follow.) It can be shown that the total weght of the MST s less than the optmal soluton cost. Suppose x 1,...,x n s the order n whch the optmal soluton vsts the ctes. One can see that the cost of gong from x to x +1 n the optmal soluton s at least l(x, x +1 ). Snce the collecton of edges (x, x +1 ) forms a spannng tree, we can be conclude that the weght of the MST c(opt). Next we show that the cost of M s at most c(opt) 2. Suppose the odd degree vertces are n the optmal soluton n the order o 1,...,o k. We can see that l(o, o +1 ) s at most equal to the dstance we travel n the optmal soluton to go from o to o +1. So the cost of mnmum weghted matchng on the odd degree vertces s at most c(opt) 2. So the total cost of the Euleran tour T s at most 3c(OPT) 2. Now we need to transform the Euleran tour nto a feasble plan. Frst, every edge (x, y) n T s replaced wth the actual plan to drve from x to y that we found when computng l(x, y). If d(x, y) U d x d y the plan s smply to go straght from x to y, we call these drect edges. Otherwse the plan must nvolve stoppng along the way n one or more gas statons, we call these ndrect edges. Notce that the cost of ths plan s exactly that of the Euleran tour. Unfortunately, as we wll see below ths plan need not be feasble. Defne a strand, to be a sequence of consecutve ctes n the tour connected by drect edges. If a cty s connected wth two ndrect edges, then t forms a strand by tself. Suppose the th strand has ctes x 1,...,xk. To ths we add x0 (x k+1 ), the last (frst) gas staton n the ndrect edge connectng x 1 (x k ) wth the rest of the tour. Each strand now starts and ends wth a gas staton. We can vew the tour as a decomposton nto strands as shown n Fg. 3. Note that f the dstance between x 0 and x k+1 s more than U the overall plan s not feasble. To fx we add for every cty a refll trp to ts closest gas staton and then greedly try to remove them, whle 9
refll trp ndrect edge x 0 x 1... x 2 x 3 x 4 x k x k+1 drect edge cty gas staton Fgure 3: Fgure to decomposton of soluton nto strands. mantanng feasblty, untl we get a mnmal set of refll trps. Let us bound the extra cost these trps ncur. Lemma 2. Let L be the length of the th strand. Then the total dstance traveled on the refll trps of ctes n the strand s at most 2α 1 α L. Proof. Assume there are q refll trps n ths strand. Label the ctes wth refll trps to ther nearest gas statons x j 1,...,x jq. Also label x 0 as xj 0 and x k as xj q +1. The cost of each refll trp s at most αu. So the total cost of the refll trps s at most αuq. Also note that T (x jp, xj p+2 ) (1 α)u (otherwse the refll trp at x j p+1 can be dropped). Ths gves us: 2L > 0 p q 1 T (x jp, xj p+2 ) q (1 α)u = q 2L (1 α)u So the rato of the cost of the refll trps to the cost of the strand s at most 2α 1 α. The cost of the soluton s the total length of the strands (whch s the length of the tour) plus the total cost of the perodc refll trps. (Note that wthout loss of generalty we can assume that our tour always starts from a gas staton. For the case wth only drect edges, there s exactly one strand, startng and endng at the frst cty wth the gas staton). In other words, the total cost of the soluton s: l(t ) + αuq ( 1 + 2α 1 α ) l(t ) ( ) 1 + α 3 1 α 2 c(opt). Theorem 3. There s a soluton of cost at most 3(1+α) 2(1 α) c(opt) for the tour gas staton problem. 4 Conclusons Current problems of nterest are to explore mprovements n the approxmaton factors for the specal cases of Eucldean metrcs, and planar graphs. In addton we would also lke to develop faster algorthms for the sngle source and destnaton case, perhaps at the cost of sacrfcng optmalty of the soluton. References [1] http://www.aaa.com/. [2] http://www.gasbuddy.com/. 10
[3] E. M. Arkn, J. S. B. Mtchell, and G. Narasmhan. Resource-constraned geometrc network optmzaton. In Proceedngs of the fourteenth annual symposum on Computatonal geometry (SCG 98), pages 307 316, 1998. [4] E. M. Arkn, R. Hassn, and A. Levn. Approxmatons for mnmum and mn-max vehcle routng problems. Journal of Algorthms, 59(1):1 18, 2006. [5] B. Awerbuch, Y. Azar, A. Blum, and S. Vempala. New approxmaton guarantees for mnmumweght k-trees and prze-collectng salesmen. SIAM Journal on Computng, 28(1):254 262, 1998. Prelmnary verson appeared n STOC 1995. [6] N. Bansal, A. Blum, S. Chawla, and A. Meyerson. Approxmaton algorthms for deadlne-tsp and vehcle routng wth tme-wndows. In Proceedngs of the 36th annual ACM symposum on Theory of computng (STOC 04), pages 166 174, 2004. [7] A. Blum, S. Chawla, D. R. Karger, T. Lane, A. Meyerson, and M. Mnkoff. Approxmaton algorthms for orenteerng and dscounted-reward TSP. In Proceedngs of the 44rd Annual IEEE Symposum on Foundatons of Computer Scence (FOCS 03), page 46, 2003. [8] N. Chrstofdes. Worst-case analyss of a new heurstc for the travelng salesman problem. Techncal report, Graduate School of Industral Admnstraton, Carnege-Mellon Unversty, 1976. [9] T. H. Cormen, C. E. Leserson, R. L. Rvest, and C. Sten. Introducton to Algorthms. M.I.T. Press and McGraw-Hll, 2001. [10] G. N. Frederckson, M. S. Hecht, and C. E. Km. Approxmaton algorthms for some routng problems. SIAM Journal on Computng, 7(2):178 193, 1978. [11] B. L. Golden, L. Levy, and R. Vohra. The orenteerng problem. Naval Research Logstcs, 34: 307 318, 1987. [12] E. L. Lawler. Combnatoral Optmzaton: Networks and Matrods. Dover Publcatons, 2001. [13] E. L. Lawler, J. K. Lenstra, A. H. G. R. Kan, and D. B. Shmoys. The Travelng Salesman Problem : A Guded Tour of Combnatoral Optmzaton. John Wley & Sons, 1985. [14] C.-L. L, D. Smch-Lev, and M. Desrochers. On the dstance constraned vehcle routng problem. Operatons Research, 40(4):790 799, 1992. [15] A. R. K. M. Hamovch. Bounds and heurstcs for capactated routng problems. Mathematcs of Operatons Research, 10(4):527 542, 1985. [16] L. S. M. Hamovch, A.G. Rnnoooy Kan. Analyss of heurstcs for vehcle routng problems. Vehcle Routng: Methods and Studes, pages 47 61, 1988. [17] V. Nagarajan and R. Rav. Mnmum vehcle routng wth a common deadlne. In Proceedngs of the 9th Internatonal Workshop on Approxmaton Algorthms for Combnatoral Optmzaton Problems (APPROX 06), pages 212 223, 2006. [18] C. H. Papadmtrou and K. Stegltz. Combnatoral Optmzaton. Dover Publcatons, Inc., 1998. 11
A The sequence gas staton problem Suppose nstead of a gven source and destnaton, we are asked to fnd the cheapest way to start from a gven locaton, vst some a set of locatons n a gven order durng the trp and then reach the fnal destnaton. We defne the problem n a formal way as follows: Gven an edge weghted graph G = (V, E) and a lst of vertces s 0,...,s p, we wsh to fnd the cheapest way to start from s 0, vst s 1,...,s p 1 n ths order and then reach s p. Note that we cannot reduce ths problem to p separate source-destnaton subproblems and combne the solutons drectly. To see why, consder the case where the gas prce s very hgh at some staton s and on the way from s 1 to s there s a very cheap gas staton near s. If we want to use the soluton for the separate subproblems and then combne them, we wll reach s wth an empty tank so we have to fll the tank at s snce we are out of gas; but the optmal soluton s to reach s wth some gas n the tank to make t possble to reach next staton after s wthout fllng the tank at s. between some node s j and s j+1 s not an optmal way that would be chosen n the To solve ths problem, we wll make a new graph as follows: Make p 1 new copes of the current graph G and call them G 1,...,G p 1. G wll become G 0. Call v n G j as v,j. Now connect G and G +1 by mergng s +1, and s +1,+1 nto one node. The soluton to the orgnal problem s to fnd the cheapest way to go from s 1,0 to s p,p 1 n the new graph. we can see that any path n ths graph that goes from s 1,0 to s p,p 1 wll pass through s +1, 0 p 1. B Fxed-path Number the nodes along the path from 1 to n, so that we start at 1 and want to reach n. Wthout loss of generalty assume we start wth an empty tank. We present a fast, yet smple, exact algorthm for the case where the number stops s unbounded. Theorem 4. There s an O(n log n) tme algorthm for the fxed-path gas staton problem wth an unbounded number of stops. The frst step conssts n fndng, for each gas staton, ts prevous and next staton. Defne prev() as the staton j wth the cheapest gas among those that satsfy d(j, ) U. Smlarly let next() be the staton j > wth the cheapest gas such that d(, j) U. Any eventual te s broken by favorng the staton closest to n. To compute these two values we keep a prorty queue on the statons that le on a movng wndow of length U. Startng at 1, we slde the wndow toward n nsertng and removng statons as we go along. Rght after nsertng nto (removng from) the queue some staton, askng for the mnmum n the queue gves us prev() (next()). The whole procedure takes O(n log n) tme. Staton s sad to be a break pont f prev() =. Identfyng such statons s mportant because we can break our problem nto smaller subproblems (to go from one break pont to the next) and then paste these solutons to get a global optmal soluton. Lemma 3. Let be a break pont. There s an optmal soluton that reaches wth an empty tank. Proof. Let j < be the last staton we stopped to get gas before reachng. Snce s a break pont, we have c() c(j). Therefore at j we fll just enough gas to reach wth an empty tank. Now consder the subproblem of gong from to k startng and endng wth an empty tank, such that there s no break pont n (, k). The followng algorthm solves our subproblem optmally. 12
drve-to-next(, k) 1 Let x be. 2 If d(x, k) U then just fll enough gas to go k. 3 Otherwse, fll up and drve to next(x). Let x be next(x), go to step 2. The key observaton s that for every staton x consdered by the algorthm, f d(x, k) > U then c(x) c(next(x)). Snce all statons n a range of U after x offer gas at cost at least c(x), an optmal soluton flls up at x and drves up to the next cheapest staton,.e., next(x). Remark: even though drve-to-next solves our specal subproblem optmally, the strategy does not work n general. To see why consder an nstance where c() > c( + 1) and d(1, n) = U. Whle the optmum stops on every staton, drve-to-next wll tell us to go straght from 1 to n. C Sngle Gas Staton In ths verson, there s a sngle gas staton and our vehcle starts there. It must return to the gas staton before t runs out of gas after travelng a dstance of at most U from the prevous fll-up. Fx U constants (ρ 1, ρ 2,...,ρ l ). Our algorthm frst vsts ctes at dstance ρ 1 2 from the gas staton (we U refer to these ctes as C 0 ). Beyond ρ 1 2 we work n teratons. In the th teraton we vst ctes (C ) that le at dstance ( U 2 ρ, U 2 ρ ] +1 from the gas staton. If we make 1 ρ 1 ρ +1 = γ a constant, after teratons we wll have vsted all ctes. We wll argue that n each teraton we travel log γ 1 ρ 1 1 α O(c(OPT)) dstance, whch gves us the desred result. The ρ values wll be chosen to mnmze the constants nvolved to get the followng theorem. Theorem 5. There s a 6.362 ln 1 1 α 1.534 factor approxmaton for the unform cost tour gas staton problem wth a sngle staton, for α 0.5. Notce that that for α 0.5 the above approxmaton rato s 1. U Frst we consder the ctes C 0 at dstance ρ 1 2 or less from the gas staton. Fnd a TSP tour on the gas staton and C 0 and chop t nto segments of length (1 ρ 1 )U. The dstance from the gas U staton to any locaton s at most ρ 1 2 and so the segments can be traversed wth loops of length at most U. In fact we can start choppng the TSP tour at the gas staton and make the frst and the last segment be of length (1 ρ 1 2 )U. The total length of these tours wll be: cost(tsp) ρ1 U cost(c 0 ) U cost(tsp) 3 (1 ρ 1 )U (1 ρ 1 ) 2(1 ρ 1 ) OPT The second nequalty holds f we assume ρ 1.5. The thrd comes from usng Chrstofdes algorthm [8] to fnd the TSP tour and the fact that OPT s a vald TSP tour. Notce that t does not work well when ctes are far away from the gas staton (α 1). In our scheme those far away ctes wll be vsted n a dfferent fashon. In the th teraton we vst ctes U C at dstance (ρ 2, ρ +1 U 2 ] by fndng a collecton of paths of length at most (1 ρ +1)U spannng C and then turnng these segments nto loops. Suppose we knew that n the optmal soluton there are k loops that span some cty n C ths quantty can be guessed. Frst we run Kruskal s algorthm but stop once the number of components becomes k, let R be the resultng forest. Each tree s doubled to form a loop and then chopped 13
nto segments of length (1 ρ +1 )U. Let k be the number of such segments. The cost of the these loops s therefore, cost(c ) 2 cost(r ) + k ρ +1 U Lemma 4. The number of segments k s at most (2γ + 1)k. Proof. The edges n R form a mnmum weght forest wth k components, we can relate ths to the cost of OPT. Consder turnng each loop n OPT nto a path by keepng the stretch between the frst and the last cty n C. The set P of such paths s a forest wth k components, therefore cost(r ) cost(p) (1 ρ )Uk Usng ths we can bound the number of segments we get after doublng and choppng R : k 2 cost(r ) (1 ρ +1 )U + k 2 (1 ρ )Uk (1 ρ +1 )U + k (2γ + 1) k We now bound the cost of vstng the ctes n C. cost(c ) 2 cost(r ) + k ρ +1 U 2 cost(opt) 2k ρ U + (2γ + 1)k ρ +1 U 2 cost(opt) + (2γ 1) (cost(opt) k ρ U) 2k ρ U + (2γ + 1)k ρ +1 U (2γ + 1) cost(opt) + (2γ + 1) k (ρ +1 ρ )U Let k be the number of loops n the optmal soluton whose length s greater than ρ 1 U, notce U that loops spannng ctes beyond ρ 1 2 must be at least ths long, therefore k k for all. Addng up over all teratons we get: After l = l cost(c ) =1 log γ 1 ρ 1 1 α (2γ + 1)(l cost(opt) + k(ρ l ρ 1 )U) ( (2γ + 1) l + 1 ρ ) 1 cost(opt) ρ 1 teratons we wll have vsted all ctes at a cost of: [ ( 3 1 ρ 1 + (2γ + 1) log 2(1 ρ 1 ) γ 1 α + 1 + 1 )] 1 cost(opt) ρ 1 We can use numercal optmzaton to mnmze the approxmaton rato n the expresson from above. The values ρ 1 = 0.7771 and γ = 3.1811 gves us Theorem 5. D A Greedy Algorthm In ths case we do not make any assumpton on the maxmum dstance from a cty to ts closest gas staton. We wll use the Pont-to-Pont Orenteerng path as the bass of the greedy scheme. In the Pont-to-Pont Orenteerng problem, each vertex n the graph has a prze. The goal s to fnd a path P of maxmum length d (predefned) between two gven vertces s and t so that the total prze of P s maxmzed. A 3-approxmaton algorthm for ths problem s descrbed n [6]. The greedy algorthm works as follows: At the begnnng the prze of all the ctes are ntalzed to 1. 14
As the algorthm proceeds whenever we vst a cty n a tour, we reset ts prze to 0. The greedy algorthm wll repeatedly choose the Pont-to-Pont Orenteerng path that begns and ends at s wth maxmum length U, untl the prze of all the vertces are reset to zero. Usng an argument smlar to that n set-cover t can be shown that both the total cost and the number of cycles gven by ths approach s at most O(log T ) tmes the optmum cost. Theorem 6. The greedy method gves an O(log T ) approxmaton guarantee for both the total cost and the number of the cycles n the sngle gas staton problem. 15