Arnaud Cadas
email: arnaud.cadas@inria.fr

Josu Doncel
email: josu.doncel@ehu.eus

Ana Bušić
email: ana.busic@inria.fr

Optimal Control of Dynamic Bipartite Matching Models

Keywords: Dynamic matching models, Markov decision processes, Optimal control

A dynamic bipartite matching model is given by a bipartite matching graph which determines the possible matchings between the various types of supply and demand items. Both supply and demand items arrive to the system according to a stochastic process. Matched pairs leave the system and the others wait in the queues, which induces a holding cost. We model this problem as a Markov Decision Process and study the discounted cost and the average cost problem. We fully characterize the optimal matching policy for complete matching graphs and for the N -shaped matching graph. In the former case, the optimal policy consists of matching everything and, in the latter case, it prioritizes the matchings in the extreme edges and is of threshold type for the diagonal edge. In addition, for the average cost problem, we compute the optimal threshold value. For more general graphs, we need to consider some assumptions on the cost of the nodes. For complete graphs minus one edge, we provide conditions on the cost of the nodes such that the optimal policy of the N -shaped matching graph extends to this case. For acyclic graphs, we show that, when the cost of the extreme edges is large, the optimal matching policy prioritizes the matchings in the extreme edges. We also study the W -shaped matching graph and, using simulations, we show that there are cases where it is not optimal to prioritize to matchings in the extreme edges.

Introduction

The theory of matching started with Petersen and König and was under a lot of interests in graph theory with problems like maximum matchings. It was extended to online matching setting [START_REF] Manshadi | Online stochastic matching: Online actions based on offline statistics[END_REF][START_REF] Feldman | Online stochastic matching: Beating 1-1/e[END_REF][START_REF] Jaillet | Online stochastic matching: New algorithms with better bounds[END_REF] where one population is static and the other arrives according to a stochastic process. In the recent years, fully dynamic matching models have been considered where the whole population is random. The importance of matching models was shown through applications in many fields: health [16,[START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF], ridesharing [START_REF] Banerjee | The Value of State Dependent Control in Ridesharing Systems[END_REF], power grid [START_REF] Zdeborová | Message passing for optimization and control of a power grid: Model of a distribution system with redundancy[END_REF], or pattern recognition [START_REF] Schalkoff | Pattern Recognition: Statistical, Structural and Neural Approaches[END_REF].

We study matching models from a queueing theory perspective, where a supply item and a demand item arrive to the system at each time step and can be matched or stay in buffers. [13, Theorem 1] proves that in a matching model where items arrive one by one, there exists no arrival distribution which verifies the necessary stability conditions for bipartite matching graphs. This result justifies why we assume arrivals by pairs as in [START_REF] Busic | Approximate optimality with bounded regret in dynamic matching models[END_REF][START_REF] Busic | Stability of the bipartite matching model[END_REF]. We consider that there is a holding cost that is a function of the buffer sizes. Our objective is to find the optimal matching policy in the discounted cost problem and in the average cost problem for general bipartite matching graphs. For this purpose, we model this problem as a Markov Decision Process.

The search for good policies and the performance analysis of various matching models have received great interest in the recent literature. For example, the FCFS infinite bipartite matching model was introduced in [START_REF] Caldentey | Fcfs infinite bipartite matching of servers and customers[END_REF] and further studied in [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] that established the reversibility of the dynamics and the product form of stationary distribution. In [START_REF] Busic | Stability of the bipartite matching model[END_REF] the bipartite matching model was extended to other matching policies. In that paper, the authors established the necessary stability conditions and studied the stability region of various policies, including priorities and MaxWeigth. It is shown that MaxWeight has maximal stability region. For ride-sharing systems, state-dependent dispatch policies were identified in [START_REF] Banerjee | The Value of State Dependent Control in Ridesharing Systems[END_REF] which achieved exponential decay of the demanddropping probability in heavy traffic regime. In [START_REF] Gurvich | On the dynamic control of matching queues[END_REF], the authors presented the imbalance process and derived a lower bound on the holding costs.

Optimality results are scarce, and have been derived for some matching models in the asymptotic regimes. An extension of the greedy primal-dual algorithm was developed in [START_REF] Nazari | Reward maximization in general dynamic matching systems[END_REF] and was proved to be asymptotically optimal for the long-term average matching reward. However, they considered rewards on the edges, which differs from our model with holding costs. In [START_REF] Busic | Approximate optimality with bounded regret in dynamic matching models[END_REF], the authors considered the asymptotic heavy-traffic setting, and identified a policy that is approximately optimal with bounded regret using a workload relaxation approach.

In this paper, we study the optimal matching policy of bipartite graphs in the non-asymptotic setting, i.e. we allow for any arrival rates under the stability conditions established in [START_REF] Busic | Stability of the bipartite matching model[END_REF]. We use arguments of structured policies to analyze the optimal matching control and we fully characterize the optimal policy for the following matching models:

-We first consider a matching model that is a complete graph. For this case, we show that the policy that matches all the possible items is optimal. We remark that this result is applied, in particular, to all the bipartite and connected graphs of less than 4 nodes (except for the N -shaped graph). -We then consider the N -shaped graph, which is formed by two supply and two demand classes. For this system, we show that the optimal matching policy is of threshold type for the diagonal edge and with priority to the end edges of the matching graph. We also compute the optimal threshold for the average cost problem. This part of the paper was already published in a conference [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF].

If we aim to extend the optimal matching policy identified in the case N to more general bipartite matching graphs, we require certain assumptions on the cost of the nodes. For instance, in a complete graph minus one node, we provide conditions on the cost of the nodes such that the cost associated to any state coincides with the cost of its projection on the N -shaped graph. As a consequence of this, there is a threshold-type policy that is optimal in a matching model that consists of a complete graph minus one edge. Moreover, we show that, in an arbitrary acyclic graph, if the cost of the extreme nodes is larger or equal than that of their neighbors nodes, the optimal matching policy prioritizes the matchings of the extreme edges. Finally, we explore the W -shaped graph and we differentiate two cases. On one hand, we consider that the cost of the extreme nodes is large, in which case we conjecture that the optimal policy is of threshold type with priority to the extreme edges. We also present the set of properties that are needed to prove our conjecture, how they can be used to show that this policy is optimal and what are the difficulties in their preservation. On the other hand, we consider that the cost of the middle edge is large and, according to our numerical experiments, the matching policy that prioritizes the extreme edges is not optimal.

The remainder of the article is organized as follows. In Section 2, we describe the optimal control problem we investigate in this paper. We characterize the optimal matching policy for complete matching graphs in Section 3 and for N -shaped graphs in Section 4. Then, in Section 5, we consider general matching graphs and, in Section 6, the W -shaped matching graph. We provide the main conclusions of our work in Section 7.

Model Description

We consider a bipartite matching graph (D∪S, E) where D = {d 1 , d 2 , . . . , d n D } and S = {s 1 , s 2 , . . . , s n S } are, respectively, the set of demand nodes (or queues) and the set of supply nodes. E ⊂ D × S is the set of allowed matching pairs. In Figure 1 it is depicted an example of a matching graph with three demand nodes and three supply nodes. In each time slot n, a demand item and a supply item arrive to the system according to the i.i.d. arrival process A(n). We assume independence between demand and supply arrivals. The demand item arrives to the queue d i with probability α i and the supply item arrives to the queue s j with probability β j , i.e:

∀(i, j) ∈ A P(A(n) = e (i,j) ) = α i β j > 0 with n D i=1 α i = 1,
n S j=1 β j = 1 and where A = D × S is the set of allowed arrival pairs, e (i,j) = e di +e sj and e k ∈ N n D +n S is the vector of all zeros except in the k-th coordinate where it is equal to one, k ∈ D ∪ S. We assume that the α i and β j are chosen such that the arrival distribution satisfies the necessary and sufficient conditions for stabilizability of the MDP model: Ncond given in [START_REF] Busic | Stability of the bipartite matching model[END_REF], i.e ∀D D, ∀S S:

di∈D α i < sj ∈S(D) β j and sj ∈S β j < di∈D(S) α i (1)
where D(j) = {i ∈ D : (i, j) ∈ E} is the set of demand classes that can be matched with a class j supply and S(i) = {j ∈ S : (i, j) ∈ E} is the set of supply classes that can be matched with a class i demand. The extension to subsets S ⊂ S and D ⊂ D is D(S) = j∈S D(j) and S(D) = i∈D S(i).

s 1 s 2 s 3 d 1 d 2 d 3 β 1 β 2 β 3 α 1 α 2 α 3
Fig. 1 A matching graph with three supply classes and three demand classes.

We denote by q k (n) the queue length of node k at time slot n, where k ∈ D ∪ S. Let Q(n) = (q k (n)) k∈D∪S be the vector of the queue length of all the nodes and Q = {q ∈ N n D +n S : k∈D q k = k∈S q k be the set of all the possible queues length. We must have q(n) ∈ Q for all n. Matchings at time n are carried out after the arrivals at time n. Hence, Q(n) evolves over time according to the following expression:

Q(n + 1) = Q(n) + A(n) -u(Q(n), A(n)), (2)
where u is a deterministic Markovian decision rule which maps the current state

Y (n) = (Q(n), A(n))
(n) = Q(n) + A(n)
as the vector of the queue length of all the nodes just after the arrivals. In order to ease the notations and because the matchings only depends on the queues length after the arrivals, we will note u(Q(n), A(n)) = u(X(n)) for the reminder of the paper. When the state of the system is Y (n) = (q, a), x = q + a, u(x) must belong to the set of admissible matchings which is defined as:

U x =    u = (i,j)∈E u (i,j) e (i,j) ∈ N n D +n S : (a) ∀i ∈ D, k∈S(i) u (i,k) ≤ x di , (b) ∀j ∈ S, k∈D(j) u (k,j) ≤ x sj   
where u (i,j) is the number of matchings in the edge (i, j). U x is defined for all x ∈ Q. We consider a linear cost function on the buffer size of the nodes:

c(Q(n), A(n)) = c(X(n)) = k∈D∪S c k x k (n).
Our analysis presented in the following sections holds for more general cost functions as long as they satisfy Assumption 1 and the assumptions of Theorem 1 and Theorem 2. We chose a linear cost function because it satisfies these assumptions (see Lemma 1 and Lemma 2 in Section 2.1) and allow us to give an analytical form for the optimal threshold in the N -shaped graph. The buffer size of the nodes is infinite, thus we are in the unbounded costs setting.

A matching policy π is a sequence of deterministic Markovian decision rules, i.e. π = (u(X(n))) n≥1 . The goal is to obtain the optimal matching policy for two optimization problems:

-The average cost problem:

g * = inf π g π with g π (y) = lim N →∞ 1 N N -1 n=0 E π y [c(Y (n))]
-The discounted cost problem:

v * θ = inf π v π θ with v π θ (y) = lim N →∞ N -1 n=0 θ t E π y [c(Y (n))]
where θ ∈ [0, 1) is the discount factor and y ∈ Y = Q × A is the starting state. Both problems admit an optimal stationary policy, i.e. the decision rule depend only on the state of the system and not on the time [START_REF] Puterman | Markov decision processes: discrete stochastic dynamic programming[END_REF]. The notation E π and using the matching policy π to determine the matched items u(X(n)) for all n.

As A(n) are i.i.d., to ease the notation from now on, we denote by A a random variable with the same distribution as A(1). For a given function v, Y (n) = (q, a), x = q + a, u ∈ U x , we define for all 0 ≤ θ ≤ 1:

L θ u v(q, a) = c(q, a) + θE[v(q + a -u, A)] = c(x) + θE[v(x -u, A)] L θ v(q, a) = c(q, a) + min u∈Ux θE[v(q + a -u, A)] = c(x) + min u∈Ux θE[v(x -u, A)]
and in particular, we define T u = L 1 u and T = L 1 . A solution of the discounted cost problem can be obtained as a solution of the Bellman fixed point equation v = L θ v. In the average cost problem, the Bellman equation is given by g * +v = T v.

We say that a value function v or a decision rule u is structured if it satisfies a special property, such as being increasing, decreasing or convex. Throughout the article, by increasing we mean nondecreasing and we will use strictly increasing for increasing. A policy is called structured when it only uses structured decision rules.

The framework of this work is that of property preservation when we apply the Dynamic Programming operator. First, we identify a set of structured value functions V σ and a set of structured deterministic Markovian decision rules D σ such that if the value function belongs to V σ an optimal decision rule belongs to D σ . Then, we show that the properties of V σ are preserved by the Dynamic Programming operator and that they hold in the limit.

Assumption 1

The cost function c is a nonnegative function with the same structured properties as the value function, i.e c ∈ V σ .

Theorem 1 [START_REF] Hyon | Scheduling services in a queuing system with impatience and setup costs[END_REF]Theorem 1] lets us conclude that there exists an optimal policy which can be chosen in the set of structured stationary matching policies

Π σ = {π = (u(X(n))) n≥1 : u ∈ D σ }.
and for every µ, 0 ≤ µ < 1, there exists η, 0 ≤ η < 1 and some integer J such that for every J-tuple of Markov deterministic decision rules π = (u 1 , . . . , u J ) and every y µ J y P π (y |y)w(y ) < ηw(y),

where P π denotes the J-step transition matrix under policy π. Let 0 ≤ θ < 1. Let V w the set of functions in the state space which have a finite w-weighted supremum norm, i.e., sup y |v(y)/w(y)| < +∞. Assume that ( * ) for each v ∈ V w , there exists a deterministic Markov decision rule u such that

L θ v = L θ u v. Let V σ and D σ be such that (a) v ∈ V σ implies that L θ v ∈ V σ ; (b) v ∈ V σ implies that there exists a decision u ∈ D σ such that u ∈ arg min u L θ u v; (c) V σ
is a closed subset of the set of value functions under pointwise convergence.

Then, there exists an optimal stationary policy π * = (u * (X(n))) n≥1 that belongs to Π σ with u * ∈ arg min u L θ u v. This result is an adapted version of [START_REF] Puterman | Markov decision processes: discrete stochastic dynamic programming[END_REF]Theorem 6.11.3]. The former removes the need to verify that V σ ⊂ V w (assumption made in the latter) and its statement separates the structural requirements ((a), (b) and (c)) from the technical requirements related to the unboundedness of the cost function ((3), ( 4), ( 5) and ( * )).

