﻿ A Dynamic Programming Algorithm for the Ridersharing Problem Restricted with Unique Destination and Zero Detour on Trees

Journal of Applied Mathematics and Physics
Vol.05 No.09(2017), Article ID:79084,8 pages
10.4236/jamp.2017.59140

A Dynamic Programming Algorithm for the Ridersharing Problem Restricted with Unique Destination and Zero Detour on Trees

Yiming Li1, Huiqiang Lu2, Zhiqian Ye3, Xiao Zhou4

1Wenzhou University, Wenzhou, China

2Zhejiang University of Technology, Hangzhou, China

3Zhejiang University, Hangzhou, China

4Tohoku University, Sendai, Japan    Received: August 7, 2017; Accepted: September 12, 2017; Published: September 15, 2017

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.

Keywords:

Dynamic Programming Algorithm, Rideshare, Tree 1. Introduction

There are many previous researches for assigning passengers to drivers -. In this paper we deal with a more general ridesharing problem, introduced by Gu et al. , in which each individual is a driver or passenger. Let G be a connected and edge-weighted graph with vertex set $V\left(G\right)$ and edge set $E\left(G\right)$ . Let k be a positive integer, and let a ridesharing infomation R be a set of k trips $\left(i,{s}_{i},{t}_{i},{c}_{i},{d}_{i},{P}_{i}\right)$ , $1\le i\le 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\left(R\right)$ be the set of the indices of all trips in R which should be served, that is, $I\left(R\right)=\left\{i|\left(i,{s}_{i},{t}_{i},{c}_{i},{d}_{i},{P}_{i}\right)\in R\right\}$ . A ridesharing of a graph G with R is a mapping $f:I\left(R\right)\to I\left(R\right)$ such that, for each $i\in I\left(R\right)$ , if ${f}^{-1}\left(i\right)\overline{)=}\varnothing$ then $i\in {f}^{-1}\left(i\right)$ , $|{f}^{-1}\left(i\right)|\le {c}_{i}$ and there is a trip (walk) P satisfying ${P}_{j}\subseteq P$ for each $j\in {f}^{-1}\left(i\right)$ and the distance of P is at most ${d}_{i}$ plus the distance of ${P}_{i}$ , where ${f}^{-1}\left(i\right)=\left\{j|f\left(j\right)=i\right\}$ , that is, ${f}^{-1}\left(i\right)$ is the set of the indices of trips served by the i-th driver. Let $driver\left(f\right)$ be the number of drivers of a ridesharing f, that is,

$driver\left(f\right)=|\left\{i|{f}^{-1}\left(i\right)\overline{)=}\varnothing \right\}|.$

A ridesharing f of G with R is optimal if $driver\left(f\right)$ 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 . 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\left({k}^{2}n\right)$ , 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 . 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\left({k}^{2}n\right)$ 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 $\left(i,{s}_{i},{t}_{i},{c}_{i},{d}_{i},{P}_{i}\right)$ , $1\le i\le 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\le i\le 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=\left\{\left(i,{s}_{i},{c}_{i}\right)|1\le i\le k\right\}$ , and let $\left(T,R,r\right)$ 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=\left(v,{v}^{\prime }\right)\in E\left(T\right)$ such that v is the parent of ${v}^{\prime }$ in T, we denote by ${T}_{e}$ the subtree of T which is rooted at v and is induced by v, ${v}^{\prime }$ and the descendants of ${v}^{\prime }$ in T. For a subtree ${T}^{\prime }$ of T rooted at v, let

$R\left({T}^{\prime },v\right)=\left\{\left(i,{s}_{i},{c}_{i}\right)\in R|{s}_{i}\in V\left({T}^{\prime }\right)\\left\{v\right\}\right\}.$

For each $\alpha$ , $0\le \alpha \le k$ , we denote by $cap\left({T}^{\prime },v,\alpha \right)$ the maximum number of additional trips which can be served after serving all trips in $R\left({T}^{\prime },v\right)$ using at most $\alpha$ drivers, that is,

$cap\left({T}^{\prime },v,\alpha \right)=\underset{f}{\mathrm{max}}cap\left(f\right)$

where the maximum is taken over all ridesharings f with the instance $\left({T}^{\prime },R\left({T}^{\prime },v\right),v\right)$ satisfying $driver\left(f\right)\le \alpha$ and

