 # A Primal-Dual Online Deterministic Algorithm for Matching with Delays

In the Min-cost Perfect Matching with Delays (MPMD) problem, 2 m requests arrive over time at points of a metric space. An online algorithm has to connect these requests in pairs, but a decision to match may be postponed till a more suitable matching pair is found. The goal is to minimize the joint cost of connection and the total waiting time of all requests. We present an O(m)-competitive deterministic algorithm for this problem, improving on an existing bound of O(m^(log(5.5))) = O(m^2.46). Our algorithm also solves (with the same competitive ratio) a bipartite variant of MPMD, where requests are either positive or negative and only requests with different polarities may be matched with each other. Unlike the existing randomized solutions, our approach does not depend on the size of the metric space and does not have to know it in advance.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Consider a gaming platform that hosts two-player games, such as chess, go or Scrabble, where participants are joining in real time, each wanting to play against another human player. The system matches players according to their known capabilities aiming at minimizing their dissimilarities: any player wants to compete against an opponent with comparable skills. A better match for a player can be found if the platform delays matching decisions as meanwhile more appropriate opponents may join the system. However, an excessive delay may also degrade the quality of experience. Therefore, a matching mechanism that runs on a gaming platform has to balance two conflicting objectives: to minimize the waiting time of any player and to minimize dissimilarities between matched players.

The problem informally described above, called Min-cost Perfect Matching with Delays (MPMD), has been recently introduced by Emek et al. . The problem is inherently online111The offline variant of the problem, where all player arrivals are known a priori, can be easily solved in polynomial time.: a matching algorithm for the gaming platform has to react in real time, without knowledge about future requests (player arrivals) and make its decision irrevocably: once two requests (players) are paired, they remain paired forever.

The MPMD problem was also considered in a bipartite variant, called Min-cost Bipartite Perfect Matching with Delays (MBPMD) introduced by Ashlagi et al. . There requests have polarities: one half of them is positive, and the other half is negative. An algorithm may match only requests of different signs. This setting corresponds to a variety of real-life scenarios, e.g., assigning drivers to passengers on ride-sharing platforms or matching patients to donors in kidney transplants. Similarly to the MPMD problem, there is a trade-off between minimizing the waiting time and finding a better match (a closer driver or a more compatible donor).

### 1.1 Problem Definition

Formally, both in the MPMD and MBPMD problems, there is a metric space  equipped with a distance function , both known in advance to an online algorithm. An online part of the input is a sequence of requests . A request (e.g., a player arrival) is a triple , where is the arrival time of request , is the request location, and is the polarity of the request.

In the bipartite case, half of the requests are positive and for any such request ; the remaining half are negative and there . In the non-bipartite case, requests do not have polarities, but for technical convenience we set for any request .

In applications described above, the function dist measures the dissimilarity of a given pair of requests (e.g., discrepancy between player capabilities in the gaming platform scenario or the physical distance between a driver and a passenger in the ride-sharing platform scenario). For instance, for chess, a player is commonly characterized by her Elo rating (an integer) . In such case, may be simply a set of all integers with the distance between two points defined as the difference of their values.

Requests arrive over time, i.e., . We note that the integer is not known beforehand to an online algorithm. At any time , an online algorithm may match a pair of requests (players) and that

• have already arrived ( and ),

• have not been matched yet,

• satisfy (i.e., have opposite polarities in the bipartite case; in the non-bipartite case, this condition trivially holds for any pair).

The cost incurred by such matching edge is then . That is, it is the sum of the connection cost defined as and the waiting costs of and , defined as and , respectively.

The goal is to eventually match all requests and minimize the total cost of all matching edges. We perform worst-case analysis, assuming that the requests are given by an adversary. To measure the performance of an online algorithm Alg for an input instance , we compare its cost to the cost of an optimal offline solution Opt that knows the entire input sequence in advance. The objective is to minimize the competitive ratio  defined as .

### 1.2 Previous Work

The MPMD problem was introduced by Emek et al. , who presented a randomized -competitive algorithm. There, is the number of points in the metric space and is its aspect ratio (the ratio between the largest and the smallest distance in ). The competitive ratio was subsequently improved by Azar et al.  to . They also showed that the competitive ratio of any randomized algorithm is at least . The currently best lower bound of for randomized solutions was given by Ashlagi et al. .

Ashlagi et al.  adapted the algorithm of Azar et al.  to the bipartite setting and obtained a randomized -competitive algorithm for this variant. The currently best lower bound of for this variant was also given in .

Both lower bounds use requests. Therefore, they imply that no randomized algorithm can achieve a competitive ratio lower than in the non-bipartite case and lower than in the bipartite one. (Recall that is the number of requests in the input.)

