Back
 JAMP  Vol.5 No.9 , September 2017
A Dynamic Programming Algorithm for the Ridersharing Problem Restricted with Unique Destination and Zero Detour on Trees
Abstract: We deal with the problem of sharing vehicles by individuals with similar itineraries which is to find the minimum number of drivers, each of which has a vehicle capacity and a detour to realize all trips. Recently, Gu et al. showed that the problem is NP-hard even for star graphs restricted with unique destination, and gave a polynomial-time algorithm to solve the problem for paths restricted with unique destination and zero detour. In this paper we will give a dynamic programming algorithm to solve the problem in polynomial time for trees restricted with unique destination and zero detour. In our best knowledge it is a first polynomial-time algorithm for trees.

1. Introduction

There are many previous researches for assigning passengers to drivers [1]-[7]. In this paper we deal with a more general ridesharing problem, introduced by Gu et al. [8], in which each individual is a driver or passenger. Let G be a connected and edge-weighted graph with vertex set V ( G ) and edge set E ( G ) . Let k be a positive integer, and let a ridesharing infomation R be a set of k trips ( i , s i , t i , c i , d i , P i ) , 1 i k , where

s i and t i are the source (start location) and the destination, respectively, of the i-th trip;

c i is the number of seats (capacity) of the i-th driver available for passengers including the driver;

d i is the detour distance limit which the i-th driver can tolerate for offering ridesharing services; and

P i is the preferred path of the i-th trip from s i to t i in G.

Let I ( R ) be the set of the indices of all trips in R which should be served, that is, I ( R ) = { i | ( i , s i , t i , c i , d i , P i ) R } . A ridesharing of a graph G with R is a mapping f : I ( R ) I ( R ) such that, for each i I ( R ) , if f 1 ( i ) = then i f 1 ( i ) , | f 1 ( i ) | c i and there is a trip (walk) P satisfying P j P for each j f 1 ( i ) and the distance of P is at most d i plus the distance of P i , where f 1 ( i ) = { j | f ( j ) = i } , that is, f 1 ( i ) is the set of the indices of trips served by the i-th driver. Let d r i v e r ( f ) be the number of drivers of a ridesharing f, that is,

d r i v e r ( f ) = | { i | f 1 ( i ) = } | .

A ridesharing f of G with R is optimal if d r i v e r ( f ) is minimum among all ridesharings f. The ridesharing problem is to find an optimal ridesharing f for a given graph G and a ridesharing information R.

Recently, Gu et al. showed that the problem is NP-hard even for star graphs restricted with unique destination, and gave a polynomial-time algorithm to solve the problem for paths restricted with unique destination and zero detour [8]. In this paper we will give a dynamic programming algorithm to solve the problem for trees T restricted with unique destination and zero detour. Our algorithm runs in time O ( k 2 n ) , where k is the number of the trips and n is the number of the vertices in T. In our best knowledge it is a first polynomial-time algorithm for trees.

2. A Dynamic Programming Algorithm

The ridesharing problem is NP-hard even for star graphs restricted with unique destination if some detours are not zero [8]. However, in this section, we have the following theorem for the problem of trees restricted with unique destination and zero detour.

The ridesharing problem of trees T can be solved in time O ( k 2 n ) if the destinations of all the k trips are same and the detour of each driver is zero, where n is the number of the vertices in T.

In the remainder of this section we give an algorithm to solve the ridesharing problem for trees in polynomial time as a proof of Theorem 2. Let k be a positive integer and let R be a set of the k trips ( i , s i , t i , c i , d i , P i ) , 1 i k , as an instance of the ridesharing problem of T. Since we deal with the problem restricted with unique destination and zero detours, let r be the unique destination. Then for each i, 1 i k , we have t i = r and d i = 0 , and P i is the unique path in T. For the sake of notational convenience we redefine the ridesharing information R = { ( i , s i , c i ) | 1 i k } , and let ( T , R , r ) be an instance of the ridesharing problem of T with the ridesharing information R and the unique destination r in the remainder of this paper.