$cap\left(f\right)=\underset{i\in I\left(R\left({T}^{\prime },v\right)\right),\text{\hspace{0.17em}}{f}^{-1}\left(i\right)\overline{)=}\varnothing }{\sum }{c}_{i}-|R\left({T}^{\prime },v\right)|.$

Let $cap\left({T}^{\prime },v,\alpha \right)=-\infty$ if $\alpha$ drivers can not serve all trips in $R\left({T}^{\prime },v\right)$ with the unique destination v. The main step of our algorithm is to compute the table of the functions $cap$ from leaves to the root r of T by dynamic programming. From the table on the root r, it is obvious that the minimum $\alpha$ satisfying $cap\left({T}_{r},r,\alpha \right)\overline{)=}-\infty$ 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 $cap\left({T}_{v},v,\alpha \right)$ , we trivially have the following lemma.

Let v be an arbitrary leaf of T. Then $cap\left({T}_{v},v,\alpha \right)=0$ for each $\alpha \ge 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},\cdots ,{v}_{l}$ be the children of v ordered arbitrarily, and let ${e}_{j}$ , $1\le j\le l$ , be the edge joining v to ${v}_{j}$ , as illustrated in Figure 1. The subtree ${T}_{{v}_{j}}$ , $1\le j\le 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},\cdots ,{e}_{j}$ and the subtrees ${T}_{{v}_{1}},{T}_{{v}_{2}},\cdots ,{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 $cap\left({T}_{{e}_{j}},v,\alpha \right)$ for all $\alpha$ and $j$ , $0\le \alpha \le k$ and $1\le j\le 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\left({v}_{j}\right)=\left\{\left(i,{s}_{i},{c}_{i}\right)\in R|{s}_{i}={v}_{j}\right\}$ be the subset of R such that the start location is at ${v}_{j}$ , and let

$\gamma \left({T}_{{e}_{j}},v,\alpha \right)=\underset{0\le {\alpha }_{1}\le \alpha }{\mathrm{max}}\left\{cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)+\underset{{I}^{\prime }\subseteq I\left(R\left({v}_{j}\right)\right),\text{\hspace{0.17em}}|{I}^{\prime }|=\alpha -{\alpha }_{1}}{\mathrm{max}}\underset{i\in {I}^{\prime }}{\sum }{c}_{i}-|R\left({v}_{j}\right)|\right\}.$ (1)

Then

$cap\left({T}_{{e}_{j}},v,\alpha \right)=\left\{\begin{array}{ll}\gamma \left({T}_{{e}_{j}},v,\alpha \right)\hfill & \text{ }\text{if}\text{\hspace{0.17em}}\gamma \left({T}_{{e}_{j}},v,\alpha \right)\text{\hspace{0.17em}}\ge \text{\hspace{0.17em}}0;\hfill \\ -\infty \hfill & \text{ }\text{otherwise}\text{.}\text{ }\hfill \end{array}$ (2)

Furthermore, all $cap\left({T}_{{e}_{j}},v,\alpha \right)$ , $0\le \alpha \le k$ , can be computed from all $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ , $0\le {\alpha }_{1}\le k$ , in time $O\left({k}^{2}\right)$ .

Proof. We first prove

$cap\left({T}_{{e}_{j}},v,\alpha \right)\le \gamma \left({T}_{{e}_{j}},v,\alpha \right).$ (3)

If $cap\left({T}_{{e}_{j}},v,\alpha \right)=-\infty$ , then Equation (3) trivially holds. We thus assume that $cap\left({T}_{{e}_{j}},v,\alpha \right)\overline{)=}-\infty$ , that is, there is a ridesharing f with the instance $\left({T}_{{e}_{j}},R\left({T}_{{e}_{j}},v\right),v\right)$ such that $driver\left(f\right)\le \alpha$ and $cap\left({T}_{{e}_{j}},v,\alpha \right)=cap\left(f\right)$ . Let ${f}^{\prime }$ be a mapping from $I\left(R\left({T}_{{v}_{j}},{v}_{j}\right)\right)$ to $I\left(R\left({T}_{{v}_{j}},{v}_{j}\right)\right)$ such that ${f}^{\prime }\left(i\right)=f\left(i\right)$ for each $i\in I\left(R\left({T}_{{v}_{j}},{v}_{j}\right)\right)$ . Then clearly ${f}^{\prime }$ is a ridesharing of ${T}_{{v}_{j}}$ with the instance $\left({T}_{{v}_{j}},R\left({T}_{{v}_{j}},{v}_{j}\right),{v}_{j}\right)$ since f is a ridesharing of ${T}_{{e}_{j}}$ and ${T}_{{v}_{j}}$ is a subtree of ${T}_{{e}_{j}}$ . Let ${\alpha }_{1}=driver\left({f}^{\prime }\right)$ , then by the definition of $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ , we have $cap\left({f}^{\prime }\right)\le cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ . Let