The status of the achievable performance of deterministic solutions is far from being resolved. No better lower bounds than the ones used for randomized settings are known for deterministic algorithms. The first solution that worked for general metric spaces was given by Bienkowski et al. and achieved an embarrassingly high competitive ratio of  . Roughly speaking, their algorithm is based on growing spheres around not-yet-paired requests. Each sphere is created upon a request arrival, grows with time, and when two spheres touch, the corresponding requests become matched.

Concurrently and independently of our current paper, Azar and Jacob-Fanani  improved the deterministic ratio to , where is a parameter of their algorithm. When is small enough, this ratio becomes . Their approach is similar to that of , but they grow spheres in a smarter way: slower than time progresses and only in the negative direction of time axis.

Better deterministic algorithms are known only for simple spaces: Azar et al.  gave an -competitive algorithm for trees and Emek et al.  constructed a -competitive deterministic solution for two-point metrics (the latter competitive ratio is best possible).

### 1.3 Our Contribution

In this paper, we focus on deterministic solutions for both the MPMD and MBPMD problems, i.e., for both the non-bipartite and the bipartite variants of the problem. We present a simple -competitive LP-based algorithm that works in both settings.

In contrast to the previous randomized solutions to these problems [2, 4, 20], and similarly to other deterministic solutions [6, 12], we do not need the metric space to be finite and known in advance by an online algorithm. (All previous randomized solutions started by approximating by a random HST (hierarchically separated tree)  or a random HST tree with reduced height .) This approach, which can be performed only in the randomized setting, greatly simplifies the task as the underlying tree metric reveals a lot of structural information about the cuts between points of and hence about the structure of an optimal solution. In the deterministic setting, such information has to be gradually learned as time passes. For our algorithm, we require only that, together with any request , it learns the distances from to all previous requests.

In contrast to the previous deterministic algorithms [6, 12], we base our algorithm on the moat-growing framework, developed originally for (offline) constrained connectivity problems (e.g., for Steiner problems) by Goemans and Williamson . Glossing over a lot of details, in this framework, one writes a primal linear relaxation of the problem and its dual. The primal program has a constraint (connectivity requirement) for any subset of requests and the dual program has a variable for any such subset. The algorithm maintains a family of active sets, which are initially singletons. In the runtime, dual variables are increased simultaneously, till some dual constraint (corresponding to a pair of requests) becomes tight: in such case an algorithm connects such pair and merges the corresponding sets. At the end, an algorithm usually performs pruning by removing redundant edges.

When one tries to adapt the moat-growing framework to online setting, the main difficulty stems from the irrevocability of the pairing decision: the pruning operation performed at the end is no longer an option. Another difficulty is that an algorithm has to combine the concept of actual time that passes in an online instance with the virtual time that dictates the growth of dual variables. In particular, dual variables may only start to grow once an online algorithm learns about the request and not from the very beginning as they would do in the offline setting. Finally, requests appear online, and hence both primal and dual programs evolve in time. For instance, this means that for badly defined algorithms, appearing dual constraints may be violated already once they are introduced.

We note that (the number of requests) is incomparable with (the number of different points in the metric space ) and their relation depends on the application. Our algorithm is better suited for applications, where is infinite or virtually infinite (e.g., it corresponds to an Euclidean plane or a city map for ride-sharing platforms 

) or very large (e.g., for some real-time online games, where player capabilities are represented as multi-dimensional vectors describing their rank, reflex, offensive and defensive skills, etc.

).

### 1.4 Alternative Deterministic Approaches (That Fail)

A few standard deterministic approaches fail when applied to the MPMD and MBPMD problems. One such attempt is the doubling technique (see, e.g., ): an online algorithm may trace the cost of an optimal solution Opt and perform a global operation (e.g., match many pending requests) once the cost of Opt increases significantly (e.g., by a factor of two) since the last time when such global operation was performed. This approach does not seem to be feasible here as the total cost of Opt may decrease when new requests appear.

Another attempt is to observe that the randomized algorithm by Azar et al.  is a deterministic algorithm run on a random tree that approximates the original metric space. One may try to replace a random tree by a deterministically generated tree that spans requested points of the metric space. Such spanning tree can be computed by the standard greedy routine for the online Steiner tree problem . However, it turns out that the competitive ratio of the resulting algorithm is . (The main reason is that the adversary may give an initial subsequence that forces the algorithm to create a spanning tree with the worst-case stretch of and such initial subsequence can be served by Opt with a negligible cost. The details are given in Appendix B.)

### 1.5 Related Work

Originally, online metric matching problems have been studied in variants where delaying decisions was not permitted. In this variant, requests with positive polarities are given at the beginning to an algorithm. Afterwards, requests with negative polarities are presented one by one to an algorithm and they have to be matched immediately to existing positive requests. The goal is to minimize the weight of a perfect matching created by the algorithm. For general metric spaces, the best deterministic algorithms achieve the optimal competitive ratio of  [27, 30, 36] and the best randomized solution is -competitive [7, 34]. Better bounds are known for line metrics [1, 23, 25, 31]: here the best deterministic algorithm is -competitive  and the best randomized one achieves the ratio of  .

