Pass-and-swap queues

Order-independent (OI) queues, introduced by Berezner, Kriel, and Krzesinski in 1995, expanded the family of multi-class queues that are known to have a product-form stationary distribution by allowing for intricate class-dependent service rates. This paper further broadens this family by introducing pass-and-swap (P&S) queues, an extension of OI queues where any customer that completes service is not necessarily the customer that leaves the system. More precisely, we supplement the OI queue model with an undirected graph on the customer classes, which we call a swapping graph, such that there is an edge between two classes if customers of these classes can be swapped with one another. When a customer completes service, it passes over customers in the remainder of the queue until it finds a customer it can swap position with, that is, a customer whose class is a neighbor in the graph. In its turn, the customer that is ejected from its position takes the position of the next customer it can swap with, and so on. This is repeated until a customer cannot find another customer to be swapped with anymore; this customer is the one that leaves the queue. After proving that P&S queues have a product-form stationary distribution, we derive a necessary and sufficient stability condition for (open networks of) P&S queues that also applies to OI queues. We then study irreducibility properties of closed networks of P&S queues and derive the corresponding product-form stationary distribution. Lastly, we demonstrate that closed networks of P&S queues can be applied to describe the dynamics of new and existing load-distribution and scheduling algorithms in machine pools.


Introduction
Since the pioneering work of Jackson [17] in the 1950s, queueing networks with a product-form stationary distribution have played a central role in the development of queueing theory [26,10]. In general, we say that the stationary distribution of a network has a product form if it can be written as the product of the stationary distributions of the queues that compose this network. Further examination of queueing networks with this property led to several breakthroughs, such as the discovery of BCMP [6] and Kelly [19] networks, which demonstrated the broad applicability of product-form queueing networks. In addition to implying statistical independence of the queues, this product-form property is appealing for its potential for further performance analysis. As a result, several methods for efficient performance analysis, such as Buzen's algorithm [11] and the mean-value-analysis algorithm [25], were developed.
In a product-form queueing network, the notion of product form is also often present on the level of an individual queue in the sense that, aside from the normalization constant, the stationary distribution of each queue is a product of factors, each of which corresponds to a customer in the queue [27]. Dedicated paper.

Definition
We consider a multi-class queue with a finite set I = {1, . . . , I} of customer classes. For each i ∈ I, class-i customers enter the queue according to an independent Poisson process with intensity λ i > 0. Customers are queued in their arrival order, with the oldest customer at the head of the queue, and are identified by their class. For now, we assume that the queue has an infinite capacity and that each customer leaves the queue immediately upon service completion.
Microstate and macrostate We consider two state descriptors of this multi-class queue. The queue microstate represents the classes of customers in the queue in their arrival order. More specifically, a microstate c ∈ I * has the form c = (c 1 , . . . , c n ), where n is the total number of customers in the queue and c p is the class of the p-th oldest customer, for each p ∈ {1, . . . , n}. In particular, c 1 is the class of the oldest customer, at the head of the queue. The empty microstate, with n = 0, is denoted by ∅. The set I * represents all possible microstates and I n represents the subset of I * consisting of all microstates with exactly n customers present, for each n ∈ N. To each microstate c ∈ I * , we associate a macrostate |c| = (|c| 1 , . . . , |c| I ) ∈ N I that only retains the number of present customers of each class, and does not keep track of their order in the queue. As a result, for each c ∈ I * and each i ∈ I, the integer |c| i gives the number of class-i customers in microstate c. For each x, y ∈ N I , we write x ≤ y if x i ≤ y i for each i ∈ I.
Service rates We now explain the way in which service is provided to customers in an OI queue. This is done in such a way that the evolution of the microstate of the queue over time exhibits a memoryless property (and thus represents a Markov process). More particularly, the overall service rate in microstate c is denoted by µ(c), for each c ∈ I * . This function µ, defined on I * , is called the rate function of the queue. Along with the individual rates of service provided to the customers in the queue, it satisfies the following two conditions. First, the overall rate of service µ(c) provided when the queue is in microstate c depends only on the number of customers of each class that are present and not on their arrival order. In other words, for each c, d ∈ I * , we have µ(c) = µ(d) whenever |c| = |d|. For this reason, we shall also refer to µ(c) as µ(x) when x is the macrostate corresponding to microstate c. Second, the service rate of each customer is independent of (the number and classes of the) customers that are behind this customer in the queue. In particular, for each c = (c 1 , . . . , c n ) ∈ I * and p ∈ {1, . . . , n}, the service rate of the customer in position p in microstate c, of class c p , is equal to the increment of the overall service rate induced by the arrival of this customer, denoted by ∆µ(c 1 , . . . , c p ) = µ(c 1 , . . . , c p ) − µ(c 1 , . . . , c p−1 ), where we use the convention that (c 1 , . . . , c p−1 ) = ∅ when p = 0. This implies in particular that the function µ is non-decreasing, in the sense that µ(c 1 , . . . , c n , i) ≥ µ(c 1 , . . . , c n ), ∀c = (c 1 , . . . , c n ) ∈ I * , ∀i ∈ I.
The service rate of the first p customers in the queue, given by µ(c 1 , . . . , c p ) = p q=1 ∆µ(c 1 , . . . , c q ), depends neither on the classes of the customers in positions p + 1 to n nor even on the total number n of customers in the queue.
We set µ(∅) = 0 since the queue exhibits a zero departure rate when there are no customers in the queue. We additionally assume that µ(c) > 0 for each c = ∅. In other words, we assume that the oldest customer always receives a positive service rate, to ensure irreducibility of the Markov process describing the evolution of the microstate over time.
Remark 2.1. The definition of OI queues that we presented above is slightly more restrictive than that of [7,20]. Indeed, in these two papers, the overall service rate function µ is scaled by a factor that depends on the total number of customers in the queue, while we assume this scaling factor to be equal to one. We omit this scaling factor for simplicity of notation. However, unless stated otherwise, the results in the sequel of this paper can be straightforwardly generalized to account for this factor.
Examples As observed in [7,20], the framework of OI queues encompasses several classical queueing models, such as the first-come-first-served (FCFS), infinite-server, and processor-sharing queues of BCMP networks [6], multiserver stations with concurrent classes of customers (MSCCC) [22], and multiserver centers with hierarchical concurrency constraints (MSHCC) [21]. In this paper, we will be especially interested in the following multi-server queues, introduced in [16] and identified as OI queues in [9].
Example 2.2 (Multi-server queue). Consider an infinite-capacity queue with a set I = {1, . . . , I} of customer classes and a set S = {1, . . . , S} of servers. All customers have an exponentially-distributed size with unit mean and, for each i ∈ I, class-i customers enter the queue according to a Poisson process with rate λ i > 0 and can be processed by the servers of the set S i ⊆ S. This defines a bipartite compatibility graph between customer classes and servers, in which there is an edge between a class and a server if this server can process customers of this class. In the example of Figure 1a, customers of classes 1 and 2 can only be processed by servers 1 and 2, respectively, while class-3 customers can be served by both servers. In other words, we have   Each server applies the FCFS discipline to the customers it can serve, so that each customer is in service on all the servers that can process this customer but not the customers that arrived earlier in the queue. For each s ∈ S, the service rate of server s is denoted by µ s > 0. When a class-i customer is in service on a subset T ⊆ S i of its compatible servers, its service rate is s∈T µ s . The overall service rate, equal to the sum of the service rates of the servers that can process at least one customer in the queue, is given by One can verify that this multi-server queue is an OI queue. In the example of Figure 1b, the queue microstate is c = (1, 3, 3, 2, 2, 3, 1, 2). The oldest customer, of class 1, is in service on server 1, at rate ∆µ(1) = µ(1) − µ(∅) = µ 1 − 0 = µ 1 . The second oldest customer, of class 3, is in service on server 2, at rate ∆µ(1, 3) = µ(1, 3) − µ(1) = (µ 1 + µ 2 ) − µ 1 = µ 2 . The other customers have a zero service rate. If the oldest class-1 customer completes service, the oldest class-3 customer will be in service on both servers, at rate ∆µ(3) = µ(3) − µ(∅) = (µ 1 + µ 2 ) − 0 = µ 1 + µ 2 , while the other customers will still have a zero service rate.
Example 2.3 (Degenerate multi-server queue). The following example will be useful in Section 6. Consider a multi-server queue in which there is a one-to-one correspondence between classes and servers, in the sense that I = S (so that I = S) and S i = {i} for each i ∈ I. An example with I = S = 2 is shown in Figure 2. For each s ∈ S, server s applies FCFS service policy to the customers of class s, while ignoring the others. Consequently, with s = c p , (2.2) simplifies to ∆µ(c 1 , . . . , c p ) = µ s if |(c 1 , . . . , c p−1 )| s = 0 and ∆µ(c 1 , . . . , c p ) = 0 otherwise. This queue is said to be degenerate because the service rate of one class does not depend on the numbers of customers of other classes in the queue.

Stationary analysis
The evolution of the queue microstate leads to a Markov process with state space I * , and this Markov process is irreducible. Indeed, for any two microstates c = (c 1 , . . . , c n ) ∈ I * and d = (d 1 , . . . , d m ) ∈ I * , the Markov process can first jump from state c to state ∅ as a result of n transitions corresponding to departures of the customer at the head of the queue, and then from state ∅ to state d as a result of m transitions corresponding to customer arrivals. Theorem 2.4 below recalls that this Markov process has a product-form stationary distribution and that the OI queue satisfies the quasi-reversibility property (cf. [18,Section 3.2]). This property implies that, when the Markov process associated with the queue microstate is stationary, the departure instants of the customers of each class form independent and stationary Poisson processes and that, at every instant, the current queue microstate is independent of the departure instants of the customers of each class prior to that instant. Quasi-reversibility also implies that an open network of OI queues connected by a random routing process has a product-form stationary distribution [18,Theorem 3.7] under mild conditions on the routing process (namely, each customer can become part of any given class with a positive probability and eventually leaves the network with probability one). A similar result holds for closed networks of OI queues under some irreducibility assumptions [18,Section 3.4]. The interested reader is referred to [18,Sections 3.2 and 3.4] and [26,Chapter 8] for a more complete account on quasi-reversibility. The proof below can be found in [7,20] but we present it here for ease of later reference when we introduce the P&S queue.
where Φ is the balance function of the OI queue, defined on I * by

4)
and π(∅) is an arbitrary positive constant. The queue is stable if and only if (2.5) in which case the queue is quasi-reversible and the stationary distribution of the Markov process associated with its microstate is given by Proof. We will first verify that any measure π of the form (2.3) satisfies the following partial balance equations in each microstate c = (c 1 , . . . , c n ) ∈ I * : • Equalize the flow out of microstate c due to a departure with the flow into microstate c due to an arrival (if c = ∅): π(c)µ(c) = π(c 1 , . . . , c n−1 )λ cn . (2.7) • Equalize, for each i ∈ I, the flow out of microstate c due to the arrival of a class-i customer with the flow into microstate c due to the departure of a customer of this class: We show that Φ satisfies this equation by induction over the queue length n. For the base step, with n = 0, it suffices to observe that, for each i ∈ I, the right-hand side of (2.9) simplifies to Φ(i)µ(i), which is equal to Φ(∅) by (2.4). Now let n ≥ 1 and assume that (2.9) is satisfied for each c ∈ I n−1 . Let c ∈ I n and i ∈ I. The first n terms in the sum on the right-hand side of (2.9) can be rewritten as follows: where the first and last equalities follow from (2.4) and the order independence of µ, while the second equality is obtained by applying the induction assumption to microstate (c 1 , . . . , c n−1 ) and class i. By (2.4), we also have that Φ(c 1 , . . . , c n , i) ∆µ(c 1 , . . . , c n , i) = Φ(c 1 , . . . , c n ) µ(c 1 , . . . , c n , i) − µ(c 1 , . . . , c n ) µ(c 1 , . . . , c n , i) , (2.11) so that summing (2.10) and (2.11) yields (2.9). This concludes the proof by induction. The stability condition (2.5) is equivalent to the statement that c∈I * π(c)/π(∅) is finite for any stationary measure π, which is indeed necessary and sufficient for ergodicity. Equation (2.6) guarantees that the stationary distribution sums to unity.

