Batching and Matching for Food Delivery in Dynamic Road Networks
Manas Joshi, Arshdeep Singh, Sayan Ranu, Amitabha Bagchi, Priyank Karia, Puneet Kala
BBatching and Matching for Food Delivery inDynamic Road Networks
Manas Joshi ‡ , Arshdeep Singh ∗ , Sayan Ranu ∗ , Amitabha Bagchi ∗ , Priyank Karia † , Puneet Kala †‡ Dept. of Computer Science and Engineering, IIT, Delhi, India. [email protected] ∗ Dept. of Computer Science and Engineering, IIT, Delhi, India. {cs5160625, sayanranu, bagchi}@iitd.ac.in † Swiggy, Bangalore, India. {puneet.k,priyank.karia}@swiggy.in
Abstract —Given a stream of food orders and available deliveryvehicles, how should orders be assigned to vehicles so that thedelivery time is minimized? Several decisions have to be made:(1) assignment of orders to vehicles, (2) grouping orders intobatches to cope with limited vehicle availability, and (3) adaptingto dynamic positions of delivery vehicles. We show that theminimization problem is not only
NP-hard but inapproximable in polynomial time. To mitigate this computational bottleneck,we develop an algorithm called F
OOD M ATCH , which maps thevehicle assignment problem to that of minimum weight perfectmatching on a bipartite graph. To further reduce the quadraticconstruction cost of the bipartite graph, we deploy best-firstsearch to only compute a subgraph that is highly likely tocontain the minimum matching. The solution quality is furtherenhanced by reducing batching to a graph clustering problemand anticipating dynamic positions of vehicles through angulardistance . Extensive experiments on food-delivery data from largemetropolitan cities establish that F
OOD M ATCH is substantiallybetter than baseline strategies on a number of metrics, whilebeing efficient enough to handle real-world workloads.
I. I
NTRODUCTION AND R ELATED W ORK
The market for food delivery today is valued at aboveC83 billion [1]. Several companies, such as Uber Eats, Take-away.com, Swiggy, Zomato, etc. have a valuation above billion USD [2], [3]. Once the customer places an order,the food delivery process unfolds in four discrete steps: (1) assigning a delivery vehicle to an order ( assignment time ), (2) a delivery vehicle driving to the restaurant to pick up the order( first mile time ), (3) preparation and packaging of the food bythe restaurant ( preparation time ) and (4) dropping off the orderat the customer’s location ( last mile time ). Note that the foodpreparation time can progress in parallel with the first mileand assignment time. Mathematically, the time to deliver anorder is expressed as follows.Delivery Time = max { assignment time + first mile time , preparation time } + last mile time (1)Naturally, minimizing the delivery time is key to ensuringa positive customer experience. This minimization problem,however, is composed of several challenging subproblems. • Vehicle assignment:
Given a stream of unallocated ordersand available vehicles, what is the best order assignmentpolicy to vehicles so that the delivery time is minimized? • Batching:
A vehicle may have the capacity to carrymultiple orders. How should we batch orders so that theycan be allocated to the same vehicle? • Scalability:
It is critical that the computation time ofassigning orders to vehicles is faster than the rate at whichnew orders arrive. The proposed minimization problem is
NP-hard and inapproximable . Can we design a heuristicthat is efficient enough to be deployable on real-world loadvolumes and yet generate effective order assignments?
A. Limitations of Existing Work
Yildiz et al. [4] propose an exact algorithm under theunrealistic assumption of perfect information about the arrivalof orders. In reality, orders and vehicles come as a data stream.An approach applicable on data streams was proposed byReyes et al. [5]. However, several simplifying assumptions aremade that are not realistic. First, the distance between a sourceand a destination is computed using the Haversine distancebetween the corresponding latitude and longitude values. Inreality, the delivery time is dependent on the road networkdistance. This assumption not only results in unrealistic dis-tances, it also ignores the scalability challenges associatedwith computing shortest (or quickest) path distances in roadnetworks. Second, batching is allowed only if two orders arefrom the same restaurant. Third, it lacks a comprehensiveevaluation on real, high-volume food delivery data.Apart from the two papers mentioned above, there is littlework that is closely aligned to ours. Ji et. al. [6] focus on theproblem of efficient geographical batching of orders for fooddelivery but do not solve the assignment and routing problem.Zeng et al. [7] propose a solution for last mile delivery in ageneric setting where there is no concept of food preparationtime. Dai et. al. [8] focus on leveraging crowdsourcing tooptimise the cost of delivery.
Connections to ride-sharing:
The need to assign vehiclesto customer orders and batch multiple orders in a single vehiclealso arises in the ride-sharing problem for taxi service [9]–[15]. Although ride-sharing has been extensively studied in thedata mining community, there are several intricacies that arespecific to food delivery, and thus techniques for ride-sharingdo not transfer to our problem.
1. Waiting time:
In ride-sharing, once a customer requestsa cab, it is important to send a cab to the customer as soonas possible; otherwise, the customer’s wait duration increasesand the customer experience suffers. Thus, sending the nearestavailable cab is often a good solution. In food-delivery, thisis often not the case. To elaborate, consider order 2 in Fig. 1 a r X i v : . [ c s . D B ] A ug u (5) u (5) (10) Fig. 1. An instance of the food delivery problem. The graph represents theroad network. Edge weight represents road segment traversal time. Subscriptsrefer to order ID and vehicle ID. Food preparation time is in parentheses. Thefigure shows three order pick-up and drop-off points and three vehicles. where the food needs to be picked up from the restaurant in u and delivered to the customer at u . The closest vehicle is v at u . However, if v is sent to u , it will incur a waitingtime of minute, since the food preparation time is minutelonger than the time it would take for the vehicle to reach therestaurant. Any idle time incurred by a vehicle is a loss ofproductivity and a better solution would be to send v .
2. Optimization function:
In ride-sharing the optimizationfunction is proportional to the distance travelled by a customer.In food-delivery all deliveries typically incur the same deliverycharge since only those restaurants are shown to a user thatare within a distance radius. Thus, the optimization functionis to enhance customer experience in terms of promptness ofdelivery rather than the revenue.
3. Serviceability:
In food-delivery, once an order is placed,serviceability is non-negotiable; all orders must be deliveredwithin a promised time limit (typically minutes). In ride-sharing, although not desirable, refusing cab to a customer dueto low availability is one of the possible action choices. B. Contributions
The above discussion highlights the need for a specializedand realistic algorithm for food delivery. Our proposed tech-nique F
OOD M ATCH addresses these needs. Specifically, wemake the following key contributions. • We formulate the problem of minimizing food delivery timein road networks. This minimization problem is not only
NP-hard but also inapproximable (§ II). • To ensure scalability and high solution quality, we frameorder assignment as a minimum weight perfect matching problem on a bipartite graph. To overcome the quadraticcost of constructing the bipartite graph, we use best-firstsearch to extract a subspace of the search space that is highlylikely to contain the minimum weight matching. In addition,F
OOD M ATCH incorporates several novel concepts such as batching of orders through a delivery-optimized distancefunction, and angular distance to adapt to dynamic locationsof delivery vehicles (§ IV). • Through extensive experiments on food-delivery data pro-vided by Swiggy, India’s largest food-delivery com-pany [16], we establish that F
OOD M ATCH is scalable forreal-world workloads in the largest cities of India. Moreimportantly, F
OOD M ATCH imparts reduction in fooddelivery time when compared to baseline strategies (§ V).
TABLE IS
UMMARY OF NOTATIONS USED . Notation Meaning β ( e ) Temporal edge weight of edge e in road network (See Def. 1).Order o = (cid:104) o r , o c , o t , o i , o p (cid:105) See Def. 2. O vt Orders assigned to vehicle v at time t .A(o) See Def. 4.M AX O and M AX I Maximum number of orders and items that can be assignedto a vehicle respectively. Ω Rejection Penalty (See Prob1). ∆ Length of accumulation window. O ( (cid:96) ) and V ( (cid:96) ) The unassigned orders and available vehicles at the end ofthe (cid:96) th accumulation window. π and π [1] π represents a batch of orders and π [1] represents the firstorder in π that will be picked up in the quickest route plan. η Terminating threshold for batching (See § IV-B2) γ Weighing factor between angular distance and temporal dis-tance (See Eq. 8).
To the best of our knowledge, this is the first large-scaleempirical evaluation of food-delivery strategies on real data. • As a by-product of our work, we release the first real, large-scale food-delivery data for further academic research.II. P
ROBLEM F ORMULATION
In this section, we define the preliminary concepts, formu-late the problem and analyze its computational complexity. Allnotations used in our work are summarized in Table I.
Definition G = ( V, E, β ) , where V is the set of nodesrepresenting intersections of road segments, E = { ( u, v ) : u, v ∈ V } is the set of directed edges representing roadsegments and β : ( E, t ) (cid:55)→ R + is a function mapping eachedge to its weight at time t . The weight of an edge e ∈ E attime t is the time required to traverse the corresponding roadsegment at that time of the day. The edge weights can either be fetched from Google MapsAPI, or extracted from the GPS pings of vehicles operated bythe food delivery company.
Definition G =( V, E, β ) , a food order o is a tuple (cid:104) o r , o c , o t , o i , o p (cid:105) , where o r ∈ V is the restaurant location (pick-up node), o c ∈ V isthe customer location (drop-off node), o t is the time of request, o i are the number of items associated with the order and o p is the (expected) preparation time for the order. A food delivery company employs delivery vehicles to pick-up and deliver orders. We use the notation O vt to denote theorders assigned to vehicle v at time t . In addition, loc ( v, t ) denotes the node at which v is located at time t . A vehiclemay not be positioned exactly at a node. In such situations,we approximate its location to the closest node in the roadnetwork. We assume all vehicles have a maximum carryingcapacity of M AX I. Furthermore, at any time, no more thanM AX O orders can be allocated to the same vehicle. To deliverthe orders in O vt , v follows the quickest route plan . Definition G =( V, E, β ) and a set of orders O vt = { o , . . . , o m } , a routeplan is a permutation of { o ri , o ci : 1 ≤ i ≤ m } ⊂ V such thatfor each i , o ri appears before o ci in the permutation. More simply, a route plan is a sequence of pick-up and drop-off nodes to fulfil the set of orders in O vt . In this work, weassume that any travel from one node to another follows thehortest (quickest) path. We use the notation SP ( u i , u i +1 , t ) to denote the length of the shortest (quickest) path fromnode u i to u i +1 at time t . Thus, the length of a route plan RP = { u , · · · , u m } is (cid:80) m − i =1 SP ( u i , u i +1 , t ) . The quickest route plan is the one with the smallest length among allfeasible route plans for O vt . Any vehicle v always followsthe quickest route plan for its assigned order set O vt . Owingto this formulation, hereon, whenever we refer to a route planfor a vehicle, we assume it to be quickest route plan.We note that the number of feasible route plans grows ex-ponentially with | O vt | ≤ M AX O. However, M AX O is typicallysmall since vehicles in the food delivery paradigm tend to beriders on motorcycles or bicycles, e.g., Swiggy allows at most3 orders per rider. Consequently, it is computationally feasibleto try all permutations and compute the quickest route plan.
Definition O and available vehicles V , an order assignmentfunction A : O → V specifies the vehicle v ∈ V to which o ∈ O has been assigned. Order o may be assigned to v onlyif it satisfies the following properties: • v has the capacity to carry o , i.e., (cid:80) ∀ o j ∈ O vt o ij + o i ≤ M AX I. • | O vt | < M AX O.If o violates any of these constrains for every availablevehicle then it is “unassigned” and A ( o ) = N U LL . Fur-thermore, any assignment algorithm consumes some finiteamount of time to map orders to vehicles. We use the notation time ( A ( o )) to denote the computation time of A ( o ) .Suppose o is assigned to vehicle v , i.e. A ( o ) = v . f irstM ile ( o, v ) of order o is the (temporal) distance from v ’scurrent location loc ( v, o t ) to the restaurant pick-up location o r in the route followed by v . Similarly, the lastM ile ( o, v ) is thedistance from o r to drop-off location o c . Example
1: Let us consider Fig. 1. Suppose vehicle v ,located at u , has been assigned to order o . o needs to bepicked up from the restaurant at u and dropped-off at u . Thequickest route for this task is RP = { u , u , u , u } . Thus, f irstM ile ( o , A ) = 8 and lastM ile ( o , A ) = 13 . Definition o when assigned to vehicle v : EDT ( o, A ( o )) = EDT ( o, v )= max { time ( A ( o )) + f irstM ile ( o, v ) , o p } + lastM ile ( o, v ) (2) EDT ( o, v ) adds mathematical preciseness to Eq. 1. Example
2: For simplicity, we assume time ( A ( o )) for allorders in Fig. 1. Continuing from Ex. 1, EDT ( o , v ) =max { , } + 13 = 21 . On the other hand, if A ( o ) = v thequickest route plan is { u , u , u } ) , and thus EDT ( o , v ) =max { , } + 7 = 12 . Definition shortest deliverytime for an order o is SDT ( o ) = o p + SP ( o r , o c , o t ) . SDT ( o ) is achieved only if a vehicle v is already waiting at o r or arrives just in time before the food is prepared. It servesas a natural lower bound on the expected delivery time. Definition o under a specific assignment A is the difference between the time taken to deliver an order and the shortest deliverytime, i.e., XDT ( o, A ( o )) = EDT ( o, A ( o )) − SDT ( o ) . Example
3: Continuing from Ex. 1 and Ex. 2, extra deliverytimes of o and o are and respectively. With the above definitions in place, our goal is now tominimize the aggregate extra delivery time. Note that it maynot be possible to assign all orders to vehicles while satisfyingthe constraints in Def. 4. In our formulation such rejectedorders incur a large rejection penalty Ω . Problem O and a stream of available vehicles V , if A is the set of all possible feasible assignments of O to V , givean algorithm to find: argmin A ∈A (cid:88) o ∈ O XDT ( o, A ( o ))(1 − δ o ( A )) + Ω δ o ( A ) Here, δ o ( A ) = 1 if A ( o ) = N U LL , i.e., o is rejected;otherwise, δ o ( A ) = 0 . Ω is a large positive constant. When there are no rejections, minimizing the extra deliverytime is equivalent to minimizing total expected delivery time.
A. Problem Hardness
Problem 1 is not just NP-hard but inapproximably hard. Thisfollows from a result of Krumke [17] on the inapproximabilityof the online Dial-a-Ride problem.
Definition G = ( V, E ) with edge weight function w representing the time taken tocommute across an edge. An instance of SS-OL-DARP-F isa set of orders { ( t i , u i , v i ) : i ≥ } where t i is the time ofrelease of the i th order, u i ∈ V is the source of the i th orderand v i is its destination. We assume that t i ≤ t i +1 for all i ≥ and that order i is made available as input at time t i .A single server has to fulfill all orders. An order ( t i , u i , v i ) is fulfilled when an object is picked up from u i at any time t ≥ t i and delivered at v i . Every object is assumed to be ofthe same size and the server is constrained to carry at most C objects at a time for some C > . A schedule σ is a sequenceof moves made by the server on the graph in order to fulfillthe received orders. Given a schedule σ if the delivery time ofthe i th order is σ i then SS-OL-DARP-F seeks to minimize theaggregate flow time, i.e., (cid:80) i σ i − t i . From Def. 8, we deduce that for the food delivery problem,if we assume we have only one delivery vehicle and all foodpreparation times are 0, online FDP is exactly SS-OL-DARP-F, i.e., given an instance of SS-OL-DARP-F, we can create aninstance of FDP by mapping every order ( t j , u j , v j ) of SS-OL-DARP-F to a food order o j of FDP such that o rj = u j , o cj = v j , o tj = t j , o ij = 1 and o pj = 0 . Thus, FDP is ageneralization of SS-OL-DARP-F. Hence, if SS-OL-DARP-Fis inapproximable, so is online FDP. Krumke [17] establishedthe inapproximability of SS-OL-DARP-F. We state this inap-proximability as a theorem with respect to our problem. Theorem ε > , no polynomialtime algorithm exists that can achieve an approximation ratioof n / − ε for the FDP with order set O such that | O | = n . ince no polynomial time algorithm for the FDP can achievea reasonable approximation ratio we investigate heuristics.III. B ASELINE : T HE G REEDY A PPROACH
Given a stream of orders, we accumulate them over an accu-mulation window of temporal length ∆ . After the accumulationperiod ends, all unassigned orders are allocated to availablevehicles in a greedy manner, following which the processingof the next accumulation begins.Let O ( (cid:96) ) be the set of unallocated orders at the end ofthe (cid:96) -th accumulation window and V ( (cid:96) ) be the set of activevehicles. The greedy assignment policy picks the unassignedorder-vehicle pair with the minimum marginal cost . Definition o be a new order thatarrived at time t . The marginal cost of assigning o to vehicle v is the increase in the extra delivery time of all orders alreadyassigned to v . mCost ( o, v ) = Cost ( v, O vt ∪ { o } ) − Cost ( v, O vt ) (3)where, Cost ( v, O vt ) = (cid:88) ∀ o ∈ O vt XDT ( o, v ) (4) Example
4: Revisiting Fig. 1,
Cost ( v , { o } ) = 3 (RecallEx. 3) and Cost ( v , ∅ ) = 0 . Thus, mCost ( o , v ) = 3 . Greedy iteratively selects the best unassigned order-vehiclepair ( o ∗ , v ∗ ) till no further assignments are possible. ( o ∗ , v ∗ ) = argmin ( o,v ) ∈ O ( (cid:96) ) ×V ( (cid:96) ) mCost ( o, v ) In each iteration, Greedy assigns A ( o ∗ ) = v ∗ . Example
5: Let us revisit Fig. 1. The instance shows threeavailable vehicles v , v and v and three unallocated orders o , o and o long with their preparation times. The greedyalgorithm first assigns vehicle v to order o since it has theleast marginal cost of . Next, the algorithm assigns order o to vehicle v at a cost of units and finally assigns order o to vehicle v with a route plan ( o r , o r , o c , o r ) for another units. This results in an overall cost of 6 units. Limitations:
Greedy is prone to producing sub-optimalsolutions due to making locally optimal choices. For example,in Fig. 1, we can achieve better costs by performing an one-to-one assignment as v to o , v to o and v to o for an overallcost of units. Here, we choose a suboptimal assignment for v to achieve an overall assignment with a better cost. Time complexity:
Since we have to look at all permuta-tions of at most M AX O locations to find an optimal routeplan O ( M AX O · ( M AX O !) · q ) time where O ( q ) is the timetaken for shortest path computation. We compute mCost ( o, v ) for order-vehicle pair which takes O ( M AX O · M AX O ! · qmn ) time where m = |V ( (cid:96) ) | and n = | O ( (cid:96) ) | . This is the firstround of the algorithm. Once ( o ∗ , v ∗ ) has been found, weneed to recompute the mCost ( o, v ∗ ) for the remaining ordersviz-a-viz v ∗ before an optimal can be found in the nextround and so on till the orders are all assigned. Hence thetotal time is O (cid:0) M AX O · ( M AX O !) · q ( mn + n ) (cid:1) . The O notation suppresses a logarithmic term required to find themin marginal cost at each step. If Dijkstra’s algorithm isused O ( q ) = O ( | E | + | V | log( | V | )) . However, through indexstructures [18], this cost can be significantly lower in practice. Selecting ∆ : Increasing ∆ has both positive and negativeimpact on the quality and scalability. In terms of quality, thenegative impact comes from the fact that an order remainsunallocated till the end of the window. Thus, the assignmenttime increases with increase in ∆ . On the other hand, sincewe accumulate more data and then the assignment happens,the minimum marginal costs have a high likelihood of beingsmaller. In terms of scalability, the cost per window goes up.However, we need to process fewer windows. Furthermore,in each window, we need to fetch the current location of allvehicles. With fewer of windows, this cost reduces. In general,it is hard to provide theoretical guarantees on the quality orscalability with respect to ∆ . We revisit this question againduring our empirical evaluation in § V.IV. F OOD M ATCH
As illustrated in the previous section, locally optimalchoices by Greedy may not converge to the globally optimalsolution. Rather, we should minimize the cumulative marginalcosts across all assignments. To achieve this objective, we or-ganize the assignment space in the form of a weighted bipartitegraph , which we call the F
OOD G RAPH . On the F
OOD G RAPH ,we compute the minimum weight perfect matching . A. Matching in F OOD G RAPH F OOD G RAPH is constructed as follows. Let O ( (cid:96) ) = { o , . . . , o k } be the set of unassigned orders at the end ofthe (cid:96) th accumulation window, and V ( (cid:96) ) the set of all activevehicles. The two partitions of the F OOD G RAPH are the orderpartition U = O ( (cid:96) ) and the vehicle partition U = V ( (cid:96) ) . Weadd an edge between o ∈ U and v ∈ U with weight w ( o, v ) . w ( o, v ) = Ω if ( o, v ) violates theconstraints of Def. 4 min ( mCost ( o, v ) , Ω) otherwiseOn this F OOD G RAPH , we compute the minimum weightperfect matching through the following minimization problem:Minimize (cid:88) ∀ o,v w ( o, v ) · x o,v Subject to (cid:88) o x o,v ≤ o ∈ U (cid:88) v x o,v ≤ v ∈ U (cid:88) ∀ o,v x o,v = min ( | U | , | U | ) where x o,v = 1 if o is assigned to v ; otherwise, x o,v = 0 .Minimum weight perfect matching in a bipartite graph iscomputed through Kuhn-Munkres algorithm [19]. Example
6: Fig. 2 shows the bipartite graph formed for theproblem instance shown in Fig. 1. The solid edges indicate themappings that will be selected by Kuhn-Munkres algorithm,i.e. x o,v = 1 . The cumulative cost of the assignments is units, which is unit better than Greedy. Time Complexity:
Let n = | O ( (cid:96) ) | and m = |V ( (cid:96) ) | . Asdiscussed in the analysis of Greedy, computing mCost ( o, v ) v v v Fig. 2. The bipartite graph formed for the instance in Fig. 1.The cost of eachedge is shown as edge weight. Bold lines indicate the assignment found byKuhn-Munkres algorithm. consumes O ( M AX O · ( M AX O !) q ) time. Constructing thecomplete bipartite graph requires O ( nm M AX O · ( M AX O !) q ) time. Let k ⊥ = min( n, m ) and k (cid:62) = max( n, m ) . Kuhn-Munkres algorithm computes a maximum weighted match-ing in O ( k (cid:62) k ⊥ ) time, giving an overall complexity of O ( nm M AX O · ( M AX O !) q + k (cid:62) k ⊥ ) . Limitations:
Although better than Greedy, there is scope toimprove further. • Batching:
By definition, no two edges will be incidenton the same node in a minimum weight perfect matching.Hence, batching is not feasible. Furthermore, if |V ( (cid:96) ) | < | O ( (cid:96) ) | , | O ( (cid:96) ) | − |V ( (cid:96) ) | orders would remain unassigned. • Scalability:
The O ( nm M AX O · ( M AX O !) q + k (cid:62) k ⊥ ) timecomplexity is too expensive to handle real-world workloads. • Dynamic Environment:
The matching process assumes thatthe marginal costs (edge weights in F
OOD G RAPH ) remainstatic while the minimization problem is being solved. Inreality, it is a dynamic environment where the vehicles aremoving. Thus, the marginal costs may become stale by thetime the assignments are made.In the subsequent sections, we address these limitations.
B. Batching
In this section, we describe our algorithm to create orderbatches. Once these batches are created then it is these batchesthat become nodes in partition U of F OOD G RAPH ratherthan individual orders, and the cost of the edges are now themarginal cost of assigning a batch of orders to a vehicle.Multiple orders should be grouped into a single batch, ifthey can be delivered by a single vehicle such that none of
Algorithm 1
Batching
Input:
Accumulation Window l , Quality cutoff η Output:
Order Partition U , corresponding route plans Σ r ← Π(0) ← {(cid:104){ o } , v, { o r , o c }(cid:105) : ∀ o ∈ O ( l ) } W (0) ← { w i,j : o i , o j ∈ O ( l ) × O ( l ) } G O (0) ← (Π(0) , W (0)) while true do if AvgCost ( G O ( r )) / | Π( r ) | > η then break i, j ← argmin W ( r ) if | π gi | + | π gj | > M AX O then continue σ m ← Compute optimal route plan for merged nodes π i and π j . g m ← { o : o ∈ π gi ∪ π gj } π m ← (cid:104) g m , v m , σ m (cid:105) Π( r + 1) ← Π( r ) ∪ { π m } \ { π i , π j } W ( r + 1) ← Update edges from π m to π k ∈ Π( r + 1) W ( r + 1) ← Remove π i and π j G O ( r + 1) ← (Π( r + 1) , W ( r + 1)) r ← r + 1 U ← { g i : π i ∈ Π( r ) } Σ ← { σ i : π i ∈ Π( r ) } return U , Σ these orders suffer a long detour due to being batched. Intu-itively, batching is similar to clustering. However, each order isnot a high-dimensional point and hence clustering algorithmsfor euclidean spaces cannot be applied. More importantly, weneed to formulate a distance function that is appropriate for ourproblem. Empowered with these observations, we formulatebatching as a graph clustering problem.
1) The Order Graph:
The order graph, G O ( (cid:96) ) , is an edge-weighted graph where each node corresponds to a batch (set)of orders and two batches π i and π j are connected by an edgeif it satisfies the following two conditions: (i) | π i | + | π j | ≤ M AX O and (ii) (cid:80) ∀ o ∈ π i ∪ π j o i ≤ M AX I. Recall, o i denotesthe number of items associated with order o .The weight w i,j of the edge between π i and π j indicatesthe quality of batching orders in π i with π j into a single batch π i,j . To quantify w i,j , we simulate three vehicles v i , v j , and v i,j with order sets π i , π j and π i ∪ π j respectively. The edgeweight w i,j is defined as follows: w i,j = Cost ( v i,j , π i,j ) − ( Cost ( v i , π i ) + Cost ( v j , π j )) (5) Recall,
Cost ( v, O ) (Eq. 4) quantifies the extra delivery timeincurred by each order in set O in the optimal route plan whenallocated to vehicle v . The initial location of each simulatedvehicle is considered to be the first location in the optimalroute plan for its corresponding order set. Lower weightsindicate better batching.We note here that although the concept of order graphs hasbeen used in the literature [10], [20], our usage of the ordergraph is much different. In particular, the edge weights (Eq. 5)are specialized for the the food delivery problem. Furthermore,we go beyond both [10], [20] to introduce a novel iterativeclustering method for constructing batches. This allows us tocreate batches of size or more in contrast to [10], where batchsize is limited to two, and is a more sophisticated method thanthat of [20], where only cliques are allowed to form batches.
2) Batching by Iterative Clustering:
Alg. 1 presents thepseudocode. Initially, we have a node corresponding to eachorder o ∈ O ( (cid:96) ) and the edges are constructed as discussedabove (line 2). Fig. 3(a) shows the initial order graph for Fig. 1.The clustering proceeds in an iterative manner. At iteration r , we have G O ( (cid:96) ) ( r ) , a (partially) clustered version of G O ( (cid:96) ) ,with node set Π( r ) = { π , . . . , π m } , such that ∀ i, π i ⊆ O ( (cid:96) ) and ∀ i, j, π i ∩ π j = ∅ (lines 5-16). To construct G O ( (cid:96) ) ( r +1) , we merge the endpoints of the minimum weight edge in G O ( (cid:96) ) ( r ) into a single cluster π i,j (lines (9-11) and remove π i and π j . π i,j is connected to remaining clusters in G O ( (cid:96) ) ( r ) based on the conditions described earlier and edge weights arecomputed as outlined in Eq. 5 (lines 12-15). Stopping Criterion:
To determine when to stop, we trackthe quality of each batch (node) in the order graph. We stopfurther batching, when the average quality of batches fallbelow a certain threshold. Formally, we assign an
AvgCost to the entire order graph as the average of the costs of theindividual batches.
AvgCost (cid:0) G O ( (cid:96) ) ( r ) (cid:1) = (cid:80) | Π( r ) | i =1 Cost ( v i , π i ) | Π( r ) | (6) ⇒ o ⇒ o ⇒ o O ,0 O ,0O ,0 < 0, σ >< 34, σ >< 34, σ >o ⇒ o o ⇒ o o ⇒ o (a) O ,0 O ,0O ,0 O ,0 O ,0 (b) η = 2 O O O ,0 O ,0O ,0 AvgCost = 0.5
Π,2 (c) η = 2 O O O ,0O ,0 AvgCost = 2
Π,6 O
78 6 (d) η = 2 O O O ,0 AvgCost = 2.33
Π,2 O O Π,5 (e)
Fig. 3. (a) Order graph of Fig. 1. The edge weight and the optimal route plan are shown beside each edge. (b) An example order graph. (c) First iteration ofclustering for order graph in Fig. 3(b). (d) Second iteration of clustering for order graph in Fig. 3(b) for M AX O = 3 . (e) Second iteration of clustering fororder graph in Fig. 3(b) for M AX O = 2 . When
AvgCost ( G O ( (cid:96) ) ( r )) exceeds a pre-defined threshold η , we stop. It is worth noting that computing Cost ( v i , π i ) does not add any computational burden. Specifically, for batch π i,j formed by merging π i and π j , we have Cost ( v i,j , π i,j ) = Cost ( v i , π i ) + Cost ( v i , π i ) + w i,j ( r ) . Here, all components inthe right hand side of the equation are already known. Hence,computing Cost ( v i,j , π i,j ) takes O (1) time.An important question arises at this juncture: Can we guar-antee that
AvgCost is a monotonically increasing function?
Otherwise, convergence cannot be guaranteed. Theorem 2answers this question.
Theorem AvgCost (cid:0) G O ( (cid:96) ) ( r + 1) (cid:1) ≥ AvgCost (cid:0) G O ( (cid:96) ) ( r ) (cid:1) for all r ≥ . Thus, convergenceis guaranteed. P ROOF . In the definition of
AvgCost (Eq. 6), the denominatordecreases with r . Thus, it is sufficient to show that thenumerator (cid:80) | Π( r +1) | i =1 Cost ( v i , π i ) in the ( r + 1) th iteration isalways larger than the numerator (cid:80) | Π( r ) | i =1 Cost ( v i , π i ) in the r th iteration. From the definition of edge weights in Eq. 5, ifvertices π i and π j are clustered to form G O ( (cid:96) ) ( r + 1) from G O ( (cid:96) ) ( r ) then, | Π( r +1) | (cid:88) i =1 Cost ( v i , π i ) − | Π( r ) | (cid:88) i =1 Cost ( v i , π i ) = w i,j ( r ) . Hence, if we can establish that ∀ i, j, w i,j ( r ) ≥ ,we are done. From Eq. 5, this is equivalent to showing Cost ( v i,j , π i,j ) ≥ ( Cost ( v i , π i ) + Cost ( v j , π j )) . Assumethat the optimal route plan for v i,j with order set π i,j = π i ∪ π j is the sequence of pick-up/drop-off points σ i,j = { a , a , · · · , a k } . We now partition σ i,j into two subsequences σ i and σ j such that σ i contains only those pick-up and drop-offlocations from σ i,j that are to be visited to deliver the ordersin π i and the same for σ j with respect to π j . With this setup,the extra delivery time incurred by orders in π i through routeplan σ i is less than or equal to the extra delivery time incurredthrough σ i,j since σ i is a subsequence of σ i,j . The same holdsfor π j as well when delivered through σ j . Therefore, Cost ( v i,j , π i ∩ π j , σ i,j ) ≥ Cost ( v i , π i , σ i ) + Cost ( v j , π j , σ j ) . By definition, the optimal route plans for π i and π j willincur lower costs than the particular route plans σ i and σ j and thus Cost ( v i,j , π i ∩ π j ) ≥ Cost ( v i , π i ) + Cost ( v j , π j ) . (cid:3) Example
7: We illustrate the clustering procedure on alarger order graph shown in Fig. 3(b). For this example, weassume η = 2 and the order capacity o i for all orders is . Inthe order graph depicted in Fig. 3(b), the closest clusters are O and O . They are merged to form a new cluster O , . Thecost of each batch is shown within the corresponding node.For example, the cost of O , is as shown in Fig. 3(c).If M AX O = 3 , in the next iteration, the minimum weightedge connects the clusters O , to O (Fig. 3(d)). In case M AX O = 2 , O and O would be merged as shown inFig. 3(e). The algorithm terminates when either the averagebatch quality exceeds threshold η = 2 (satisfied in Fig. 3(e))or no edges are left to merge (also satisfied in Fig. 3(e)). Time Complexity:
As in the previous analysis, we assumethe cost of shortest path queries O ( q ) , n = | O ( (cid:96) ) | . Computingthe order graph takes O ( n q ) time. The number of iterationsis bounded by n − . In each iteration, we find the edgewith lowest weight ( O (log n ) time) and recompute the weightsof the edges from the remaining nodes to the newly formedcluster ( O ( n M AX O · ( M AX O !) q ) time). This gives an overallcomplexity of: O ( n q M AX O · ( M AX O !)) . C. Scaling F OOD M ATCH
The O ( nm M AX O · ( M AX O !) q + k (cid:62) k ⊥ ) complexity ofbipartite matching stems from two components: creating thebipartite F OOD G RAPH ( O ( nm M AX O · ( M AX O !) q )) and ap-plying Kuhn-Munkres algorithm for minimum weight perfectmatching (cid:0) O ( k (cid:62) k ⊥ ) (cid:1) . Creating F OOD G RAPH is the dominantcontributor to the computation cost since it involves computingthe edge weight among each pair of order and vehicle. We nowexplore strategies to reduce this intensive computation.In practice, it is likely that the vehicle assigned to anorder o is located close to the pick-up location o r . To verifythis intuition, we analyze the assignments made by Kuhn-Munkres’s algorithm on order and vehicle data from a largecity in India (City B in Table II). Specifically, for each vehicle v , we rank all orders o ∈ O ( (cid:96) ) in ascending order based onnetwork distance SP ( loc ( v, t ) , o r , t ) , i.e., from the vehicle’slocation to the order’s restaurant location. Next, we computethe percentile rank of the allocated order to v . Fig. 4(a)presents the distribution of percentile ranks of allocated order.Fig. 4(a) reveals that for of all vehicles, the assignedorder has a percentile rank below . This behavior revealsthat distant order-vehicle pairs rarely play a role in the eventualassignment and therefore, the corresponding edges in theF OOD G RAPH could be pruned. Incorporating this method-ology, however, raises an intriguing question:
How do wedetermine which vehicles are far away from an order withouteven computing the distances to them?1) Efficient F OOD G RAPH construction:
First, we formalizeour objective. Let
Π = { π , · · · , π m } be the set of batches
20 40 60 80 100
Percentile Rank A ss i g n m e n t s ( % ) City B (a) (b)
Fig. 4. (a) Cumulative distribution of percentile ranks of assigned vehiclesto orders. (b) Illustration of angular distance. obtained from Alg. 1. For each batch π i , we examine its(quickest) route plan and identify the order π i [1] ∈ π i thatneeds to be picked up first from restaurant location π i [1] r .With this information, we extract the subset of nodes V Π ⊆ V ,where V Π ⊆ V = { u ∈ V | ∃ π i ∈ Π , π i [1] r = u } . V Π is the set of nodes where the route plan of at least onebatch starts. Now, given an available vehicle v ∈ V ( (cid:96) ) , ourgoal is to identify the k closest nodes in V Π from v ’s currentlocation loc ( v, t ) . With this information, we want to constructa sparsified bipartite F OOD G RAPH , where we add edges fromvehicle v to only those batches that start from a node withinthe top- k list of v . To all remaining batches, we would add anedge of weight Ω (c.f. Prob. 1) and avoid computing the trueedge weight (marginal cost). k is selected based on percentileinformation extracted from the data. For example, Fig. 4(a)shows that of all vehicles get assigned an order thatis within the top- percentile. Thus, k could be set to × | Π | . We achieve this objective, through best-first search.Alg. 2 presents the pseudocode for our best-first-basedmethod for constructing the sparsified F OOD G RAPH . Givenan available vehicle v ∈ V ( (cid:96) ) , we extract its current location(node) source = loc ( v, t ) (line 3). From source , we initiate abest-first search (lines 8-15). Specifically, we utilize a priorityqueue P Q to store candidate nodes that should be visited (line4). PQ stores tuples (cid:104) u, δ u (cid:105) , where δ u = SP ( source, u, t ) isthe length of the shortest path from source to u . P Q retrievesnodes in ascending order of δ u . Initially, P Q contains only source (line 5). Once the top node u is popped from P Q (line9), we add an edge from vehicle v to all batches that start from u (if any) in the F OOD G RAPH (lines 12-15). The edge weightof assigning a batch to a vehicle is obtained by generalizingmarginal cost (Def. 9) to a set of orders. Specifically, mCost ( π, v ) = Cost ( v, O vt ∪ π ) − Cost ( v, O vt ) (7)Next, we mark u as visited and insert all of the unvisitedneighbors u (cid:48) of u in P Q with δ (cid:48) u = δ u + β ( u, u (cid:48) , t ) , where β ( u, u (cid:48) , t ) is the edge weight of edge ( u, u (cid:48) ) (average timetaken) in the road network at time t (line 11, 17-18). Thisprocess continues iteratively, till either v attains a degree of k in F OOD G RAPH or P Q becomes empty (line 8). Once thiscondition is satisfied, we add edges of weight Ω from v toall remaining batches that are not already connected (line 19).Finally, this entire process is repeated ∀ v ∈ V ( (cid:96) ) (line 2). Lemma v has an edgeweight smaller than Ω to batch π in the F OOD G RAPH obtainedthrough Alg. 2, then π is among the top- k closest batches to v . The distance between v and π is measured as the shortestpath distance from v ’s location to the first pick-up node in π . Algorithm 2
Sparsified F
OOD G RAPH construction
Input:
Available vehicles V ( (cid:96) ) , order batch Π , Maximum degree k , current time t ,road network G ( V, E, β ) Output:
Sparsified F
OOD G RAPH Initialize bipartite graph B with node sets V ( (cid:96) ) and Π , and empty edge set E b . for each v ∈ V ( (cid:96) ) do source ← loc ( v, t ) P Q ← Empty Priority Queue P Q.insert ( (cid:104) source, (cid:105) ) Initialize ∀ u ∈ V, visited ( u ) ← false Π v ← ∅ while P Q.empty () = false and degree ( v, B ) < k do (cid:104) u, δ (cid:105) ← P Q.pop () if visited ( u ) = true then continue visited ( u ) ← true I ( u ) ← { π ∈ Π | π [1] r = u } for each π i ∈ I ( u ) do Add edge from v to π i in E b with edge weight given by Eq. 7. end for Π v ← Π v ∪ I ( u ) N ( u ) ← ( u (cid:48) | ( u, u (cid:48) ) ∈ E, visited ( u ) = F alse, ) ∀ u (cid:48) ∈ N ( u ) , P Q.insert ( (cid:104) u (cid:48) , δ + β ( e = ( u, u (cid:48) ) , t ) (cid:105) ) ∀ π i ∈ Π \ Π v , add edge from v to π i in E b with Ω edge weight. end for return bipartite graph B ( V ( (cid:96) ) , Π , E b ) Proof:
Alg. 2 explores nodes in ascending order oftheir network distance from the current location of the ve-hicle. Hence, if node u is popped from the priority queuebefore node u , it is guaranteed that SP ( source, u , t ) ≤ SP ( source, u , t ) . Since the while loop in Alg. 2 exits as soonas vehicle v attains a degree of k , for any unvisited batch π ,it is guaranteed that k batches have been visited prior to π .This, in turn, means any of the visited batches start at a nodecloser to source than π . D. Managing Dynamic Environment1) Handling dynamic vehicle positions:
Alg. 2 assumes thatthe location of a vehicle v is static while the F OOD G RAPH is being constructed. In reality, v moves according to itsassigned route plan in the previous accumulation window.Thus, by the time F OOD G RAPH construction finishes, theassigned batches may no longer be the k closest ones to v . Fig. 4(b) illustrates this issue more concretely. Considervehicle v that is located at position (node) source at time t andis moving towards location dest . We assume the F OOD G RAPH construction process starts at time t and finishes at t +∆ . Now,consider two candidate locations (nodes) u and u (cid:48) . u (cid:48) is closerto source at time t . However, at time t + ∆ , there is a highlikelihood that u is closer to v since v is progressively movingaway from u (cid:48) as dest is located in an opposite direction to u (cid:48) . To mitigate this issue, we incorporate the novel idea of angular distance . The angular distance of vehicle v with node u is proportional to the angle formed by the direction vectors from source to dest with that of source to u . In Fig. 4(b),the angles are Θ and Θ (cid:48) for u and u (cid:48) respectively. Giventhe source and destination locations, the direction vector iscaptured through bearing . Definition
10 (Bearing): The bearing Θ s,t captures thedirection along a great circle between two points of s ( ϕ s , λ s ) and t ( ϕ t , λ t ) where ϕ and λ are the latitude and longitude inradians. Mathematically, it is computed as follows: ig. 5. Flowchart of F OOD M ATCH . Θ( s, t ) = atan2( X, Y ) where, X = cos( ϕ t ) sin( λ t − λ s ) Y = cos( ϕ s ) sin( ϕ t ) − sin( ϕ s ) cos( ϕ t ) cos( λ t − λ s ))atan2( X, Y ) = arctan(
X/Y ) is rendered in the range [0 , π ] .The angular distance of vehicle v to node u at time t is: adist ( v, u, t ) = 1 − cos (Θ ( loc ( v, t ) , dest ) − Θ ( loc ( v, t ) , u ))2 Here, dest denotes the next destination node in the routeplan followed by v . The properties of the angular distance areas follows. (1) The numerator ranges from to , and hencewe divide it by to obtain a distance value between to . (2) indicates that u lies in the same direction as dest whereas, indicates u is located in a diametrically opposite direction. Thecloser the distance is to , the more similar are the directions.Angular distance allows us to estimate whether the distanceto a node is likely to deteriorate with time or improve.Thus, instead of relying only on the average traveling timeas the edge weight in the road network, we make the edgeweight a function of both the travel time and the angulardistance. Specifically, we definite a vehicle-sensitive edgeweight α ( v, e, t ) for edge e = ( u, u (cid:48) ) as follows: α ( v, e, t ) = (1 − γ ) adist ( v, u (cid:48) , t )+ γ β ( e, t )max ∀ e (cid:48) ∈ E { β ( e (cid:48) , t ) } (8)Here γ is a weighting factor. Recall from Def. 1 that β ( e (cid:48) , t ) denotes the average traveling time in edge e at time t .
2) Reshuffling:
In food delivery, we have a buffer timeuntil the food is prepared. We utilize this buffer by allowing reshuffling of assignments done in previous accumulationwindows. Specifically, an order o assigned to a vehicle v isavailable for re-assignment in subsequent windows if v has notyet picked it up. Similarly, vehicle v also gets added to V ( (cid:96) ) and may get assigned a new order. In other words, reshufflingtakes into account the dynamic nature of the problem andexploits new data to find better assignments for previouslymade assignments that have not been picked up yet. E. Putting it All Together
Fig. 5 outlines the pipeline of F
OOD M ATCH . Given a datastream of orders and available vehicles, we accumulate them inwindows of length ∆ . Within the current window W ( (cid:96) ) , V ( (cid:96) ) collects all available vehicles. O ( (cid:96) ) , on the other hand, collectsall unassigned orders as well as orders that have been assignedto a vehicle but not yet been picked up from their restaurants. TABLE IIS
UMMARY OF ORDER HISTORY DATASET
City
GrubHub
159 183 1046 19 . NA NACity A O ( (cid:96) ) is next clustered to form batches. These batches andthe available vehicles V ( (cid:96) ) are used to form the bipartiteF OOD G RAPH . The construction of F
OOD G RAPH is expeditedthrough best first search. In addition, we incorporate dynamicmovement of vehicles through angular distances. Finally, Weperform minimum weight perfect matching on F
OOD G RAPH using the
Kuhn-Munkres algorithm.V. E
XPERIMENTS
In this section, we benchmark F
OOD M ATCH and establish: • Quality: F OOD M ATCH is effective in generating high-quality assignments and is, on average, better than thebaseline strategies. • Scalability: F OOD M ATCH scales to the demands of foodorders on the busiest Indian cities. • Impact of optimization strategies:
Batching, reshuffling,best-first search and angular distance impart significantimprovement in both assignment quality and efficiency.Our code and datasets are available at https://github.com/idea-iitd/FoodMatch
A. Datasets
Table II presents the datasets used for our experiments.Grubhub is provided by Reyes et al. [5]. The remainingdatasets are provided by Swiggy - India’s leading food deliveryservice [3]. Due to business intelligence-related concerns,neither GrubHub nor Swiggy reveal the city names. TheSwiggy data represents all orders delivered in these cities overa period of -days. City Characteristics:
City B and City C correspond totwo large metropolitan cities in India, whereas City A isrelatively smaller. Although City C has a larger number ofrestaurants, Swiggy fulfilled more orders in City B inthe time period under consideration. Furthermore, Swiggy alsoemployed about more vehicles to cope with the higherorder volume. In Fig. 6(a), we plot the ratio
No.ofOrdersNo.ofV ehicles in each 1-hour timeslot of a city. Timeslot indicates theperiod 12AM-12:59PM, indicates 1AM-1:59AM and so on.A ratio above indicates that the number of vehicles thatwere available in that timeslot was lower than the number oforders received. We point out some of the key observationsfrom Fig. 6(a). (1) The order-to-vehicle ratio is the highestacross all cities during the lunch and dinner periods. (2)
Theratio is the highest in City B.
Road Network:
The Swiggy datasets also come withthe road networks of the the corresponding cities. They areobtained from OpenStreetMap [21]. The vehicle GPS pings are map-matched to the road network to obtain network-alignedtrajectories [22]. The weight of each road network edge is setto the average travel time across all of Swiggy’s vehicles inthe corresponding road. Instead of computing a single averagespeed across the entire 24-hour period, we create time slots
10 20
Time Slot O r d e r / V e h i c l e s R a t i o City BCity CCity A (a)
City B City C City A Grubhub
City X D T ( h o u r s / d a y ) FoodMatch Reyes (b)
XDT
City B City C City A
City X D T ( h o u r s / d a y ) FoodMatchGreedy (c)
XDT
City B City C City A
City . . . . . . . . . O r d e r s p e r k m FoodMatch Greedy (d)
O/Km
City B City C City A
City W a i t i n g T i m e ( h o u r s / d a y ) FoodMatch Greedy (e) WT City B City C City A
City O v e r fl o w n W i nd o w s ( % ) GreedyKMFoodMatch (f)
Overflow (All)
City B City C City A
City O v e r fl o w n W i nd o w s ( % ) GreedyKM FoodMatch (g)
Overflow (Peak)
City B City C City A
City R unn i n g T i m e ( S ec s ) GreedyKMFoodMatch (h)
Time (All)
Time Slot I m p r o v e m e n t ( % ) City BCity CCity A (i)
XDT
Time Slot I m p r o v e m e n t ( % ) City BCity CCity A (j)
O/KM
Time Slot I m p r o v e m e n t ( % ) City BCity C City A (k)
WTFig. 6. (a) Distribution of the order-to-vehicle ratio across timeslots. (b) Comparison with Reyes. (c-e) Comparison with Greedy. (f-g) Number of accumulationwindows where the time taken for assignment is above ∆ = 3 minutes across (e) all slots, and (f) peak slots. (h) Average running times of F
OOD M ATCH ,K M ,and greedy. (i-k) Improvement over K M across timeslots in (i) XDT, (j) O/KM, and (k) WT. corresponding to each hour of the day. The edge-weight iscomputed for each time slot separately. Food preparation time:
Similar to edge weights, wepartition the food preparation times of each restaurant into
24 1 -hour slots. The food preparation within an -hour slot isnext modeled as a Gaussian distribution N ( µ R,T , σ
R,T ) foreach restaurant R in timeslot T . B. Experimental Setup
All algorithms are implemented in C ++ and experimentsare performed on a machine with Intel(R) Xeon(R) CPU @2.10GHz with 252GB RAM on Ubuntu 18.04.3 LTS. Evaluation Framework:
All experiments on Swiggy datasetsare reported based on -fold cross validation . We use daysfor training, where we learn the parameters such as travel timesfor each edge, food preparation times, etc. We benchmark theperformance of all assignment strategies on orders receivedon the unseen th day. This process is then repeated timestaking each day as the test day and the remaining days fortraining. The initial position of vehicles on the test day is setto the location at which their first GPS ping is received.In Grubhub, we use the entire dataset for testing since noparameters need to be learned. The network is absent andhence, spatial distance is used a proxy for network distance.The distributions of food preparation times in Grubhub aregiven to us separately. Operational Constraints:
The food-delivery service needsto operate within several domain constraints. We use the sameconstraints used by Swiggy. If an order remains unallocatedfor minutes, it is rejected . The rejection penalty Ω (RecallProblem 1) is set to seconds, i.e., 2 hours. Batching ofmore than 3 orders is rarely observed in real data, and henceM AX O is set to . The maximum item capacity of each vehi-cle, M AX I, is set to . Most delivery companies guarantee amaximum delivery time. For Swiggy, this time is minutes,which acts as a bound on the maximum possible distance be-tween the vehicle and pick-up location. Thus, in F OOD G RAPH ,if SP ( loc ( v, t ) , π [1] r , t ) > , mCost ( π, v ) = Ω . Parameters:
The default size of accumulation window ∆ is minutes for City B and City C and minute for City A. ∆ is smaller in City A since the volume of orders is smaller inCity A. We evaluate the impact of ∆ in greater depth in §V-H(see Fig. 8). The weighting factor γ is set to . (Eq. 8). k is set × | O ( (cid:96) ) ||V ( (cid:96) ) | (Sec. IV-C1). η (Sec. IV-B2) is set to 60seconds (Sec. IV-B2). Baselines:
Reyes et al. [5] is the state of the art. Its limitationare discussed in detail in § I-A. In this section, we empiricallycompare its performance with F
OOD M ATCH . In addition, wealso benchmark against the Greedy approach (§. III). We usehierarchical hub labeling [18] to index shortest paths queriesin all benchmarked algorithms that operate on road networks.
Metrics:
The performance is quantified through: • Extra delivery time (XDT):
XDT is our objective function(Problem 1) and serves as the primary performance indicator. • Orders per kilometer (O/Km):
While our objective functionis a customer-facing metric, O/Km quantifies operational effi-ciency in terms of distance travelled per order. Mathematically,let D k be the total distance covered by all vehicles whilecarrying k orders. Then average orders per km is (cid:80) k · D k (cid:80) D k .We illustrate this metric through Fig. 1.Assume the edge weights represent the distance in Km. Letvehicle v start at u and pick up o and o by travelling 6kmand 5km respectively and finally deliver the two orders at u and u by travelling 8km and 5km respectively. The averagenumber of orders per km is × × × × = 1 . . • Average vehicle waiting time (WT):
Once a vehicle reachesits pickup location, it must wait until food is prepared. Sincedrivers are paid for every minute of duty, the WT (assignmenttime + firsmile - food preparation time) should be minimized.Similar to O/KM, WT is an indicator of operational efficiency.
C. Comparison with Reyes
Reyes et al. does not incorporate the underlying road net-work to compute distances between locations. Instead, it usesHaversine distance. Furthermore, it uses a linear programmingformulation that allows batching only if orders are from the ity B City C City A
City I m p r o v e m e n t ( % ) B & RB & R+BFSB & R+BFS+A (a)
Optimizations
20 40 60 80 100
No. of Vehicles (%) X D T ( h o u r s / d a y ) City BCity C City A (b)
Extra Delivery Time
25 50 75 100
No. of Vehicles (%) . . . . . A v g . O / K m City BCity C City A (c)
Orders/Km
25 50 75 100
No.of Vehicles(%) W T ( h o u r s / d a y ) City BCity C City A (d)
Waiting Time . . . . . No. of Vehicles (%) O r d e r R e j ec t i o n s ( % ) City BCity C City A (e)
No. of RejectionsFig. 7. (a) Impact of various optimization techniques on XDT. (b-e) Impact of number of vehicles on (b) XDT and (c) O/Km, (d) WT, and (e) percentageof order rejections. same restaurant. Due to these unrealistic design choices, theperformance suffers. As visible in Fig. 6(b), the number ofman hours lost per day (XDT) is times higher on averagein Reyes. In Grubhub, the difference is less due to two reasons.First, F OOD M ATCH does not have access to the road network.Second, the order volume in Grubhub is significantly lower,which reduces the impact of optimization strategies such asbatching and reshuffling.
D. Comparison with Greedy
Next, we compare the performance against Greedy. Fig. 6(c)presents the results. The extra delivery time in F
OOD M ATCH is, on average, less than Greedy. The improved perfor-mance of F
OOD M ATCH indicates that optimizing a globalobjective through minimum weight perfect matching helps.Furthermore, through a dedicated batching step, F
OOD M ATCH is better able to cope with scarcity of delivery vehicles. Wealso observe that for both F
OOD M ATCH and Greedy, the XDTsare substantially higher in City B and City C. This is a directresult of the fact that they represent two large metropolitancities in India with substantially higher order volumes. InFig. 6(d) and Fig. 6(e), we measure the improvement withrespect to our secondary metrics O/km and WT. Recall thatwe do not directly optimize these metrics. However, theyare important indicators of operational efficiency and hencegood performance is desired. On both metrics, we observe adramatic improvement. For example, the combined man hourswasted by delivery personnel waiting for food to be prepared ishigher by hours in both City B and City C when ordersare assigned through Greedy. On the other hand, the ordersdelivered per km is higher in F
OOD M ATCH . This is adirect consequence of having a dedicated batching componentin the F
OOD M ATCH pipeline.
E. Scalability
A critical feature of F
OOD M ATCH is its scalability as wesee in Figs. 6(f)-6(g). As discussed earlier, if the rate of orderarrival is higher than the rate of order assignment, then thealgorithm is not efficient enough for real-time deployment.In this experiment, we partition the timeline into -minutewindows and find the percentage of windows where theassignment time of all orders that arrived within that windowis higher than minutes. We call such windows overflown . Inaddition to Greedy and F OOD M ATCH , we also include vanillaKuhn-Munkres (K M ) without any of the other optimizationsas a baseline in this experiment. This allows us to preciselymeasure the impact of best-first search on scalability. Fig. 6(f) presents the percentage of overflown windows across all slotsand Fig. 6(g) present the same statistics in the peak slotscorresponding to lunch and dinner periods. As clearly visible,F OOD M ATCH is the only algorithm with overflows. Incontrast, at least of the windows are overflown in Greedyand K M during peak hours in City B and City C. In City A,scalability is not an issue for any of the techniques since theorder volume is low.The same pattern is also visible in Figs. 6(h), where weexamine the raw running times. We see that F OOD M ATCH isthe fastest and Greedy is the slowest on average.
F. Impact of Optimizations F OOD M ATCH builds on K M by layering it with severaloptimizations such as Batching and Reshuffling (B&R), sparsi-fied F OOD G RAPH through best-first-search (BFS) and Angulardistance (A). In this section, we systematically inspect theimpact of these optimizations.First, we compare the performance of F
OOD M ATCH withjust Kuhn-Munkres (K M ) that does not include any of theoptimizations. To enable comparison of performance acrosscities and metrics, we plot the improvement ( % ) obtainedby F OOD M ATCH over K M . For example, let K M XDT andF
OOD M ATCH
XDT be the extra delivery times with algorithmK M and F OOD M ATCH respectively. Then, improvement ofF
OOD M ATCH with respect to K M is:I MP K M ,XDT = K M XDT − F OOD M ATCH
XDT K M XDT × (9)For the metric of O/km, since higher values indicatebetter performance, we switch the numerator of Eq. 9 toF OOD M ATCH
O/Km − K M O/Km . Negative values indicatebetter performance by the baseline, whereas positive valuesindicate superior performance by F
OOD M ATCH . K M Vs. F
OOD M ATCH
In Figs. 6(i)-6(k), we measure theimprovement over K M across various timeslots of the day. Thetimeslot partitioning is done in the same manner as in Fig. 6(a).In XDT, we observe two peaks in Fig. 6(i). These peakscorrespond to the lunch and dinner periods (Recall Fig. 6(a)),and indicates that as order volumes increase, the advantage ofF OOD M ATCH becomes even more pronounced. In the othertwo metrics (Figs. 6(j) and 6(k)) as well, we observe slightincrease in improvement during lunch and dinner periods.
Individual impact of optimizations:
In Fig. 7(a), wemeasure the individual impact of each of the optimizationsemployed by F
OOD M ATCH . Specifically, we add each opti-mization in a layered manner, and compute the improvement η (seconds) X D T ( h o u r s / d a y ) City BCity C City A (a)
XDT
50 100 150 η (seconds) . . . . . . A v g . O / K m City BCity C City A (b)
Orders/Km
50 100 150 η (seconds) W T ( h o u r s / d a y ) City BCity C City A (c)
Waiting Time ∆ (minutes) X D T ( h o u r s / d a y ) City BCity C City A (d)
XDT ∆ (minutes) . . . . . . . A v g . O / K m City BCity C City A (e)
Orders/Km ∆ (minutes) W T ( h o u r s / d a y s ) City BCity C City A (f)
Waiting Time ∆ (minutes) R unn i n g T i m e ( s ec s ) City BCity C City A (g)
Running Time (All)
100 200 300 k X D T ( h o u r s / d a y ) City BCity C City A (h)
XDT
100 200 300 k . . . . . . A v g . O / K m City BCity C City A (i)
Orders/Km
100 200 300 k W T ( h o u r s / d a y ) City BCity C City A (j)
Waiting Time
100 200 300 k R unn i n g T i m e ( s ec s ) City BCity C City A (k)
Running Time (All)Fig. 8. Impact of η on (a) XDT, (b) O/Km, and (c) WT. Impact of accumulation window ∆ on (d) XDT, (e) O/Km, (f) WT, and (g) running time. Impactof k on (h) XDT, (i) O/Km, (j) WT, and (k) running time. obtained over K M . In Fig. 7(a), B&R represents Batching andReshuffling on top of K M , B&R+BFS represents Batching,Reshuffling and best-first search, and B&R+BFS+A furtheradds angular distance.As visible, the highest impact comes from Batching. Thisis natural since K M cannot batch two orders from the sameaccumulation window. In contrast, F OOD M ATCH performs anin-depth analysis of batchability through the proposed clus-tering algorithm. In the clustering process, the quality of allbatches are carefully monitored and the process continues onlyif the average cost of all batches is above a threshold η . Next,we note that although in BFS we sparsify the F OOD G RAPH ,the improvement increases (B&R+BFS). This seems counter-intuitive. To understand this behavior better, we deep-dive intothe data related to this experiment. We observe that removalof edges in F
OOD G RAPH leads to non-assignment of batchesthat are not close to any of the available vehicles. Thus, theyfeed into the subsequent accumulation window, in which manyof them get allocated to a better vehicle match. When workingwith the full F
OOD G RAPH , some far-away pairings do happen,which increases XDT. Finally, increase in improvement( % )due to the addition of angular distance showcases the need toadapt to the dynamic vehicle positions. G. Impact of Vehicles
So far we have used the same number of vehicles that wereavailable in the real world in the corresponding timeslot.
Whathappens if the number of vehicles is significantly smaller?Furthermore, is there scope to improve the economics of food-delivery business by reducing the number of vehicles?
Our nextexperiment studies these questions. Specifically, we subsample the number of delivery vehicles and observe its impact onperformance. Figs. 7(b)-7(d) present the average XDT per day,O/KM, and WT per day.As expected, the XDT reduces with more vehicles. How-ever, the rate of reduction is small beyond , whichindicates that the number vehicles can be significantly reducedwithout causing any noticeable impact on the customer expe-rience. The impact on O/Km and WT appears odd at vehicles. Specifically, we would expect O/Km to decreaseand WT to increase with increase in vehicles. While thispattern is visible in the region [40% , , in the range of [20% , , an opposite behavior is observed. To understandthis phenomenon better, we look into the order rejection rate asa function of the number of vehicles (Fig. 7(e)). We notice thatat , close to of the orders are rejected due to violatingvarious operational constraints such as M AX O, M AX I, and thedelivery guarantee of minutes. Due to the large reductionin serviceable orders, the anomalous behavior is observed inthe range [20% , . We also point out that City B has thebest O/Km due to the order-to-vehicle ratio being the highestin this city (Fig. 6(a)). On the other hand, City C has thelargest WT, since the order-to-vehicle ratio is comparativelylower despite it having the largest number of restaurants. H. Impact of Parameters
Impact of η : Higher η increases the likelihood of ordersbeing batched. When an adequate number of delivery vehiclesare available, with more batching, we expect the XDT toincrease (Thm. 2). On the other hand, higher batching leadsto better O/Km and reduced WT. This behavior is visible inFigs. 8(a)-8(c). We note that in both O/Km and WT, the gradi-ent of increase/decrease slows beyond η = 60 seconds, whichindicates that setting η = 60 seconds obtains a good balancebetween customer satisfaction and operational efficiency. Impact of ∆ : As discussed in Sec. III, ∆ has both positiveand negative impacts on quality as well as efficiency. Fig. 8studies its impact empirically. We observe that as ∆ increases,the XDT increases as well (Fig. 8(d)). This behavior can beexplained from the fact that with larger ∆ , an order mayneed to wait longer till assignment starts. With increase in ∆ ,the assignment time goes up and hence, the WT decreases(Fig. 8(f)). O/Km improves with ∆ since more orders areaggregated within the accumulation window, which in turnallows clustering to batch more orders together. In termsof computational efficiency, larger ∆ increases the cost ofmatching and batching. However, it reduces the number ofwindows on which assignment is performed. As visible in .
25 0 .
50 0 . γ X D T ( h o u r s / d a y ) City BCity C City A (a)
Extra Delivery Time .
25 0 .
50 0 . γ . . . . . A v g . O / K m City BCity CCity A (b)
Orders/Km .
25 0 .
50 0 . γ W T ( h o u r s / d a y ) City BCity C City A (c)
Waiting Time . . . Number of Vehicles (%) R e j ec t e d O r d e r s ( % ) γ = 0 . γ = 0 . γ = 0 . (d) Rejection Rate in City BFig. 9. Impact of γ on (a) XDT, (b) O/Km, (c) WT, and (d) rejection rate. Figs. 8(g), the sweet spot is achieved at ∆ = 3 minutes forCity C and City B and minute in City A. Impact of k : k dictates the maximum degree of eachvehicle in F OOD G RAPH . All three qualitative metrics displayminimal improvement with increase in k (Figs. 8(h)-8(j)).However, the increase in running time is significant in CityB and City C. This indicates that limiting k ∈ [100 , provides a good balance between efficacy and efficiency. Impact of γ : γ balances the importance of angular distanceand travel time in defining edge weights of the road network.Figs.9(a)-9(c) analyze the impact of γ on the performance.While the XDT remains almost unaffected with minimaldecrease, both O/Km and WT deteriorates sharply. As γ increases, a vehicle would have edges to only those orders thatoriginate from a node in the same direction as the vehicle’sdestination. This leads to reduced chances of batching, andhence O/Km decreases. Without batching, the vehicle oftenarrives in the restaurant early and increases its waiting time.Furthermore, when the number of vehicles is less, reducedbatching leads to higher number of order rejections (Fig. 9(d)).Hence, γ = 0 . is our recommendation.VI. C ONCLUSION
Delivery time is a key factor in both improving customerexperience as well as increasing business productivity in thefood delivery business. Despite food-delivery being a multi-billion dollar industry, there has been little research on strate-gies aimed at minimizing this key metric. Our contribution,F
OOD M ATCH , addresses this need. Our empirical evaluationsestablish that (1) F OOD M ATCH has an order of magnitudesmaller extra delivery time compared to Reyes [5], and less than Greedy. (2) F OOD M ATCH leads to higher numberof orders delivered per km, while reducing waiting time atrestaurants for delivery personnel by ≈ . (3) Besides,F
OOD M ATCH scales to real-world workloads on large cities.At a broader level, the proposed work empowers food-deliverycompanies with an in-depth understanding of the various sub-problems such as batching of orders into groups, coping with dynamic availability and positions of delivery vehicles andthe associated scalability challenges. We hope F
OOD M ATCH will provide delivery services with a platform that may beexperimented upon with live data and further improved withinsights obtained from its performance in the real world.R
Transportation Science , vol. 53, no. 5,pp. 1372–1388, 2019.[5] D. Reyes, A. L. Erera, M. W. P. Savelsbergh, S. Sahasrabudhe, andR. J. O’Neil, “The meal delivery routing problem,” Optimization Online,2018.[6] S. Ji, Y. Zheng, Z. Wang, and T. Li, “Alleviating users’ pain of waiting:Effective task grouping for online-to-offline food delivery services,” in
WWW , 2019, p. 773–783.[7] Y. Zeng, Y. Tong, and L. Chen, “Last-mile delivery made practical: Anefficient route planning framework with theoretical guarantees,”
Proc.VLDB Endow. , vol. 13, no. 3, p. 320–333, Nov. 2019.[8] H. Dai, J. Tao, H. Jiang, and W. Chen, “O2O on-demand deliveryoptimization with mixed driver forces,”
IFAC-PapersOnLine , vol. 52,no. 13, pp. 391 – 396, 2019, 9th IFAC Conference on ManufacturingModelling, Management and Control MIM 2019.[9] C. F. Yuen, A. P. Singh, S. Goyal, S. Ranu, and A. Bagchi, “Beyondshortest paths: Route recommendations for ride-sharing.” in
Proc. WorldWide Web Conference (WWW ’19) , May 2019, pp. 2258–2269.[10] L. Zheng, L. Chen, and J. Ye, “Order dispatch in price-aware rideshar-ing,”
PVLDB , vol. 11, no. 8, p. 853–865, 2018.[11] J. Wang, P. Cheng, L. Zheng, C. Feng, L. Chen, X. Lin, and Z. Wang,“Demand-aware route planning for shared mobility services,”
PVLDB ,vol. 13, no. 7, pp. 979–991, 2020.[12] S. Ma, Y. Zheng, and O. Wolfson, “T-share: A large-scale dynamic taxiridesharing service,” in
ICDE , 2013, pp. 410–421.[13] P. Cheng, H. Xin, and L. Chen, “Utility-aware ridesharing on roadnetworks,” in
SIGMOD , 2017, p. 1197–1210.[14] N. Garg and S. Ranu, “Route recommendations for idle taxi drivers:Find me the shortest route to a customer!” in
Proceedings of the 24thACM SIGKDD International Conference on Knowledge Discovery &Data Mining , 2018, pp. 1425–1434.[15] Y. Tong, Y. Zeng, Z. Zhou, L. Chen, J. Ye, and K. Xu, “A unifiedapproach to route planning for shared mobility,”
PVLDB , vol. 11, no. 11,pp. 1633–1646, Jul. 2018.[16] D. Gupta, “The Swiggy delivery challenge,”Jun 2019. [Online]. Available: https://bytes.swiggy.com/the-swiggy-delivery-challenge-part-one-6a2abb4f82f6[17] S. O. Krumke, “Online optimization: Competitive analysis and beyond,”Technische Universitat Berlin, Tech. Rep. ZIB Report 02-25, June 2002.[18] D. Delling, A. Goldberg, T. Pajor, and R. Werneck, “Robust exactdistance queries on massive networks,” Microsoft, Tech. Rep. MSR-TR-2014-12, July 2014.[19] F. Bourgeois and J.-C. Lassalle, “An extension of the Munkres algorithmfor the assignment problem to rectangular matrices,”
Commun. ACM ,vol. 14, no. 12, p. 802–804, 1971.[20] J. Alonso-Mora, S. Samaranayake, A. Wallar, E. Frazzoli, and D. Rus,“On-demand high-capacity ride-sharing via dynamic trip-vehicle assign-ment,”
Proceedings of the National Academy of Sciences