Another strand of research concerning online matching problems arose around a non-metric setting where points with different polarities are connected by graph edges and the goal is to maximize the cardinality or the weight of the produced matching. For a comprehensive overview of these type of problems we refer the reader to a recent survey by Mehta .

The M(B)PMD problem is an instance in a broader category of problems, where an online algorithm may delay its decisions, but such delays come with a certain cost. Similar trade-offs were employed in other areas of online analysis: in aggregating orders in supply-chain management [9, 10, 11, 15, 16], aggregating messages in computer networks [18, 28, 29], or recently for server problems [5, 13].

## 2 Primal-Dual Formulation

We start with introducing a linear program that allows us to lower-bound the cost of an optimal solution. To this end, fix an instance

of M(B)PMD. Let be the set of all requests. We call any unordered pair of different requests in an edge; let be the set of all edges that correspond to potential matching pairs, i.e., the set of all edges in the non-bipartite case, and the edges that connect requests of opposite polarities in the bipartite variant. For each set , by  we denote the set of all edges from crossing the boundary of , i.e., having exactly one endpoint in .

For any set , we define (surplus of set ) as the number of unmatched requests in a maximum cardinality matching of requests within set .

• In the non-bipartite variant (MPMD), we are allowed to match any two requests. Hence, if is of even size, then . Otherwise, as in any maximum cardinality matching of requests within exactly one request remains unmatched.

• In the bipartite variant (MBPMD), we can always match two requests of different polarities. Hence, the surplus of a set is the discrepancy between the number of positive and negative requests inside , i.e., .

To describe a matching, we use the following notation. For each edge

, we introduce a binary variable

, such that if and only if is a matching edge. For any set and any feasible matching (in particular the optimal one), it holds that .

Fix an optimal solution Opt for . If a pair of requests is matched by Opt, it is matched as soon as both and arrive, and hence the cost of matching with in the solution of Opt is equal to . This, together with the preceding observations, motivates the following linear program :

 minimize ∑e∈Eopt-cost(e)⋅xe subject to ∑e∈δ(S)xe≥sur(S) ∀S⊆V xe≥0 ∀e∈E.

As any matching is a feasible solution to , the cost of the optimal solution of lower-bounds the cost of the optimal solution for instance of M(B)PMD. Note that there might exist a feasible integral solution of that does not correspond to any matching. To exclude all such solutions, we could add constraints for all singleton sets . The resulting linear program would then exactly describe the matching problem (cf. Chapter 25 of ). However, our main concern is not , but its dual and its current shape is sufficient for our purposes. The program , dual to , is then

 maximize ∑S⊆Vsur(S)⋅yS subject to ∑S:e∈δ(S)yS≤opt-cost(e) ∀e∈E yS≥0 ∀S⊆V.

Note that in any solution, the dual variables corresponding to sets for which , can be set to without changing feasibility or objective value.

The following lemma is an immediate consequence of weak duality.

Fix any instance of the M(B)PMD problem. Let be the value of any optimal solution of and be the value of any feasible solution of . Then .

###### Proof.

Let and be the values of optimal solutions for and , respectively. Since any matching is a feasible solution for , . Hence, . ∎

Lemma 2 motivates the following approach: We construct an online algorithm Greedy Dual (GD), which, along with its own solution, maintains a feasible solution for corresponding to the already seen part of the input instance. This feasible dual solution not only yields a lower bound on the cost of the optimal matching, but also plays a crucial role in deciding which pair of requests should be matched.

Note that since the requests arrive in an online manner, evolves in time. When a request arrives, the number of subsets of increases (more precisely, it doubles), and hence more dual variables are introduced. Moreover, the newly arrived request creates an edge with every existing request and the corresponding dual constraints are introduced. Therefore, showing the feasibility of the created dual solution is not immediate; we deal with this issue in Section 4.

## 3 Algorithm Greedy Dual

The high-level idea of our algorithm is as follows: Greedy Dual (GD) resembles moat-growing algorithms for solving constrained forest problems . During its runtime, GD partitions all the requests that have already arrived into active sets.222A reader familiar with the moat-growing algorithm may think that active sets are moats. However, not all of them are growing in time. If an active set contains any free requests, we call this set growing, and non-growing otherwise. At any time, for each active growing set , the algorithm increases continuously its dual variable until a constraint in corresponding to some edge becomes tight. When it happens, GD makes both active sets (containing and , respectively) inactive, and the set being their union active. In addition, if this happened due to two growing sets, GD matches as many pairs of free requests in these sets as possible: in the non-bipartite variant GD matches exactly one pair of free requests, while in the bipartite variant, GD matches free requests of different polarities until all remaining free requests have the same sign.