${I}^{\prime }=\left\{i\in I\left(R\left({v}_{j}\right)\right)|{f}^{-1}\left(i\right)\overline{)=}\varnothing \right\}.$

Then the $driver\left(f\right)$ drivers in f consists of the $driver\left({f}^{\prime }\right)$ drivers from start locations in ${T}_{{v}_{j}}$ and the $|{I}^{\prime }|$ drivers from start locations at ${v}_{j}$ , and hence $driver\left(f\right)=driver\left({f}^{\prime }\right)+|{I}^{\prime }|$ . Therefore, we have $\alpha ={\alpha }_{1}+|{I}^{\prime }|$ and

$\begin{array}{c}cap\left({T}_{{e}_{j}},v,\alpha \right)=cap\left(f\right)=\underset{i\in I\left(R\left({T}_{{e}_{j}},v\right)\right),\text{\hspace{0.17em}}{f}^{-1}\left(i\right)\overline{)=}\varnothing }{\sum }{c}_{i}-|R\left({T}_{{e}_{j}},v\right)|\\ =\underset{i\in I\left(R\left({T}_{{v}_{j}},{v}_{j}\right)\right),\text{\hspace{0.17em}}{f}^{-1}\left(i\right)\overline{)=}\varnothing }{\sum }{c}_{i}+\underset{i\in I\left(R\left({v}_{j}\right)\right),\text{\hspace{0.17em}}{f}^{-1}\left(i\right)\overline{)=}\varnothing }{\sum }{c}_{i}-|R\left({T}_{{v}_{j}},{v}_{j}\right)|-|R\left({v}_{j}\right)|\\ =cap\left({f}^{\prime }\right)+\underset{i\in {I}^{\prime }}{\sum }\text{ }\text{ }\text{ }{c}_{i}-|R\left({v}_{j}\right)|\le cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)+\underset{i\in {I}^{\prime }}{\sum }\text{ }\text{ }{c}_{i}-|R\left({v}_{j}\right)|\\ \le \gamma \left({T}_{{e}_{j}},v,\alpha \right),\end{array}$

verified Equation (3).

We next prove that

$cap\left({T}_{{e}_{j}},v,\alpha \right)\ge \gamma \left({T}_{{e}_{j}},v,\alpha \right)$ (4)

if $\gamma \left({T}_{{e}_{j}},v,\alpha \right)\ge 0$ . By Equation (1) m choose ${\alpha }_{1}$ and ${I}^{\prime }$ such that $0\le {\alpha }_{1}\le \alpha$ , ${I}^{\prime }\subseteq I\left(R\left({v}_{j}\right)\right)$ , $|{I}^{\prime }|=\alpha -{\alpha }_{1}$ and

$\gamma \left({T}_{{e}_{j}},v,\alpha \right)=cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)+\underset{i\in {I}^{\prime }}{\sum }{c}_{i}-|R\left({v}_{j}\right)|.$ (5)

Since $\gamma \left({T}_{{e}_{j}},v,\alpha \right)\ge 0$ , we have $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)\overline{)=}-\infty$ , and hence there is a ridesharing ${f}^{\prime }$ with the instance $\left({T}_{{v}_{j}},R\left({T}_{{v}_{j}},{v}_{j}\right),{v}_{j}\right)$ such that $driver\left({f}^{\prime }\right)\le {\alpha }_{1}$ and $cap\left({f}^{\prime }\right)=cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ . One can obtain a ridesharing $f$ with the instance $\left({T}_{{e}_{j}},R\left({T}_{{e}_{j}},v\right),v\right)$ from ${f}^{\prime }$ using ${\alpha }_{1}$ drivers in ${f}^{\prime }$ plus the new $|{I}^{\prime }|$ drivers having the trip indices in ${I}^{\prime }$ . By Equation (5) we have $cap\left(f\right)=\gamma \left({T}_{{e}_{j}},v,\alpha \right)$ , and by the definition $cap\left({T}_{{e}_{j}},v,\alpha \right)\ge cap\left(f\right)$ , and hence we have $cap\left({T}_{{e}_{j}},v,\alpha \right)\ge \gamma \left({T}_{{e}_{j}},v,\alpha \right)$ , verified Equation (4) .