In the case of the average cost problem, we will use the results of the discounted cost problem. We consider the average cost problem as a limit when θ tends to one and we show that the properties still hold for this limit. In order to prove the optimality in the average cost case, we will use [START_REF] Puterman | Markov decision processes: discrete stochastic dynamic programming[END_REF]Theorem 8.11.1]:

Theorem 2 [17, Theorem 8.11.1] Suppose that the following properties hold:

(A1) ∃ C ∈ R, ∀y = (q, a) ∈ Y, x = q + a, -∞ < C ≤ c(x) < +∞, (A2) ∀y ∈ Y, ∀ 0 ≤ θ < 1, v * θ (y) < +∞ (A3) ∃ H ∈ R, ∀y ∈ Y, ∀ 0 ≤ θ < 1, -∞ < H ≤ v * θ (y) -v * θ (0) (A4) There exists a nonnegative function M (y) such that (a) ∀y ∈ Y, M (y) < +∞ (b) ∀y ∈ Y, ∀ 0 ≤ θ < 1, v * θ (y) -v * θ (0) ≤ M (y) (
c) There exists u ∈ U 0 for which y P(y|0, u)M (y) < +∞ Let H and M be defined in Assumptions (A3) and (A4). We define a subset V σ H of V σ which contains all the value functions v ∈ V σ such that

H ≤ v(y) -v(0) ≤ M (y) for all y ∈ Y. Then, if (a) for any sequence (θ n ) n≥0 , 0 ≤ θ n < 1, for which lim n→+∞ θ n = 1, lim n→+∞ [v * θn -v * θn (0)e] ∈ V σ H with e(y) = 1 for all y ∈ Y and (b) v ∈ V σ H implies that there exists a decision u ∈ D σ such that u ∈ arg min u T u v; Then D σ ∩ arg min u T u v = ∅ and u * ∈ D σ ∩ arg min u T u v
implies that the stationary matching policy which uses u * is lim sup average optimal.

Remark 1 When v θ (0) is used in this theorem, we mean v θ (y) with y = (0, a) for any a ∈ A.

Preliminaries

We first show that the technical requirements of Theorem 1 due to the unboundness of the costs are verified when the cost function is linear.

Lemma 1 Assuming that the cost function is linear, the conditions ( (3), ( 4), ( 5) and ( * )) are verified.

Proof We show that the technical details given in (3)-( 5) are verified. Let y = (q, a) ∈ Q × A, x = q + a, we choose w(y) = i x i . In our case, the cost is a linear function of x therefore, c(y)/w(y) ≤ max i∈D∪S c i . This shows (3). In addition,

1 w(y) y P(y |y, u)w(y ) = E w(x -u + a ) w(y) A = a ≤ E w(x + a ) w(y) A = a = i x i + 2 i x i ≤ 2
since w(y) is increasing and two items arrive to the system in each step following a process which is independent of the state of the system. This shows (4). Finally, we can repeat the previous argument to show that for all J-step matching policy π where π 0 = (0, • • • , 0) is the policy which does not match any items. Therefore, (5) is satisfied if there exist J integer and η < 1 such that µ J (w(y) + 2J) ≤ ηw(y) ⇐⇒ η > µ J (w(y) + 2J) w(y) .

Since it is decreasing with J and when J → ∞ it tends to zero, there exists a J integer such that η is less than one and, therefore, (5) is also verified. Since for each state of the system, the set of admissible matching policies is finite, it follows that (*) holds.

From this result, we conclude that, when we study the optimal matching policy in the discounted cost problem with linear costs, we only need to check that conditions (a), (b) and (c) of Theorem 1 are verified.

We now show that Assumptions (A1) to (A4) of Theorem 2 hold when the cost function is a linear function.

Lemma 2 If the cost function is linear, then Assumptions (A1) to (A4) hold.

Proof First, by Assumption 1, we know that the cost function is nonnegative and therefore Assumption (A1) holds using C = 0. Let π M L be the policy Match the Longest as defined in [START_REF] Busic | Stability of the bipartite matching model[END_REF]Definition 2.6]. This policy is stable for any bipartite matching graph as proved in [START_REF] Busic | Stability of the bipartite matching model[END_REF]Theorem 7.1], which means that the derived Markov chain is positive recurrent and g π M L < ∞. Moreover, the set {y ∈ Y : c(y) < g π M L } is nonempty because g π M L > min (i,j)∈A c di + c sj almost surely and c(0, a) = c di + c sj (for any a = e (i,j) ∈ A). It is also finite because g π M L < ∞ and c is increasing in y (because c is linear). Therefore, we can use [START_REF] Puterman | Markov decision processes: discrete stochastic dynamic programming[END_REF]Theorem 8.10.9] and Assumptions (A2) to (A4) hold.

From this result, we conclude that, when we study the optimal matching policy in the average cost problem with linear costs, we only need to check that conditions (a) and (b) of Theorem 2 are verified.

Complete Graphs

We start our study with the smallest bipartite graphs. Immediately, we can see that all bipartite and connected graphs of less than 4 nodes (except the Nshaped graph that will be studied in Section 4) are complete, i.e E = D × S. Without loss of generality, we can focus on the matching graphs such that there are more demand nodes than supply nodes, i.e n D ≥ n S (see Figure 2).

s 1 d 1 1 1 s 1 d 1 d 2 α 1 α 2 1 s 1 d 1 d 2 d 3 α 1 α 2 α 3 1 s 1 s 2 d 1 d 2 β 1 β 2 α 1 α 2
Fig. 2 Every bipartite and connected matching graphs of less than 4 nodes (except the N -shaped matching graph).

For these matching graphs, the stabilizability conditions come down to 0 < α i < 1 for i ∈ {1, 2, 3} and 0 < β j < 1 for j ∈ {1, 2}. The optimal policy is very intuitive. We can empty the system from any state and because we only consider costs on the number of items at each node and not rewards on which edge we match, it does not matter how do we empty the system. However, leaving some items in the system will only increase the total cost in the long run. Thus, we can easily convince ourselves that matching everything is optimal.

Let us now consider the more general case when there are any number of demand nodes and any number of supply nodes, i.e n D ∈ N * and n S ∈ N * . We will show that the optimal policy for the complete matching graph ((D ∪ S, E) with E = D × S) is to match everything. For this purpose, we first present the properties of the value function. Then, we show how these properties characterize the optimal decision rule and how they are preserved by the dynamic programming operator. Finally, we prove the desired results in Theorem 3 and Theorem 4.

Value Function Properties

We define the only property that is needed to prove that matching everything is optimal: Definition 1 (Increasing property) Let (i, j) ∈ E. We say that a function v is increasing in (i, j) or v ∈ I (i,j) if ∀a ∈ A, ∀q ∈ Q, v(q + e (i,j) , a) ≥ v(q, a).

We also note I a = ∪ (i,j)∈E I (i,j) .

We aim to characterize the optimal matching policy using Theorem 1 and Theorem 2. Thus, in the remainder of the article, we will consider the following set of structured value functions V σ = I a .

Optimal decision rule

In this section, we show that, for any v ∈ V σ , there is a control which matches everything and minimizes L θ u v.

Definition 2 (Full decision rule) A decision rule u x is said to be full if it matches everything, i.e x -u x = 0. We define D σ as the set of decision rules that are full.

In the next proposition, we establish that there exists an optimal decision rule which is full.

Proposition 1 Let v ∈ I a , let 0 ≤ θ ≤ 1. For any q ∈ Q and any a ∈ A, x = q + a, there exists u * ∈ U x such that u * ∈ arg min u∈Ux L θ u v(q, a) and x -u * = 0. In particular, this result holds for the average operator: T u .

Proof Let v ∈ I a , 0 ≤ θ ≤ 1, q ∈ Q, a ∈ A, x = q + a and u ∈ U x . We are going to match every items that are left after the matching u.

For i = 1, • • • , n D and for j = 1, • • • , n S ((i, j) ∈ E), let m (i,j) = min(x di - k∈S(i) u i,j-1
(i,k) , x sj -k∈D(j) u i,j-1 (k,j) ) (where u i,0 = u i-1,n S and u 0,n S = u) be the number of possible matchings that can be made in (i, j). We define u i,j that matches all the the possible (i, j) of x -u i,j-1 , that is, of the remaining items when we apply u i,j-1 : u i,j = u i,j-1 + m (i,j) e (i,j) . We also verify that this policy is admissible, i.e u i,j ∈ U x :

u i,j ∈ N n D +n S because u i,j-1 ∈ U x . (a) is true because k∈S(i) u i,j (i,k) = k∈S(i) u i,j-1 (i,k) + m (i,j) ≤ x di . (b) is true because k∈D(j) u i,j (k,j) = k∈D(j) u i,j-1 (k,j) + m (i,j) ≤ x sj .
Then, we can use the fact that v ∈ I (i,j) ⊂ I a to show that L θ u i,j v(q, a) ≤ L θ u i,j-1 v(q, a).

In the end, we get u n D ,n S , that we note as u * , such that L θ u * v(q, a) ≤ L θ u v(q, a) and every edge is emptied, i.e x -u * = 0. Indeed, if for all i ∈ D, there exist j ∈ S such that m (i,j) = x di -k∈S(i) u i,j-1

(i,k) , then u * di = k∈S(i) u * (i,k) = k∈S(i) u i,j (i,k) = k∈S(i) u i,j-1 (i,k) + m (i,j) = x di . Thus, for all i ∈ D, x di -u * di = 0. So i∈D x di -j∈S u * (i,j)
= 0 which is equivalent to j∈S x sj -j∈S i∈D u * (i,j) = 0 (because x ∈ Q), i.e j∈S x sju * sj = 0 which means that for all j ∈ S we have x sj -u * sj = 0 (because x sj -u * sj ≥ 0 as u * ∈ U x ). Otherwise, there exist i ∈ D such that for all j ∈ S, we have

m (i,j) = x sj -k∈D(j) u i,j-1 (k,j) , then u * sj = k∈D(j) u * (k,j) = k∈D(j) u i,j (k,j) = k∈D(j) u i,j-1 (k,j) + m (i,j) = x sj . Thus, for all j ∈ S, x sj - u * sj = 0. So j∈S x sj -i∈D u * (i,j) = 0 which is equivalent to i∈D x di - i∈D j∈S u * (i,j) = 0 (because x ∈ Q), i.e i∈D x di -u * di = 0 which means that for all i ∈ D we have x di -u * di = 0 (because x di -u * di ≥ 0 as u * ∈ U x )
. This was done for any u ∈ U x and because U x is finite for every x ∈ Q, we can choose u such that it belongs to arg min u ∈Ux L θ u v(q, a) giving the final result.

Value Function Property Preservation

In this section, we show that the properties of the value function defined in Section 3.1 are preserved by the dynamic programming operator. In other words, we show that if

v ∈ V σ , then L θ v ∈ V σ . We recall that V σ = I a . Lemma 3 If a function v ∈ I a , then L θ v ∈ I a .
Proof Let q ∈ Q and a ∈ A, x = q + a. Let (i, j) ∈ E, we define q = q + e (i,j) , x = q + a. Since v is increasing with (i, j), we have that v(q, a) ≥ v(q, a). We aim to show that L θ v(q, a) ≥ L θ v(q, a).

Let u x ∈ arg min u∈Ux L θ v(q, a) and u x ∈ arg min u∈Ux L θ v(q, a). Using Proposition 1, we can choose u x such that x -u x = 0 and u x such that x -u x = 0. Hence,

L θ v(q, a) = c(x) + θE[v(x -u x , A)] = c(x) + θE[v(0, A)] ≤ c(x) + θE[v(0, A)] = c(x) + θE[v(x -u x , A)] = L θ v(q, a).
since c ∈ I (i,j) ⊂ I a from Assumption 1. This inequality remains valid for any (i, j) ∈ E, giving us the final result.

Structure of the Optimal Policy

We now present that, using the result of Theorem 1, there exists an optimal matching policy which is formed of a sequence of decision rules that belong to D σ . Theorem 3 The optimal control for the discounted cost problem is to match everything.

Proof We apply Theorem 1 where V σ is the set of functions satisfying Definition 1 and D σ the set defined in Definition 2. ( 3)-( 5) are verified because of Lemma 1.

We now focus on the structural conditions of the theorem. From Lemma 3, it follows (a) since they show that if

v ∈ V σ , then L θ v ∈ V σ . The result of Proposition 1 shows (b) because the policy that belong to D σ minimize L θ u v if v ∈ V σ .
Finally, since limits preserve inequalities, the point-wise convergence of functions of V σ belong to this set, which shows (c).

The following theorem shows that the previous result is also proven for the average cost problem.

Theorem 4

The optimal control for the average cost problem is to match everything.

Proof We want to apply Theorem 2 using the same value function set V σ and the same decision rule set D σ as in the proof of the previous theorem. Assumptions (A1) to (A4) hold because of Lemma 2.

Let (θ n ) n∈N be a sequence such that 0 ≤ θ n < 1 for all n ∈ N and lim n→+∞ θ n = 1. Let n ∈ N. We know that v * θn ∈ V σ (see the proof of Theorem 3). The inequalities in the definitions of the properties used in V σ still hold if we add a constant to v, thus v * θn -v * θn (0)e ∈ V σ . Using Assumption (A3) and Assumption (A4), we have

H ≤ v * θn -v * θn (0)e ≤ M , so v * θn -v * θn (0)e ∈ V σ
H . This last result holds for each n ∈ N and since limits preserve inequalities

V σ H is a closed set, lim n→+∞ [v * θn -v * θn (0)e] ∈ V σ H which shows (a)
. The result of Proposition 1 shows (b) because the policy that belong to

D σ minimize L 1 u v = T u v if v ∈ V σ H ⊂ V σ .

N -shaped graph

The first model where difficulties arise due to the fact that we can not always empty the system is the N -shaped graph. It is formed by two supply nodes and two demand nodes with a N -shaped set of edges (see Figure 3). For this graph, we have

D = {d 1 , d 2 }, S = {s 1 , s 2 } and E = {(1, 1), (1, 2), (2, 2)}.
Let us also define (2, 1) as the imaginary edge between d 2 and s 1 (imaginary because (2, 1) / ∈ E) that we introduce to ease the notations. To ensure stability, we assume that α > β.

s 1 s 2 d 1 d 2 β 1 -β α 1 -α
Fig. 3 The N -shaped matching graph.