### 3.1 Algorithm Description

More precisely, at any time, GD partitions all requests that arrived until that time into active sets. It maintains mapping , which assigns an active set to each such request. An active set , whose all requests are matched is called non-growing. Conversely, an active set is called growing if it contains at least one free request. GD ensures that the number of free requests in an active set is always equal to . We denote the set of free requests in an active set by ; if is non-growing, then .

When a request arrives, the singleton becomes a new active and growing set, i.e., . The dual variables of all active growing sets are increased continuously with the same rate in which time passes. This increase takes place until a dual constraint between two active sets becomes tight, i.e., until there exists at least one edge , such that

 A(u)≠A(v) and ∑S:e∈δ(S)yS=opt-cost(e). (1)

In such case, while there exists an edge satisfying (1), GD processes such edge in the following way. First, it merges active sets and . By merging we mean that the mapping is adjusted to the new active set for each request of . Old active sets and become inactive.333Note that inactive is not the opposite of being active, but means that the set was active previously: some sets are never active or inactive. Second, as long as there is a pair of free requests that can be matched with each other, GD matches them.

In the non-bipartite variant, GD matches at most one pair as each active set contains at most one free request. In the bipartite variant, GD matches pairs of free requests until all unmatched requests in (possibly zero) have the same polarity. Observe that in either case, the number of free requests after merge is equal to . Finally, GD marks edge . Marked edges are used in the analysis, to find a proper charging of the connection cost to the cost of the produced solution for . The pseudocode of GD is given in Algorithm 1 and an example execution that shows a partition of requests into active sets is given in Figure 1. Figure 1: A partition of requests into active sets created by GD. Different polarities of requests are represented by discs and squares. Free requests are depicted as empty discs and squares, matched requests by filled ones. Active growing sets have bold boundaries and each of them contains at least one free request. Active non-growing sets contain only matched requests. Dashed lines represent marked edges and solid curvy lines represent matching edges. Dashed gray sets are already inactive; the inactive singleton sets have been omitted.

### 3.2 Greedy Dual Properties

It is instructive to trace how the set changes in time for a request . At the beginning, when arrives, is just the singleton set . Then, the set  is merged at least once with another active set. If is merged with a non-growing set, the number of requests in increases, but its surplus remains intact. After is merged with a growing set, some requests inside the new may become matched. It is possible that, in effect, the surplus of the new set is zero, in which case the new set is non-growing. (In the non-bipartite variant, this is always the case when two growing sets merge.) After becomes non-growing, another growing set may be merged with , and so on. Thus, the set can change its state from growing to non-growing (and back) multiple times.

The next observation summarizes the process described above, listing properties of GD that we use later in our proofs.

###### Observation .

The following properties hold during the runtime of GD.

1. For a request , when time passes, refers to different active sets that contain .

2. At any time, every request is contained in exactly one active set. If this request is free, then the active set is growing.

3. At any time, an active set contains exactly free requests.

4. Active and inactive sets together constitute a laminar family of sets.

5. For any two requests and , once becomes equal to , they will be equal forever.

## 4 Correctness

We now prove that Greedy Dual is defined properly. In other words, we show that the dual values maintained by GD always form a feasible solution of (Lemma 4) and GD returns a feasible matching of all requests at the end (Lemma 4). From now on, we denote the values of a dual variable at time by .

By the definition, the waiting cost of a request is the time difference between the time it arrives and the time it is matched. In the following lemma, we relate the waiting cost of a request to the dual variables for the active sets it belongs to.

Fix any request . For any time , it holds that

 ∑S:u∈SyS(τ)≤τ−atime(u).

The relation holds with equality if is free at time .

###### Proof.

We show that the inequality is preserved as time passes. At time , request is introduced and sets containing appear. Their values are initialized to . Therefore, at that time, as desired.

Whenever a merging event or an arrival of any other requests occur, new variables may appear in the sum , but, at these times, the values of these variables are equal to zero, and therefore do not change the sum value.

It remains to analyze the case when time passes infinitesimally by and no event occurs within this period. It is sufficient to argue that the sum increases exactly by if is free at and at most by otherwise. Recall that may grow only if is an active growing set. By Property 2 of Observation 3.2, the only active set containing is . This set is growing if is free (and then increases exactly by ) and may be growing or non-growing if is matched (and then increases at most by ). ∎

The following lemma shows that throughout its runtime, GD maintains a feasible dual solution.

At any time, the values maintained by the algorithm constitute a feasible solution to .

###### Proof.

We show that no dual constraint is ever violated during the execution of GD.

When a new request arrives at time , new sets containing appear and the dual variables corresponding to these sets are initialized to .

Each already existing constraint, corresponding to an edge not incident to , is modified: new variables for sets containing both and exactly one of endpoints of appear in the sum. However, all these variables are zero, and hence the feasibility of such constraints is preserved.