By Equations (3) and (4) m Equation (2) holds true. We finally show that for each $\alpha$ , $0\le \alpha \le k$ , $cap\left({T}_{{e}_{j}},v,\alpha \right)$ , can be computed from all $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ , $0\le {\alpha }_{1}\le k$ , in time $O\left({k}^{2}\right)$ as follows.

By Equation (1) for a given ${\alpha }_{1}$ , clearly ${I}^{\prime }$ is the set of the $\alpha -{\alpha }_{1}$ indices $i\in I\left(R\left({v}_{j}\right)\right)$ such that ${c}_{i}$ is at least $\alpha -{\alpha }_{1}$ largest among all ${c}_{{i}^{\prime }}$ , ${i}^{\prime }\in I\left(R\left({v}_{j}\right)\right)$ . One can sorted all ${c}_{i}$ , $i\in I\left(R\left({v}_{j}\right)$ ), in non-increasing order, and compute all prefix sum of ${c}_{i}$ . This can be done in time $O\left(klogk\right)$ . Then, for any given pair of $\alpha$ and ${\alpha }_{1}$ , $0\le {\alpha }_{1}\le \alpha \le k$ ,

$\underset{{I}^{\prime }\subseteq I\left(R\left({v}_{j}\right)\right),\text{\hspace{0.17em}}|{I}^{\prime }|=\alpha -{\alpha }_{1}}{max}\underset{i\in {I}^{\prime }}{\sum }\text{ }{c}_{i}$

can be computed in $O\left(1\right)$ time. One thus can compute $\gamma \left({T}_{{e}_{j}},v,\alpha \right)$ in time $O\left(k\right)$ for each $\alpha$ since ${\alpha }_{1}\le \alpha \le k$ , and hence $cap\left({T}_{{e}_{j}},v,\alpha \right)$ for all $\alpha$ , $0\le \alpha \le k$ , can be computed from all $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ in time $O\left({k}^{2}\right)$ . ,

We finally compute the function $cap\left({T}_{v}^{j},v,\alpha \right)$ for all $\alpha$ and $j$ , $0\le \alpha \le k$ and $1\le j\le l$ , as in the following lemma.

For each $\alpha$ , $0\le \alpha \le k$ ,

$cap\left({T}_{v}^{j},v,\alpha \right)=\underset{0\le {\alpha }_{1},{\alpha }_{2}\le \alpha ,\text{\hspace{0.17em}}{\alpha }_{1}+{\alpha }_{2}=\alpha }{\mathrm{max}}\left\{cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)\right\}.$

Furthermore, all $cap\left({T}_{v}^{j},v,\alpha \right)$ , $0\le \alpha \le k$ , can be computed from all $cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)$ and $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{2}\right)$ in time $O\left({k}^{2}\right)$ .

Proof. We first prove

$cap\left({T}_{v}^{j},v,\alpha \right)\le \underset{0\le {\alpha }_{1},{\alpha }_{2}\le \alpha ,\text{\hspace{0.17em}}{\alpha }_{1}+{\alpha }_{2}=\alpha }{max}\left\{cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)\right\}.$ (6)