Pass-and-swap queues
This section contains our first main contribution. Pass-and-swap (P&S) queues, obtained by supplementing OI queues with an additional mechanism when customers complete service, are defined in Section 3.1. In contrast to signals and negative customers considered for quasi-reversible queues [12], the P&S mechanism occurs upon a service completion and can move several customers at the same time within the queue. Section 3.2 shows that both the product-form nature of the stationary measure of the Markov process associated with the microstate and the quasi-reversibility property of the queue are preserved by this mechanism.

Definition
As before, the set of customer classes is denoted by I = {1, . . . , I} and we adhere to the state descriptors: the microstate c = (c 1 , . . . , c n ) ∈ I * gives the classes of customers as they are ordered in the queue and the macrostate |c| = (|c| 1 , . . . , |c| I ) ∈ N I gives the numbers of customers of each class. Likewise, the customer arrival processes and completion times are as defined in Section 2.1. We however part with the assumption that a customer that completes service leaves the queue directly and that all customers behind move forward one position. With the pass-and-swap mechanism that we will now define, each service completion will potentially trigger a chain reaction within the queue. More precisely, a customer that completes service may take another customer's position further down the queue and require a new round of service in this position. The customer ejected from this position may in turn take the position of another customer further down the queue, and so on. The decision of which customer replaces which other customer is driven by the pass-and-swap mechanism described below.
Pass-and-swap mechanism We supplement the OI queue with a simple graph, that is, an undirected graph without loops or multiple edges. This will be called the swapping graph of the queue. The vertices of this graph represent the customer classes and, for each i, j ∈ I, when there is an edge between class i and class j in the graph, a class-i customer can take the position of a class-j customer upon service completion. In that case, we say that (the customers of) classes i and j are mutually swappable. Observe that the graph is undirected, meaning that the swapping relation is symmetric: if class i can be swapped with class j, then class j can also be swapped with class i. For each i ∈ I, we let I i ⊆ I denote the set of neighbors of class i in the graph, that is, the set of classes that are swappable with class i.
Based on this graph, the pass-and-swap mechanism is defined as follows. A customer whose service is complete scans the rest of the queue, passes over subsequent customers that it cannot swap with, and replaces the first swappable customer, if any. This ejected customer, in turn, scans the rest of the queue and replaces the first swappable customer afterwards. This is repeated until an ejected customer finds no customers in the remainder of the queue it can swap with. In this case, the customer leaves the queue.
More formally, let c = (c 1 , . . . , c n ) ∈ I * denote a queue microstate. Assume that the service of the customer in some position p 1 ∈ {1, . . . , n} completes and let i 1 = c p1 denote the class of this customer. If there is at least one position q ∈ {p 1 + 1, . . . , n} such that c q ∈ I i1 , we let p 2 denote the smallest of these positions and i 2 = c p2 the class of the corresponding customer. The class-i 1 customer that was originally in position p 1 replaces the class-i 2 customer in position p 2 , and this class-i 2 customer is ejected. If there is at least one position q ∈ {p 2 + 1, . . . , n} such that c q ∈ I i2 , we let p 3 denote the smallest of these positions and i 3 = c p3 the class of the corresponding customer. The class-i 2 customer that was originally in position p 2 replaces the class-i 3 customer in position p 3 , and this class-i 3 customer is ejected. Going on like this, we define recursively p v+1 = min{q ≥ p v + 1 : c q ∈ I cp v } for each v ∈ {1, . . . , u − 1}, where p u ∈ {p, . . . , n} is the position of the first ejected customer that cannot replace any other subsequent customer in the queue, that is, for which there is no q ∈ {p u + 1, . . . , n} such that c q ∈ I cp u . This customer is the one that leaves the queue. The integer u ∈ {1, . . . , n − p + 1} gives the total number of customers that are involved in the transition, and the microstate reached after this transition is (c 1 , . . . , c p1−1 , c p1+1 , . . . , c p2−1 , i 1 , c p2+1 , . . . , c p3−1 , i 2 , c p3+1 , . . . , c pu−1 , i u−1 , c pu+1 , . . . , c n ).
Observe that the transition is recorded as a departure of a class-i u customer and not as a departure of a class-i 1 customer in general. In the special case where u = 1, the customer that completed service could not replace any subsequent customer, so that this customer left the queue. An OI queue supplemented with the pass-and-swap mechanism is called a pass-and-swap queue (P&S). The stochastic process keeping track of the microstate over time in the P&S queue has the Markov property, just like the OI queue. For both the OI and the P&S queue, however, the stochastic process that describes the macrostate over time does yield no such Markov property in general.
Example 3.1. We give a toy example that illustrates the P&S mechanism. More concrete applications will be described in Section 6. Consider the multi-server queue of Example 2.2 supplemented with the swapping graph shown in Figure 3a. Class 2 can be swapped with classes 1 and 3 but classes 1 and 3 cannot be swapped with one another. Assume that the queue is in the state c = (1, 3, 3, 2, 2, 3, 1, 2) depicted in Figure 3b, and that the customer in first position, of class 1, completes service. The corresponding chain reaction is depicted on the same figure by arrows. Class 1 can only be swapped with class 2 and the first subsequent class-2 customer is in the fourth position. Therefore, the class-1 customer that completed service is passed along the queue up until the fourth position and then swapped with the class-2 customer at this position. The ejected class-2 customer can be swapped with customers of classes 1 and 3. Therefore, this customer is passed along the queue up until the sixth position and swapped with the class-3 customer at this position. We repeat this with the ejected class-3 customer, which replaces the last class-2 customer, which leaves the queue. The transition is recorded as a departure of a class-2 customer and the new queue state is d = (3, 3, 1, 2, 2, 1, 3). 1 2 3 (a) Swapping graph.  Additional comments The P&S mechanism is applied instantaneously upon a service completion. Replacements are performed from the front to the back of the queue, so that, when a customer is ejected from some position p ∈ {1, . . . , n}, this customer never replaces a customer at a position q ∈ {1, . . . , p − 1}, even if c q ∈ I cp . Also note that customer classes now have a dual role: they determine not only the service rate received by each customer through the rate function µ, but also the chain reaction that happens upon each service completion through the swapping graph. One could also associate two classes with each customer, one that determines its service rate and another that determines its swapping relations. Finally, the original OI queue, in which the customer that completes service is the one that leaves the queue, is obtained by applying the P&S mechanism based on a swapping graph without edges. Therefore, an OI queue is also a P&S queue, so that the results that we will derive for P&S queues in the sequel also apply to OI queues.
The following notation will be useful. We write δ p (c) = (d, i) if the service completion of the customer in position p in microstate c leads to microstate d and triggers the departure of a class-i customer, for each n ≥ 1, c ∈ I n , d ∈ I n−1 , p ∈ {1, . . . , n}, and i ∈ I. In Example 3.1 for instance, we have δ 1 (c) = ((3, 3, 1, 2, 2, 1, 3), 2). With a slight abuse of notation, we also write δ p (c) = i if we only want to specify that the departing customer is of class i.

Stationary analysis
The Markov process associated with the queue microstate on the state space I * is irreducible. Indeed, given any microstates c = (c 1 , . . . , c n ) ∈ I * and d = (d 1 , . . . , d m ) ∈ I * , the Markov process can again jump from microstate c to microstate ∅ thanks to n transitions corresponding to departures (for instance, triggered by the service completion of the customer at the head of the queue), and then from microstate ∅ to microstate d thanks to m transitions corresponding to arrivals.
Theorem 3.2 below shows that introducing the P&S mechanism does actually not change the stationary distribution of this Markov process compared to the original OI queue. In particular, this stationary distribution is independent of the swapping graph. Intuitively, this can be thought of as a consequence of the symmetric property of the swapping relation. Another implication of Theorem 3.2 is that the consequences of the quasi-reversibility property stated in Section 2.2 for OI queues also apply to P&S queues. As a result, an open network of P&S queues connected by a random routing process has a product-form stationary distribution. The only peculiarity is that, when a customer completes service in a P&S queue, this customer is not necessarily the one that leaves this queue. The case of closed networks is more complicated and will be considered in Section 5. The sketch of the proof given below is completed in Appendix A.1. Sketch of proof. The proof resembles that of Theorem 2.4, except that the second set of partial balance equations (2.8) has a different form. More specifically, we will verify that any measure π of the form (2.3) satisfies the following partial balance equations in each microstate c = (c 1 , . . . , c n ) ∈ I * : • Equalize the flow out of microstate c due to a departure with the flow into microstate c due to an arrival (if c = ∅): π(c)µ(c) = π(c 1 , . . . , c n−1 )λ cn . (3.1) • Equalize, for each i ∈ I, the flow out of microstate c due to the arrival of a class-i customer with the flow into microstate c due to the departure of a customer of this class:

Complementary results on pass-and-swap queues
We now use Theorem 3.2 to derive further results on the stationary behavior of P&S queues. Section 4.1 gives an alternative stability condition that is simpler to verify than (2.5). The result of this section extends that obtained for OI queues in the Ph.D. thesis [14] and before that for multi-server queues in [9]. In Section 4.2, we use the quasi-reversibility property to prove that the average service and departures rates of each class are equal to each other and independent of the swapping graph. Recall that, since an OI queue is also a P&S queue, the results of this section readily apply to OI queues.

Stability condition
Theorem 4.1 below gives a necessary and sufficient condition for the stability of P&S queues. This condition is simpler than (2.5) as it only compares the per-class arrival rates λ 1 , . . . , λ I to the rate function µ. A first version of this theorem was stated in the Ph.D. thesis [14,Theorem 3.4] for OI queues. The proof that we give in Appendix A.2 is different in that it does not involve Whittle networks [26].
To state the stability condition, it is worth recalling that, for each c ∈ I * , the macrostate associated with microstate c is the vector |c| = (|c| 1 , . . . , |c| I ) ∈ N I that counts the number of customers of each class present in the queue. Also recall that the service rate µ(c) depends on the number of customers of each class that are contained in microstate c but not on their order. This means that, once the macrostate corresponding to a microstate is given, the service rate function is not sensitive to the microstate itself anymore. Therefore, in the sequel, we also refer to µ(c) as µ(|c|) for simplicity of notation.
For each i ∈ I, we let e i denote the I-dimensional vector with one in component i and zero elsewhere. We define the functionμ on the power set of I bȳ where e A = i∈A e i for each A ⊆ I. The monotonicity of µ ensures thatμ is well defined, with values in R + ∪ {+∞}, and is itself a non-decreasing set function. If the overall service rate only depends on the set of active classes, as is the case in the multi-server queue of Examples 2.2 and 3.1, we haveμ(A) = µ(x) for each x ∈ N I such that A = {i ∈ I : x i > 0}, but in general, we may haveμ(A) > µ(x) for each such x.  This result is the only one in this paper that cannot be straightforwardly extended to P&S queues with an arbitrary scaling factor as considered in [7,20]. However, it can be extended to P&S queues with a non-decreasing scaling factor by including this scaling rate into the definition ofμ.

Departure and service rates
We now consider the relation between the service rates and departure rates of customers in the P&S queue. Consider a stable P&S queue, as defined in Section 3.1, and let π denote the stationary distribution of the Markov process tracking the microstate over time. For each c = (c 1 , . . . , c n ) ∈ I * and i ∈ I, we also define the overall departure rate of class i in microstate c to be while the overall service rate of class i in this microstate is defined as  While it is not necessarily true that φ d i (c) = φ s i (c), the next proposition states that, for each x ∈ N I and i ∈ I, the overall probability flow out of macrostate x due to a departure of a class-i customer is equal to the overall probability flow out of macrostate x due to a service completion of a class-i customer. Since the latter quantity does not depend on the swapping graph, this equality implies that, for each x ∈ N I and i ∈ I, the overall probability flow out of macrostate x due to a departure of a class-i customer does not depend on the swapping graph. Upon dividing (4.5) by c∈I * :|c|=x π(c), we also obtain that the conditional expected departure and service rates of a class given the macrostate are equal to each other.