Moreover, for any edge where is an existing request, a new dual constraint for this edge appears in . We show that it is not violated, i.e., . As discussed before, for the sets containing . Therefore,

 ∑S:e∈δ(S)yS(τ) =∑S:v∈S∧u∉SyS(τ)+∑S:u∈S∧v∉SyS(τ) =∑S:v∈S∧u∉SyS(τ)≤∑S:v∈SyS(τ) ≤atime(u)−atime(v) (by Lemma 4) ≤opt-cost(e).

Now, we prove that once a dual constraint for an edge becomes tight, the involved values are no longer increased. According to the algorithm definition, and  become merged together. By Property 5 of Observation 3.2

, from this moment on, any active set

contains either both and  or neither of them. Hence, there is no active set , such that , and in particular there is no such active growing set. Therefore, the value of remains unchanged, and hence the dual constraint corresponding to edge remains tight and not violated. ∎

Finally, we prove that GD returns a proper matching. We need to show that if a pair of requests remains unmatched, then appropriate dual variables increase and they will eventually trigger the matching event.

For any input for the M(B)PMD problem, GD returns a feasible matching.

###### Proof.

Suppose for a contradiction that GD does not match some request . Then, by Property 2 of Observation3.2, is always an active growing set and by Property 3, . Therefore, the corresponding dual variable always increases during the execution of GD and appears in the objective function of with a positive coefficient. By Lemma 4, the solution of maintained by GD is always feasible, and hence the optimal value of would be unbounded. This would be a contradiction, as there exists a finite solution to the primal program (as all distances in the metric space are finite). ∎

## 5 Cost Analysis

In this section, we show how to relate the cost of the matching returned by Greedy Dual to the value of the produced dual solution. First, we show that the total waiting cost of the algorithm is equal to the value of the dual solution. Afterwards, we bound the connection cost of GD by times the dual solution, where is the number of requests in the input. This, along with Lemma 2, yields the competitive ratio of .

### 5.1 Waiting Cost

In the proof below, we link the generated waiting cost with the growth of appropriate dual variables. To this end, suppose that a set is an active set for time period of length . By Property 3 of Observation 3.2, contains exactly free points, and thus the waiting cost incurred within this time by requests in is . Moreover, in the same time interval, the dual variable increases by , which contributes the same amount, , to the growth of the objective function of . The following lemma formalizes this observation and applies it to all active sets considered by GD in its runtime.

The total waiting cost of GD is equal to , where is the time when GD matches the last request.

###### Proof.

We define as the family of sets that are active and growing at time . By Property 2 and Property 3 of Observation 3.2, the number of free requests at time , henceforth denoted , is then equal to . The total waiting cost at time can be then expressed as

 ∫T0wait(τ)dτ =∫T0∑Ssur(S)⋅1[S∈G(τ)]dτ =∑Ssur(S)∫T01[S∈G(τ)]dτ=∑Ssur(S)⋅yS(T),

where the last equality holds as at any time, GD increases value if and only if is active and growing. ∎

### 5.2 Connection Cost

Below, we relate the connection cost of GD to the value of the final solution of , created by GD. We focus on the set of marked edges, which are created by GD in Line 12 of Algorithm 1. We show that for any time, the set of marked edges restricted to an active or an inactive set  forms a “spanning tree” of requests of . That is, there is a unique path of marked edges between any two requests from . (Note that this path projected to the metric space may contain cycles as two requests may be given at the same point of .) We start with a helper observation.

###### Observation .

Fix any set . If is active at time , then its boundary does not contain any marked edge at time .

###### Proof.

After an edge becomes marked, both and belong to newly created active set. From now on, by Property 5 of Observation 3.2, they remain in the same active set till the end of the execution. Therefore, this edge will never be contained in a boundary of an active set. ∎

At any time, for any active or inactive set , the subset of all marked edges with both endpoints in forms a spanning tree of all requests from .

###### Proof.

We show that the property holds at time passes. When a new request arrives, a new active growing set containing only one request is created. This set is trivially spanned by an empty set of marked edges.

By the definition of GD, a new active set appears when a dual constraint for some edge becomes tight. Right before it happens, the active sets containing and are and , respectively. At that time, marked edges form spanning trees of sets and and, by Observation 5.2, there are no marked edges between these two sets. Hence, these spanning trees together with the newly marked edge constitute a spanning tree of the requests of . Finally, a set may become inactive only if it was active before, and GD never adds any marked edge inside an already existing active or inactive set. ∎

Using the lemma above, we are ready to bound the connection cost of one matching edge by the cost of the solution of .

The connection cost of any matching edge is at most , where is the time when GD matches the last request.

###### Proof.

Fix a matching edge created by GD at time . Its connection cost is the distance between the points corresponding to requests and in the underlying metric space.