If $cap\left({T}_{v}^{j},v,\alpha \right)=-\infty$ , then Equation (6) trivially holds. We thus assume that $cap\left({T}_{v}^{j},v,\alpha \right)\overline{)=}-\infty$ , that is, there is a ridesharing f with the instance $\left({T}_{v}^{j},R\left({T}_{v}^{j},v\right),v\right)$ such that $driver\left(f\right)\le \alpha$ and $cap\left({T}_{v}^{j},v,\alpha \right)=cap\left(f\right)$ . Let ${f}_{1}$ be a mapping from $I\left(R\left({T}_{v}^{j-1},v\right)\right)$ to $I\left(R\left({T}_{v}^{j-1},v\right)\right)$ such that ${f}_{1}\left(i\right)=f\left(i\right)$ for each $i\in I\left(R\left({T}_{v}^{j-1},v\right)\right)$ . Then clearly ${f}_{1}$ is a ridesharing of ${T}_{v}^{j-1}$ with the instance $\left({T}_{v}^{j-1},R\left({T}_{v}^{j-1},v\right),v\right)$ . Let ${\alpha }_{1}=driver\left({f}_{1}\right)$ . By the definition of $cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)$ we have $cap\left({f}_{1}\right)\le cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)$ . Similarly, let ${f}_{2}$ be a mapping from $I\left(R\left({T}_{{e}_{j}},v\right)\right)$ to $I\left(R\left({T}_{{e}_{j}},v\right)\right)$ such that ${f}_{2}\left(i\right)=f\left(i\right)$ for each $i\in I\left(R\left({T}_{{e}_{j}},v\right)\right)$ . Then clearly ${f}_{2}$ is a ridesharing of ${T}_{{e}_{j}}$ with the instance $\left({T}_{{e}_{j}},R\left({T}_{{e}_{j}},v\right),v\right)$ . Let ${\alpha }_{2}=driver\left({f}_{2}\right)$ . By the definition of $cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)$ we have $cap\left({f}_{2}\right)\le cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)$ . Furthermore, $cap\left(f\right)=cap\left({f}_{1}\right)+cap\left({f}_{2}\right)$ and $driver\left(f\right)=driver\left({f}_{1}\right)+driver\left({f}_{2}\right)$ , and hence $\alpha ={\alpha }_{1}+{\alpha }_{2}$ . We thus have

$\begin{array}{c}cap\left({T}_{v}^{j},v,\alpha \right)=cap\left(f\right)=cap\left({f}_{1}\right)+cap\left({f}_{2}\right)\\ \le cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right),\end{array}$

verified Equation (6).

We next prove

$cap\left({T}_{v}^{j},v,\alpha \right)\ge \underset{0\le {\alpha }_{1},{\alpha }_{2}\le \alpha ,\text{\hspace{0.17em}}{\alpha }_{1}+{\alpha }_{2}=\alpha }{max}\left\{cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)\right\}.$ (7)

Choose ${{\alpha }^{\prime }}_{1}$ and ${{\alpha }^{\prime }}_{2}$ such that $0\le {{\alpha }^{\prime }}_{1},{{\alpha }^{\prime }}_{2}\le \alpha$ , ${{\alpha }^{\prime }}_{1}+{{\alpha }^{\prime }}_{2}=\alpha$ and

$cap\left({T}_{v}^{j-1},v,{\alpha }_{{1}^{\prime }}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{{2}^{\prime }}\right)=\underset{0\le {\alpha }_{1},{\alpha }_{2}\le \alpha ,\text{\hspace{0.17em}}{\alpha }_{1}+{\alpha }_{2}=\alpha }{\mathrm{max}}\left\{cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)\right\}.$

We may assume $cap\left({T}_{v}^{j-1},v,{{\alpha }^{\prime }}_{1}\right)\overline{)=}-\infty$ and $cap\left({T}_{{e}_{j}},v,{{\alpha }^{\prime }}_{2}\right)\overline{)=}-\infty$ ; otherwise Equation (7) trivially holds.

Since $cap\left({T}_{v}^{j-1},v,{{\alpha }^{\prime }}_{1}\right)\overline{)=}\infty$ , there is a ridesharing ${f}_{1}$ with the instance $\left({T}_{v}^{j-1},R\left({T}_{v}^{j-1},v\right),v\right)$ such that $cap\left({f}_{1}\right)=cap\left({T}_{v}^{j-1},v,{{\alpha }^{\prime }}_{1}\right)$ . Similarly, since $cap\left({T}_{{e}_{j}},v,{{\alpha }^{\prime }}_{2}\right)\overline{)=}-\infty$ , there is a ridesharing ${f}_{2}$ with the instance $\left({T}_{{e}_{j}},R\left({T}_{{e}_{j}},v\right),v\right)$ such that $cap\left({f}_{2}\right)=cap\left({T}_{{e}_{j}},v,{{\alpha }^{\prime }}_{2}\right)$ . Let $f$ be a mapping such that for each $i\in I\left(R\left({T}_{v}^{j},v\right)\right)$