Proposition 4.2.
For each x ∈ N I and i ∈ I, we have Proof. If x i = 0, the result is immediate since φ d i (c) = φ s i (c) = 0 for any microstate c for which |c| = x. For the case x i > 0, note that the stationary distribution of the P&S queue satisfies (3.2), but, because of Theorem 2.4, it also satisfies (2.8). Therefore, the right-hand sides of these two equations are equal. Equating these two sides and summing over all microstates c = (c 1 , . . . , c n ) for which |c| = x − e i , we obtain  . . , c n ), the completion of customer c p will trigger a departure of customer c q , then, in microstate d = (c n , . . . , c 1 ), the completion of customer c q will trigger a departure of customer c p , as the swapping graph is undirected. Moreover, both microstates lead to the same macrostate x. The fact that π(c) = π(d) is offset by the nature of the order-independent service rates, as formalized in the proof of Proposition 4.2.

Closed models
We saw that P&S queues are quasi-reversible, so that stable open networks of P&S queues have a productform stationary distribution under mild conditions on the routing process. In this section, we consider closed networks of P&S queues in more detail and conclude that, also for closed networks, the stationary distribution has a product form. In contrast to open networks, this does not follow directly from quasi-reversibility since, in general, the obtained Markov process does not meet the irreducibility assumptions posed in [18,Section 3.4]. In Section 5.1, we first consider a closed P&S queue in which the number of customers of each class is fixed and departing customers are appended back to the end of the queue instead of leaving. These results are extended to a closed tandem network of two P&S queues in Section 5.2. This tandem network turns out to have rich applications, as we will see in Section 6.

A closed pass-and-swap queue
We first consider a closed network that consists of a single P&S queue. In Section 5.1.1, we give an example of such a closed P&S queue to illustrate its dynamics. Section 5.1.2 then gives a more formal description of this model, including necessary notation. This section also studies the structure of the Markov process underlying this closed P&S queue and establishes sufficient conditions for this Markov process to be irreducible. Provided that the Markov process is indeed irreducible, Section 5.1.3 provides the stationary distribution of the closed P&S queue and establishes its product-form nature.

Introductory example
Consider a closed P&S queue with six customer classes (I = {1, 2, . . . , 6}) and the swapping graph shown in Figure 4a. When a class-i customer departs the queue, this customer does not leave the system. Instead, it is appended back to the queue as a class-i customer. For simplicity, we assume that there is a single customer of each class in the queue. More precisely, we assume that the queue starts in microstate c = (1, 2, 3, 4, 5, 6), as depicted in Figure 4b. A possible sequence of transitions is shown in Figures 4c and 4d. Each transition is triggered by the service completion of the customer that is currently at the head of the queue. In particular, in the transition from Figure 4b to Figure 4c, the service of customer 1 completes, and this customer replaces customer 3, which replaces customer 6 in accordance with the swapping graph in Figure 4a. In the transition from Figure 4c to Figure 4d, the service of customer 2 completes, and this customer replaces customer 4, which replaces customer 6. In both cases, customer 6 is appended back to the end of the queue, in the last position, so that this customer's position remains unchanged by the transition.    It is worth noting that, in the three states shown in Figure 4, customer 1 precedes customers 3 and 4, which precede customer 6. This order will be conserved by the P&S mechanism, as the service completion of customer 1 systematically triggers the movement of either customer 3 or customer 4, that in turn will replace customer 6. Similarly, customer 2 will always precede customers 4 and 5 that, in their turn, will always precede customer 6. In the sequel, we will formalize this phenomenon and characterize the communicating classes of the Markov process associated with the microstate of a closed P&S queue.

Queueing model
The closed P&S queue inherits virtually all properties and notation from Section 3.1. As mentioned before, the only difference is that, upon a service completion, the customer that would have left if the queue were open is, instead, appended back to the end of the queue as a customer of the same class. There is also no external arrival process, so that the macrostate of the queue is determined by its initial state and does not change over time. We therefore let I = {1, . . . , I} denote the set of classes of the customers in the initial state of the queue. The (fixed) macrostate of the queue is denoted by ℓ = (ℓ 1 , . . . , ℓ I ) ∈ N I and the total number of customers by n = ℓ 1 + . . . + ℓ I . Note that ℓ i > 0 for each i ∈ I, as we only regard classes of customers present in the queue.
In Section 5.1.1, we found that it was possible for an ordering of customers to be preserved by the P&S mechanism. To help formalize this phenomenon, we introduce the notion of a placement order. We first define a placement graph of the queue as an acyclic orientation of its swapping graph, that is, a directed acyclic graph obtained by assigning an orientation to each edge of the swapping graph. A placement order of the queue is then defined as (the strict partial order associated with) the reachability relationship of one of its placement graphs. In other words, a strict partial order ≺ on I is said to be a placement order if there exists a placement graph such that, for each i, j ∈ I with i = j, i ≺ j if and only if there is a directed path from class i to class j in the placement graph. It will be useful later to observe that, for each classes i, j ∈ I that are neighbors in the swapping graph, we have either i ≺ j or j ≺ i.
We say that a microstate c = (c 1 , . . . , c n ) ∈ I n adheres to the placement order if c q ⊀ c p for each p, q ∈ {1, . . . , n} such that p < q. Since the placement order is only partial, there may be pairs of classes for which neither c p ≺ c q nor c q ≺ c p hold. As a result, adherence is a weaker property than having c p ≺ c q for each p, q ∈ {1, . . . , n} such that p < q. As a special case, we mention that adherence allows that c p = c q when p < q.
Example 5.1. We consider the closed P&S queue of Section 5.1.1. The placement graph in Figure 5 is obtained by orienting the edges of the swapping graph of Figure 4a from bottom to top. All microstates in Figure 4 adhere to the corresponding placement order. For example, the placement graph implies that 1 ≺ j for j ∈ {3, 4, 6} and 2 ≺ j for j ∈ {4, 5, 6}, which in turn implies that the customer at the front of the queue is either customer 1 or customer 2. All microstates in Figure 4 indeed satisfy this property. Customers 1 and 2 can alternate positions, as neither 1 ≺ 2 nor 1 ≻ 2. In general, not all possible microstates of a closed P&S queue adhere to a placement order. In Example 5.1, if the initial queue microstate is (3, 1, 2, 3, 4, 5, 6), a class-1 customer is both preceded and succeeded by a class-3 customer, making it impossible to orient the edge between classes 1 and 3 in the swapping graph. Furthermore, each microstate can only adhere to at most one placement order, so that the sets of microstates that adhere to different placement orders are disjoint. To prove this, it suffices to observe that, for each microstate that adheres to a placement order, the relative placement of customers within the microstate specifies the orientation of all edges of the swapping graph, which in turn uniquely defines a placement order.
In the rest of this section and in Section 5.1.3, we focus on the case where the initial microstate of the queue does adhere to a placement order. Proposition 5.2 describes the phenomenon encountered in Section 5.1.1 in full generality, while Proposition 5.3 provides a stronger result, assuming that all customers receive a positive service rate. The case of microstates that do not adhere to a placement order is treated in Appendix A.3.
Proposition 5.2. If the initial microstate of the closed P&S queue adheres to the placement order ≺, then any microstate reached by applying the P&S mechanism also adheres to this placement order.
Proof. Let c = (c 1 , . . . , c n ) denote the initial microstate of the queue and assume that c adheres to the placement order ≺. Let p ∈ {1, . . . , n} such that ∆µ(c 1 , . . . , c p ) > 0 and consider the transition induced by the service completion of the customer in position p. In the course of this transition, one or more customers are moved from the head towards the tail of the queue, the last one being moved to the last position. We now argue that the microstate reached after this transition still adheres to ≺, after which the proposition follows immediately, since application of the P&S mechanism only consists of a number of such transitions.
We first show that the customer that completes service, of class c p , does not pass over any customer of a class i such that c p ≺ i. If there is no integer p ′ ∈ {p + 1, . . . , n} such that c p ≺ c p ′ , the conclusion is immediate. Now assume that there is such an integer and let q denote the smallest integer in {p + 1, . . . , n} such that c p ≺ c q . We will show that: (i) classes c p and c q are neighbors in the swapping graph, and (ii) there is no r ∈ {p + 1, . . . , q − 1} such that classes c p and c r are neighbors in the swapping graph.
By definition of the P&S mechanism, this will imply that the customer that completes service at position p replaces the customer at position q in microstate c, so that, after the transition, the prefix of length q − 1 of the new microstate is (c 1 , . . . , c p−1 , c p+1 , . . . , c q−1 , c p ). By definition of q, this prefix still adheres to the placement order, and since the rest of the microstate does not change, the complete microstate will as well. The same reasoning can be repeated for each customer that is moved by applying the P&S mechanism.
We first prove property (i) by contradiction. Assume that this property is not satisfied. By definition of the placement order, this implies that there is a class i ∈ I such that c p ≺ i ≺ c q . Since microstate c adheres to the placement order, this implies that all class-i customers are between positions p and q in microstate c. In particular, there is an r ∈ {p + 1, . . . , q − 1} such that c r = i and, therefore, c p ≺ c r , which contradicts the minimality of q. Therefore, property (i) is satisfied. We now prove property (ii), again by contradiction. If this property would not be not satisfied, there would be an r ∈ {p + 1, . . . , q − 1} such that classes c p and c r are neighbors in the swapping graph. By definition of the placement order, this implies that either c p ≺ c r or c r ≺ c p . Since p < r and microstate c adheres to the placement order, the only possibility is that c p ≺ c r , which again contradicts the minimality of q. Therefore, property (ii) is satisfied. If c = d, the conclusion is immediate. Now assume that c = d. We will construct a path of microstates c 0 , c 1 , . . . , c K−1 , c K , with c 0 = c and c K = d, that the queue traverses with a positive probability, provided that it starts in microstate c. We argue that such a path c 0 , c 1 , . . . , c K is attained by the following algorithm: Step 1: Set k = 0 and c 0 = c.
Step 3: Let c k+1 denote the microstate reached when, in microstate c k , the customer in position p completes service and the P&S mechanism is applied.
Step 4: Set k = k + 1. If c k = d, then K = k and the algorithm terminates. Otherwise, go to step 2.
The idea behind this algorithm is as follows.
Step 2 identifies the first position in microstate c k at which the class of the customer does not coincide with that of the customer at the same position in microstate d. This position is denoted by p. Since (c k 1 , . . . c k p−1 ) = (d 1 , . . . , d p−1 ), the customers in positions 1 to p − 1 need not have their position altered. Now let r denote the smallest integer in {p + 1, . . . , n} such that c k r = d p . We will show in the next paragraph that, thanks to the service completion in step 3, the customer in position r in microstate c k is one step closer to (or even attains) position p in microstate c k+1 compared to microstate c k . This suffices to prove that the algorithm terminates.
Step 4 makes sure that the two microstates are equal to each other, otherwise it initiates a new P&S transition.
We now prove that, if r denotes the smallest integer in {p + 1, . . . , n} such that c k r = d p , then c k+1 r−1 = c k r . This is equivalent to proving that the customer in position r in microstate c k is not ejected in the course of the transition described in step 3. To prove this, it is sufficient to show that, for each q ∈ {p, . . . , r − 1}, classes c k q and c k r cannot be swapped with one another, that is, are not neighbors in the swapping graph. Let q ∈ {p, . . . , r − 1}. The adherence of microstate d to the placement order implies that d q ′ ≺ d p for each q ′ ∈ {p + 1, . . . , n}. As (d 1 , . . . , d p−1 ) = (c k 1 , . . . , c k p−1 ) and d p = c k r , this implies that c k q ⊀ c k r . It also follows from Lemma 5.2 that microstate c k adheres to the placement order, so that c k r ⊀ c k q . Therefore, we have c k q ⊀ c k r and c k r ⊀ c k q , which, by definition of a placement order, implies that classes c k q and c k r are not neighbors in the swapping graph.
Remark 5.4. The assumption in Proposition 5.3, namely that ∆µ(c) > 0 for each c ∈ I * , is a sufficient condition for this result to hold but it is not a necessary condition. It is for example worth noting that this assumption is not satisfied by the multi-server queue of Example 2.2, yet the closed variant of this queue satisfies the conclusions of these two propositions whenever µ 1 and µ 2 are positive. In general, the construction of weaker sufficient conditions appears to be challenging since the transition described in step 3 of the algorithm in the proof of Proposition 5.3 is not guaranteed to occur with a positive probability when there are states c so that ∆µ(c) = 0.