Since the destinations of all trips are same, we choose the destination r as the root of a given tree T, and regard T as rooted tree. For each vertex v of T, we denote by T v the subtree of T which is rooted at v and is induced by all descendants of v in T. For each edge e = ( v , v ) E ( T ) such that v is the parent of v in T, we denote by T e the subtree of T which is rooted at v and is induced by v, v and the descendants of v in T. For a subtree T of T rooted at v, let

R ( T , v ) = { ( i , s i , c i ) R | s i V ( T ) \ { v } } .

For each α , 0 α k , we denote by c a p ( T , v , α ) the maximum number of additional trips which can be served after serving all trips in R ( T , v ) using at most α drivers, that is,

c a p ( T , v , α ) = max f c a p ( f )

where the maximum is taken over all ridesharings f with the instance ( T , R ( T , v ) , v ) satisfying d r i v e r ( f ) α and

c a p ( f ) = i I ( R ( T , v ) ) , f 1 ( i ) = c i | R ( T , v ) | .

Let c a p ( T , v , α ) = if α drivers can not serve all trips in R ( T , v ) with the unique destination v. The main step of our algorithm is to compute the table of the functions c a p from leaves to the root r of T by dynamic programming. From the table on the root r, it is obvious that the minimum α satisfying c a p ( T r , r , α ) = is the minimum number of drivers to serve all the trips. Although we give a dynamic programming algorithm to compute the minimum number of drivers to serve all the trips, the algorithm can be easily modified to actually find an optimal ridesharing f. We thus show how to compute such all the tables on vertices v from leaves to the root in the remainder of this section.

2.1. The Vertex v Is a Leaf in T

In this case, since v is a leaf in T, there is no trips from v's descendants in T v . Therefore, by the definition of c a p ( T v , v , α ) , we trivially have the following lemma.

Let v be an arbitrary leaf of T. Then c a p ( T v , v , α ) = 0 for each α 0 .

2.2. The Vertex v Is an Internal Vertex in T

In this case v is an internal vertex in T. Let v 1 , v 2 , , v l be the children of v ordered arbitrarily, and let e j , 1 j l , be the edge joining v to v j , as illustrated in Figure 1. The subtree T v j , 1 j l , of T is rooted at v j and is induced by all descendants of v j in T. We denote by T v j the subtree of T which consists of the vertex v, the edges e 1 , e 2 , , e j and the subtrees T v 1 , T v 2 , , T v j . T v j 1 is indicated by a dotted line in Figure 1. Obviousely T v = T v l .

Figure 1. Subtrees T v , T v j 1 and T e j rooted at v.

We first compute the function c a p ( T e j , v , α ) for all α and j , 0 α k and 1 j l , as in the following lemma 1, where T e j is the subtree obtained from T v j by adding the edge e j , indicated by a dotted thick line in Figure 1.

Let R ( v j ) = { ( i , s i , c i ) R | s i = v j } be the subset of R such that the start location is at v j , and let

γ ( T e j , v , α ) = max 0 α 1 α { c a p ( T v j , v j , α 1 ) + max I I ( R ( v j ) ) , | I | = α α 1 i I c i | R ( v j ) | } . (1)

Then