$f\left(i\right)=\left\{\begin{array}{ll}{f}_{1}\left(i\right)\hfill & \text{ }if\text{\hspace{0.17em}}i\in \text{\hspace{0.17em}}I\left(R\left({T}_{v}^{j-1},v\right)\right),\text{ }\hfill \\ {f}_{2}\left(i\right)\hfill & \text{ }otherwise,\text{\hspace{0.17em}}that\text{\hspace{0.17em}}is,\text{\hspace{0.17em}}i\in \text{\hspace{0.17em}}I\left(R\left({T}_{{e}_{j}},v\right)\right).\text{ }\hfill \end{array}$

Then clearly $f$ is a ridesharing of ${T}_{v}^{j}$ with the instance $\left({T}_{v}^{j},R\left({T}_{v}^{j},v\right),v\right)$ such that $cap\left(f\right)=cap\left({f}_{1}\right)+cap\left({f}_{2}\right)$ and $driver\left(f\right)=driver\left({f}_{1}\right)+driver\left({f}_{2}\right)$ . By the definition of $cap\left({T}_{v}^{j},v,\alpha \right)$ , we have

$\begin{array}{c}cap\left({T}_{v}^{j},v,\alpha \right)\ge cap\left(f\right)=cap\left({f}_{1}\right)+cap\left({f}_{2}\right)\\ =cap\left({T}_{v}^{j-1},v,{{\alpha }^{\prime }}_{1}\right)+cap\left({T}_{{e}_{j}},v,{{\alpha }^{\prime }}_{2}\right)\\ =\underset{0\le {\alpha }_{1},{\alpha }_{2}\le \alpha ,\text{\hspace{0.17em}}{\alpha }_{1}+{\alpha }_{2}=\alpha }{\mathrm{max}}\left\{cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)+cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)\right\},\end{array}$

verified Equation (7).

Furthermore, clearly $cap\left({T}_{v}^{j},v,\alpha \right)$ for all $\alpha$ and $j$ , $0\le \alpha \le k$ , can be computed in time $O\left({k}^{2}\right)$ from all $cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)$ and $cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)$ . ,

2.3. Algorithm

From Lemmas 2.1―1 one can obtain the following algorithm to compute all $cap\left({T}_{v},v,\alpha \right)$ , $v\in V\left(T\right)$ and $0\le \alpha \le k$ .

Algorithm Alg( ${T}_{v},R,v,cap$ ) begin if $v$ is a leaf in $T$ , then $cap\left({T}_{v},v,\alpha \right)=0$ for all $\alpha$ , $0\le \alpha \le k$ , by Lemm 2.1; else if $v$ is an internal vertex in $T$ , then begin let ${v}_{1},{v}_{2},\cdots ,{v}_{l}$ be the children of $v$ ordered arbitrarily, and let ${e}_{j}$ , $1\le j\le l$ , be the edge joining $v$ to ${v}_{j}$ ; for each $j$ , $1\le j\le l$ , compute all $cap\left({T}_{{e}_{j}},v,\alpha \right)$ , $0\le \alpha \le k$ , from all $cap\left({T}_{{v}_{j}},{v}_{j},{\alpha }_{1}\right)$ m $0\le {\alpha }_{1}\le k$ , by Lemma 1; for each $j$ , $1\le j\le l$ , compute all $cap\left({T}_{v}^{j},v,\alpha \right)$ , $0\le \alpha \le k$ , from all $cap\left({T}_{v}^{j-1},v,{\alpha }_{1}\right)$ , $0\le {\alpha }_{1}\le k$ , and all $cap\left({T}_{{e}_{j}},v,{\alpha }_{2}\right)$ , $0\le {\alpha }_{2}\le k$ , by Lemma 1; let $cap\left({T}_{v},v,\alpha \right)=cap\left({T}_{v}^{l},v,\alpha \right)$ for all $\alpha$ , $0\le \alpha \le k$ ; end end

Clearly it runs in time $O\left({k}^{2}n\right)$ 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.M., Lu, H.Q., Ye, Z.Q. 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. https://doi.org/10.4236/jamp.2017.59140

References

1. 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. 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. 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. 4. Brucker, P. and Nordmann, L. (1994) The k-Track Assignment Problem. Computing, 54, 97-122. https://doi.org/10.1007/BF02238071

5. 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. 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. 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. 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