Stationary analysis
We now turn to the stationary distribution of the Markov process underlying the closed P&S queue and establish its product-form nature. Recall that the initial macrostate of the queue equals ℓ, which cannot change over time due to the closed nature of the queue. We assume that the initial microstate adheres to a placement order ≺. Since all subsequent microstates must also adhere to this placement order due to Proposition 5.2, we restrict the state space of the Markov process to the state space C that consists of all microstates c = (c 1 , . . . , c n ) that satisfy |c| = ℓ and adhere to the placement order ≺. The rate function µ and balance function Φ of the queue are assumed to be defined on the whole set I * for simplicity, although we could just as well define them on a subset of I * . Theorem 5.5 below provides the stationary distribution of the closed P&S queue and reveals its product form.
Theorem 5.5. Assume that the Markov process associated with the microstate of the closed P&S queue, with state space C, is irreducible. The stationary distribution of this Markov process is then given by , ∀c ∈ C, where the function Φ is given by (2.4).
Proof. It suffices to show that the function Φ satisfies the balance equations of the Markov process, after which the result follows by normalization. Let c = (c 1 , . . . , c n ) ∈ C and i = c n . Since a departing customer immediately re-enters the queue as a customer of the same class, the balance equation for any microstate c ∈ C reads in the open queue, the service completion of the customer in position p in state d would lead to state (c 1 , . . . , c n−1 ) with a departure of a class-i customer. It follows from Proposition 5.2 that the set C contains all microstates d ∈ I * such that δ p (d) = ((c 1 , . . . , c n−1 ), i) for some p ∈ {1, . . . , n}. Therefore, it suffices to prove that the balance function Φ satisfies By applying (3.3) to microstate (c 1 , . . . , c n−1 ) and class i, we obtain that Φ(c 1 , . . . , c n−1 ), as defined in (2.4), is equal to the right-hand side of (5.3). To conclude, it suffices to observe that (2.4) implies Φ(c)µ(c) = Φ(c 1 , . . . , c n−1 ).
Remark 5.6. According to Proposition 5.3, a sufficient condition for the Markov process considered in Theorem 5.5 to be irreducible is that ∆µ(c) > 0 for each c ∈ I * . If this process is not irreducible, all steps of the proof of Theorem 5.5 remain valid, so that the distribution defined by (5.1) is still a stationary distribution of the Markov process, but it may not be the only one. Since Φ(c) > 0 for each c ∈ I * by (2.4), this observation shows that the Markov process considered in Theorem 5.5 always has a positive stationary distribution, which implies that this process has no transient state, that is, all its communicating classes are closed.
Remark 5.7. A variant of Theorem 5.5 can also be derived for closed P&S queues with initial microstates that do not adhere to a placement order. We have deferred derivation of this more general result to Appendix A.3 to simplify the discussion. Furthermore, Theorem 5.5 will be sufficient for the applications of Section 6.

A closed tandem network of two pass-and-swap queues
Now that the product-form of the stationary distribution of a single closed P&S queue has been established, we turn to the study of a closed tandem of two P&S queues. This model has rich applications, as we will see in Section 6. Again, we first explain the model through an introductory example in Section 5.2.1, after which we formalize the model and describe structural properties in Section 5.2.2. We also derive the stationary distribution in Section 5.2.3.

Introductory example
We consider the closed tandem network of two P&S queues depicted in Figure 6. Both queues have the same set of customer classes and the same swapping graph as the closed queue of Section 5.1. We also assume that there is a single customer of each class in the network. The routing process is as follows: for each i ∈ I, if a class-i customer departs from a queue, this customer is routed to the back of the other queue as a class-i customer. The initial microstate of the first queue is c = (1, 2, 3, 4, 5, 6) and that of the second queue is d = ∅, as shown in Figure 6a. Figure 6b shows the state reached after customer 1 (that is, the only customer belonging to class 1) completes service. As in the introductory example of Section 5.1, this customer replaces customer 3, and customer 3 replaces customer 6. The difference is that customer 6 is now routed to the second queue rather than to the first. Figure 6c shows the state reached after several service completions, each time that of the customer at the head of the first queue.    Figure 4, the rate function is not specified because we will only consider the service completion of the customer at the head of a queue.
As in Section 5.1.1, the order of customers seems to be preserved by the P&S mechanism. However, the orders of customers in the two queues are reversed. For instance, while customer 6 comes after customers 3 and 4 in the first queue (as in Section 5.1.1), in the second queue customer 6 always precedes these customers. We will show that this symmetry in customer orders holds for any closed tandem network of two P&S queues.