We will show that the optimal policy for this case has a specific structure. For this purpose, we first present the properties of the value function. Then, we show how these properties characterize the optimal decision rule and how they are preserved by the dynamic programming operator. Finally, we prove the desired results in Theorem 5 and Theorem 6.

Value Function Properties

We start by using the increasing property in (1, 1) and (2, 2) as defined in Definition 1 that we will note I (1,1) and I (2,2) . We also define an increasing property in the imaginary edge (2, 1) using the same definition as in Definition 1 (even if (2, 1) / ∈ E) that we will note I (2,1) .

Remark 2

The increasing property in (2, 1) can be interpreted as the fact that we prefer to match (1, 1) and (2, 2) rather than to match (1, 2). Indeed,

v(q + e (1,1) + e (2,2) -e (1,2) , a) = v(q + e (2,1) , a) ≥ v(q, a).
We also define the convexity in (1, 2) and (2, 1) as follows:

Definition 3 (Convexity property) A function v is convex in (1, 2) or v ∈ C (1,2) if v(q + e (1,
2) , a) -v(q, a) is increasing in (1, 2), i.e., ∀a ∈ A, ∀q ∈ Q such that q d1 ≥ q s1 , we have

v(q + 2e (1,2) , a) -v(q + e (1,2) , a) ≥ v(q + e (1,2) , a) -v(q, a). Likewise, v is convex in (2, 1) or v ∈ C (2,1) if v(q+e (2,1)
, a)-v(q, a) is increasing in (2, 1), i.e., ∀a ∈ A, ∀q ∈ Q such that q s1 ≥ q d1 , we have v(q + 2e (2,1) , a) -v(q + e (2,1) , a) ≥ v(q + e (2,1) , a) -v(q, a).

Definition 4 (Boundary property)

A function v ∈ B if ∀a ∈ A, v(0, a) -v(e (2,1) , a) ≤ v(e (1,2) , a) -v(0, a).
As we will show in Proposition 3, the properties I (1,1) , I (2,2) , I (2,1) and C (1,2) characterize the optimal decision rule. On the other hand, C (2,1) and B are required to show that C (1,2) is preserved by the operator L θ .

We aim to characterize the optimal matching policy using Theorem 1 and Theorem 2. Thus, in the remainder of the section, we will consider the following set of structured value functions

V σ = I (1,1) ∩ I (2,2) ∩ I (2,1) ∩ C (1,2) ∩ C (2,1) ∩ B. (6)

Optimal decision rule

In this section, we show that, for any v ∈ V σ , there is a control of thresholdtype in (1, 2) with priority to (1, 1) and (2, 2) that minimizes L θ u v.

Definition 5 (Threshold-type decision rule) A decision rule u x is said to be of threshold type in (1, 2) with priority to (1, 1) and (2, 2) if:

1. it matches all of (1, 1) and (2, 2). 2. it matches (1, 2) only if the remaining items (in d 1 and s 2 ) are above a specific threshold, denoted by t (with t ∈ N ∪ ∞).

i.e,

u x = min(x d1 , x s1 )e (1,1) + min(x d2 , x s2 )e (2,2) + k t (x)e (1,2) where k t (x) = 0 if x d1 -x s1 ≤ t x d1 -x s1 -t otherwise .
We define D σ as the set of decision rules that are of threshold type in (1, 2) with priority to (1, 1) and (2, 2) for any t ∈ N ∪ ∞.

Remark 3 If t = ∞, the decision rule will never match [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. Otherwise, the decision rule will match (1, 2) until the remaining items in d 1 and s 2 are below or equal to the threshold t.

In the next proposition, we establish that there exists an optimal decision rule with priority to (1, 1) and (2, 2).

Proposition 2 Let v ∈ I (1,1) ∩I (2,2) ∩I (2,1) , let 0 ≤ θ ≤ 1. For any q ∈ Q and a ∈ A, x = q + a, there exists u * ∈ U x such that u * ∈ arg min u∈Ux L θ u v(q, a), u *

(1,1) = min(x d1 , x s1 ) and u * (2,2) = min(x d2 , x s2 ). In particular, this result holds for the average operator:

T u . Proof Let v ∈ I (1,1) ∩ I (2,2) ∩ I (2,1) , 0 ≤ θ ≤ 1, q ∈ Q, a ∈ A, x = q + a and u ∈ U x . The maximum number of matchings in (1, 1) is denoted by m (1,1) = min(x d1 , x s1 ) and in (2, 2) by m (2,2) = min(x d2 , x s2 ). Let p (1,2) = min(u (1,2) , x s1 -u (1,1) , x d2 -u (2,2)
) be the number of possible matchings that can be transformed from (1, 2) to (1, 1) and (2, 2) matchings. We define a policy u p (1,2) that removes the p (1,2) matchings in (1, 2) and matches p (1,2) times (1, 1) and (2, 2), that is,

u p (1,2) = u + p (1,2) (e (1,1) + e (2,2) - e (1,2) ). We verify that this policy is admissible, i.e u p (1,2) ∈ U x : u p (1,2) ∈ N 4 is true because u ∈ U x . (a) is true because u p (1,2) (2,2) = u (2,2) + p (1,2) ≤ x d2 . (b) is true because u p (1,2) (1,1) = u (1,1) + p (1,2) ≤ x s1 . Then, we can use the fact that v ∈ I (2,1) to show that L θ u p (1,2) v(q, a) ≤ L θ u v(q, a).
Moreover, we define u * that matches all the the possible (1, 1) and (2, 2) of x -u p (1,2) , that is, of the remaining items when we apply u p (1,2) :

u * = u p (1,2) + e (1,1) (m (1,1) -u p (1,2) (1,1) ) + e (2,2) (m (2,2) -u p (1,2)
(2,2) ). We also verify that this policy is admissible, i.e u * ∈ U x : u * ∈ N 4 is true because u p (1,2) ∈ U x , m (1,1) ≥ 0 and m (2,2) ≥ 0. We immediately get that u * (2,2) = m (2,2) ≤ x d2 and u *

(1,1) = m (1,1) ≤ x s1 . For x d1 and x s2 , we need to discuss the value of p (1,2) :

1. If p (1,2) = u (1,2) . Then we have u * (1,2) = u p (1,2)
(1,2) = 0. Thus,

u * (1,1) + u * (1,2) = m (1,1) ≤ x d1 u * (2,2) + u * (1,2) = m (2,2) ≤ x s2 2. If p (1,2) = x s1 -u (1,1) . Then, u * (1,1) + u * (1,2) = m (1,1) + u (1,2) -x s1 + u (1,1) ≤ u (1,2) + u (1,1) ≤ x d1 u * (2,2) + u * (1,2) = m (2,2) + u (1,2) -x s1 + u (1,1) ≤ x d2 + u (1,2) -x s1 + u (1,1) = x s2 + u (1,2) -x d1 + u (1,1) ≤ x s2 3. If p (1,2) = x d2 -u (2,2) . Then, u * (1,1) + u * (1,2) = m (1,1) + u (1,2) -x d2 + u (2,2) ≤ x s1 + u (1,2) -x d2 + u (2,2) = x d1 + u (1,2) -x s2 + u (2,2) ≤ x d1 u * (2,2) + u * (1,2) = m (2,2) + u (1,2) -x d2 + u (2,2) ≤ u (1,2) + u (2,2) ≤ x s2
In every case, (a) and (b) are true. Hence, since

v ∈ I (1,1) ∩ I (2,2) , it results that L θ u * v(q, a) ≤ L θ u p (1,2) v(q, a).
As a result, we have

L θ u * v(q, a) ≤ L θ u v(q, a), u * (1,1) = m (1,1) = min(x s1 , x d1 ) and u * (2,2) = m (2,2) = min(x s2 , x d2
). This was done for any u ∈ U x and because U x is finite for every x ∈ Q, we can choose u such that it belongs to arg min u ∈Ux L θ u v(q, a) giving the final result.

From this result, it follows that there exists an optimal decision rule that matches all possible (1, 1) and (2, 2). Our goal now is to find the optimal number of matchings in [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. We introduce first some notation: [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] after having matched all possible (1, 1) and (2, 2).

Definition 6 Let 0 ≤ θ ≤ 1, x ∈ Q. We define: K x = {0} if x d1 ≤ x s1 {0, • • • , min(x d1 -x s1 , x s2 -x d2 )} otherwise the set of possible matching in

Remark 4

The state of the system after having matched all possible (1, 1) and (2, 2) is of the form (0, l, l, 0) if x d1 ≤ x s1 and of the form (l, 0, 0, l) otherwise (because of the definition of Q and U x ).

Value Function Property Preservation

In this section, we show that the properties of the value function defined in Section 4.1 are preserved by the dynamic programming operator. In other words, we show that if

v ∈ V σ , then L θ v ∈ V σ . We recall that V σ = I (1,1) ∩ I (2,2) ∩ I (2,1) ∩ C (1,2) ∩ C (2,1) ∩ B.
We first show that the monotonicity on (1, 1), (2, 2) and (2, 1) is also preserved by the dynamic programming operator.

Lemma 4 If a function v ∈ I (1,1) ∩ I (2,2) ∩ I (2,1) , then L θ v ∈ I (1,1) ∩ I (2,2) ∩ I (2,1) .
Proof Let q ∈ Q and a ∈ A, x = q + a. We define q = q + e (1,1) , x = q + a. Since v is increasing with (1, 1), we have that v(q, a) ≥ v(q, a). We aim to show that L θ v(q, a) ≥ L θ v(q, a).

Let u x ∈ arg min u∈Ux L θ v(q, a). Since (x) s1 ≥ 1 and (x) d1 ≥ 1, using Proposition 2, we can choose u x such that (u x ) (1,1) = min(x d1 , x s1 ) ≥ 1. Therefore, we can define

u x = u x -e (1,1) . u x ∈ U x because u x ∈ U x , (u x ) (1,1) = (u x ) (1,1) -1 ≥ 0, (u x ) (1,1) + (u x ) (1,2) = (u x ) (1,1) -1 + (u x ) (1,2) ≤ x d1 -1 = x d1 and (u x ) (1,1) = (u x ) (1,1) -1 ≤ x s1 -1 = x s1 . Besides, x -u x = x -u x and c(x) ≥ c(x) since c ∈ I (1,1) from Assumption 1. Hence, L θ ux v(q, a) = c(x) + θE[v(x -u x , A)] = c(x) -c(x) + c(x) + θE[v(x -u x , A)] = c(x) -c(x) + L θ v(q, a) ≤ L θ v(q, a).
And, since u x ∈ U x , then by definition L θ v(q, a) ≤ L θ ux v(q, a) and, as a result, L θ v(q, a) ≤ L θ v(q, a). The same arguments with q = q + e (2,2) can be made to show that L θ v(q, a) ≤ L θ v(q, a).

The proof is similar for I (2,1) but also requires to handle the case when no matching can be made in [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. Let q ∈ Q and a ∈ A, x = q + a. We denote q = q + e (1,1) + e (2,2) -e (1,2) , x = q + a. Since v ∈ I (2,1) , we know that v(q, a) ≤ v(q, a). c(x) ≤ c(x) holds because of Assumption 1. We aim to show that L θ v(q, a) ≤ L θ v(q, a).

Using Proposition 2, let u x ∈ arg min u∈Ux L θ v v(q, a) such that (u x ) (2,2) = min(x d2 , x s2 ) and (u x ) (1,1) = min(x d1 , x s1 ). Suppose that x d1 ≥ 1 and x s2 ≥ 1. We define u x = u x -e (1,1) -e (2,2) + e (1,2) , thus x -u x = x -u x and u x ∈ U x because u x ∈ U x , x s1 = x s1 -1 ≥ (u x ) (1,1) -1 = min(x d1 , x s1 ) -1 = min(x d1 , x s1 + 1) -1 ≥ 0, x d2 = x d2 -1 ≥ (u x ) (2,2) -1 = min(x d2 , x s2 ) -1 = min(x d2 + 1, x s2 ) -1 ≥ 0. Thus, L θ ux v(q, a) = c(x) + θE[v(x -u x , A)] = c(x) -c(x) + c(x) + θE[v(x -u x , A)] = c(x) -c(x) + L θ v(q, a) ≤ L θ v(q, a),
and L θ v(q, a) ≤ L θ ux v(q, a) as u x ∈ U x . Suppose now that x d1 = 0 or x s2 = 0. In that case, we cannot do more matchings in state x than we can do in state x: u x ∈ U x . Thus,

L θ ux v(q, a) = c(x) + θE[v(x -u x , A)] ≤ c(x) + θE[v(x -u x , A)] since v ∈ I (2,1) = c(x) -c(x) + c(x) + θE[v(x -u x , A)] = c(x) -c(x) + L θ v(q, a) ≤ L θ v(q, a),
and L θ v(q, a) ≤ L θ ux v(q, a) as u x ∈ U x . In both cases we get the desired result

L θ v(q, a) ≤ L θ v(q, a).
The proof that the dynamic programming operator preserves the convexity in (1, 2) was more difficult than anticipated. We had to introduce the boundary property B to show that L θ v ∈ C (1,2) for a specific case.

Lemma 5 If v ∈ I (1,1) ∩ I (2,2) ∩ I (2,1) ∩ C (1,2) ∩ B, then L θ v ∈ C (1,2) .
Proof Let q ∈ Q, q d1 ≥ q s1 , a ∈ A, x = q + a, q = q + e (1,2) , x = q + a, q = q+e (1,2) and x = q+a. Since v is convex in (1, 2), we have v(q, a)-v(q, a) ≤ v(q, a) -v(q, a) (this inequality also holds for the cost function c because of Assumption 1). We aim to show that L θ v(q, a) -L θ v(q, a) ≤ L θ v(q, a) -L θ v(q, a). For y ∈ x, x, x , let u y ∈ arg min u L θ u v(y). From Proposition 3, we can choose u y such that u y = min(y d1 , y s1 )e (1,1) + min(y d2 , y s2 )e (2,2) + k t (y)e [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] .

Let us also define m = x-u x . Suppose that q d1 ≥ q s1 +1 or a ∈ A\{e (2,1) }, we can distinguish 3 cases: (a) k t (x) > 0, (b) k t (x) = 0 and k t (x) > 0 and (c) k t (x) = 0 and k t (x) = 0:

(a) If k t (x) > 0. Then, L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m, A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m, A) -v(m, A)] = L θ v(q, a) -L θ v(q, a) because c ∈ C (1,2) . (b) If k t (x) = 0 and k t (x) > 0. Then, L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m + e (1,2) , A) -v(m, A)] = c(x) -c(x) + L θ v(q, a) -L θ ux+e (1,2) v(q, a) ≤ c(x) -c(x) = c(x) -c(x) + θE[v(m + e (1,2) , A) -v(m + e (1,2) , A)] = L θ v(q, a) -L θ v(q, a) because c ∈ C (1,2) and because k t (x) = k t (x) = 0 and 1 ∈ K x . (c) If k t (x) = 0 and k t (x) = 0. Then, L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m + e (1,2) , A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m + 2e (1,2) , A) -v(m + e (1,2) , A)] = L θ v(q, a) -L θ v(q, a) because c ∈ C (1,2) and v ∈ C (1,2) .
Suppose now that q d1 = q s1 and a = e (2,1) , we can distinguish 2 cases: k t (x) > 0 and k t (x) = 0:

-If k t (x) > 0. Then, L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m -e (2,1) , A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m, A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m -e (2,1) , A) -v(m -e (2,1) , A)] = L θ v(q, a) -L θ v(q, a) because v ∈ I (2,1) and c ∈ C (1,2) . -If k t (x) = 0. Then, L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m -e (2,1) , A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m -e (2,1) + e (1,2) , A) -v(m -e (2,1) , A)] = L θ v(q, a) -L θ v(q, a) because v ∈ B and c ∈ C (1,2) .
Then, to show that the dynamic programming operator preserves B, we had to introduce an other property: C (2,1) (convexity in (2, 1)). The preservation of these two last properties are combined in the next lemma (see proof in Appendix A).

Lemma 6 If v ∈ I (1,1) ∩I (2,2) ∩I (2,1) ∩C (1,2) ∩C (2,1) ∩B, then L θ v ∈ C (2,1) ∩B.
In this section, we have shown that the structural properties of the value function presented in Section 4.1 are preserved by the dynamic programming operator. That is, if v ∈ V σ , then L θ v also belongs to this set. Using this result, we give the structure of the optimal policy in the next section.

Structure of the Optimal Policy

We now present that, using the result of Theorem 1, there exists an optimal matching policy which is formed of a sequence of decision rules that belong to D σ (with a fixed threshold).

Theorem 5

The optimal control for the discounted cost problem is of threshold type in (1, 2) with priority to (1, 1) and (2, 2).

Proof We apply Theorem 1 where V σ is the set of functions defined in (6) and D σ the set defined in Definition 5. ( 3)-( 5) are verified because of Lemma 1.

We now focus on the structural conditions of the theorem. From Lemma 4, Lemma 5 and Lemma 6 of Section 4.3, it follows (a) since they show that if v ∈ V σ , then L θ v ∈ V σ . The result of Proposition 3 shows (b) because the policy that belong to

D σ minimize L θ u v if v ∈ V σ .
Finally, since limits preserve inequalities, the point-wise convergence of functions of V σ belong to this set, which shows (c).

The following theorem shows that the previous result is also proven for the average cost problem.

Theorem 6

The optimal control for the average cost problem is of threshold type in (1, 2) with priority to (1, 1) and (2, 2).

Proof We want to apply Theorem 2 using the same value function set V σ and the same decision rule set D σ as in the proof of the previous theorem. Assumptions (A1) to (A4) hold because of Lemma 2.

Let (θ n ) n∈N be a sequence such that 0 ≤ θ n < 1 for all n ∈ N and lim n→+∞ θ n = 1. Let n ∈ N. We know that v * θn ∈ V σ (see the proof of Theorem 5). The inequalities in the definitions of the properties used in V σ still hold if we add a constant to v, thus v * θn -v * θn (0)e ∈ V σ . Using Assumption (A3) and Assumption (A4), we have H ≤ v * θn -v * θn (0)e ≤ M , so v * θn -v * θn (0)e ∈ V σ H . This last result holds for each n ∈ N and since limits preserve inequalities

V σ H is a closed set, lim n→+∞ [v * θn -v * θn (0)e] ∈ V σ
H which shows (a). The result of Proposition 3 shows (b) because the policy that belong to

D σ minimize L 1 u v = T u v if v ∈ V σ H ⊂ V σ .

Computing the Optimal Threshold

We consider the matching policy of threshold type in (1, 2) with priority to (1, 1) and (2, 2) in the average cost case. 2) be the set of matching policy of threshold type in (1, 2) with priority to (1, 1) and (2, 2).