c a p ( T e j , v , α ) = { γ ( T e j , v , α ) if γ ( T e j , v , α ) 0 ; otherwise . (2)

Furthermore, all c a p ( T e j , v , α ) , 0 α k , can be computed from all c a p ( T v j , v j , α 1 ) , 0 α 1 k , in time O ( k 2 ) .

Proof. We first prove

c a p ( T e j , v , α ) γ ( T e j , v , α ) . (3)

If c a p ( T e j , v , α ) = , then Equation (3) trivially holds. We thus assume that c a p ( T e j , v , α ) = , that is, there is a ridesharing f with the instance ( T e j , R ( T e j , v ) , v ) such that d r i v e r ( f ) α and c a p ( T e j , v , α ) = c a p ( f ) . Let f be a mapping from I ( R ( T v j , v j ) ) to I ( R ( T v j , v j ) ) such that f ( i ) = f ( i ) for each i I ( R ( T v j , v j ) ) . Then clearly f is a ridesharing of T v j with the instance ( T v j , R ( T v j , v j ) , v j ) since f is a ridesharing of T e j and T v j is a subtree of T e j . Let α 1 = d r i v e r ( f ) , then by the definition of c a p ( T v j , v j , α 1 ) , we have c a p ( f ) c a p ( T v j , v j , α 1 ) . Let

I = { i I ( R ( v j ) ) | f 1 ( i ) = } .

Then the d r i v e r ( f ) drivers in f consists of the d r i v e r ( f ) drivers from start locations in T v j and the | I | drivers from start locations at v j , and hence d r i v e r ( f ) = d r i v e r ( f ) + | I | . Therefore, we have α = α 1 + | I | and

c a p ( T e j , v , α ) = c a p ( f ) = i I ( R ( T e j , v ) ) , f 1 ( i ) = c i | R ( T e j , v ) | = i I ( R ( T v j , v j ) ) , f 1 ( i ) = c i + i I ( R ( v j ) ) , f 1 ( i ) = c i | R ( T v j , v j ) | | R ( v j ) | = c a p ( f ) + i I c i | R ( v j ) | c a p ( T v j , v j , α 1 ) + i I c i | R ( v j ) | γ ( T e j , v , α ) ,

verified Equation (3).

We next prove that

c a p ( T e j , v , α ) γ ( T e j , v , α ) (4)

if γ ( T e j , v , α ) 0 . By Equation (1) m choose α 1 and I such that 0 α 1 α , I I ( R ( v j ) ) , | I | = α α 1 and

γ ( T e j , v , α ) = c a p ( T v j , v j , α 1 ) + i I c i | R ( v j ) | . (5)

Since γ ( T e j , v , α ) 0 , we have c a p ( T v j , v j , α 1 ) = , and hence there is a ridesharing f with the instance ( T v j , R ( T v j , v j ) , v j ) such that d r i v e r ( f ) α 1 and c a p ( f ) = c a p ( T v j , v j , α 1 ) . One can obtain a ridesharing f with the instance ( T e j , R ( T e j , v ) , v ) from f using α 1 drivers in f plus the new | I | drivers having the trip indices in I . By Equation (5) we have c a p ( f ) = γ ( T e j , v , α ) , and by the definition c a p ( T e j , v , α ) c a p ( f ) , and hence we have c a p ( T e j , v , α ) γ ( T e j , v , α ) , verified Equation (4) .

By Equations (3) and (4) m Equation (2) holds true. We finally show that for each α , 0 α k , c a p ( T e j , v , α ) , can be computed from all c a p ( T v j , v j , α 1 ) , 0 α 1 k , in time O ( k 2 ) as follows.

By Equation (1) for a given α 1 , clearly I is the set of the α α 1 indices i I ( R ( v j ) ) such that c i is at least α α 1 largest among all c i , i I ( R ( v j ) ) . One can sorted all c i , i I ( R ( v j ) ), in non-increasing order, and compute all prefix sum of c i . This can be done in time O ( k l o g k ) . Then, for any given pair of α and α 1 , 0 α 1 α k ,

m a x I I ( R ( v j ) ) , | I | = α α 1 i I c i

can be computed in O ( 1 ) time. One thus can compute γ ( T e j , v , α ) in time O ( k ) for each α since α 1 α k , and hence c a p ( T e j , v , α ) for all α , 0 α k , can be computed from all c a p ( T v j , v j , α 1 ) in time O ( k 2 ) . ,

We finally compute the function c a p ( T v j , v , α ) for all α and j , 0 α k and 1 j l , as in the following lemma.

For each α , 0 α k ,

c a p ( T v j , v , α ) = max 0 α 1 , α 2 α , α 1 + α 2 = α { c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) } .

Furthermore, all c a p ( T v j , v , α ) , 0 α k , can be computed from all c a p ( T v j 1 , v , α 1 ) and c a p ( T v j , v j , α 2 ) in time O ( k 2 ) .