We consider the state of GD right after it matches with . By Lemma 5.2, the active set containing and is spanned by a tree of marked edges. Let be the (unique) path in this tree connecting with . Using the triangle inequality, we can bound by the length of projected onto the underlying metric space.

Recall that for any edge , it holds that . Moreover, if is marked, the dual constraint for edge holds with equality, that is, . Therefore,

 dist(pos(u),pos(v)) ≤∑(w,w′)∈Pdist(pos(w),pos(w′))≤∑e∈Popt-cost(e) =∑e∈P∑S:e∈δ(S)yS(τ)=∑S|δ(S)∩P|⋅yS(τ) ≤∑S|δ(S)∩P|⋅sur(S)⋅yS(τ) ≤∑S|δ(S)∩P|⋅sur(S)⋅yS(T).

The penultimate inequality holds because a dual variable can be positive only if . It is now sufficient to prove that for each (active or inactive) set , it holds that , i.e., the path crosses each such set at most twice.

For a contradiction, suppose that there exists an (active or inactive) set , whose boundary is crossed by path more than twice. We direct all edges on  towards (we follow starting from request and move towards ). Note that may be inside or outside of . Let be the first edge on such that and , i.e., the first time when path leaves . Let be the first edge after , such that and , that is, the first time when path returns to after leaving it with edge . Edge must exist as we assumed that crosses the boundary of at least three times.

By Lemma 5.2, a subset of the marked edges constitutes a spanning tree of . Hence, there exists a path of marked edges contained entirely in that connects requests and . Furthermore, a sub-path of connects and outside of . These two paths together with edges and form a cycle of marked edges. However, by Lemma 5.2 and Observation 5.2, at any time, the set of marked edges forms a forest, which is a contradiction. ∎

### 5.3 Bounding the Competitive Ratio

Using above results we are able to bound the cost of Greedy Dual.

Greedy Dual is -competitive for the M(B)PMD problem.

###### Proof.

Fix any input instance and let be the corresponding dual program. Let be the cost of the solution to output by GD. By Lemma 5.1, the total waiting cost of the algorithm is bounded by and by Lemma 5.2, the connection cost of a single edge in the matching is bounded by . Therefore,

 \textscGD(I)≤D+m⋅2D=(2m+1)⋅D≤(2m+1)⋅\textscOpt(I),

where the first inequality holds as there are exactly matched edges and the last equality follows by Lemma 2. ∎

## References

•  Antonios Antoniadis, Neal Barcelo, Michael Nugent, Kirk Pruhs, and Michele Scquizzato. A o(n)-competitive deterministic algorithm for online matching on a line. In Proc. 12th Workshop on Approximation and Online Algorithms (WAOA), pages 11–22, 2014.
•  Itai Ashlagi, Yossi Azar, Moses Charikar, Ashish Chiplunkar, Ofir Geri, Haim Kaplan, Rahul M. Makhijani, Yuyi Wang, and Roger Wattenhofer. Min-cost bipartite perfect matching with delays. In

Proc. 20th Int. Workshop on Approximation Algorithms for Combinatorial Optimization (APPROX)

, pages 1:1–1:20, 2017.
•  Tetske Avontuur, Pieter Spronck, and Menno van Zaanen. Player skill modeling in Starcraft II. In

Proc. 9th AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment, AIIDE-13