Proposition 4 Let ρ = β(1-α) α(1-β) ∈ (0, 1), R = cs 1 +c d 2 c d 1 +cs 2 and Π T (1,
Assume that the cost function is a linear function. The optimal threshold t * , which minimizes the average cost on Π T (1,2) , is

t * = k if f ( k ) ≤ f ( k ) k otherwise
where k

= log ρ-1 (R+1) log ρ log ρ -1 and f (x) = (c d1 +c s2 )x+(c d1 +c d2 +c s1 +c s2 ) ρ x+1 1-ρ - (c d1 + c s2 ) ρ 1-ρ + ((c d1 + c s1 )αβ + (c d2 + c s2 )(1 -α)(1 -β) + (c d2 + c s1 )(1 - α)β + (c d1 + c s2 )α(1 -β)).
The threshold t * is positive.

Proof The idea of the proof is to look at the Markov chain derived from the policy u ∞ t ∈ Π T (1,2) . We show that the Markov chain is positive recurrent and we compute the stationary distribution. Using the strong law of large numbers for Markov chains, we show that the average cost g u ∞ t is equal to the expected cost of the system under the stationary distribution. Then, we find an analytical form for the expected cost which depends on the threshold on (1, 2), i.e, t. Finally, we minimize the function over t. See details in Appendix B.

General Matching Graphs

Complete Graphs Minus One Edge

In this section, we are going to generalize the results of the N -shaped graph to any complete graph minus one edge with specific costs. Let us note this latter matching graph G = (D ∪ S, E) with E = (D × S) \ {(i * , j * )}, where (i * , j * ) (i * ∈ D and j * ∈ S) is the missing edge (see Figure 4 for an example). We note G N = (D N ∪ S N , E N ) the N -shaped matching graph with D N , S N and E N defined as in Section 4.

s 1 s 2 s 3 d 1 d 2 d 3 β 1 β 2 β 3 α 1 α 2 α 3
Fig. 4 A complete matching graph minus the edge (3, 1).

First, let us define some transformations, to move from Y (the Markov Decision Process defined on G) to Y N (the Markov Decision Process defined on G N ).

Definition 7 Let Q and A be the sets of possible state and arrival of G. Let Q N and A N be the sets of possible state and arrival of G N . We define the projection from Q to Q N and the projection from A to A N as

p N Q (q) =   i∈D(j * ) q di , q d i * , q s j * , j∈S(i * ) q sj   and p N A (a) =        e (1,1) if a = e (i,j * ) , i ∈ D(j * ) e (2,2) if a = e (i * ,j) , j ∈ S(i * ) e (2,1)
if a = e (i * ,j * ) e [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] otherwise .

We can easily show that p

N Q (x) = p N Q (q)+p N A (a) where x = q+a. Let a N ∈ A N , we also define (p N A ) -1 (a N ) = {a ∈ A : p N A (a) = a N }.
Let A be the arrival process associated to G, we construct an arrival process A N for G N in the following way:

∀a N ∈ A N , P(A N = a N ) = a∈(p N A ) -1 (a N ) P(A = a)
We formalize what we mean by specific costs in the following assumption:

Assumption 2 Let c and c N be the cost functions associated to Y and Y N . We assume that c and c N are cost functions such that c

(x) = c N (p N Q (x)) for all x ∈ Q.
For example, Assumption 2 is satisfied for any linear cost function c which have the same coefficient c di = c 1 for all i ∈ D(j * ) and the same coefficient c sj = c 2 for all j ∈ S(i * ). We just have to construct a linear cost function c N with the following coefficients c

N d1 = c 1 , c N d2 = c d i * , c N s1 = c s j * and c N d2 = c 2 .
We now translates what is the decision rule of threshold-type in (1, 2) with priority in (1, 1) and (2, 2) for G.

Definition 8 (Threshold-type decision rule) A decision rule u x is said to be of threshold type with priority to i * and j * if:

1. it matches all of (i, j * ) for all i ∈ D(j * ) and (i * , j) for all j ∈ S(i * ). 2. it matches (i, j) (i ∈ D(j * ) and j ∈ S(i * )) only if the remaining items (in the sum of d i for i ∈ D(j * )) are above a specific threshold, denoted by t (with t ∈ N ∪ ∞).

i.e, u x is such that i∈D(j * ) (u x ) (i,j * ) = min( i∈D(j * ) x di , x s j * ),

j∈S(i * ) (u x ) (i * ,j) = min(x d i * , j∈S(i * ) x sj ) and i∈D(j * ) j∈S(i * ) (u x ) (i,j) = k t (x)
where

k t (x) = 0 if i∈D(j * ) x di -x s j * ≤ t i∈D(j * ) x di -x s j * -t otherwise .
We define D * as the set of decision rules that are of threshold type with priority to i * and j * for any t ∈ N ∪ ∞.

The next theorem shows that the stationary policy based on this decision rule of threshold-type with priority to i * and j * is optimal based on the results of Section 4.4 and some lemmas to bridge the gap between G and G N .

Theorem 7

The optimal control for the discounted cost problem and the average cost problem is of threshold type with priority to i * and j * .

Proof Let 0 ≤ θ < 1, let π be a stationary policy on Y and π * = (u(X(n))) n≥0 (with u ∈ D * as defined in Definition 8) be a threshold-type policy with priority in i * and j * . Let y 0 = (q 0 , a 0 ) ∈ Q × A and y N 0 = (p N Q (q 0 ), p N A (a 0 )). Using Lemma 8, there exists a policy π N such that:

v π θ (y 0 ) = v π N θ (y N 0 ) ≥ v (π N ) * θ (y N 0 ) = v π * θ (y 0 )
where (π N ) * = (u N (X N (n))) n≥0 (with u N ∈ D σ as defined in Definition 5) is a threshold-type policy with priority in (1, 1) and (2, 2). The inequality comes from our optimality result on G N : Theorem 5. The last equality comes from Lemma 7. This was done for any y 0 = (q 0 , a 0 ) ∈ Q × A and the average cost problem follows easily (with Theorem 6), giving us the final result.

Lemma 7 Let 0 ≤ θ < 1, let π * = (u(X(n))) n≥0 (with u ∈ D * as defined in Definition 8) be a threshold-type policy with priority in i * and j * and let (π N ) * = (u N (X N (n))) n≥0 (with u N ∈ D σ as defined in Definition 5) be a threshold-type policy with priority in (1, 1) and (2, 2). Given Assumption 2, we

have v π * θ (y) = v (π N ) * θ
(y N ) for all y = (q, a) ∈ Q×A, with y N = (p N Q (q), p N A (a)). The result remains true for the average cost problem with g π * and g (π N ) * .

Proof Let 0 ≤ θ < 1, let π * = (u(X(n))) n≥0 (with u ∈ D * as defined in Definition 8) be a threshold-type policy with priority in i * and j * and let (π N ) * = (u N (X N (n))) n≥0 (with u N ∈ D σ as defined in Definition 5) be a threshold-type policy with priority in (1, 1) and (2, 2). Let

y 0 = (q 0 , a 0 ) ∈ Q × A, with y N 0 = (p N Q (q 0 ), p N A (a 0 )).
First, let us note that (π N ) * is the "projection" of π * on G N in the following sense. Let x ∈ Q, u(x) ∈ D * the matching of state x (u(x) ∈ U x ) under the policy π * and u

N (p N Q (x)) ∈ D σ the matching of state p N Q (x) (u N (p N Q (x)) ∈ U N p N Q (x)
) under the policy (π N ) * . We can easily see that

u N (1,1) (p N Q (x)) = i∈D(j * ) u (i,j * ) (x), u N (2,2) (p N Q (x)) = j∈S(i * ) u (i * ,j) (x) and u N (1,2) (p N Q (x)) = i∈D(j * ) j∈S(i * ) u (i,j) (x).
Then, we are going to prove by induction that for any a

N 1 ∈ A N , • • • , a N n ∈ A N and any a 1 ∈ (p N A ) -1 (a N 1 ), • • • , a n ∈ (p N A ) -1 (a N n ), we have p N Q (x n ) = x N n .
We already specifically chose y N 0 to verify this property:

p N Q (x 0 ) = p N Q (q 0 ) + p N A (a 0 ) = q N 0 + a N 0 = x N 0 . Now, assume that p N Q (x n-1 ) = x N n-1 . Then, p N Q (q n ) =   i∈D(j * ) (q n ) di , (q n ) d i * , (q n ) s j * , j∈S(i * ) (q n ) sj   =   i∈D(j * ) (x n-1 -u(x n-1 )) di , (x n-1 -u(x n-1 )) d i * , (x n-1 -u(x n-1 )) s j * , j∈S(i * ) (x n-1 -u(x n-1 )) sj   =   i∈D(j * ) (x n-1 ) di - j∈S(i) u(x n-1 ) (i,j) , (x n-1 ) d i * - j∈S(i * ) u(x n-1 ) (i * ,j) , (x n-1 ) s j * - i∈D(j * ) u(x n-1 ) (i,j * ) , j∈S(i * ) (x n-1 ) sj - i∈D(j) u(x n-1 ) (i,j)   = p N Q (x n-1 ) - i∈D(j * ) u(x n-1 ) (i,j * ) e (1,1) - j∈S(i * ) u(x n-1 ) (i * ,j) e (2,2) - i∈D(j * ) j∈S(i * ) u(x n-1 ) (i,j) e (1,2) = p N Q (x n-1 ) -u N (p N Q (x n-1 )) (1,1) e (1,1) -u N (p N Q (x n-1 )) (2,2) e (2,2) -u N (p N Q (x n-1 )) (1,2) e (1,2) = p N Q (x n-1 ) -u N (p N Q (x n-1 )) = x N n-1 -u N (x N n-1 ) = q N n and p N A (a n ) = a N n (because p N A ((p N A ) -1 (a N )) = a N for all a N ∈ A N ). Thus, p N Q (x n ) = p N Q (q n ) + p N A (a n ) = q N n + a N n = x N n .
Finally, using this property and Assumption 2, we have

E π * y0 [c(Y (n))] = a1∈A,••• ,an∈A c(x n ) n k=1 P(A = a k ) = a N 1 ∈A N ,••• ,a N n ∈A N a1∈(p N A ) -1 (a N 1 ) • • • an∈(p N A ) -1 (a N n ) c(x n ) × n k=1 P(A = a k ) = a N 1 ∈A N ,••• ,a N n ∈A N a1∈(p N A ) -1 (a N 1 ) • • • an∈(p N A ) -1 (a N n ) c N (p N Q (x n )) × n k=1 P(A = a k ) = a N 1 ∈A N ,••• ,a N n ∈A N a1∈(p N A ) -1 (a N 1 ) • • • an∈(p N A ) -1 (a N n ) c N (x N n ) × n k=1 P(A = a k ) = a N 1 ∈A N ,••• ,a N n ∈A N c N (x N n ) n k=1 a k ∈(p N A ) -1 (a N k ) P(A = a k ) = a N 1 ∈A N ,••• ,a N n ∈A N c N (x N n ) n k=1 P(A N = a N k ) = E (π N ) * y N 0 [c N (Y N (n))].
This equality is true for any n ∈ N. Therefore, v π * θ (y 0 ) = v (π N ) * θ (y N 0 ) and g π * (y 0 ) = g (π N ) * (y N 0 ). This was done for any y 0 = (q 0 , a 0 ) ∈ Q × A with y N 0 = (p N Q (q 0 ), p N A (a 0 )), giving the final result. Lemma 8 Let 0 ≤ θ < 1, let π be a stationary policy on Y , y = (q, a) ∈ Q×A and y N = (p N Q (q), p N A (a)). Given Assumption 2, there exists a policy π N on Y N such that v π θ (y) = v π N θ (y N ). The result remains true for the average cost problem with g π and g π N .

Proof The proof is very similar to the one of Lemma 7. We just have to introduce new independent random variables Â(n) which help bridge the gap between Y and Y N . See more details in Appendix C

Acyclic Graphs

In Section 4, we fully characterizes the optimal matching control of the Nshaped matching graph, which is an acyclic graph. Therefore, in this section, we study the optimal matching control of an arbitrary acyclic matching graph. We show that, under certain assumptions on the costs of the nodes, the optimal matching policy consists of prioritizing the matching of the extreme edges.

For an acyclic matching graph, we say that (i, j) is an extreme edge if the unique adjacent node of d i is s j or if the unique adjacent node of s j is d i . We denote by E * the set of extreme nodes. We say that an edge (i 1 , j 1 ) belongs to the neighborhood of an edge (i 2 , j 2 ) if i 1 = i 2 or j 1 = j 2 . We denote by N ((i, j)) the neighborhood of an edge (i, j).

We assume that the neighborhood of all the edges is not empty, i.e., the matching graph is connected, and that in the neighborhood of an extreme edge there are not extreme edges. An example of the matching graphs under study is provided in Figure 5. As it can be observed, the set of extreme edges is E * = {(1, 1), [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF], [START_REF] Busic | Approximate optimality with bounded regret in dynamic matching models[END_REF][START_REF] Busic | Stability of the bipartite matching model[END_REF]} and the neighborhood of (1, 1) is

N ((1, 1)) = {(1, 2)}, whereas that of (3, 3) is N ((3, 3)) = {(2, 3), (4, 3)}. s 1 s 2 s 3 s 4 s 5 d 1 d 2 d 3 d 4 d 5 d 6 β 1 β 2 β 3 α 1 α 2 α 3 β 4 β 5 α 4 α 5 α 6
Fig. 5 An example of an acyclic matching graph.

Value Function Properties

We start by using the increasing property in a given edge (i, j) as defined in Definition 1 that we will note I (i,j) . We also define the undesirability property for a given edge.

Definition 9 (Undesirability property) Let (i 1 , j 1 ) ∈ E. We say that a function v is undesirable in (i 1 , j 1 ) or v ∈ U (i1,j1) if for all (i 2 , j 2 ) ∈ N ((i 1 , j 1 ))

v(q + e (i1,j1) -e (i2,j2) , a) ≥ v(q, a),
for all a ∈ A and q ∈ Q such that

q sj 2 ≥ 1 if i 1 = i 2 and q di 2 ≥ 1 if j 1 = j 2 .
Remark 5 We note that the undesirable property is the same as saying that, for all (i 2 , j 2 ) ∈ N ((i 1 , j 1 ))

v(q + e (i1,j1) , q) ≥ v(q + e (i2,j2) , a), that is, it is preferable to match the items in (i 1 , j 1 ) than in (i 2 , j 2 ).

In the remainder of this section, we denote

V σ = (i,j)∈E * I (i,j) ∩ U (i,j) (10)
and we assume that c is a linear function with higher holding costs on the extreme edges rather than its neighbors, i.e., c di ≥ c d i for all (i , j) ∈ N ((i, j)) (or c sj ≥ c s j for all (i, j ) ∈ N ((i, j))). This additional assumption is needed for the cost function c to satisfy the property of Definition 9 and thus Assumption 1.

Optimal decision rule

In this section, we show that, for any v ∈ V σ , there is a matching policy that prioritizes the matchings in the extreme edges and minimizes L θ u v.

Definition 10 (Prioritizing the extreme edges) We say that a matching policy prioritizes the extreme edges if it matches all the items in the extreme edges. This means that, for all (i, j) ∈ E * , u (i,j) = min(x di , x sj ).

We consider that D σ is the decision rule that prioritizes the extreme edges. We also consider that E * = {(i 1 , j 1 ), (i 2 , j 2 ), . . . , (i m , j m )}, which means that the number of extreme edges is equal to m.

Remark 6

In the example of Figure 5, we have that m = 3 and i 1 = j 1 = 1, i 2 = j 2 = 3 as well as i 3 = 6 and j 3 = 5.

We now show that, if v ∈ V σ , there exists a decision rule that prioritizes the extreme edges.

Proposition 5 Let a ∈ A, q ∈ Q, x = q + a, v ∈ V σ , 0 ≤ θ ≤ 1. There exists u * ∈ U x such that u * ∈ arg min u∈Ux L θ u v(q, a) and u * (i,j) = min(x di , x sj ) for all (i, j) ∈ E * . In particular, this result holds for the average cost operator T u .

Proof Let q ∈ Q, a ∈ A, x = q + a and u ∈ U x . We define x (i,j) = min(x di , x sj ) for all (i, j) ∈ E to ease the notations. We recall that E * = {(i 1 , j 1 ), (i 2 , j 2 ), . . . , (i m , j m )}. For k = 1, . . . , m, we define

p k = min(x (i k ,j k ) -u (i k ,j k ) , (i,j)∈N ((i k ,j k )) u (i,j) ).
We now observe that, for all (i, j) ∈ N ((i k , j k )), we can define 0 ≤ p i,j ≤ u (i,j) such that

p k = (i,j)∈N ((i k ,j k )) p i,j .
where the first inequality holds by definition of p k and the second by definition of x (i k ,j k ) . We also show (a) for all i ∈ D(j k ) as follows:

r∈S(i) (u 0 ) (i,r) = (u 0 ) (i,j k ) + r∈S(i)\{j k } (u 0 ) (i,r) = u (i,j k ) -p i,j k + r∈S(i)\{j k } u (i,r) ≤ r∈S(i) u (i,r) ≤ x di ,
where the first inequality holds since p i,j k ≥ 0 and the second since u ∈ U x . We now show (b) for j k as follows:

r∈D(j k ) (u 0 ) (r,j k ) = r∈D(j k ) u (r,j k ) ≤ x sj k ,
where the inequality holds since u ∈ U x .

-We now aim to show that u * ∈ U x and we observe that it is enough to show that, for any k ∈ {1, . . . , m},

u 0 = u + m k e (i k ,j k ) ∈ U x .
We first observe that, if m k = 0, then u 0 = u and therefore u 0 ∈ U x . Therefore, we now consider than m k > 0. For this case,

m k > 0 ⇐⇒ x (i k ,j k ) > u (i k ,j k ) = u (i k ,j k ) + p k .
We observe that p k = x (i k ,j k ) -u (i k ,j k ) cannot be given since the above expression gives a contradiction. Therefore, we have that p k = (i,j)∈N ((i k ,j k )) u (i,j) . For this case, p i,j = u (i,j) for all (i, j) ∈ N ((i k , j k )) and therefore

u (i,j) = 0. ( 12
)
First, we have u 0 ∈ N n D +n S because m k ≥ 0 and u ∈ U x . Then, we show (a) and (b) assuming that d i k is of degree one (the proof for the case that s j k is of degree one is symmetric and therefore we omitted it). We first show (a) for i k as follows:

(u 0 ) (i k ,j k ) = u (i k ,j k ) + m k = x (i k ,j k ) ≤ x di k .
Finally, we show (b) for j k as follows:

r∈D(j k ) (u 0 ) (r,j k ) = (u 0 ) (i k ,j k ) + r∈D(j k )\{i k } (u 0 ) (r,j k ) = (u 0 ) (i k ,j k ) + r∈D(j k )\{i k } (u ) (r,j k ) = (u 0 ) (i k ,j k ) = x (i k ,j k ) ≤ x sj k ,
where the third equality holds by [START_REF] Jaillet | Online stochastic matching: New algorithms with better bounds[END_REF].

Value Function Property Preservation

We now show that the properties of the value function that belong to V σ are preserved by the dynamic programming operator. That is., we consider the value function v ∈ V σ and we aim to show that Lv ∈ V σ . We first show that the increasing property is preserved by the dynamic operator property. The proof uses the same arguments as for the preservation of the increasing property in (1, 1) and (2, 2) of Lemma 4 and therefore we omit it.

Lemma 9 Let (i, j) ∈ E * . If v ∈ I (i,j) ∩ U (i,j) , then Lv ∈ I (i,j) .

We also show that the undesirability property is preserved by the dynamic programming operator.

Lemma 10 Let (i, j) ∈ E * . If v ∈ I (i,j) ∩ U (i,j) , then Lv ∈ U (i,j) .
Proof Let (i 1 , j 1 ) ∈ E * and (i 2 , j 2 ) ∈ N ((i 1 , j 1 )). We consider that i 1 = i 2 (the case j 1 = j 2 is symmetric and therefore it can be proven analogously). Let a ∈ A, q ∈ Q such that q j2 ≥ 1 and let x = q + a. We define q = q + e (i1,j1) -e (i2,j2) and x = q + a. Since v ∈ U (i,j) , we know that v(q, a) ≥ v(q, a). We aim to show that L θ v(q, a) ≥ L θ v(q, a).

Let u x ∈ arg min u∈Ux L θ u v(q, a), using Proposition 5, we can choose u x such that (u x ) (i1,j1) = min(x di 1 , x sj 1 ). Assume that

x di 1 ≥ 1, then (u x ) (i1,j1) ≥ 1 because x j1 = x j1 + 1 ≥ 1. We define u x = u x + e (i2,j2) -e (i1,j1) . We know that u x ∈ U x since 0 ≤ (u x ) (i1,j1) -1 ≤ x sj 1 -1 = x sj 1 , r∈D(j2) (u x ) (r,j2) = r∈D(j2) (u x ) (r,j2) +1 ≤ x sj 2 +1 = x sj 2
and u x ∈ U x . Besides, x-u x = x-u x and the desired result follows since

L θ v(q, a) ≤ L θ ux v(q, a) = c(x) + θE[v(x -u x , A)] = c(x) + θE[v(x -u x , A)] = c(x) -c(x) + L θ v(q, A) ≤ L θ v(q, A),
where the last inequality holds since c ∈ V σ . Assume now that x di 1 = 0, then we cannot do more matchings in x than we could do in x, i.e u x ∈ U x . Indeed, we have (u

x ) (i1,j1) ≤ x di 1 = 0 ≤ x sj 1 and r∈D(j2) (u x ) (r,j2) ≤ x sj 2 ≤ x sj 2 . Therefore, L θ v(q, a) ≤ L θ ux v(q, a) = c(x) + θE[v(x -u x , A)] ≤ c(x) + θE[v(x -u x , A)] = L θ v(q, A),
where the last inequality holds since c ∈ V σ and v ∈ V σ , giving us the final result.

Structure of the Optimal Policy

In this section, we use the result of Theorem 1 and of Theorem 2 to show that there exists an optimal policy that consists of a sequence of decision rules that belongs to D σ , i.e., that prioritizes the extreme edges.

Theorem 8

The optimal control for the discounted cost problem prioritizes the extreme edges.

Proof We apply Theorem 1 where V σ is the set of functions defined in [START_REF] Gurvich | On the dynamic control of matching queues[END_REF] and D σ the set defined in Definition 5.

From Lemma 9 and Lemma 10, it follows (a). The result of Proposition 5 shows (b). And, since limits preserve inequalities, the point-wise convergence of functions of V σ belong to this set, which shows (c).

The following theorem shows that the previous result is also verified for the average cost problem.

Theorem 9

The optimal control for the average cost problem prioritizes the extreme edges.

Proof We want to apply Theorem 2 using the same value function set V σ and the same decision rule set D σ as in the proof of the previous proposition.

Let (θ n ) n∈N be a sequence such that 0 ≤ θ n < 1 for all n ∈ N and lim n→+∞ θ n = 1. Let n ∈ N. We know that v * θn ∈ V σ (see the proof of Theorem 8). The inequalities in the definitions of the properties used in V σ still hold if we add a constant to v, thus v * θn -v * θn (0)e ∈ V σ . Using Assumption (A3) and Assumption (A4), we have

H ≤ v * θn -v * θn (0)e ≤ M , so v * θn -v * θn (0)e ∈ V σ
H . This last result holds for each n ∈ N and since limits preserve inequalities

V σ H is a closed set, lim n→+∞ [v * θn -v * θn (0)e] ∈ V σ
H which shows (a). The resulf of Proposition 5 shows (b) because the policy that belongs to D σ minimizes

L 1 u v = T u v if v ∈ V σ H ⊂ V σ .

Neighborhood of Extreme edges

For the above results, we have assumed that the extreme edges do not have other extreme edges in their neighborhoods. We now explain how the results of this section also hold when in the neighborhood of an extreme edge there are other extreme edges. An example the matching models we now study consists of the matching graph of Figure 5 with an additional demand node d 7 and an edge [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF][START_REF] Busic | Stability of the bipartite matching model[END_REF]. We first note that, if the cost of the extreme edges that are neighbors is the same, these edges can be merged and seen as a single edge whose arrival probability is equal to the sum of their arrival probabilities. Otherwise, we require that the undesirability and increasing properties to be satisfied by the extreme edge with the highest cost and the above arguments can be used to show that the optimal policy prioritizes the most expensive extreme edges.

W -shaped graph

We now focus on a W -shaped matching graph. As it can be observed in Figure 6, this matching graph is formed by three demand nodes, two supply nodes and the following set of edge: E = {(1, 1), (2, 1), (2, 2), (3, 2)}. Let us also define (1, 2) ((3, 1)) as the imaginary edge ((1, 2), [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] / ∈ E) between d 1 and s 2 (d 3 and s 1 ) that we introduce to ease the notations.

s 1 s 2 d 1 d 2 d 3 β 1 β 2 α 1 α 2 α 3
Fig. 6 The W -shaped graph.

We assume that α 1 < β 1 and α 3 < β 2 , which is required to ensure the stability of the system.

Proving the optimal policy on the W -shaped graph is much more difficult than on the N -shaped graph. We will study the former under different assumptions on the costs. First, we will present a conjecture of the optimal policy when there is a higher cost on the extreme nodes. Then, we will show through numerical evidence that it is not optimal to always match in priority the extreme edges when there is a higher cost on the middle node.

Higher cost on the extreme nodes

We define an extreme node as the node with degree one in an extreme edge (as defined in Section 5.2). In the W -shaped graph, there are two extreme nodes: d 1 and d 3 . We assume for the remainder of this section that there is a higher cost on those nodes rather than on d 2 , i.e the cost function c satisfy U (1,1) ∩ U (3,2) (as defined in Definition 9). For a linear cost function, this comes down to c d1 ≥ c d2 and c d3 ≥ c d2 . Our goal is to extend the results of Section 4 to this case. However, this Wshaped matching graph is much more difficult than than the N -shaped one. We were not able to prove what is the optimal policy but we have a strong conjecture. First, we will present our conjecture and explain why it should be the optimal policy. Then, we will show which properties are needed to prove this conjecture and the work that has been done in that way. Finally, we will explain what are the remaining challenges to solve.

Conjecture of the optimal policy

Using the insight gained with the N -shaped graph, we want to have some intuition about which policy should be optimal in the W -shaped graph. We already know that matching in priority the extreme edges (1, 1) and (3, 2) is optimal because we are in the context of Section 5.2. Therefore, the question left is how do we want to match (2, 1) and (2, 2) ? In the N -shaped graph, the non-extreme edge is matched only if it is above a threshold (based on the remaining items after matching the extreme edges) in order to have a buffer for the extreme nodes. Thus, translating the optimal policy of the N -shaped graph to the W -shaped graph would be to match in priority the edges (1, 1) and (3, 2), then only match (2, 1) if it is above a threshold (based on the remaining items in s 1 after the matchings in (1, 1)) and only match (2, 2) if it is above a threshold (based on the remaining items in s 2 after the matchings in (3, 2)). After having matched everything we can in the edges (1, 1) and (3, 2), we obtain a state such that doing any possible number of matchings in either (2, 1) or (2, 2) does not prevent us from doing any possible number of matchings in the other edge. So it seems reasonable to assume that the thresholds are independent. Let us now define more formaly our conjecture of the optimal policy: Definition 11 (Threshold-type decision rule) A decision rule u x is said to be of threshold type in (2, 1) and (2, 2) with priority to (1, 1) and (3, 2) if:

1. it matches all of (1, 1) and (3, 2). 2. it matches (2, 1) ((2, 2)) only if the remaining jobs in s 1 (s 2 ) are above a specific threshold, noted t (2,1) (t (2,2)

) with t (2,1) ∈ N ∪ ∞ (t (2,2) ∈ N ∪ ∞).
i.e, u x = min(x d1 , x s1 )e (1,1) + min(x d3 , x s2 )e (3,2) + min(k t (2,1) (x), x d2 )e (2,1) + min(j t (2,2) (x), x d2 )e [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] where

k t (2,1) (x) = 0 if x s1 -x d1 ≤ t (2,1) x s1 -x d1 -t (2,1)
otherwise

and j t (2,2) (x) = 0 if x s2 -x d3 ≤ t (2,2) x s2 -x d3 -t (2,2)
otherwise

We will now present the work that has already been done in order to prove the optimality of this policy.

Value Functions Properties

We start by defining the properties that are needed to prove the optimality of our conjecture. First, we consider the properties needed to prove that we match everything (with priority) in the extreme edges (1, 1) and (3, 2) using our results for acyclic graphs. Thus, we assume the increasing and undesirability properties in the extreme edges (1, 1) and [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] as defined in Definition 1 and Definition 9 that we will note I (1,1) , I (3,2) , U (1,1) and U [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . Then, we use properties inspired from the N -shaped graph to prove that we have thresholds in (2, 1) and (2, 2) such as the convexity and boundery properties. The convexity property is defined in (2, 1), [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF], [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] and [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] in a similar way as in Definition 3, that we will note C (2,1) , C (2,2) , C (1,2) and C [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] . The property C (2,1) (resp. C (1,2) ) is defined for q ∈ Q such that q s1 ≥ q d1 (resp. q d1 ≥ q s1 ) and the property C (2,2) (resp. C (3,1) ) is defined for q ∈ Q such that q s2 ≥ q d3 (resp. q d3 ≥ q s2 ). The boundary property is defined in (2, 1) and (2, 2) in a similar way as in Definition 4, that we will note B (2,1) and B [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . For the property B (2,1) , e (1,2) is used in the left hand side and e (2,1) is used in the right hand side. For the property B (2,2) , e (3,1) is used in the left hand side and e (2,2) is used in the right hand side. Finally, we will need new properties to prove that we have a threshold in (2, 1) and [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. The exchangeable property is there to be able to define the threshold based on the remaining items in s 1 or s 2 after having matched the extreme edges. The modularity property is there to prove the independence between the two thresholds.

Definition 12 (Exchangeable property) A function v is exchangeable in (2, 1) and [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] or v ∈ H (2,1), [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] if ∀a ∈ A, ∀q ∈ Q, v(q + e (2,1) , a) -v(q, a) = v(q + e (3,1) , a) -v(q -e (2,1) + e (3,1) , a).

Likewise, v is exchangeable in (2, 2) and (1, 2) or v ∈ H (2,2),(1,2) if ∀a ∈ A, ∀q ∈ Q, v(q + e (2,
2) , a) -v(q, a) = v(q + e (1,2) , a) -v(q -e (2,2) + e (1,2) , a). Definition 13 (Modularity property) A function v is modular in (2, 1) and [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] or v ∈ M (2,1), [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] if ∀a ∈ A, ∀q ∈ Q, v(q + e (2,1) + e (2,2) , a) -v(q + e (2,1) , a) = v(q + e (2,2) , a) -v(q, a).

The properties I (1,1) , I (3,2) , U (1,1) , U (3,2) , C (2,1) , C (2,2) , H (2,1), [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] , H (2,2), [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] and M (2,1),(2,2) will be used in Proposition 7 which shows that if the value function satisfy them, then our conjecture is the optimal decision rule. Using our insight from the N -shaped graph, B (2,1) , B (2,2) , C (1,2) and C [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] should be required to show that C (2,1) and C (2,2) are preserved by the operator L θ .

Optimal decision rule

First, the optimality of matching in priority the extreme edges (1, 1) and (3, 2) is comes immediately from our work in Section 5.2.

Proposition 6 Let v ∈ I (1,1) ∩ I (3,2) ∩ U (1,1) ∩ U [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] , let 0 ≤ θ ≤ 1. For any q ∈ Q and any a ∈ A, x = q + a, there exists u * ∈ U x such that u * ∈ arg min u∈Ux L θ u v(q, a) and u * (1,1) = min(x d1 , x s1 ) and u * (3,2) = min(x d3 , x s2 ).

Proof This is a corollary of Proposition 5.

Then, we show that there is a control of threshold-type in (2, 1) and in (2, 2) with priority to [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] to handle (1, 2) left over items when defining the threshold in [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. You also need the property M (2,1), [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] to prove the independence between the two thresholds. See details in Appendix D.

Value Function Property Preservation

The preservation of all the properties by the dynamic programming operator is still a work in progress. The properties related to matching in priority the extreme edges, i.e I (1,1) , I (3,2) , U (1,1) and U [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] are preserved as corollary of Lemma 9 and Lemma 10. However, it is very difficult to prove the preservation of the convexity properties, i.e C (2,1) and C (2,2) . One challenge is that if we use a similar proof as for Lemma 5, then we need an increasing property in the imaginary edges (1, 2) and (3, 1) (the undesirability property in (1, 1) and (3, 2) is not enough). The problem is that I (1,2) and I (3,1) cannot be preserved for all q ∈ Q. We have to constrain both properties on subsets of Q and their preservation is still difficult at the boundary of these subsets.

Higher cost on the middle node

Now, we want to study the W -shaped graph when our assumption of higher cost on the extreme nodes is not valid. For example, let us take the case where there is a higher cost on d 2 than on d 3 . Given that the optimal policy on the N -shaped graph always match in priority the extreme edges for any cost, we would expect to have the same result for the W -shaped graph. However, we have numerical evidence that always matching in priority (1, 1) and (3, 2) is not optimal. Indeed, let c d1 = 10, c d2 = 10, c d3 = 1, c s1 = 1, c s2 = 1000, α 1 = 0.5 -, α 2 = 0.25 + , α 3 = 0.25, β 1 = 0.5, β 2 = 0.5 and = 0.1. For these parameters, we observed that a policy of threshold type in (2, 1) and (3, 2) with priority in (1, 1) and (2, 2) (using a similar definition as Definition 11 but now k t (2,1) (x) depends on the remaining items in s 1 and d 2 plus d 3 and j t (3,2) (x) only depends on the remaining items in d 3 ) performed better than our conjecture, i.e a policy of threshold type in (2, 1) and (2, 2) with priority in (1, 1) and (3, 2) (see Figure 7). For both policies, we selected the best thresholds by numerical experiments which are t (2,1) = 14 and t (3,2) = 0 for the former policy and t (2,1) = 11 and t (2,2) = 0 for the latter policy. This numerical experiment was based on the concept of workload and results in heavy-traffic regime found in [START_REF] Busic | Approximate optimality with bounded regret in dynamic matching models[END_REF]. We chose these parameters in order for the nodes d 1 and s 2 to be critical in term of stability. By that, we mean that the stability conditions for D = {d 1 } and S = {s 2 } are the closest to be violated among all subsets (see ( 1)). Heavy-traffic results suggest, in that case, that we should have some buffer in D(s 2 ) = {d 2 , d 3 }. In addition, because we have higher cost in d 2 rather than d 3 , this implies that we prefer to have the buffer in d 3 rather than d 2 . All these conditions lead to matching in priority (2, 2) rather than (3, 2) a better performing policy.

To conclude, the optimal policy on the W -shaped graph should take various forms depending on the cost structure and results from heavy-traffic regime could lead us to the right ones.

Conclusion

We consider bipartite matching graphs with linear costs in the buffer size. We model this problem as a Markov Decision problem where the goal is to find the optimal matching control, that is, how to match items so as to minimize the cost of the system. We study the derived optimal control problem for the discounted cost and the average cost problems. In both cases, we fully characterize the optimal policy in a wide range of matching models. For a complete graph, the optimal policy consists of matching all items. For the N -shaped matching graph, we show that there exists an optimal policy that is of threshold type for the diagonal edge with priority to the end edges of the matching graph. We also fully characterize the optimal threshold for the average cost problem. Then, we show that, under some assumptions in the costs of the nodes, this threshold-based structure of the optimal matching policy extends to more complex models such as a complete graph minus one edge. In an arbitrary acyclic graph, we show that, when the cost of the extreme nodes is larger or equal than the cost of its neighbor nodes, the optimal policy always matches all in the extreme edges. Finally, we investigate the W -shaped matching model. For this case, we conjecture that the optimal matching policy is also of threshold type with priority to the extreme edges when the cost of the extreme nodes is large and we provide numerical evidence that, when the cost of the middle node is large, the optimal matching control does not prioritize the extreme edges. Therefore, the optimal matching control seems to depend on the cost of the nodes for the W -shaped matching model.

The characterization of the optimal matching policy in an arbitrary bipartite matching graph remains as an open question. For future work, it would be interesting to prove our conjecture of the optimal matching policy on the W -shaped matching graph when the cost of the extreme nodes is large and characterize the optimal policy when the cost of the intermediate node is large. We believe that this result will allow us to characterize the optimal matching policy of more complex matching graphs, such as of graphs that can be projected on W -shaped graphs or of an arbitrary acyclic graph. Another possible future research is the study of the optimal matching policy for general (nonbipartite) graphs. In this case, items arrive one by one to the system and there are not two different sets of nodes. In spite of these differences with respect to bipartite matching graphs, we think that the techniques applied in this article can be used to characterize the optimal matching policy for non-bipartite matching graphs.

-If a = e (1,1) or a = e (2,2) . Suppose that k t (e (1,2) ) = 0. Then,

L θ v(0, a) -L θ v(e (2,1) , a) = c(a) -c(a + e (2,1) ) + θE[v(0, A) -v(e (2,1) , A)] ≤ c(a + e (1,2) ) -c(a) + θE[v(e (1,2) , A) -v(0, A)] = L θ v(e (1,2) , a) -L θ v(0, a) because c ∈ B and v ∈ B. Suppose now that k t (e (1,2) ) > 0. Then, L θ v(0, a) -L θ v(e (2,1) , a) = c(a) -c(a + e (2,1) ) + θE[v(0, A) -v(e (2,1) , A)] ≤ c(a) -c(a + e (2,1) ) ≤ c(a + e (1,2) ) -c(a) + θE[v(0, A) -v(0, A)] = L θ v(e (1,2) , a) -L θ v(0, a) because v ∈ I (2,1) and c ∈ B. -If a = e (1,2) . Suppose that k t (2e (1,2) ) = 0. Then, L θ v(0, a) -L θ v(e (2,1) , a) = c(a) -c(a + e (2,1) ) + θE[v(e (1,2) , A) -v(0, A)] ≤ c(a + e (1,2) ) -c(a) + θE[v(2e (1,2) , A) -v(e (1,2) , A)] = L θ v(e (1,2) , a) -L θ v(0, a) because c ∈ B and v ∈ C (1,2) . Suppose now that k t (2e (1,2) ) > 0 and k t (e (1,2) ) = 0. Then, L θ v(0, a) -L θ v(e (2,1) , a) = c(a) -c(a + e (2,1) ) + θE[v(e (1,2) , A) -v(0, A)] = c(a) -c(a + e (2,1) ) + L θ v(0, a) -L θ ua+e (1,2) v(0, a) ≤ c(a) -c(a + e (2,
) + θE[v(0, A) -v(0, A)] ≤ c(a + e (1,2) ) -c(a) + θE[v(0, A) -v(0, A)] = L θ v(e (1,2) , a) -L θ v(0, a) because c ∈ B. -If x = e (2,1) . Then, L θ v(0, a) -L θ v(e (2,1) , a) = c(a) -c(a + e (2,1) ) + θE[v(e (2,1) , A) -v(2e (2,1) , A)] ≤ c(a + e (1,2) ) -c(a) + θE[v(0, A) -v(e (2,1) , A)] = L θ v(e (1,2) , a) -L θ v(0, a) because c ∈ B and v ∈ C (2,1) . A.2 Preservation of C (2,1)
Proof Let a ∈ A and q ∈ Q such that q s1 ≥ q d1 , x = q + a. We define q = q + e (2,1) , x = q + a, q = q + e (2,1) and x = q + a. Since v is convex in (2, 1), we have v(q, a) -v(q, a) ≤ v(q, a) -v(q, a) (this inequality also holds for the cost function c because of Assumption 1). We aim to show that L θ v(q, a) -L θ v(q, a) ≤ L θ v(q, a) -L θ v(q, a). For y ∈ x, x, x , let u y ∈ arg min u L θ u v(y). From Proposition 3, we can choose u y such that u y = min(y d1 , y s1 )e (1,1) + min(y d2 , y s2 )e (2,2) + k t (y)e [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . Let us also define m = x -u x . We can distinguish 2 cases: (a) q s1 ≥ q d1 + 1 or a ∈ A \ {e (1,2) } and (b) q s1 = q d1 and a = e (1,2) :

(a) If q s1 ≥ q d1 + 1 or a ∈ A \ {e (1,2) }. Then, L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m + e (2,1) , A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m + 2e (2,1) , A) -v(m + e (2,1) , A)] = L θ v(q, a) -L θ v(q, a) because c ∈ C (2,1) and v ∈ C (2,1) . (b) If q s1 =
q d1 and a = e (1,2) . Suppose that k t (x) = 0. Then,

L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m -e (1,2) , A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m -e (1,2) + e (2,1) , A) -v(m -e (1,2) , A)] = L θ v(q, a) -L θ v(q, a)
because c ∈ C (2,1) and v ∈ B. Suppose now that k t (x) > 0. Then, 2) . Let us look at the Markov chain derived from this policy. The set of possible states (except for Y 0 ) is

L θ v(q, a) -L θ v(q, a) = c(x) -c(x) + θE[v(m + e (2,1) , A) -v(m, A)] ≤ c(x) -c(x) + θE[v(m + 2e (2,1) , A) -v(m + e (2,1) , A)] = L θ v(q, a) -L θ v(q, a) because c ∈ C (2,1) and v ∈ C (2,1) . B Proof of Proposition 4 Proof Let u ∞ t ∈ Π T (1,
S A = {(s i , a) : i ∈ N, a ∈ A} with s i = (t -i, 0, 0, t -i) if i ≤ t (0, i -t, i -t, 0)
The s i are all possible states after the matchings (using u ∞ t ). In order to see more clearly the behavior of the Markov chain, we group some states together. Fig. 8 The graph associated to the Markov chain derived from u ∞ t and defined on the state space S. pe

S 0 • • • St S t+1 • • • pe (1,
(1,1) = αβ, pe (2,2) = (1 -α)(1 -β), pe (1,2) = α(1 -β) and pe (2,1) = β(1 -α).
Let us define S = {S i : i ∈ N} with S 0 = {(s 0 , e (1,2) ), (s 0 , e (1,1) ), (s 0 , e (2,2) ), (s 1 , e (1,2) )} and S i = {(s i-1 , e (2,1) ), (s i , e (1,1) ), (s i , e (2,2) ), (s i+1 , e (1,2) )} for all i ∈ N * . Figure 8 shows that this Markov chain defined on S is clearly irreducible.

The detailed balance equations are the following:

β(1 -α)π Si = α(1 -β)π Si+1 i = 0, 1, . . .
Solving these equations under the constraint that ∞ i=0 π Si = 1 give:

π Si = ρ i (1 -ρ) i = 0, 1, . . . (13)
with ρ = β(1-α) α(1-β) ∈ (0, 1). So [START_REF] Mairesse | Stability of the stochastic matching model[END_REF] is the stationary distribution of our Markov chain (on S) and the latter is positive recurrent. Using these results, we can derive caracteristics of the Markov chain on S A . First of all, it is irreducible too because of the irreducibility of the chain on S and the fact that within a group S i , there exists a path from each state to each other states either by looping in the group S i or by going to a neighboor (S i-1 or S i+1 ) and coming back to the initial group S i . Then, since the arrival process is independant of the state and because we must have π Si = π (si-1,e (2,1) ) + π (si,e (1,1) ) + π (si,e (2,2) ) + π (si+1,e (1,2) ) , we can think of the following as the stationary distribution: π (si,a) = ρ i (1 -ρ)p a [START_REF] Manshadi | Online stochastic matching: Online actions based on offline statistics[END_REF] with p a as defined in Figure 8 Therefore, ( 14) is the stationary distribution of the Markov chain derived from the policy u ∞ t and the latter is positive recurrent. Using the monotone convergence theorem and the strong law of large number for Markov chains, we can compute the average cost g u ∞ t :

g u ∞ t (y) = lim N →∞ 1 N N -1 n=0 E u ∞ t y [c(Y (n))] = E π [c(Y )]
where E π means the expectation over the stationary distribution π defined as [START_REF] Manshadi | Online stochastic matching: Online actions based on offline statistics[END_REF]. Finally, we can compute this value:

+ (c d2 + c s2 )ρ t+i (1 -ρ)(1 -α) (15)
It is easy to see that, for any c, the following properties hold:

t i=1 c • i • ρ t-i = c t -ρ 1-ρ t 1-ρ and i∈N c•i•ρ t-i = c ρ t+1
1-ρ .Also, for any c and q, we have that q

• c • (1 -ρ) t i=1 ρ t-i = q • c • (1 -ρ t ) and q • c • (1 -ρ) i∈N ρ t+i = q • c • ρ t .
Proof Let w(ρ, R) = 1 log ρ log ρ-1 (R+1) log ρ . We compute the derivative of w with respect to ρ and we obtain ∂w ∂ρ = -1/ρ (log ρ) 2 log ρ -1 (R + 1) log ρ We now observe that when ρ → 1, it follows that B 1 (ρ, R) = log 1/(R + 1) -1 + 1, which is negative since R ≥ 0 (note that the costs are assumed to be all positive). As a result, (17) holds if B 1 (ρ, R) is increasing with ρ, with From the previous result, it follows that the smallest value of k is given when ρ → 0. In the following result, we give the value of f (ρ, R) when tends ρ → 0. From this result, we have that the smallest value of k is -1. Therefore, if f (-1) < f (0), where f is defined as in Proposition 4, t * gets negative values. In the following result, we show that this condition is never satisfied. From this expressions, it follows that f (0) < f (-1) if and only if

(c d1 + c d2 + c s1 + c s2 ) ρ 1 -ρ -(c d1 + c s2 ) ρ 1 -ρ < -(c d1 + c s2 ) + (c d1 + c d2 + c s1 + c s2 ) 1 1 -ρ - (c d1 + c s2 )ρ 1 -ρ
note that x n-1 = xn-1 because â1 = a 1 , • • • , ân-1 = a n-1 and they both follow the same dynamics under the same policy π. Then, )) = a N for all a N ∈ A N ). Thus,

p N Q (q n ) =   i∈D(j * ) (q n ) di , (q n ) d i * , (q n ) s j * ,
p N Q (x n ) = p N Q (q n ) + p N A (a n ) = q N n + a N n = x N n .

Theorem 1 [ 11 ,

 111 Theorem 1] Assume that the following properties hold: there exists positive function w on Y such that sup y |y, u)w(y ) < +∞,