Proof. We first prove

c a p ( T v j , v , α ) m a x 0 α 1 , α 2 α , α 1 + α 2 = α { c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) } . (6)

If c a p ( T v j , v , α ) = , then Equation (6) trivially holds. We thus assume that c a p ( T v j , v , α ) = , that is, there is a ridesharing f with the instance ( T v j , R ( T v j , v ) , v ) such that d r i v e r ( f ) α and c a p ( T v j , v , α ) = c a p ( f ) . Let f 1 be a mapping from I ( R ( T v j 1 , v ) ) to I ( R ( T v j 1 , v ) ) such that f 1 ( i ) = f ( i ) for each i I ( R ( T v j 1 , v ) ) . Then clearly f 1 is a ridesharing of T v j 1 with the instance ( T v j 1 , R ( T v j 1 , v ) , v ) . Let α 1 = d r i v e r ( f 1 ) . By the definition of c a p ( T v j 1 , v , α 1 ) we have c a p ( f 1 ) c a p ( T v j 1 , v , α 1 ) . Similarly, let f 2 be a mapping from I ( R ( T e j , v ) ) to I ( R ( T e j , v ) ) such that f 2 ( i ) = f ( i ) for each i I ( R ( T e j , v ) ) . Then clearly f 2 is a ridesharing of T e j with the instance ( T e j , R ( T e j , v ) , v ) . Let α 2 = d r i v e r ( f 2 ) . By the definition of c a p ( T e j , v , α 2 ) we have c a p ( f 2 ) c a p ( T e j , v , α 2 ) . Furthermore, c a p ( f ) = c a p ( f 1 ) + c a p ( f 2 ) and d r i v e r ( f ) = d r i v e r ( f 1 ) + d r i v e r ( f 2 ) , and hence α = α 1 + α 2 . We thus have

c a p ( T v j , v , α ) = c a p ( f ) = c a p ( f 1 ) + c a p ( f 2 ) c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) ,

verified Equation (6).

We next prove

c a p ( T v j , v , α ) m a x 0 α 1 , α 2 α , α 1 + α 2 = α { c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) } . (7)

Choose α 1 and α 2 such that 0 α 1 , α 2 α , α 1 + α 2 = α and

c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) = max 0 α 1 , α 2 α , α 1 + α 2 = α { c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) } .

We may assume c a p ( T v j 1 , v , α 1 ) = and c a p ( T e j , v , α 2 ) = ; otherwise Equation (7) trivially holds.

Since c a p ( T v j 1 , v , α 1 ) = , there is a ridesharing f 1 with the instance ( T v j 1 , R ( T v j 1 , v ) , v ) such that c a p ( f 1 ) = c a p ( T v j 1 , v , α 1 ) . Similarly, since c a p ( T e j , v , α 2 ) = , there is a ridesharing f 2 with the instance ( T e j , R ( T e j , v ) , v ) such that c a p ( f 2 ) = c a p ( T e j , v , α 2 ) . Let f be a mapping such that for each i I ( R ( T v j , v ) )

f ( i ) = { f 1 ( i ) i f i I ( R ( T v j 1 , v ) ) , f 2 ( i ) o t h e r w i s e , t h a t i s , i I ( R ( T e j , v ) ) .

Then clearly f is a ridesharing of T v j with the instance ( T v j , R ( T v j , v ) , v ) such that c a p ( f ) = c a p ( f 1 ) + c a p ( f 2 ) and d r i v e r ( f ) = d r i v e r ( f 1 ) + d r i v e r ( f 2 ) . By the definition of c a p ( T v j , v , α ) , we have

c a p ( T v j , v , α ) c a p ( f ) = c a p ( f 1 ) + c a p ( f 2 ) = c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) = max 0 α 1 , α 2 α , α 1 + α 2 = α { c a p ( T v j 1 , v , α 1 ) + c a p ( T e j , v , α 2 ) } ,

verified Equation (7).