Queueing model
Just like in Section 5.1, the queues in the closed tandem network are ordinary P&S queues as described in Section 3. There are however no external arrivals or departures: the departure process of one queue now forms the arrival process of the other. In particular, both queues share the same set I = {1, . . . , I} of customer classes. The microstate of the first queue is denoted by c = (c 1 , . . . , c n ) ∈ I * and that of the second queue by d = (d 1 , . . . , d m ) ∈ I * , where n and m are the number of customers present in the first and second queue, respectively. We refer to (c; d) = ((c 1 , . . . , c n ); (d 1 , . . . , d m )) as the microstate of the network. We furthermore assume that both queues have the same swapping graph. The rate functions of the two queues may however differ: whereas customers in the first queue complete service according to the rate function µ, the rate function in the second queue is denoted by ν. Because of the closedness of the system, we have that the sum of the macrostates of the two queues, denoted by ℓ = |c| + |d|, is constant over time. We refer to this vector ℓ = (ℓ 1 , . . . , ℓ I ) as the network macrostate and we assume that ℓ i > 0 for every i ∈ I, as otherwise we can simply disregard classes that are not present in the closed tandem network. Macrostates |c| and |d|, however, do fluctuate over time. We let Φ (resp. Λ) denote the balance function of the first (resp. second) queue. The functions µ, ν, Φ, and Λ are assumed to be defined on I * for simplicity.
As mentioned above, both queues have the same swapping graph. Similarly to Section 5.1.2, we define a placement order ≺ of the network by directing the edges of this swapping graph so that a directed acyclic graph, called the placement graph of the network, arises; we again write that i ≺ j if and only if there exists a directed path from class i to class j in the placement graph. We now say that a network microstate (c; d) adheres to the placement order ≺ if the following three conditions are satisfied: For example, the three network microstates shown in Figure 6 adhere to the placement order ≺ defined by the placement graph of Figure 5. Focusing on the microstate shown in Figure 6c, we have c = (2, 5, 1) and d = (6, 4, 3). The concatenation considered above is (2, 5, 1, 3, 4, 6), and it indeed adheres to the placement order. This definition is symmetric with respect to the queues in the sense that microstate (c; d) adheres to the placement order ≺ if and only if microstate (d; c) adheres to the reverse placement order ≻ defined as follows: for each i, j ∈ I, i ≻ j if and only if j ≺ i.
As for the case of a single queue, we focus here on the case where the initial microstate adheres to a placement order. Propositions 5.8 and 5.9 below are the counterparts of Propositions 5.2 and 5.3 for closed tandem networks of two queues. The proofs of these two propositions rely on the proof of their single-queue counterparts.
Proposition 5.8. If the initial network microstate adheres to the placement order ≺, then any microstate reached by applying the P&S mechanism to either of the two queues also adheres to this placement order.
Proof. By symmetry, it suffices to prove that, if a network microstate adheres to the placement order ≺, then any network microstate reached by a service completion in the first queue also adheres to this placement order. Consider a microstate (c; d) that adheres to the placement order and let c = (c 1 , . . . , c n ) and d = (d 1 , . . . , d m ). Let c ′ = (c ′ 1 , . . . , c ′ n−1 ) denote the microstate of the first queue right after a service completion in this queue and i the class of the customer that departs this queue. The microstate of the network right after the transition is (c ′ ; d ′ ) with d ′ = (d 1 , . . . , d m , i). Applying Proposition 5.2 to the first queue yields that microstate (c ′ 1 , . . . , c ′ n−1 , i) adheres to the placement order, from which we can derive that properties (i) and (iii) are satisfied by the new network microstate. Finally, the fact that microstate (c; d) satisfies properties (ii) and (iii) implies that microstate d ′ satisfies property (ii). Proposition 5.9. Assume that either ∆µ(c) > 0 for each c ∈ I * or ∆ν(d) > 0 for each d ∈ I * (or both). All microstates that adhere to the same placement order and correspond to the same macrostate form a single closed communicating class of the Markov process associated with the network microstate.
Proof. Without loss of generality, we assume that ∆µ(c) > 0 for each c ∈ I * . The case where ∆ν(d) > 0 for each d ∈ I * is solved by exchanging the roles of the two queues. Given the result of Proposition 5.8, it suffices to show that, for all microstates (c; d) and (c ′ ; d ′ ) that adhere to the same placement order and correspond to the same macrostate, microstate (c ′ ; d ′ ) can be reached from microstate (c; d) with a positive probability.
Consider two microstates (c; d) and (c ′ ; d ′ ) that adhere to the same placement order and satisfy |c| + |d| = |c ′ | + |d ′ |. The numbers of customers in microstates c, d, c ′ , and d ′ are denoted by n, m, n ′ , and m ′ , respectively. We now build a series of transitions that leads from microstate (c; d) to microstate (c ′ ; d ′ ) with a positive probability.
First let (c ′′ ; ∅) denote the microstate reached from microstate (c; d) by having, m times in a row, the customer at the head of the second queue complete service. Proposition 5.8 guarantees that microstate (c ′′ ; ∅) adheres to the placement order so that, by property (i), microstate c ′′ adheres to the placement order. Since we assumed that microstate (c ′ ; d ′ ) adheres to the placement order, we also have that microstate (c ′ 1 , . . . , c ′ n ′ , d ′ m ′ , . . . , d ′ 1 ) adheres to the placement order. Therefore, it follows from Proposition 5.3 that, if the first queue evolved in isolation, as in Section 5.1, it would be possible to reach microstate (c ′ 1 , . . . , c ′ n ′ , d ′ m ′ , . . . , d ′ 1 ) from microstate c ′′ with positive probability. We can adapt the algorithm in this proposition to prove that, in the tandem network, microstate ((c ′ 1 , . . . , c ′ n ′ , d ′ m ′ , . . . , d ′ 1 ); ∅) can also be reached from microstate (c ′′ ; ∅) with a positive probability: it suffices to add a transition, after step 3, that consists of the service completion of the (only) customer in the second queue (so that this customer joins the back of the first queue). Once microstate ( is reached, it suffices to have the customer at the back of the first queue complete service m ′ times in a row. Since a service completion at the final position of a queue does not trigger any P&S movement, the network microstate (c ′ ; d ′ ) is reached, which concludes the proof.

Stationary analysis
We now derive the stationary distribution of the Markov process associated with the network microstate. As in Section 5.1.3, we focus on the special case where the initial microstate adheres to the placement order ≺, so that, by Proposition 5.8, all subsequent microstates also adhere to this placement order. Therefore, we restrict the state space of the Markov process to the set Σ that consists of all network microstates (c; d) that adhere to the placement order ≺ and satisfy |c| + |d| = ℓ, where ℓ denotes the initial network macrostate. Theorem 5.10 below gives the stationary distribution of the Markov process associated with the network microstate.
Theorem 5.10. Assume that the Markov process associated with the microstate of the closed tandem network, with state space Σ, is irreducible. The stationary distribution of this Markov process is then given by where Φ and Λ are the balance functions of the first and second queues, respectively, and the normalization constant G is given by Proof. Before writing down the balance equations, we introduce some useful notation. Let X denote the subset of N I that consists of the vectors x = (x 1 , . . . , x I ) such that x ≤ ℓ and, for each i, j ∈ I with i ≺ j, x j = 0 whenever x i = 0. This is the set of possible macrostates of the first queue. For each x ∈ X , let C x denote the set of microstates c = (c 1 , . . . , c n ) ∈ I * that adhere to the placement order and satisfy |c| = x. The set of possible microstates of the first queue is C = x∈X ℓ C x . Similarly, let Y denote the subset of N I that consists of the vectors y = (y 1 , . . . , y I ) such that |y| ≤ ℓ and, for each i, j ∈ I with i ≺ j, y i = 0 whenever y j = 0. This is the set of possible macrostates of the second queue. Also, for each y ∈ Y, let D y denote the set of microstates d = (d 1 , . . . , d m ) such that (d m , . . . , d 1 ) adheres to the placement order and |d| = y. The set of possible microstates of the second queue is D = y∈Y ℓ D y . As a result, the state space Σ can be partitioned as follows: where the symbol × stands for the Cartesian product. In particular, if the microstate of the first queue is equal to c ∈ C, then the set of possible microstates of the second queue is Y ℓ−|c| , and vice versa.
To prove the theorem, it suffices to verify that any measure given by (5.4) satisfies the following partial balance equations in each microstate (c; d) ∈ Σ, with c = (c 1 , . . . , c n ), d = (d 1 , . . . , d m ), x = |c|, and y = |d|: • Equalize the flow out of microstate (c; d) due to a service completion at the first queue with the flow into that microstate due to an arrival at this queue, that is, to a service completion at the second queue (if c = ∅): • Equalize the flow out of microstate (c; d) due to a service completion at the second queue with the flow into that microstate due to an arrival at this queue, that is, to a service completion at the first queue Remark 5.11. Mutatis mutandis, Remarks 5.6 and 5.7 also apply to a closed tandem network of two P&S queues. In particular, an equivalent of Appendix A.3 can be derived in case the initial network microstate does not adhere to a placement order.

Application to load distribution and scheduling in machine pools
In this section, we explain how P&S queues can be applied to analyze the performance of load-distribution and scheduling algorithms in pools of machines at which jobs arrive to be processed. This machine-pool model can represent various queueing systems, like the computer clusters or manufacturing systems mentioned in the introduction, in which not every machine is able to fulfill the service requirement of any job. As an introductory example, in Section 6.1, we consider a load-distribution algorithm where the assignment decision is based on the order of tokens stored in a queue at the dispatcher. We will see later that this algorithm is related to other load-distribution algorithms considered in the literature. We then explain how the queueing model that describes the dynamics of this algorithm can be cast as a closed tandem network of two P&S queues like that of Section 5.2. In Section 6.2, we introduce a more general framework that encompasses other load-distribution and scheduling algorithms and then give two prototypical examples of such algorithms. In all cases, deriving the stationary distribution of the system state is a direct application of the results of Section 5.2, provided that the associated Markov process satisfies the appropriate irreducibility conditions.

First-come-first-served and seize-the-oldest-available-token
We first consider a load-distribution algorithm whereby each incoming job is either immediately assigned to an available machine, put on hold until a machine becomes available, or blocked. Each incoming job may have constraints that restrict the set of machines to which this job can be assigned.

System description
Consider a machine pool that consists of a set S = {1, . . . , S} of machines. There is a single dispatcher at which jobs arrive to be assigned to a machine. Each machine processes its assigned jobs in FCFS order and, for each s ∈ S, the service time of a job on machine s is exponentially distributed with a positive rate µ s . Each incoming job has a type that determines the set of machines to which this job can be assigned. The set of job types is denoted by K = {1, . . . , K} and, for each k ∈ K, type-k jobs arrive according to a Poisson process with rate ν k and can be assigned to any machine within the set S k ⊆ S. Conversely, for each s ∈ S, we let K s ⊆ K denote the set of job types that can be assigned to machine s (that is, such that s ∈ S k ). This defines a bipartite assignment graph between job types and machines, in which there is an edge between a type and a machine if the jobs of this type can be assigned to this machine; in this case, we say that these jobs are compatible with the machine.
In the examples of this section, job types will be identified by letters rather than numbers to prevent confusion in the remainder. In the assignment graph of Figure 7 for instance, type-A jobs are compatible with machines 1 and 3 and type-B jobs with machines 2 and 3, so that All present jobs are stored in a single queue in their order of arrival in the pool, with the oldest job at the head of the queue. To implement the load-distribution algorithm that we will describe below, we could equivalently have assumed that each machine has its own queue of jobs, and that unassigned jobs are stored at the dispatcher. We will however adhere to the central-queue perspective, as it is more practical from a modeling perspective. For each s ∈ S, at most ℓ s jobs can be assigned to machine s at a time, including the job in service on this machine, for some ℓ s > 0. Machine s is said to be available if there are currently less than ℓ s jobs assigned to this machine and unavailable otherwise. Equivalently, for each s ∈ S, we can assume that the job assignments to machine s are controlled via ℓ s tokens, so that a job seizes a token of machine s when it is assigned to this machine and releases its token upon service completion. Furthermore, for each k ∈ K, at most ℓ k type-k jobs can be put on hold if they arrive while no compatible machine is available, for some ℓ k ≥ 0.
We first describe the assignment rule applied upon an arrival, and then we will see what happens upon a service completion. For each k ∈ K, when a type-k job arrives, one of the following events occurs: (i) if one or more machines in the set S k are available, the job is immediately assigned to the machine identified by the token that has been available the longest (among the tokens that correspond to a compatible machine). In other words, if the available tokens are sorted in their release order in a queue at the dispatcher, with the oldest available token at the head of the queue, the incoming job scans this queue from head to tail and seizes the first encountered token that belongs to a compatible machine; (ii) otherwise, if there are currently less than ℓ k type-k jobs on hold, the incoming job is put on hold until it can be assigned to one of its compatible machines; (iii) otherwise, the job is lost.
We now describe what happens upon a service completion. For each s ∈ S, if a job completes service on machine s, the oldest job of a type in K s on hold, if any, is assigned to machine s, and then machine s starts processing the oldest job assigned to this machine. Note that there cannot be a job of a type in K s on hold if machine s was previously available, as in this case this job would have been assigned to machine s earlier.
We assume that these operations occur immediately upon a job arrival or a service completion.
Remark 6.1. The assign-to-the-longest-idle-server (ALIS) algorithm introduced in [2] corresponds to the special case where ℓ s = 1 for each s ∈ S and ℓ k = 0 for each k ∈ K, so that a job is blocked whenever all its compatible machines are already busy. It was shown in [2] that, in this case, performance is insensitive to the job size distribution beyond its mean. A token-based assignment rule that generalizes ALIS to a scenario where ℓ s ≥ 1 for each s ∈ S and that preserves its insensitivity property was introduced in [13]; this algorithm is also a special case of the algorithm that we have just defined. The first-come-first-served and assign-to-the-longest-idle-server (FCFS-ALIS) assignment rule introduced in [3] corresponds to the special case where ℓ s = 1 for each s ∈ S and ℓ k = +∞ for each k ∈ K. In practice, taking larger values for ℓ s for s ∈ S can be beneficial if there is a communication delay between the dispatcher and the machines, such that a job cannot enter in service immediately after it is assigned to a machine. Furthermore, taking unequal values for ℓ k for k ∈ K allows to differentiate service between job types. In the remainder of this section, we shall assume that 1 ≤ ℓ k < +∞ for each k ∈ K and 1 ≤ ℓ s < +∞ for each s ∈ S.

Interpretation as a closed tandem network of pass-and-swap queues
We now cast the above-mentioned model as a closed tandem network of two P&S queues. To this end, it is worth making a clear distinction between two types of tokens in the machine pool. First observe that the entry of type-k jobs can also be described as if regulated via ℓ k tokens: an incoming type-k job seizes one of these tokens when it can enter the system but cannot be assigned immediately to a compatible machine. These tokens are called holding tokens. Once a job has claimed such a holding token, this token is only released when the job is assigned to some compatible machine, or equivalently, when it seizes a token specific to some compatible machine (of which there are ℓ s per machine s). Such machine-specific tokens are called assignment tokens. Both holding and assignment tokens are either available or held by a job and the dynamics of the machine pool are entirely described by the movement of these tokens. Incoming jobs have a preference for assignment tokens over holding tokens in the sense that, for each k ∈ K, an arriving type-k job seizes an assignment token of a machine in S k , if any, and otherwise a holding token of type k, if any. We will show that this preference can be modeled by the P&S mechanism. We first give an overview of the closed tandem network and then we will detail the dynamics of each queue separately.
Overview We consider a closed tandem network of two P&S queues like the one described in Section 5.2. Customers represent tokens and the set of customer classes is I = K ⊔ S, where ⊔ denotes the disjoint union operator. This set has cardinality I = K + S 1 . Class-s customers represent the assignment tokens of machine s, for each s ∈ S, while class-k customers represent the holding tokens for type-k jobs, for each k ∈ K. The first queue contains the tokens held by jobs present in the machine pool and the second queue contains the available tokens. The overall number of class-i customers in the network is ℓ i , for each i ∈ I. Both P&S queues have the same swapping graph, so that we obtain a closed tandem network of two P&S queues like that described in Section 5.2. The placement order is as follows: s ≺ k for each s ∈ S and k ∈ K s (or equivalently, for each k ∈ K and s ∈ S k ). The corresponding placement graph is obtained from the assignment graph introduced in Section 6.1.1 by orienting edges from the (classes that correspond to) machines towards the (classes that correspond to) job types. For example, the placement graph associated with the assignment graph of Figure 7 is shown in Figure 8a. The swapping graph of the network is simply the underlying undirected graph of the placement graph. This placement order guarantees that, if a class-k customer is in the first queue, then, for each s ∈ S k , all class-s customers are also in the first queue and precede this class-k customer. This corresponds to the fact that, in the machine pool, a type-k job can only be on hold if all machines in S k are unavailable. We will come back to this interpretation later when we specify the dynamics of each queue in detail. An example of a network state that adheres to this placement order is given by a state where all customers are lined up in the second queue, with first those of the classes in K in an arbitrary order, and then those of the classes in S, also in an arbitrary order. We assume that the system starts in such a state, which corresponds to an empty machine pool in which all tokens are available.
Compatibility graph of the first multi-server queue. Each server corresponds to a machine in the pool.

3 2 A B
A B (c) Compatibility graph of the second multi-server queue. Each server corresponds to a job type in the pool.  Figure 7. Since the servers in the second queue and the holding classes are associated with the job types, they are identified by letters rather than numbers (in accordance with Figure 7). The class colors, if visible, are visual aids that help distinguish between the classes associated with assignment tokens (in green) and those associated with holding tokens (in orange). The same class and server indexing and color code will be adopted in Figures 9  and 10.
First queue Customers in the first queue represent tokens held by jobs present in the machine pool, either assigned to a machine or on hold. This queue is a multi-server queue, like that of Example 3.1, and each server represents a machine in the pool. More specifically, the set of servers is S and, for each s ∈ S, the service rate of server s is equal to the service rate µ s of machine s. Using the same index set S for the set of servers in the first queue and for the set of classes associated with assignment tokens may seem to be ambiguous at first, but the idea is the same as in the degenerate queue of Example 2.3: there will be a one-to-one correspondence between these servers and these classes. More specifically, for each s ∈ S, a class-s customer can be served by server s and by this server only, so that S s = {s}. For example, the compatibility graph of the first queue in the tandem network associated with the assignment graph of Figure 7 is shown in Figure 8b. This graph shows that classes 1, 2, and 3 can only be served by the server with the same number. Additionally, for each k ∈ K, the set of servers that can process class-k customers is S k , the set of machines to which type-k jobs can be assigned. In the end, for each s ∈ S, server s can process customers of the classes in {s} ∪ K s . Each server processes its assigned customers in FCFS order. Note that, for each letters s and t to refer to machines. In the example, the index of a class will be a number if this class represents the assignment tokens of a machine and a letter if it represents the holding tokens of a job type.
k ∈ K, the set S k now plays two roles in the tandem network: it represents the set of servers that can process customers of this class in the first queue as well as the set of customer classes that can be swapped with class-k customers.
Recall that, according to the placement order, a class-k customer (representing a holding token) cannot precede a customer of a class in S k (representing an assignment token) in the first queue. With the above definition of S i for each i ∈ I, this implies that a class-k customer will actually never be in service in the first queue (except in the degenerate case, left aside in this discussion, where ℓ s = 0 for some s ∈ S k ). The only way that a class-k customer leaves the first queue is if a customer of a class in S k completes service and ejects this class-k customer. In the machine pool, this means that a job completes service on a machine in S k and the assignment token released by this job is seized by a type-k job that was on hold (so that this type-k job releases its holding token). Note that the dynamics of the tandem network would be the same if the set of servers that can process class-k customers were a strict subset of S k .
We let c = (c 1 , . . . , c n ) ∈ I * denote the microstate of the first queue. As observed before, the placement order guarantees that, if there is a customer of a class k ∈ K at a position p ∈ {1, . . . , n} in the first queue, then, for each s ∈ S k , each class-s customer is also in the first queue, at a position q ∈ {1, . . . , p − 1} that precedes that of the class-k customer. Therefore, the state space of the microstate of the first queue is a strict subset C of the set of sequences c ∈ I * such that |c| ≤ ℓ, where ℓ = (ℓ 1 , . . . , ℓ I ) is the vector that gives the maximum number of customers of each class. The overall and per-customer service rates are still given by (2.1) and (2.2), with the sets S k for k ∈ K and S s for s ∈ S as defined above. Because of the placement order, (2.2) simplifies to ∆µ(c 1 , . . . , c p ) = 0 for each p ∈ {1, . . . , n} such that c p ∈ K. Furthermore, the one-to-one correspondence between the servers and the classes associated with assignment tokens guarantees that, for each p ∈ {1, . . . , n} such that s = c p ∈ S, we have ∆µ(c 1 , . . . , c p ) = µ s if |(c 1 , . . . , c p−1 )| s = 0 and ∆µ(c 1 , . . . , c p ) = 0 otherwise. Now assume that a customer in some position p ∈ {1, . . . , n} completes service and let s = c p ∈ S denote this customer's class. Because of the P&S mechanism, only one of these two types of transitions can occur: (i) If the first queue contains a customer of a class in K s (necessarily in position at least p + 1 because of the placement order), the class-s customer replaces the first of these customers, say of class k ∈ K s , and this class-k customer joins the second queue. In the machine pool, this means that an assignment token from machine s is released by a departing job and is immediately seized by a type-k job that was on hold; this type-k job releases its holding token which is appended to the queue of available tokens.
(ii) If there is no customer with a class in K s in the first queue, the class-s customer leaves this queue and joins the second queue. In the machine pool, this means that a token from machine s is released by a departing job and is immediately appended to the queue of available tokens because there is no job of a type in K s on hold.
In both cases, a customer leaves the first queue and is added to the second, meaning that a token is released in the machine pool. Examples of transitions are shown in Figure 9 for the machine pool of Figure 7. In the state of Figure 9a, all assignment tokens are held by a present job and there is also a type-A job on hold. From Figure 9a to Figure 9b, the oldest class-2 customer completes service in the first queue and joins the second queue. In the machine pool, this means that a job completes service on machine 2 and its token is added to the queue of available tokens because there is not job of a compatible type on hold. This is a transition of type (ii). From Figure 9b to Figure 9c, the oldest class-3 customer completes service in the first queue; this customer replaces the class-A customer which joins the second queue. In the machine pool, this means that a job completes service on machine 3 and its token is seized by a type-A job on hold. This is a transition of type (i). The transition from Figure 9c to Figure 9d, triggered by a service completion in the second queue, will be commented on later.
Second queue We now provide a symmetric description for the second queue, in which customers correspond to available tokens. This queue is again a multi-server queue like that of Example 3.1, but the servers correspond to job types and not to machines. More specifically, the set of servers is K and, for each k ∈ K, the service rate of server k is equal to ν k , the arrival rate of type-k jobs in the machine pool. There is a A 3 2 1 3 1 2 (a) Initial state.
State reached after the service completion of the oldest class-2 customer in the first queue.    Figure 7, assuming that ℓ k = 2 for each k ∈ K and ℓ s = 2 for each s ∈ S.
one-to-one correspondence between the servers in this second queue and the classes associated with holding tokens in the sense that, for each k ∈ K, the set of servers that can process class-k customers is K k = {k}. Also, for each s ∈ S, the set of servers that can process class-s customers is K s , corresponding to the set of job types that can seize a token from machine s in the machine pool. For example, the compatibility graph of the second queue in the tandem network associated with the assignment graph of Figure 7 is shown in Figure 8c. Each server processes its assigned customers in FCFS order. Due to the placement order, a class-s customer cannot precede a customer of a class in K s in the second queue. With the above definition of K i for each i ∈ I, this implies that a class-s customer will never be in service in the second queue (except in the degenerate case, left aside in this discussion, where ℓ k = 0 for some k ∈ K s ); the only way a class-s customer leaves this queue is if a customer of a class in K s completes service and ejects this class-s customer. In the machine pool, this means that a type-k job enters and seizes a token from machine s. Note that the dynamics would be the same if the set K s of servers that can process class-s customer were a strict subset of K s .
We let d = (d 1 , . . . , d m ) ∈ I * denote the microstate of the second queue. As observed before, the placement order guarantees that, if there is a customer of a class s ∈ S at some position p ∈ {1, . . . , m} in the second queue, then, for each k ∈ K s , each class-k customer is also in the second queue, at a position q ∈ {1, . . . , p − 1} that precedes that of this class-s customer. Therefore, the state space of the microstate of the second queue is a strict subset D of the set of sequences d ∈ I * such that |d| ≤ ℓ. The overall service rate in this queue is equal to the sum of the arrival rates of the job types that can seize at least one available token, given by For each p ∈ {1, . . . , m}, the token in position p can be seized or moved by the incoming jobs that are compatible with this token but not with the older available tokens, and these jobs arrive at rate The functions ν and ∆ν play the same role for the second queue as the functions µ and ∆µ, given by (2.1) and (2.2), for the first queue. Again because of the placement order, (6.2) simplifies to ∆ν(d 1 , . . . , d p ) = 0 for each p ∈ {1, . . . , m} such that d p ∈ S. Additionally, the one-to-one correspondence between the servers and the classes associated with holding tokens guarantees that, for each p ∈ {1, . . . , m} such that k = d p ∈ K, we have ∆ν(d 1 , . . . , d p ) = ν k if |(d 1 , . . . , d p−1 )| k = 0 and ∆ν(d 1 , . . . , d p ) = 0 otherwise. Now assume that a customer in some position p ∈ {1, . . . , m} completes service. If k = c p ∈ K denotes this customer's class, then, because of the P&S mechanism, only one of these two transitions can occur: (i) If the second queue contains a customer of a class in S k (necessarily in position at least p + 1 because of the placement order), the class-k customer replaces the first of these customers, say of class s ∈ S k , and this class-s customer joins the first queue. In the machine pool, this means that an incoming type-k job seizes an assignment token from machine s because this was the oldest available token of a compatible machine.
(ii) If there is no customer of a class in S k in the second queue, the class-k customer leaves this queue and is added to the first queue. In the machine pool, this means that a type-k job enters and does not find any available token from a machine in S k , so that this job seizes a class-k token and will hold this token until it is assigned to a machine in S k .
In both cases, a customer leaves the second queue and joins the first, meaning that a token is seized in the machine pool. An example of a type-(i) transition is shown in Figure 9 for the machine pool of Figure 7. From Figure 9c to Figure 9d, the oldest class-B customer completes service in the second queue; this customer replaces the class-2 customer that joins the first queue. In the machine pool, this means that a type-2 job enters and seizes an assignment token corresponding to machine 2.
Remark 6.2. Both queues are degenerate in the following sense. In the second queue, for each k ∈ K, class k is the only class within the set K that can be processed by server k. Therefore, if we let A = {k ∈ K : |d| k > 0}, then, for each k ∈ A, the service rate of the oldest class-k customer is ν k , irrespective of the order of the customers in microstate d (provided that this microstate adheres to the placement order). This implies that the relative order of the customers of the classes in K in microstate d modifies neither their service rates nor the departure rate of the customers of the classes in S. On the contrary, in general, the relative order of the customers of the classes in S modifies their departure rate. A similar remark could be made for the first queue by exchanging the roles of the sets K and S.

Generalization to other load-distribution algorithms
The key insight from Section 6.1 is that we can describe the dynamics of tokens using a closed tandem network of two P&S queues, so that one queue contains tokens held by jobs in the machine pool and the other available tokens. In Section 6.2.1, we propose a more general framework based on the same idea. This framework extends the example of Section 6.1 in two ways: it allows not only for more general compatibility constraints between customer classes and servers, but also for multiple levels of preferences between customers. Sections 6.2.2 and 6.2.3 give a prototypical example for each extension.

Queueing model
Consider a closed tandem network of two P&S queues like that described in Section 5.2. Let I = {1, . . . , I} denote the set of customer classes and ≺ the placement order of this network. Recall that, for each i, j ∈ I such that i ≺ j, class-i customers precede (resp. succeed) class-j customers in the first (resp. second) queue. The swapping graph of the network is simply the underlying undirected graph of the placement graph. For each i ∈ I, let ℓ i denote the number of class-i customers in the network. We assume that both P&S queues are multi-server queues, like that described in Example 3.1, with compatibility graphs that will be described in the next paragraphs. In the applications we consider, customers represent tokens in a machine pool, so that the first queue contains tokens held by present jobs and the second queue available tokens. Let S = {1, . . . , S} denote the set of servers in the first queue and, for each s ∈ S, µ s the service rate of server s. For each class i ∈ I that is minimal with respect to the placement order ≺ (that is, there is no class j ∈ I with i ≻ j), we let S i ⊆ S denote the set of servers that can process class-i customers in the first queue. This defines a bipartite graph between the set of minimal classes and the set of servers. The set of servers that can process non-minimal classes is defined by an ascending recursion over the placement order. More specifically, for each class i ∈ I that is not minimal with respect to the placement order, the set of servers that can process class-i customers is S i = j∈I:j≺i S j . Going back to the example of Figure 8 Similarly, we let K = {1, . . . , K} denote the set of servers in the second queue and, for each k ∈ K, ν k the service rate of server k. For each class i ∈ I that is maximal with respect to the placement order ≺ (that is, there is no class j ∈ I with i ≺ j), we let K i ⊆ K denote the set of servers that can process class-i customers. This defines a bipartite graph between the set of maximal classes and the set of servers. The set of servers that can process non-maximal classes is defined by a descending recursion over the placement order. More specifically, for each class i ∈ I that is not maximal, the set of servers that can process class-i customers is K i = j∈I:i≺j K j . By again considering the example of Figure 8 = (d 1 , . . . , d m ) and the overall and individual service rates in this queue are given by (6.1) and (6.2), respectively.
In this new framework, the placement order describes not only priorities between classes but also compatibilities between classes and servers. Using this observation, we will now see that the structure of the closed tandem network can be described more compactly by a mixed graph (that is, a graph with both directed and undirected edges). The mixed graph associated with the model of Figure 8 is shown in Figure 10. The subgraph induced in this mixed graph by the set of classes describes the placement order. The subgraph induced by the set of minimal classes and the set of machines, as shown at the bottom of Figure 10, describes the compatibilities between the minimal classes and the servers of the first queue. The set of servers that can serve a non-minimal class is the union of the sets of servers that can serve the ancestors of this class. Similarly, the subgraph induced by the sets of maximal classes and the set of job types, as shown at the top of Figure 10, describes the compatibilities between the maximal classes and the servers of the second queue. The set of servers that can serve a non-maximal class is the union of the sets of servers that can serve the descendants of this class. Figures 12 and 14 show more elaborate examples of mixed graphs that will be studied in Sections 6.2.2 and 6.2.3.
As in Section 6.1, some customers may never be in service. In the first queue, the only customers that can be in service are those of the classes that are minimal with respect to the placement order. A customer of a class i ∈ I that is not minimal can only leave this queue upon the service completion of a customer of a minimal class j ∈ I such that j ≺ i. Similarly, only customers of classes that are maximal with respect to the placement order can be in service in the second queue. A customer of a class i ∈ I that is not maximal can only leave this queue upon the service completion of a customer of a maximal class j ∈ I such that i ≺ j.
Applying the results of Section 5.2.3 allows us to directly derive a closed-form expression for the stationary distribution of the network microstate. We adopt the notation of this section. In particular, the state space of the Markov process associated with the network microstate (c, d) is denoted by Σ and characterized by (5.6). Assuming that this Markov process is irreducible, it follows from Theorem 5.10 that its stationary distribution is given by where the constant G follows from normalization. We now consider two examples that illustrate the descriptive power of this framework. Section 6.2.2 gives an extension of the introductory example of Section 6.1 to a machine pool where requests can be distributed over several machines. Section 6.2.3 looks at a token-based hierarchical load-distribution algorithm.

Distributed processing
As in Section 6.1, we consider a pool that consists of a dispatcher and a set S = {1, . . . , S} of machines. The set of job types is denoted by K = {1, . . . , K} and, for each k ∈ K, type-k jobs arrive according to an independent Poisson process with rate ν k and have independent and exponentially distributed sizes with unit mean. Depending on its type and on the system state, an incoming job can be assigned to one (or more) machine(s), put on hold, or blocked.
The difference with Section 6.1 is that an incoming job is not assigned to a single machine anymore but to a group of machines that will subsequently be able to process this job in parallel. We let T = {1, . . . , T } denote the set of group indices and, for each t ∈ T , S t ⊆ S the set of machines that belong to group t and K t ⊆ K the set of job types that can be assigned to group t. Conversely, we let T s ⊆ T denote the set of groups that contain machine s, for each s ∈ S, and T k ⊆ T the set of groups to which type-k jobs can be assigned, for each k ∈ K. This defines a tripartite assignment graph between job types, groups, and machines, as shown in Figure 11. The introductory example of Section 6.1 corresponds to the special case in which there is a one-to-one correspondence between groups and machines, that is, T = S and S t = {t} for each t ∈ T .
A job is said to be assigned to a machine if it is assigned to a group that includes this machine. All present jobs are still gathered in a single queue in their order of arrival in the pool, and each machine processes its assigned jobs in FCFS order, while ignoring other jobs. In this way, each assigned job is in service on all the machines to which this job was assigned and no older job was assigned. For each t ∈ T , if a job assigned to group t is in service on a subset S ′ ⊆ S t of its assigned machines, the departure rate of this job is s∈S ′ µ s . The token-based assignment rule introduced in Section 6.1 is generalized as follows. For each t ∈ T , the job assignment to group t is regulated via ℓ t tokens so that, for each k ∈ K t , an incoming type-k job can be assigned to group t if and only if one of the tokens of this group is available. Additionally, for each k ∈ K, at most ℓ k type-k jobs can be put on hold if no token of a compatible group is available upon their arrival. In this way, when a type-k job arrives in the machine pool, one of the following events occurs: (i) if one or more tokens of the groups in T k are available, the job seizes the one of these tokens that has been available the longest and is assigned to the corresponding group; (ii) otherwise, if there are currently less than ℓ k type-k jobs on hold, the incoming job is put on hold until it can be assigned to one of its compatible groups; (iii) otherwise, the job is lost.
When a job assigned to group t completes service, this job leaves the machine pool immediately. Its token is seized by the oldest job of a type in K t on hold, if any, otherwise it is added to the queue of available tokens. Furthermore, the machines that were processing this job immediately start processing their next assigned job, if any. This machine pool can be seen as a generalization of that introduced in [13] to a scenario where incoming jobs are put on hold (instead of being blocked) in the absence of available compatible tokens. The dynamics of this machine pool can be described by the queueing model of Section 6.2.1 as follows. The set of customer classes is I = K ⊔ T . The placement order is defined by t ≺ k for each t ∈ T and k ∈ K t . The minimal classes are those corresponding to the (assignment tokens of the) machine groups and the maximal classes are those corresponding to the (holding tokens of the) job types. For each t ∈ T , the set of servers that can process class-t customers in the first queue is S t , the set of machines that belong to group t. For each k ∈ K, the set of servers that can process class-k customers in the second queue is {k}. The mixed graph associated with the example of Figure 11 is shown in Figure 12.

Hierarchical load distribution
Let H denote a positive integer. We consider a pool of 2 H−1 machines and denote by S = {1, . . . , 2 H−1 } the set of machines. Jobs arrive according to a Poisson process with a positive rate ν. Each incoming job is compatible with all machines but will eventually be assigned to and processed by a single machine. For each s ∈ S, the service time of a job on machine s is exponentially distributed with a positive rate µ s . The job arrivals within the machine pool are regulated via 2 H − 1 tokens numbered from 1 to 2 H − 1. A job that is waiting to be assigned to a machine holds a token numbered from 1 to 2 H−1 − 1, while, for each s ∈ {1, . . . , 2 H−1 }, a job in service on machine s holds token 2 H−1 + s − 1. Initially, when the pool is empty of jobs, all tokens are arranged in ascending order in a queue of available tokens, with token 1 at the head of the queue and token 2 H − 1 at the end. If a new job arrives and there is at least one available token, this job seizes the token obtained by applying the P&S mechanism in the queue of available tokens, starting from the token at the head of the queue, with the following swapping rule: for each i ∈ {1, . . . , 2 H−1 − 1}, token i can be swapped with tokens 2i and 2i + 1. An incoming job is lost if no token is available. Conversely, a service completion provokes the following chain reaction: if token i is released by a job, this token is seized by the job that holds token ⌊i/2⌋ (so that this token is in turn released and can be seized by another job), if any, otherwise it is added to the queue of available tokens. Priorities between tokens can be represented by a perfect binary tree of height H − 1 such that, for each i ∈ {1, . . . , 2 H−1 − 1}, the children of node i are nodes 2i and 2i + 1. Figure 13 shows an example with H = 3. Leaf nodes correspond to tokens held by jobs in service on a machine. For each h ∈ {1, . . . , H − 1}, the nodes at depth h in the tree correspond to tokens 2 h−1 to 2 h − 1. A job holding one of these tokens is H − h steps away from entering in service on a machine. Indeed, if a job holds a token i ∈ {1, . . . , 2 H−1 − 1} and a token that belongs to the subtree rooted at node i is released, this job will seize either token 2i or token 2i + 1, thus getting one step closer to entering in service on a machine. The corresponding queueing model, based on the framework of Section 6.2.1, is defined as follows. The set of customer classes is I = {1, . . . , 2 H −1}. For each i ∈ I, there is a single class-i customer which corresponds, in the machine pool, to token i. The placement order is defined as follows: for each i ∈ {1, . . . , 2 H−1 − 1}, i ≻ 2i and i ≻ 2i + 1 (so that the placement graph is obtained by reversing edges in the perfect binary tree defined in the previous paragraph). In particular, if the queue of available tokens is not empty, the customer at the head of this queue is necessarily customer 1. The set of servers in the first queue is S = {1, . . . , 2 H−1 }. The set of minimal customer classes is {2 H−1 , 2 H−1 + 1, . . . , 2 H − 1} and, for each s ∈ {1, . . . , 2 H−1 }, class 2 H−1 + s − 1 is compatible with server s. In the second queue, there is a single server of rate ν. The only maximal class is class 1 and this class is compatible with this server. The mixed graph associated with the perfect binary tree of Figure 13 is shown in Figure 14.
This hierarchical load-distribution strategy could be generalized by considering a perfect a-ary tree with a ≥ 2 or a directed rooted tree, so that each node represents a class of tokens and the tokens associated with leaf nodes give access to machines. By combining this idea with that of Section 6.2.2, we could also consider a directed acyclic graph and associate a job type with one or more nodes without ancestor and a machine or a group of machines with each node without descendant.

Conclusion
In this paper, we introduced pass-and-swap (P&S) queues, an extension of order-independent (OI) queues in which, upon a service completion, customers move along the queue and swap position with other customers, depending on compatibilities defined by a so-called swapping graph. We showed that a stable P&S queue is quasi-reversible and that, surprisingly, its product-form stationary distribution is independent of its swapping graph. We then studied networks of P&S queues. Although deriving the stationary distribution of open networks is a straightforward application of quasi-reversibility, the case of closed networks is more intricate because the Markov process describing the network microstate over time is not necessarily irreducible. For closed networks with one or two queues and a deterministic routing process, we observed that the P&S mechanism allows for the enforcement of priorities between classes, in the sense that a customer cannot leave a queue before all customers of the classes with higher priority leave it. Finally, we showed that such closed networks describe the dynamics of the loss variants of several token-based load-distribution algorithms, such as ALIS and FCFS-ALIS. This work suggests that we still do not have a complete picture of all queueing dynamics that lead to a product-form stationary distribution, which leaves open an important avenue for further study. Another open question is formed by the irreducibility of the Markov process underlying closed networks. While we established irreducibility of this Markov process under the condition that, at any point in time, each customer has a positive service rate, the characterization of irreducibility properties of the Markov process underlying general closed networks, and their impact on the stationary distribution (along with its productform nature), remains an open question. A different direction of further research entails the applications of P&S queues. In particular, in Section 6, we regarded applications based on multi-server queues as defined in Example 2.2. Although applications with arbitrary customer-server compatibilities, such as load-balancing and resource-management algorithms in computer systems, form the motivation for this work, we believe that P&S queues can be successfully applied to other systems involving priorities. This would require the use of more general P&S queues than just multi-server queues.
Case v = 2: If two customers were involved in the transition, this means that the departing customer of class i was ejected by a second customer whose service was completed. The P&S mechanism and the symmetric property of the swapping relation impose that this second customer is the one we have just identified, in position q 1 , and that q 1 ≥ 1. We let i 1 = c q1 ∈ I i0 denote the class of this second customer. By the same argument as before, this second customer could be in any position p ∈ {q 2 + 1, . . . , q 1 } before the transition, where q 2 is the largest integer q ∈ {1, . . . , q 1 − 1} such that c q ∈ I i1 , if any, and q 2 = 0 otherwise. In both cases, before the departure, the queue could be in any microstate of the form d = c 1...p−1 , i 1 , c p...q1−1 , i 0 , c q1+1...n , where p ∈ {q 2 + 1, . . . , q 1 }.
Case v = 3: The departing customer was ejected by a second customer, which was ejected by a third customer whose service was completed. Pursuing the previous reasoning, we can show that the second involved customer is that of class i 1 = c q1 , in position q 1 , and the third involved customer is that of class i 2 = c q2 , in position q 2 , assuming that 1 ≤ q 2 < q 1 . Before the transition, this third customer could be in any position p ∈ {q 3 + 1, . . . , q 2 }, where q 3 is the largest integer q ∈ {1, . . . , q 2 − 1} such that c q ∈ I i2 , if any, and q 3 = 0 otherwise. Before the departure, the queue could be in any microstate d = c 1...,p−1 , i 2 , c p...q2−1 , i 1 , c q2+1...q1−1 , i 0 , c q1+1...n , where p ∈ {q 3 + 1, . . . , q 2 }.
Continuing on, we build a decreasing sequence n + 1 = q 0 > q 1 > q 2 > . . . > q u−1 > q u = 0 of positions in microstate c using the recursion q v = max{q ≤ q v−1 − 1 : c q ∈ I iv−1 } for each v ∈ {1, . . . , u − 1}. The recursion stops when the set {q ≤ q v−1 − 1 : c q ∈ I iv−1 } is empty, in which case we let u = v and q u = 0. This integer u gives the maximum number of customers that can be involved in the transition (including the departing class-i customer). We also define a sequence i 0 = i, i 1 = c q1 , i 2 = c q2 , . . . , i u−1 = c qu−1 of classes.
In the end, the microstates d that lead to microstate c by a departure of a class-i customer are those of the form Proof of the lemma. Our proof is by induction on the maximum number u ≥ 1 of customers involved in the transition. More specifically, we show that the following statement holds for each positive integer u: Equation (A.1) is satisfied for each integer n ≥ u−1, microstate c = (c 1 , . . . , c n ) ∈ I n , class i ∈ I, and decreasing integer sequence q 0 , q 1 , . . . , q u with q 0 = n + 1 and q u = 0.
Before we proceed to the proof by induction, recall that Φ satisfies the following equation, which is a rewritten version of Equation Induction step. Now let u ≥ 2 and assume that the statement is valid for each u ′ ∈ {1, 2, . . . , u − 1}.
Consider an integer n ≥ u − 1, a microstate c = (c 1 , . . . , c n ) ∈ I n , a class i ∈ I, and a decreasing integer sequence q 0 , q 1 , . . . , q u with q 0 = n + 1 and q u = 0. Also let i 0 = i, i 1 = c q1 , i 2 = c q2 , . . . , i u−1 = c qu−1 . We first apply (A.2) to microstate c and class i = i 0 and split the sum into two parts to obtain Using the definition (2.4) of Φ and the fact that µ is order independent, we rewrite the first sum differently: Now we apply the induction assumption to the positive integer u ′ = u − 1, with the integer n ′ = q 1 − 1, the microstate c ′ = c 1...q1−1 , the class i 1 , the decreasing sequence q ′ 0 = q 1 = n ′ + 1, q ′ 1 = q 2 , . . . , q ′ u−2 = q u−1 , q ′ u ′ = q ′ u−1 = q u = 0, and the indices i ′ We can verify that n ′ ≥ u ′ − 1 because the sequence q 1 , q 2 , . . . , q u is decreasing with q u = 0, so that q 1 ≥ q 2 + 1 ≥ q 3 + 2 ≥ . . . ≥ q u + (u − 1) = u − 1. For this setting, (A.1) implies that Note that the first sum ranges from 1 to u − 1, and not from 0 to u ′ − 1 = u − 2, as a result of rewriting. We again apply (2.4) and the fact that µ is order independent to move the product back into the first sum, so that we obtain We conclude by observing that the second sum corresponds to the missing term v = 0 in the first sum.

A.2 Proof of Theorem 4.1
We first prove that (4.2) is a necessary condition for stability by arguing that the Markov process describing the microstate of the queue over time cannot be ergodic in the absence of this condition. Then, we prove that this condition is sufficient, by comparing the P&S queue to a degenerate queue with pessimistic service rates.
Necessary condition Assume that there is a non-empty set A ⊆ I such thatμ(A) ≤ i∈A λ i . Since µ is non-decreasing, this means that µ(x) ≤ i∈A λ i for each x ∈ N I such that {i ∈ I : x i > 0} ⊆ A. Combining this inequality with (2.4) yields that, for any such x, and for each c ∈ I * such that |c| = x, we have In the first inequality, we restricted the outer sum so that we can apply (A.5). In the final equality, we used the multinomial theorem, stating that, for each positive integers n and N and reals ρ 1 , ρ 2 , . . . , ρ N , we have Since i∈A λi j∈A λj = 1, the final expression amounts to infinity, so that c∈I * Φ(c) i∈I λ i |c|i = ∞. This ensures that (2.5) is not satisfied, so that the Markov process on I * cannot be ergodic.

Sufficient condition
Assuming that (4.2) is satisfied, we prove stability in two steps. We first introduce a second P&S queue with the same set I of classes and arrival rates λ 1 , . . . , λ I as the original P&S queue, but with a rate functionμ such thatμ(x) ≤ µ(x) for each x ∈ N I . We will refer to this second P&S queue as the degenerate P&S queue, as the service rate received by the customers of each class only depends on the number of customers of this class. Then we will show that the degenerate P&S queue is stable. Since the degenerate P&S queue has more pessimistic service rates than the original P&S queue, this also implies that the original P&S queue is stable, as we will see below.
We first introduce several quantities that will be useful to define the degenerate P&S queue. Sinceμ satisfies (4.2), there exists an m ∈ N such that i∈A λ i < µ(me A ), ∀A ⊆ I : A = ∅.
We can also findλ = (λ 1 , . . . ,λ I ) ∈ R I + such that λ i <λ i for each i ∈ I, and The definitions of µ andλ guarantee that δ > 0. In the degenerate P&S queue, δ will be the service rate of the customer classes that have less than m present customers. As we will see later, choosing this value of δ ensures that the service rate of the degenerate queue is always smaller or equal to that of the original queue. The degenerate P&S queue is defined as follows. Just like the original P&S queue, the set of customer classes is I = {1, . . . , I} and the per-class arrival rates are λ 1 , . . . , λ I . But the rate functionμ of this new queue is defined on N I byμ(x) = i∈Iμ i (x i ), witĥ In this way, for each i ∈ I, the oldest class-i customer is served at rate min(δ,λ i ) and the m-th oldest class-i customer is served at rate max(λ i − δ, 0). The service rate of other class-i customers is zero. It follows that, for each x ∈ N I \ {0}, we haveμ(x) ≤ µ(x). Indeed, • if x i < m for each i ∈ I, thenμ (x) ≤ i∈I:xi>0 δ ≤ i∈I:xi>0 where the first inequality follows from the definition ofμ and the second holds by (A.6); • otherwise, with A = {i ∈ I : x i ≥ m}, we have A = ∅ and x ≥ me A , so that where the first inequality follows from the definition ofμ, the second holds by (A.6), and the fourth follows from the monotonicity of µ.

A.3.1 The isomorphic queue
We first define, for any closed P&S queue, its associated isomorphic queue. If the initial microstate of the original queue contains a single customer of each class, as in the example of Section 5.1.1, its associated isomorphic queue is the queue itself. We now describe how the isomorphic queue is constructed if the initial microstate of the original queue contains two or more customers of the same class. Let c = (c 1 , . . . , c n ) denote the initial microstate of the queue and consider a class i ∈ I and two positions p, q ∈ {1, . . . , n} such that c p = c q = i and p < q. We introduce an extra class j (so that I is replaced with I ∪ {j}) that has the same characteristics as class i. More specifically, we impose that ∆µ(d 1 , . . . , d m , i) = ∆µ(d 1 , . . . , d m , j) for each d = (d 1 , . . . , d m ) ∈ I * . In the swapping graph, for each k ∈ I \ {i, j}, we add an edge between classes j and k if and only if there is an edge between classes i and k.
Moving towards a setting where all customers have different classes, we alter the initial microstate c by changing the class of the customer in position q from i to j. While c p and c q are not equal anymore, the definition of class j guarantees that the dynamics of the queue remain the same. This procedure can be repeated with newly selected class i and positions p and q as long as there are at least two customers with the same class in microstate c. The queue obtained once all customers have different classes is called the isomorphic queue. Ifc is the initial microstate of the isomorphic queue obtained by repeating this procedure, we say that microstatec in the isomorphic queue corresponds to microstate c in the original queue.
Example A.2. We now illustrate the construction of an isomorphic queue by means of the closed P&S queue depicted in Figure 15. This queue has six customers belonging to three classes. There are two class-1 customers, three class-2 customers, and one class-3 customer. The initial microstate of the queue, shown in Figure 15b, is (c 1 , c 2 , c 3 , c 4 , c 5 , c 6 ) = (1, 2, 1, 2, 2, 3). This microstate does not adhere to any placement order because customers of classes 1 and 2 are interleaved. To construct the isomorphic queue, we progressively eliminate pairs of equal customer classes. For example, since c 1 = c 3 = 1, we introduce an extra class 1 ′ such that ∆µ(d 1 , . . . , d m , 1) = ∆µ(d 1 , . . . , d m , 1 ′ ) for each microstate d = (d 1 , . . . , d m ) ∈ I * , with I = {1, 2, 3}. Moreover, in the swapping graph, we add edges between class 1 ′ and classes 2 and 3. Finally, we change the class of the customer in position 3 to 1 ′ . This procedure has no effect on the future dynamics of the queue but the customers in positions 1 and 3 are now the only members of their respective classes. The result is not yet an isomorphic queue since, for example, the customers in positions 2 and 4 are both of class 2. We therefore iterate this procedure, changing the class of the customer in position 4 into class 2 ′ and adding an edge between class 2 ′ and classes 1, 1 ′ , and 3 in the swapping graph. After this action, only the customers in positions 2 and 5 belong to the same class. Changing the class of the customer in position 5 to an extra class 2 ′′ , with the same characteristics as class 2, yields the isomorphic queue shown in Figure 15. Microstate (1, 2, 1 ′ , 2 ′ , 2 ′′ , 3) in the isomorphic queue now corresponds to microstate (1, 2, 1, 2, 2, 3) in the original queue.
While the isomorphic queue has by construction the same dynamics as the original P&S queue, it has the following useful property. Lemma A.3. Every microstate of an isomorphic queue adheres to a unique placement order.
Proof. To prove this lemma, we show how to construct a placement graph for any microstate, which defines the placement order to which the state adheres, and moreover show that it is unique. Recall that a placement graph is an acyclic orientation of the swapping graph, and consists of as many vertices as there are customers in the isomorphic queue. Therefore, to construct the placement graph, the edges of the swapping graph need to be given an orientation. Recall that all customer classes appear exactly once in a state of an isomorphic queue. Therefore, we have that, for any two customer classes i and j for which an edge (i, j) exists in the swapping graph, the placement order ≺ of the placement graph to be constructed should satisfy i ≺ j or j ≺ i, depending on whether or not the class-i customer is nearer to the front of the queue than the class-j customer. Orienting each edge accordingly yields a directed graph. Due to the transitivity of the order of customers in the microstate, this directed graph must be acyclic, and therefore it is a placement graph to which the microstate adheres. Note that, if any edge's orientation corresponding to this placement order would be flipped, the corresponding pair of positions in the microstate will violate the new orientation. This proves the uniqueness, finalizing the proof.

A.3.2 Stationary distribution
Now that the isomorphic queue has been introduced, we can derive the stationary distribution for a closed P&S queue of which the initial microstate is not necessarily adhering. We can do this because the initial microstate of the isomorphic queue does necessarily adhere to a placement order, say ≺. Letl be the macrostate of the isomorphic queue corresponding to the initial macrostate ℓ of the closed P&S queue. We denote byC the set of microstatesc in the isomorphic queue that adhere to ≺ and satisfy |c| =l. Also let C denote the set of microstates of the original closed P&S queue to which the microstates inC correspond. Finally, for each c ∈ C, letC c ⊂C denote the set of microstatesc ∈C in the isomorphic queue that correspond to microstate c in the original queue. Note thatC c may consist of multiple elements and that, considering all c ∈ C, the setsC c form a partition ofC. For example, a microstate (1, 2, 2, 3) of a closed P&S queue may have corresponding microstates (1, 2, 2 ′ , 3) and (1, 2 ′ , 2, 3) in the isomorphic queue, both adhering to the same placement order. Importantly, since all microstates in C correspond to the same macrostate ℓ, the sets C c for all c ∈ C have the same cardinality. These definitions allow us to derive the stationary distribution of the Markov process associated with the microstate of the original P&S queue.
Theorem A.4. The results of Theorem 5.5 remain valid if C refers to the set of microstates of the original P&S queue to which the isomorphic microstates inC correspond.
Proof. By Lemma A.3, the initial microstate of the isomorphic queue must adhere to a placement order that we denote by ≺. Therefore, applying Theorem 5.5 to the isomorphic queue shows that the stationary distribution of the Markov process associated with its microstate is given bȳ , ∀c ∈C, whereΦ(c) = Φ(c) for each c ∈ C andc ∈C c . By construction of the isomorphic queue, the dynamics of the original P&S queue and its isomorphic queue are the same. As such, the stationary probability of the original queue residing in microstate c is equal to the stationary probability of the isomorphic queue residing in any microstate ofC c , leading to: , ∀c ∈ C.
Equation (5.1) follows by recalling thatΦ(c) = Φ(c) for eachc ∈C c and that all setsC c have the same cardinality.
Remark A.5. By Remark 5.6, the isomorphic queue cannot have transient states. Since an isomorphic queue with identical dynamics can be constructed for any closed P&S queue, this implies that the Markov process associated with the microstate of any closed P&S queue, regardless of any adherence of its initial state, cannot have transient states either. As a result, Theorem A.4 now implies a partition of the complete state space I * in closed communicating classes, each of which corresponds to a setC defined by a combination of a macrostatel and a particular placement order ≺ in the isomorphic queue.