y

  P π (y |y)w(y ) ≤ y P π0 (y |y)w(y ) = w(y) + 2J.

Fig. 7 W

 7 Fig. 7 W-shaped model. Average cost of our conjecture and a similar policy but with a priority in (2, 2) instead of (3, 2).

  1) ) ≤ c(a + e (1,2) ) -c(a) + θE[v(e (1,2) , A) -v(e (1,2) , A)] = L θ v(e (1,2) , a) -L θ v(0, a) because c ∈ B. Finally, suppose that k t (2e (1,2) ) > 0 and k t (e (1,2) ) > 0. Then, L θ v(0, a) -L θ v(e (2,1) , a) = c(a) -c(a + e (2,1)

  (i.e p e (1,1) = αβ, p e (2,2) = (1 -α)(1 -β), p e (1,2) = α(1 -β) and p e (2,1) = β(1 -α)), for all i ∈ N and a ∈ A. Let us verify that (14) is indeed a stationary distribution: k∈N a∈A π (s k ,a) p((s k , a), (s i , a )) = p a (π (si-1,e (2,1) ) + π (si,e (1,1) ) + π (si,e (2,2) )+ π (si+1,e (1,2) ) ) = p a (ρ i-1 (1 -ρ)p e (2,1) + ρ i (1 -ρ)p e (1,1) + ρ i (1 -ρ)p e (2,2) + ρ i+1 (1 -ρ)p e (1,2) ) = p a ρ i (1 -ρ)( β(1 -α) ρ + αβ + (1 -α)(1 -β) + ρα(1 -β)) = p a ρ i (1 -ρ) = π (si,a ) i∈N a∈A π (si,a) = i∈N ρ i (1 -ρ) a∈A p a = i∈N ρ i (1 -ρ) = 1

  t-i + a)π (st-i,a) + i∈N a∈A c(s t+i + a)π (st+i,a) d1 + c s2 )i + c d1 + c s1 )ρ t-i (1 -ρ)αβ + ((c d1 + c s2 )i + c d2 + c s1 )ρ t-i (1 -ρ)(1 -α)β + ((c d1 + c s2 )i + c d1 + c s2 )ρ t-i (1 -ρ)α(1 -β) + ((c d1 + c s2 )i + c d2 + c s2 )ρ t-i (1 -ρ)(1 -α)(1 -β) + i∈N ((c d2 + c s1 )i + c d1 + c s1 )ρ t+i (1 -ρ)αβ + ((c d2 + c s1 )i + c d2 + c s1 )ρ t+i (1 -ρ)(1 -α)β + ((c d2 + c s1 )i + c d1 + c s2 )ρ t+i (1 -ρ)α(1 -β) + ((c d2 + c s1 )i + c d2 + c s2 )ρ t+i (1 -ρ)(1 -α)(1 -β) = t i=1 (c d1 + c s2 )iρ t-i (1 -ρ) + (c d1 + c s1 )ρ t-i (1 -ρ)αβ + (c d2 + c s1 )ρ t-i (1 -ρ)(1 -α)β + (c d1 + c s2 )ρ t-i (1 -ρ)α(1 -β) + (c d2 + c s2 )ρ t-i (1 -ρ)(1 -α)(1 -β) + i∈N (c d2 + c s1 )iρ t+i (1 -ρ) + (c d2 + c s1 )ρ t+i (1 -ρ)αβ + (c d2 + c s1 )ρ t+i (1 -ρ)(1 -α)β + (c d2 + c s1 )ρ t+i (1 -ρ)α(1 -β)