Furthermore, clearly c a p ( T v j , v , α ) for all α and j , 0 α k , can be computed in time O ( k 2 ) from all c a p ( T v j 1 , v , α 1 ) and c a p ( T e j , v , α 2 ) . ,

2.3. Algorithm

From Lemmas 2.1―1 one can obtain the following algorithm to compute all c a p ( T v , v , α ) , v V ( T ) and 0 α k .

Algorithm Alg( T v , R , v , c a p ) begin if v is a leaf in T , then c a p ( T v , v , α ) = 0 for all α , 0 α k , by Lemm 2.1; else if v is an internal vertex in T , then begin let v 1 , v 2 , , v l be the children of v ordered arbitrarily, and let e j , 1 j l , be the edge joining v to v j ; for each j , 1 j l , compute all c a p ( T e j , v , α ) , 0 α k , from all c a p ( T v j , v j , α 1 ) m 0 α 1 k , by Lemma 1; for each j , 1 j l , compute all c a p ( T v j , v , α ) , 0 α k , from all c a p ( T v j 1 , v , α 1 ) , 0 α 1 k , and all c a p ( T e j , v , α 2 ) , 0 α 2 k , by Lemma 1; let c a p ( T v , v , α ) = c a p ( T v l , v , α ) for all α , 0 α k ; end end

Clearly it runs in time O ( k 2 n ) since T has the n vertices. This completes to prove Theorem 2.

3. Conclusion

In this paper we gave a dynamic programming algorithm to solve the ridesharing problem for trees restricted with unique destination and zero detour. Our algorithm runs in polynomial time. However, it is still open whether or not there is a polynomial-time algorithm to solve the problem restricted with unique destination and zero detour for series-parallel graphs and graphs with bounded treewidth.

Funding

This work is partially supported by JSPS KAKENHI Grant Number JP16K00003 (X. Zhou).

Cite this paper: Li, Y. , Lu, H. , Ye, Z. and Zhou, X. (2017) A Dynamic Programming Algorithm for the Ridersharing Problem Restricted with Unique Destination and Zero Detour on Trees. Journal of Applied Mathematics and Physics, 5, 1678-1685. doi: 10.4236/jamp.2017.59140.
References

[1]   Agatz, N., Erera, A., Savelsbergh, M. and Wang, X. (2011) Dynamic Ride-Sharing: A Simulation Study in Metro Atlanta. Transp. Res. Part B, 45, 1540-1564. https://doi.org/10.1016/j.trb.2011.05.017

[2]   Agatz, N., Erera, A., Savelsbergh, M. and Wang, X. (2012) Optimization for Dynamic Ride-Sharing: A Review. European Journal of Operational Research, 223, 295-303. https://doi.org/10.1016/j.ejor.2012.05.028

[3]   Baldacci, R., Maniezzo, V. and Mingozzi, A. (2004) An Exact Method for the Car Pooling Problem Based on La-grangean Column Generation. Oper. Res., 52, 422-439. https://doi.org/10.1287/opre.1030.0106

[4]   Brucker, P. and Nordmann, L. (1994) The k-Track Assignment Problem. Computing, 54, 97-122. https://doi.org/10.1007/BF02238071

[5]   Chan, N.D. and Shaheen, S.A. (2012) Ridesharing in North America: Past, Present, and Future. Transp. Rev., 32, 93-112. https://doi.org/10.1080/01441647.2011.621557

[6]   Cordeau, J.-F. and Laporte, G. (2007) The Dial-a-Ride Problem: Models and Algorithms. Annals of Operations Re-search, 153, 29-46. https://doi.org/10.1007/s10479-007-0170-8

[7]   Ghoseiri, K., Haghani, A. and Hamedi, M. (1979) Real-Time Ridesharing Matching Problem. Final Report of UMD-2009-05. U.S. Department of Transportation.

[8]   Gu, Q.-P., Liang, L. and Zhang, G. (2016) Algorithmic Analysis for Ridesharing of Personal Vehicles. Proc. of COCOA 2016, LNCS 10043, 438-452. https://doi.org/10.1007/978-3-319-48749-6_32

 
 
Top