, 2013.
•  Yossi Azar, Ashish Chiplunkar, and Haim Kaplan. Polylogarithmic bounds on the competitiveness of min-cost perfect matching with delays. In Proc. 28th ACM-SIAM Symp. on Discrete Algorithms (SODA), pages 1051–1061, 2017.
•  Yossi Azar, Arun Ganesh, Rong Ge, and Debmalya Panigrahi. Online service with delay. In Proc. 49th ACM Symp. on Theory of Computing (STOC), pages 551–563, 2017.
•  Yossi Azar and Amit Jacob-Fanani. Deterministic min-cost matching with delays. In Proc. 16th Workshop on Approximation and Online Algorithms (WAOA), 2018. To appear.
•  Nikhil Bansal, Niv Buchbinder, Anupam Gupta, and Joseph Naor. A randomized -competitive algorithm for metric bipartite matching. Algorithmica, 68(2):390–403, 2014.
•  Nikhil Bansal, Niv Buchbinder, Aleksander Madry, and Joseph Naor. A polylogarithmic-competitive algorithm for the k-server problem. Journal of the ACM, 62(5):40:1–40:49, 2015.
•  Marcin Bienkowski, Martin Böhm, Jaroslaw Byrka, Marek Chrobak, Christoph Dürr, Lukáš Folwarczný, Łukasz Jeż, Jiří Sgall, Nguyen Kim Thang, and Pavel Veselý. Online algorithms for multi-level aggregation. In Proc. 24th European Symp. on Algorithms (ESA), pages 12:1–12:17, 2016.
•  Marcin Bienkowski, Jaroslaw Byrka, Marek Chrobak, Łukasz Jeż, Dorian Nogneng, and Jirí Sgall. Better approximation bounds for the joint replenishment problem. In Proc. 25th ACM-SIAM Symp. on Discrete Algorithms (SODA), pages 42–54, 2014.
•  Marcin Bienkowski, Jaroslaw Byrka, Marek Chrobak, Łukasz Jeż, Jiři Sgall, and Grzegorz Stachowiak. Online control message aggregation in chain networks. In Proc. 13th Int. Workshop on Algorithms and Data Structures (WADS), pages 133–145, 2013.
•  Marcin Bienkowski, Artur Kraska, and Paweł Schmidt. A match in time saves nine: Deterministic online matching with delays. In Proc. 15th Workshop on Approximation and Online Algorithms (WAOA), pages 132–146, 2017.
•  Marcin Bienkowski, Artur Kraska, and Paweł Schmidt. Online service with delay on a line. In Proc. 25th Int. Colloq. on Structural Information and Communication Complexity (SIROCCO), 2018. To appear.
•  Allan Borodin and Ran El-Yaniv. Online Computation and Competitive Analysis. Cambridge University Press, 1998.
•  Niv Buchbinder, Moran Feldman, Joseph (Seffi) Naor, and Ohad Talmon. O(depth)-competitive algorithm for online multi-level aggregation. In Proc. 28th ACM-SIAM Symp. on Discrete Algorithms (SODA), pages 1235–1244, 2017.
•  Niv Buchbinder, Tracy Kimbrel, Retsef Levi, Konstantin Makarychev, and Maxim Sviridenko. Online make-to-order joint replenishment model: primal dual competitive algorithms. In Proc. 19th ACM-SIAM Symp. on Discrete Algorithms (SODA), pages 952–961, 2008.
•  Marek Chrobak and Claire Kenyon-Mathieu. Competitiveness via doubling. SIGACT News, 37(4):115–126, 2006.
•  Daniel R. Dooly, Sally A. Goldman, and Stephen D. Scott. On-line analysis of the TCP acknowledgment delay problem. Journal of the ACM, 48(2):243–273, 2001.
•  Arpad E. Elo. The rating of chessplayers, past and present. Arco Publishing, 1978.
•  Yuval Emek, Shay Kutten, and Roger Wattenhofer. Online matching: haste makes waste! In Proc. 48th ACM Symp. on Theory of Computing (STOC), pages 333–344, 2016.
•  Yuval Emek, Yaacov Shapiro, and Yuyi Wang. Minimum cost perfect matching with delays for two sources. In Proc. 10th Int. Conf. on Algorithms and Complexity (CIAC), pages 209–221, 2017.
•  Jittat Fakcharoenphol, Satish Rao, and Kunal Talwar. A tight bound on approximating arbitrary metrics by tree metrics. Journal of Computer and System Sciences, 69(3):485–497, 2004.
•  Bernhard Fuchs, Winfried Hochstättler, and Walter Kern. Online matching on a line. Theoretical Computer Science, 332(1–3):251–264, 2005.
•  Michel X. Goemans and David P. Williamson. A general approximation technique for constrained forest problems. SIAM Journal on Computing, 24(2):296–317, 1995.
•  Anupam Gupta and Kevin Lewi. The online metric matching problem for doubling metrics. In Proc. 39th Int. Colloq. on Automata, Languages and Programming (ICALP), pages 424–435, 2012.
•  Makoto Imase and Bernard M. Waxman. Dynamic Steiner tree problem. SIAM Journal on Discrete Mathematics, 4(3):369–384, 1991.
•  Bala Kalyanasundaram and Kirk Pruhs. Online weighted matching. Journal of Algorithms, 14(3):478–488, 1993.
•  Anna R. Karlin, Claire Kenyon, and Dana Randall. Dynamic TCP acknowledgement and other stories about e/(e - 1). Algorithmica, 36(3):209–224, 2003.
•  Sanjeev Khanna, Joseph Naor, and Danny Raz. Control message aggregation in group communication protocols. In Proc. 29th Int. Colloq. on Automata, Languages and Programming (ICALP), pages 135–146, 2002.
•  Samir Khuller, Stephen G. Mitchell, and Vijay V. Vazirani. On-line algorithms for weighted bipartite matching and stable marriages. Theoretical Computer Science, 127(2):255–267, 1994.
•  Elias Koutsoupias and Akash Nanavati. The online matching problem on a line. In Proc. 1st Workshop on Approximation and Online Algorithms (WAOA), pages 179–191, 2003.
•  Meghna Lowalekar, Pradeep Varakantham, and Patrick Jaillet. Online spatio-temporal matching in stochastic and dynamic domains. In Proc. 30th AAAI Conference on Artificial Intelligence, pages 3271–3277, 2016.
•  Aranyak Mehta. Online matching and ad allocation. Foundations and Trends in Theoretical Computer Science, 8(4):265–368, 2013.
•  Adam Meyerson, Akash Nanavati, and Laura J. Poplawski. Randomized online algorithms for minimum metric bipartite matching. In Proc. 7th ACM-SIAM Symp. on Discrete Algorithms (SODA), pages 954–959, 2006.
•  Krati Nayyar and Sharath Raghvendra. An input sensitive online algorithm for the metric bipartite matching problem. In Proc. 58th IEEE Symp. on Foundations of Computer Science (FOCS), pages 505–515, 2017.
•  Sharath Raghvendra. A robust and optimal online algorithm for minimum metric bipartite matching. In Proc. 19th Int. Workshop on Approximation Algorithms for Combinatorial Optimization (APPROX), pages 18:1–18:16, 2016.
•  Alexander Schrijver. Combinatorial Optimization: Polyhedra and Efficiency. Algorithms and combinatorics. Springer, 2003.