1 = 1 =Let B 1 1 (

 1111 + 1) log ρ -(R + 1)(ρ -1) + 1) log ρ -(R + 1) R + -1/ρ (log ρ) 2 log ρ -1 (R + 1) log ρ -ρ log ρ -(ρ -1) ρ -(ρ, R) = log ρ-R+1) log ρ -ρ log ρ ρ-1 +1. We now study the value of B 1 (ρ, R) when ρ → 1. First, we use L'Hopital's rule to prove the following properties:

Lemma 12

 12 We have thatlim ρ→0 w(ρ, R) = 0.Proof We aim to compute the value of

log ρ- 1 (ρ

 1 R+1) log ρ log ρ when ρ → 0. Since the numerator and the denominator of this expression tend to log 0 when ρ → 0, we use L'Hopital's rule as followslim log ρ -1 ρ (ρ -1) (R + 1)(log ρ) 2 = lim ρ→0 ρ (R + 1) log ρ -ρ -1 (R + 1) log ρ ,and both terms tend to zero when ρ → 0.

Lemma 13

 13 Let f (•) as defined in Proposition 4. For all ρ ∈ (0, 1), f (-1) > f (0).Proof To show this result, we first compute the value of f (0) and of f (1).f (0) = (c d1 + c d2 + c s1 + c s2 ) ρ 1 -ρ -(c d1 + c s2 ) ρ 1 -ρ + ((c d1 + c s1 )αβ + (c d2 + c s2 )(1 -α)(1 -β) + (c d2 + c s1 )(1 -α)β + (c d1 + c s2 )α(1 -β)) f (-1) = -(c d1 + c s2 ) + c d1 + c d2 + c s1 + c s2 1 -ρ -(c d1 + c s2 ) ρ 1 -ρ + ((c d1 + c s1 )αβ + (c d2 + c s2 )(1 -α)(1 -β) + (c d2 + c s1 )(1 -α)β + (c d1 + c s2 )α(1 -β))

  * ) (x n-1 -u(x n-1 )) di , (x n-1 -u(x n-1 )) d i * , (x n-1 -u(x n-1 )) s j * , j∈S(i * ) (x n-1 -u(x n-1 )) sj * ) (x n-1 ) di -j∈S(i) u(x n-1 ) (i,j) , (x n-1 ) d i * -j∈S(i * ) u(x n-1 ) (i * ,j) , (x n-1 ) s j * -i∈D(j * ) u(x n-1 ) (i,j * ) , j∈S(i * ) (x n-1 ) sj -i∈D(j) u(x n-1 ) (i,j)   = p N Q (x n-1 ) -i∈D(j * ) u(x n-1 ) (i,j * ) e (1,1) -j∈S(i * ) u(x n-1 ) (i * ,j) e (2,2) -i∈D(j * ) j∈S(i * ) u(x n-1 ) (i,j) e (1,2) = p N Q (x n-1 ) -i∈D(j * ) u(x n-1 ) (i,j * ) e (1,1) -j∈S(i * ) u(x n-1 ) (i * ,j) e (2,2) -i∈D(j * ) j∈S(i * ) u(x n-1 ) (i,j) e (1,2) = p N Q (x n-1 ) -(u N n ) (1,1) e (1,1) -(u N n ) (2,2) e (2,2) -(u N n ) (1,2) e (1,2) = x N n-1 -u N n = q N n and p N A (a n ) = a N n (because p N A ((p N A ) -1 (a N

  to the vector of the items that are matched at time n. Thus, Y is a Markov Decision Process where the control is denoted by u. It is sufficient to consider only deterministic Markovian decision rules and not all history-dependent randomized decision rules as proved in[START_REF] Puterman | Markov decision processes: discrete stochastic dynamic programming[END_REF] Theorem 5.5.3] and[START_REF] Puterman | Markov decision processes: discrete stochastic dynamic programming[END_REF] Proposition 6.2.1]. Let us define X

  . Let 0 ≤ θ ≤ 1. There exists u * ∈ U x such that u * is a matching policy of threshold type in (2, 1) and (2, 2) with priority to (1, 1) and (3, 2) (as defined in Definition 11) and u * ∈ arg min u∈Ux L θ u v(x). In particular, this result holds for the average operator:L 1 u = T u .Proof The idea of the proof is similar to the one of Proposition 3. However, you have to use the property H (2,1),[START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] to handle (3, 1) left over items when defining the threshold in (2, 1) and you have to use the property H (2,2),[START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]

	and (3, 2) that minimizes L θ u v.
	Proposition 7 Let v ∈ I (1,1) ∩I (3,2) ∩U (1,1) ∩U (3,2) ∩C (2,1) ∩C (2,2) ∩H (2,1),(3,1) ∩
	H (2,2),(1,2) ∩ M (2,1),(2,2)

Acknowledgements Funding from the French National Research Agency grant ANR-16-CE05-0008, the Marie Sklodowska-Curie grant agreement No 777778, the Basque Government, Spain, Consolidated Research Group Grant IT649-13, and the Spanish Ministry of Economy and Competitiveness project MTM2016-76329-R. y indicates that the expectation is over the arrival process, given that Y (0) = y

Finally, we prove that a decision rule of threshold type in [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] with priority to [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF] and [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] is optimal. This is done by choosing the right t for different cases such that k t (x) is the optimal number of matchings in (1, 2) for a given x.

Proposition 3 Let v ∈ I (1,1) ∩ I (2,2) ∩ I (2,1) ∩ C [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . Let 0 ≤ θ ≤ 1. For any q ∈ Q and for any a ∈ A, x = q + a, there exists u * ∈ D σ (see Definition 5) such that u * ∈ arg min u∈Ux L θ u v(q, a). In particular, this result holds for the average operator: T u .

Proof Let q ∈ Q, a ∈ A, x = q + a and u ∈ U x . We note m (1,1) = min(x s1 , x d1 ) and m (2,2) = min(x s2 , x d2 ). We assumed that v ∈ I (1,1) ∩ I (2,2) ∩ I (2,1) , so we can use Proposition 2 : ∃u ∈ U x such that L θ u v(q, a) ≤ L θ u v(q, a) and u = m (1,1) e (1,1) + m (2,2) e (2,2) + ke [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] with k ∈ K x . We now have to prove that there exists t ∈ N ∪ ∞ such that L θ u * v(q, a) ≤ L θ u v(q, a), ∀k ∈ K x [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF] where u * ∈ D σ (see Definition 5). If x s1 ≥ x d1 , then K x = 0 and we have u * = u which satisfies [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF]. Otherwise, x s1 < x d1 and K x = {0}. Therefore, the state of the system after having matched u (or u * ), i.e x -u (or x -u * ), is of the form (l, 0, 0, l). So when we compare L θ u * v(q, a) with L θ u v(q, a), this comes down to comparing E[v(j * e (1,2) , A)] with E[v(j e (1,2) , A)] (j * , j ∈ K x ).

First of all, suppose that ∀j ∈ N, E[v((j + 1)e (1,2) , A)] -E[v(je (1,2) , A)] ≤ 0. We choose t = ∞, so k t (x) = 0 and u * = m (1,1) e (1,1) + m (2,2) e [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . By assumption, we have

) for all k ∈ K x and because u * + ke (1,2) = u , we have proven [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF].

Then, suppose that [START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . By assumption and because v is convex in (1, 2), we have

for all k ∈ K x and because u * -(x d1 -x s1 -k)e (1,2) = u (with x d1 -x s1 -k ∈ K x for all k ∈ K x ), we have proven [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF].

. By definition of j and by convexity of v in (1, 2), we have

and

We choose t = j. If x d1 -x s1 ≤ j, then we have k t (x) = 0 and

) by ( 8) if k ≥ j or by ( 9) if k ≤ j, which proves [START_REF] Cadas | Optimal control of dynamic bipartite matching models[END_REF].

We define

We now define

We assume that u

and, taking into account [START_REF] Hyon | Scheduling services in a queuing system with impatience and setup costs[END_REF], it follows that

which holds for any u ∈ U x and therefore also for u ∈ arg min L θ v(q, a). As a result, u * ∈ arg min L θ v(q, a). Besides, for any extreme edge (i k , j k ), we have that

and the desired result follows if we show that u , u * ∈ U x .

-We aim to show that u ∈ U x . To prove this, we only need to show that, for any u ∈ U x and any k ∈ {1, . . . , m}, u 0 ∈ U x where

p i,j e (i,j) .

We start by showing that u 0 ∈ N n D +n S . First, (u 0 ) (i k ,j k ) ≥ 0 because u ∈ U x and p k ≥ 0. Then, for all (i, j) ∈ N ((i k , j k )), we have u (i,j) ≥ p i,j by definition. Thus, it follows that (u 0 ) (i,j) ≥ 0. Now, we show (a) and (b) assuming that d i k is of degree one (the proof for the case that s j k is of degree one is symmetric and therefore we omitted it). We first show (a) for d i k as follows:

2) , a)v(0, a) (this inequality also holds for the cost function c because of Assumption 1). We aim to show that

We are going to show the preservation for each possible value of a:

Using these properties in [START_REF] Nazari | Reward maximization in general dynamic matching systems[END_REF], we obtain that

We aim to obtain the value of t that minimize (16). Thus, we show that ( 16) is convex in t since its second derivative with respect to a t is positive:

which positive for ρ ∈ (0, 1). Hence, the minimum of ( 16) is given when its derivative with respect to t is equal to zero:

. The root of the previous equation is

Since this value is not necessarily integer, the optimal threshold t * is obtained in the minimum of (16) between the ceil and the floor.

We now aim to show that t * is always positive. First, we show that the value of k, as defined in the previous result, is increasing with ρ.

R+1) log ρ is increasing with ρ, where ρ ∈ (0, 1). ρ ∈ (0, 1). We compute the derivative of B 1 (ρ, R) with respect to ρ.

And the last expression is positive for ρ ∈ (0, 1) if and only if -(ρ -1) 2 /ρ + (log ρ) 2 < 0. Furthermore, since (ρ -1)/ρ and log ρ are negative when ρ ∈ (0, 1), we have that

From the previous reasoning, the desired result follows if B 2 (ρ, R) > 0. We now observe that B 2 (ρ, R) tends to zero when ρ → 1. Therefore, to show that B 2 (ρ, R) is positive it is enough to prove that it is decreasing with ρ, where ρ ∈ (0, 1). We now calculate the derivative of B 2 (ρ, R) with respect to ρ.

which is always negative and the proof ends. This is equivalent to show that

where the last expression always holds for positive values of the costs and the proof ends.

From the last three lemmas, we conclude that the value of the threshold t * of the optimal matching policy is positive.

C Proof of Lemma 8

Proof Let 0 ≤ θ < 1, let π be a stationary policy on Y , y 0 = (q 0 , a 0 ) ∈ Q × A and y N 0 = (p N Q (q 0 ), p N A (a 0 )). We start by constructing a history dependent policy π N = (u N n ) n≥0 on Y N that will make Y N "follow" (in some sense) the projection of Y on G N . First, let us introduce new independent random variables Â(n) that we sample just after the arrivals on G N . Â(n) is defined on A with the following distribution: ∀n ∈ N * , ∀a ∈ A, ∀a N ∈ A N ,

Otherwise .

Then, we define u N n the decision rule of π N at time n based on the history of the trajectory, i.e (A N (1), Â(1),

, the initial state y 0 = (q 0 , a 0 ) and the stationary policy π. Let xn ∈ Q be the state we end up by starting in x 0 = q 0 +a 0 and following the dynamics (2) with the sequence of arrivals âN 1 , • • • , âN n and under the policy π. Let u ∈ U xn be the decision rule applied for the state xn under the policy π. We construct u

Now, let us show by induction that, under π N , we have

We already specifically chose y N 0 to verify this property:

Then, using this property and Assumption 2, we have

This equality is true for any n ∈ N. Therefore, v π θ (y 0 ) = v π N θ (y N 0 ) and g π (y 0 ) = g π N (y N 0 ).

D Proof of Proposition 7

Proof Let a ∈ A, q ∈ Q, x = q+a and u ∈ U x . First of all, we need to introduce some notations. Let m (1,1) = min(x s1 , x d1 ) (resp. m (3,2) = min(x s2 , x d3 )) be the maximal number of matchings that can be done in (1, 1) (resp. (3, 2)). Let

be the set of possible matching in (2, 1) after having matched every possible (1, 1) and (3, 2). Let

be the set of possible matching in (2, 2) after having matched every possible (1, 1) and [START_REF] Ashlagi | Kidney exchange in dynamic sparse heterogenous pools[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. We can note that K x does not depend on the number of matchings in (2, 2). Indeed, if x s1 ≥ x d1 and x s2 ≥ x d3 , then x d2 = x s1 -x d1 + x s2 -x d3 because x ∈ Q, thus min(x s1 -x d1 , x d2 ) = x s1 -x d1 which can not be modified by any matching in [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. If x s1 ≥ x d1 and x s2 ≤ x d3 , then no matchings can be made in (2, 2) (J x = {0}). If x s1 ≤ x d1 , then no matchings can be made in (2, 1) (K x = {0}) and this can not be changed with matchings in [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF]. A symmetric argument can be made to show that J x does not depend on the number of matchings in [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF].

We assumed that v ∈ I (1,1) ∩ I (3,2) ∩ U (1,1) ∩ U (3,2) , so we can use Proposition 6 : ∃u ∈ U x such that L θ u v(q, a) ≤ L θ u v(q, a) and u = m (1,1) e (1,1) + m (3,2) e (3,2) + ke (2,1) + je (2,2) with k ∈ K x , j ∈ J x . We now have to prove that there exists

where u * is defined as in Definition 11. Let us first define the threshold in (2, 1) as

0} (with the convention that min{∅} = ∞). Then, given x, there are four cases:

1. x s1 = x d1 and x s2 = x d3 . In that case K x = {0} and J x = {0}, k t (2,1) = 0 and j t (2,2) = 0. Thus we have u * = u . 2. x s1 > x d1 and x s2 > x d3 . In that case, we have x d2 = x s1 -x d1 +x s2 -x d3 . So the number of matchings in (2, 1) ((2, 2)) for u * is exactly k t (2,1) (j t (2,2) ). We define [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . This means that

Suppose now that k > k t (2,1) (x) (this is only possible if t (2,1) > 0), then by definition of t (2,1) and convexity in (2, 1) (v ∈ C (2,1) ) we have: [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] which means that

Thus, we showed that L θ u 2 v(x) ≤ L θ u v(x) for any k ∈ K x and any j ∈ J x . Now, let us compare u 2 and u * . We can do a similar proof as we just did but with (2, 2) instead of [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Exact fcfs matching rates for two infinite multitype sequences[END_REF]. Suppose that j < j t (2,2) (x) (this is only possible if j t (2,2) (x) = x s2 -x d3 -t (2,2) > 0), then by definition of t (2,2) and convexity in [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] . This means that

Suppose now that j > j t (2,2) (x) (this is only possible if t (2,2) > 0), then by definition of t (2,2) and convexity in (2, 2) (v ∈ C (2,2) ) we have: 1) v(q, a) -L θ u * +(p+1)e (2,2) -kt (2,1) e (2,1) v(q, a) ≤ 0 [START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF][START_REF] Adan | Reversibility and further properties of FCFS infinite bipartite matching[END_REF] which means that

Thus, we showed that L θ u * v(q, a) ≤ L θ u 2 v(q, a) ≤ L θ u v(q, a) for any k ∈ K x and any j ∈ J x .

3. x s1 ≥ x d1 and x s2 ≤ x d3 . In that case, we have J x = {0} and j t (2,2) = 0.

If x s1 = x d1 , then K x = {0} and k t (2,1) = 0. Thus, we have u * = u . Otherwise, suppose that k < min{k t (2,1) (x), x d2 } (this is only possible if k t (2,1) (x) = x s1 -x d1 -t (2,1) > 0 and x d2 > 0), then by definition of t (2,1) and because v ∈ C (2,1) ∩ H (2,1),(3,1) , we have:

Thus, we showed that L θ u * v(q, a) ≤ L θ u v(q, a) for any k ∈ K x and any j ∈ J x . 4. x s1 ≤ x d1 and x s2 ≥ x d3 . In that case, we have K x = {0} and k t (2,1) = 0.

If x s2 = x d3 , then J x = {0} and j t (2,2) = 0. Thus, we have u * = u . Otherwise, suppose that j < min{j t (2,2) (x), x d2 } (this is only possible if j t (2,2) (x) = x s2 -x d3 -t (2,2) > 0 and x d2 > 0), then by definition of t (2,2) and because v ∈ C (2,2) ∩ H (2,2),(1,2) , we have: ∀p ∈ {0, •

2) v(q, a) ≤ L θ u v(q, a)

Thus, we showed that L θ u * v(q, a) ≤ L θ u v(q, a) for any k ∈ K x and any j ∈ J x .