## Appendix A Tightness of the Analysis

We can show that our analysis of Greedy Dual is asymptotically tight, i.e., the competitive ratio of Greedy Dual is .

Both for MPMD and MBPMD problems, there exists an instance , such that .

###### Proof.

Let be an even integer and . Let be the metric containing two points and at distance .

In the instance , requests are released at both points and at times . For the MBPMD problem, we additionally specify request polarities: at

, all odd-numbered requests are positive and all even-numbered are negative, while requests issued at

have exactly opposite polarities from those at .

Regardless of the variant (bipartite or non-bipartite) we solve, GD matches the first pair of requests at time , when their active growing sets are merged, forming a new active non-growing set. Every subsequent pair of requests appears exactly after the previous pair becomes matched. Therefore, they are matched together after their arrival, when their growing sets are merged with the large non-growing set containing all the previous pairs of requests. Hence, the total connection cost of GD is equal to . On the other hand, observe that the total cost of a solution that matches consecutive requests at each point of the metric space separately is equal to . ∎

## Appendix B Derandomization Using a Spanning Tree

In this part, we analyze an algorithm that approximates the metric space by a greedily and deterministically chosen spanning tree of requested points and employs the deterministic algorithm for trees of Azar et al. . We show that such algorithm has the competitive ratio of . For simplicity, we focus on the non-bipartite variant, but the lower bound can be easily extended to the bipartite case.

More precisely, we define a natural algorithm Tree Based (TB). TB internally maintains a spanning tree of metric space points corresponding to already seen requests. That is, whenever TB receives a request at point , it executes the following two steps.

1. If there was no previous request at , TB adds to , connecting it to the closest point from . The addition is performed immediately, at the request arrival. This part essentially mimics the behavior of the greedy algorithm for the online Steiner tree problem .

2. To serve the request , TB runs the deterministic algorithm of  on the tree .444The algorithm must be able to operate on a tree that may be extended (new leaves may appear) in the runtime. The algorithm given by Azar et al.  has this property.

The competitive ratio of Tree Based is .

###### Proof.

The idea of the lower bound is as follows. The adversary first gives requests that force TB to create a tree with the stretch of and then gives another requests, so that the initial requests can be served with a negligible cost by Opt. Afterwards, the adversary consecutively requests a pair of points that are close in the metric space, but far away in the tree .

Our metric space is a continuous ring and we assume that is an even integer. Let  be the length of this ring and let .

In the first part of the input, the adversary gives requests in the following way. The first two requests are given at time at antipodal points (their distance is ). TB connects them using one of two halves of the ring. From now on, the tree of TB will always cover a contiguous part of the ring. Each of the next requests is given exactly in the middle of the ring part not covered by . For , the -th request is given at time .

This way, the ring part not covered by shrinks exponentially, and after initial requests its length is equal to . Let and be the endpoints (the only leaves) of . Then, , but the path between and  in  is of length and uses an edge of length . As is built as soon as requests appear, its construction is finished right after the appearance of the -th request, i.e., before time .

In the second part of the input, at time , the adversary gives requests at the same points as the requests from the first phase. This way, Opt may serve the first requests paying nothing for the connection cost and paying at most for their waiting cost.

In the third part of the input, the adversary gives pairs of requests, each pair at points and . Each pair is given after the previous one is served by TB. Opt may serve each pair immediately after its arrival, paying for the connection cost. On the other hand, TB serves each such pair using a path that connects and in the tree . Before matching with , TB waits for a time which is at least the length of the longest edge on this path, (see the analysis in ). In total, the cost of TB for the last requests alone is at least , while the total cost of Opt for the whole input is at most . This proves that the competitive ratio of TB is . ∎