{'fraction_non_alphanumeric': 0.05957258332410586, 'fraction_numerical': 0.02192448233861145, 'mean_word_length': 4.128525459019497, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
M/M/1 queue in two alternating environments and its heavy traffic approximation

We investigate an M/M/1 queue operating in two switching environments, where the switch is governed by a two-state time-homogeneous Markov chain. This model allows to describe a system that is subject to regular operating phases alternating with anomalous working phases or random repairing periods. We first obtain the steady-state distribution of the process in terms of a generalized mixture of two geometric distributions. In the special case when only one kind of switch is allowed, we analyze the transient distribution, and investigate the busy period problem. The analysis is also performed by means of a suitable heavy-traffic approximation which leads to a continuous random process. Its distribution satisfies a partial differential equation with randomly alternating infinitesimal moments. For the approximating process we determine the steady-state distribution, the transient distribution and a first-passage-time density.


Introduction
The M/M/1 queue is the most well-known queueing system, whose customers arrive according to a Poisson process, and the service times are exponentially distributed. Its generalizations are often employed to describe more complex systems, such as queues in the presence of catastrophes (see, for instance, Di Crescenzo et al. [15], Kim and Lee [28], and Krishna Kumar and Pavai Madheswari [29]). In some cases, the sequence of repeated catastrophes and successive repairs yields alternating operative phases (see, for instance, Paz and Yechiali [37] and Jiang et al. [25] for the analysis of queues in a multi-phase random environment). Moreover, realistic situations related to queueing services are often governed by state-dependent rates (cf., for instance, Giorno et al. [21]), or by alternating behavior, such as cyclic polling systems (cf. Avissar and Yechiali [3]). Specifically, the analysis of queueing systems characterized by alternating mechanisms has been object of investigation largely in the past. The first systematic contribution in this area was provided in Yechiali and Naor [39], where the M/M/1 queue was analyzed in the steady-state regime when the rates of arrival and service are subject to Poisson alternations. A recent study due Huang and Lee [26] is concerning a similar queueing model with a finite size queue and a service mechanism characterized by randomly alternating behavior.
Other types of complex systems in alternating environment are provided by two single server queues, where customers arrive in a single stream, and each arrival creates simultaneously the work demands to be served by the two servers. Instances of such two-queue polling models have been studied in Boxma et al. [7] and Eliazar et al. [19]. In other cases, instead, the alternating behavior of queueing systems is described by time-dependent arrival and service rates, such as in the M t /M t /1 queue subject to under-, over-, and critical loading. Heavy-traffic diffusion approximations or asymptotic expansions for such types of systems have been investigated in Di Crescenzo and Nobile [16], Giorno et al. [22], Mandelbaum and Massey [32].
Attention has been devoted in the literature also to queues with more complex random switching mechanisms, that arise naturally in the study of packet arrivals to a local switch (see, for instance, Burman and Smith [8]). Similar mechanisms have been studied recently also by Arunachalam et al. [2], Pang and Zhou [36], Liu and Yu [30] and Perel and Yechiali [38].
Contributions in the area of queues with randomly varying arrival and service rates are due to Neuts [35], Kao and Lin [27], and Lu and Serfozo [31]. Moreover, Boxma and Kurkova [5] studied an M/M/1 queue for which the speed of the server alternates between two constant values, according to different time distributions. A similar problem for the M/G/1 queue was studied by the same authors in [6], whereas the case of the M/M/∞ queue is treated by D'Auria [10].

Motivations
Along the lines of the above mentioned investigations, in this paper we study an M/M/1 queue subject to alternating behavior. The basic model retrace the alternating M/M/1 queue studied in [39]. Indeed, we assume that the characteristics of the queue are fluctuating randomly in time, under two operating environments which alternate randomly. Initially the system starts under the first environment with probability p, or from the second one w.p. 1 − p. Then, at time t the customers arrival rates and the service rates are (λ i , µ i ) if the operational environment is E (t) = i, for i = 1, 2. The operational environment switches from E (t) = 1 to E (t) = 2 with rate η 1 , whereas the reverse switch occurs with rate η 2 . This setting allows to model queues based on two modes of customers arrivals, with fluctuating high-low rates, where the service rate is instantaneously adapted to the new arrival conditions. Moreover, the considered model is also suitable to describe instances in which only one kind of rate is subject to random fluctuations. For instance, the case when only the service rate is alternating between two values µ 1 and µ 2 refers to a queue which is subject to randomly occurring catastrophes, whose effect is to transfer the service mechanism to a slower server for the duration of a random repair time.
The above stated assumptions are also paradigmatic of realistic situations in which the underlying mechanism of the queue is affected by external conditions that alternate randomly, such as systems subject to interruptions, or up-down periods. In this case, the adaptation of the rates occurs instantaneously, differently from other settings where customers observe the queue level before taking a decision (see, for instance, Economou and Manou [18]).
It is relevant to point out that the alternation between the rates may produce regulation effects for the queue mechanism. Indeed, if the current environment leads to a traffic congestion (i.e., λ i > µ i for E (t) = i), then the switch to the other environment may yield a favorable consequence for the queue length (if λ 3−i < µ 3−i ). This can be achieved by increasing the service speed, or decreasing the customer arrival rates. Note that the above conditions on the arrival and service rates, with appropriate switching rates η 1 and η 2 , may lead to a stable queueing system, even if the queue is not stable under one of the two environments.

Plan of the paper
In Section 2 we investigate the distribution of the number of customers and the current environment of the considered alternating queue. We first obtain the steady-state distribution of the system, which is expressed as a generalized mixture of two geometric distributions. This result provides an alternative solution to that obtained in [39] with a different approach. It is worth noting that the system admits of a steady-state distribution even in a case when one of the alternating environments does not possess a steady state. Furthermore, we also obtain the conditional means and the entropies of the process.
The transient probability distribution of the queue is studied in Section 3. Since the general case is not tractable, we analyse such distribution under the assumption that only a switch from environment E (t) = 1 to environment E (t) = 2 is allowed. In this case, we express the transient probabilities in a series form which involves the same distribution in the absence of environment switch. A similar result is also obtained for the first-passage-time (FPT) density through the zero state, aiming to investigate the busy period. The Laplace transform of the FPT density is also determined in order to evaluate the probability of busy period termination, and the related expectation.
In order to investigate the queueing system also under more general conditions we are lead to construct a heavy-traffic diffusion approximation of the queue-length process. This is obtained in Section 4 by means of a customary scaling procedure similar to those adopted in Dharmaraja et al. [11] and Di Crescenzo et al. [15]. The distribution of the approximating continuous process satisfies a suitable partial differential equation with alternating terms. Examples of diffusive systems with alternating behavior can be found in the physics literature. For instance, Bezák [4] studied a modified Wiener process subject to Poisson-paced pulses. In this case the effect of pulses is the alternation of the infinitesimal variance. A similar (unrestricted) diffusion process characterized by alternating drift and constant infinitesimal variance has been studied in Di Crescenzo et al. [12] and [17]. This is different from the approximating diffusion process treated here, for which all infinitesimal moments are alternating. The approach adopted in [17] cannot be followed for the process under heavy traffic, since it is restricted by a reflecting boundary at 0.
Concerning the approximating process, which can be viewed as an alternating Wiener process, we determine the steady-state density, expressed as a generalized mixture of two exponential densities. Then, in Section 5 for the approximating diffusion process we obtain the transient distribution when only one kind of switch is allowed. The distribution is decomposed in an integral form that involves the expressions of the classical Wiener process in the presence of a reflecting boundary at zero. Also for the alternating diffusion process we investigate the FPT density through the zero state, in order to come to a suitable approximation of the busy period. In this case, we express the related distribution in an integral form, and develop a Laplace transform-based approach aimed to study the FPT mean.
In the paper, the quantities of interest are investigated through computationally effective procedures by using MATHEMATICA.

The queueing model
, t ≥ 0} be a two-dimensional continuous-time Markov chain, having state-space N 0 × {1, 2} and transient probabilities where N(0) = (j, 1), with probability p, (j, 2), with probability 1 − p, with j ∈ N 0 . Here, N (t) describes the number of customers at time t in a M/M/1 queueing system operating under two randomly switching environments, and E (t) denotes the operational environment at time t. Specifically, if E (t) = i then the arrival rate of customers at time t is λ i whereas the service rate is µ i , for i = 1, 2, with constant parameters λ 1 , λ 2 , µ 1 , µ 2 > 0. We assume that two operational regimes alternate according to fixed constant rates. In other terms, if the system is operating at time t in the environment E (t) = 1 then it switches to the environment E (t) = 2 with rate η 1 ≥ 0, whereas if E (t) = 2 then the system switches in the environment E (t) = 1 with rate η 2 ≥ 0, with η 1 + η 2 > 0. Figure 1 shows the state diagram of N(t). We recall that the considered setting is in agreement with the model introduced in [39].

Steady-state distribution
Let us now investigate the steady-state distribution of the two-environment M/M/1 queue. We will show that it can be expressed as a generalized mixture of two geometric distributions. Our approach is different from the analysis performed in [39], where the steady-state distribution is achieved through recursive formulas. Let N = (N, E ) be the two-dimensional random variable describing the number of customers and the environment of the system in the steady-state regime. We aim to determine the steadystate probabilities for the M/M/1 queue under the two environments, defined as q n,i = P(N = n, E = i) = lim t→+∞ p n,i (t), n ∈ N 0 , i = 1, 2.
Similarly, on the left of Figure 4 are plotted the conditional means for a suitable choice of the parameters, showing that E[N |E = i] is decreasing in η 1 , for i = 1, 2. The mean E(N ) is plotted as function of η 1 on the right of Figure 4.
We remark that in the cases considered in Figures 3 and 4, the parameters satisfy the condition η 1 (µ 2 − λ 2 ) + η 2 (µ 1 − λ 1 ) > 0, and thus the joint steady-state probabilities of N there exist due to Proposition 1. Moreover, in the cases considered in Figures 3 and 4, one has λ 1 > µ 1 and λ 2 < µ 2 , so that in absence of switching the queue should not admit a steadystate regime in the first environment, whereas a steady-state regime should hold in the second environment. This example shows that the switching mechanism is useful to obtain stationarity, in the sense that the alternating M/M/1 queue may admit a steady-state regime even if one of the alternating environments does not.
Making use of Proposition 1 and Eq. (20) it is easy to determine the (Shannon) entropies  (24), is plotted with λ 1 = 1, . On the right, the entropy H(N ), given in (25), is plotted for the same choices of parameters.
where 'log' means natural logarithm. The conditional entropy (24) is a measure of interest in queueing, since it gives the average amount of information that is gained when the steady-state number of customers N in the queue is observed given that the system is in environment E = i. In Figure 5 we plot the conditional entropy (24) (on the left) and the entropy (25) (on the right) for the same case of Figure (15), (20) and (22) one can also define the following entropies Note that 0 ≤ H[E |N = n] ≤ log 2 and 0 ≤ H(E ) ≤ log 2. The conditional entropy (26) gives the average amount of information on the environment when the number of customers N = n in the queue is observed, whereas the entropy (27) gives the average amount of information on with A i defined in (16). Therefore, the conditional average amount of information on the environment tends to the value given in (28)  3 Analysis of case η 2 = 0 In the general case it is hard to determine the transient distribution of N(t). Hence, we limit ourselves to the analysis of the system with η 2 = 0 and with the initial state given in (2).  We remark that, the case η 1 = 0 can be studied similarly by symmetry.

Transient probabilities
Hereafter, we express the transient probabilities (1) in terms of the analogue probabilities p (i) j,n (t) of two M/M/1 queueing systems N (i) (t), t ≥ 0, i = 1, 2, characterized by arrival rate λ i and service rate µ i . Note that, for j, n ∈ N 0 , t ≥ 0 and i = 1, 2, we have (see, e.g., Zhang and Coyle [40], or Eq. (32) of Giorno et al. [23]) where I ν (z) denotes the modified Bessel function of the first kind. Moreover, making use of Eq. (49), pag. 237, of Erdélyi et al. [20], for n ∈ N 0 , t ≥ 0 and i = 1, 2, we have Proposition 2 Let η 2 = 0. For all t ≥ 0 and j, n ∈ N 0 , the transition probabilities of N(t) can be expressed as: j,k (τ ) p where p (i) j,n (t) are provided in (29) and (30). Proof. It follows from (4) and (5), recalling the initial conditions (3). 2 In the case η 2 = 0, at most one switch can occur (from environment 1 to environment 2). Hence, Eq. (31) is also obtainable by noting that p n,1 (t) can be viewed as the probability that process N(t) is located at (n, 1) at time t, starting from (j, 1) at time 0, with probability p, and that no 'switches' occurred up to time t. Similarly, resorting to the total probability law, Eq. (32) is recovered by taking into account that process N(t) is located at (n, 2) at time t in two cases: -when starting from (j, 2) at time 0, with probability 1 − p, and performing a transition from (j, 2) to (n, 2) at time t, -when starting from (j, 1) at time 0, with probability p, then performing a transition from (j, 1) to (k, 1) at time τ (with k ∈ N 0 and 0 < τ < t), then switching from environment 1 to environment 2 at time τ , and finally performing a transition from state (k, 2) to (n, 2) in the time interval (τ, t).

First-passage time problems
We now analyze the first-passage time through zero state of the system when η 2 = 0. To this aim, first we define a new two-dimensional stochastic process { N(t) = [ N (t), E (t)], t ≥ 0} whose state diagram is given in Figure 9. This process is obtained from N(t) by removing all the transitions from (0, i), i = 1, 2. In this case only transitions from the first to the second environment are allowed. Moreover, (0, 1) and (0, 2) are absorbing states for the process N(t). We denote by Since η 2 = 0 the following equations hold: with initial conditions In order to obtain suitable relations for the state probabilities (33), we recall that the transition probabilities avoiding state 0 for the M/M/1 queue with arrival rate λ i and service rate µ i , for j, n ∈ N and t > 0 is (cf. Abate et al. [1]) and, due to relation I j−1 (z) − I j+1 (z) = 2j I j (z)/z (cf. Eq. 8.486.1, p. 928 of [24]), Proposition 3 If η 2 = 0, for j ∈ N, n ∈ N 0 and t > 0, for the state probabilities (33) one has: where α (i) j,k (t) are given in (38) and (39).
Proof. It follows from (35) and (36), recalling the initial conditions (37). 2 The term in the right-hand-side of (40) can be interpreted as follows: starting from (j, 1) at time 0, with probability p, the process reaches (n, 1), with n ∈ N, at time t without crossing (0, 1) in the interval (0, τ ), and no switches occurred up to time t. Instead, the 2 terms in the right-hand-side of (41) have the following meaning: -starting from (j, 2) at time 0, with probability 1 − p, the process reaches (n, 2) at time t, with n ∈ N, at time t without crossing (0, 2) in the interval (0, τ ); -starting from (j, 1) at time 0, with probability p, the process reaches (k, 1), with k ∈ N, at time τ ∈ (0, t) without crossing (0, 1) in the interval (0, τ ), then a switch occurs at time t, and starting from (k, 2) the process reaches (n, 2) at time t without crossing (0, 2) in the interval (τ, t).
For j ∈ N, we consider the random variable where N(0) is given in (2), with j ∈ N. Note that T j denotes the first-passage time (FPT) of the process N(t) through zero starting from (j, 1) with probability p and from (j, 2) with probability 1−p, with j ∈ N. Hence, T j is the first emptying time of the queue, with the initial state specified in (2). For η 2 = 0, the FPT of N(t) through (0, 1) or (0, 2) is identically distributed as the FPT of N(t) through the same states. Therefore, the first passage through (0, 1) or (0, 2) for N(t) can be studied via the probabilities obtained in Proposition 3. Specifically, recalling (33), for j ∈ N we have: γ n,1 (t) + γ n,2 (t) = 1.
We focus our attention on the FPT probability density Hereafter we show that such density can be expressed in terms of the first-passage-time density from state j ∈ N to state 0 of the M/M/1 queues with rates λ i and µ i , i = 1, 2, given by (see, for instance, [1]): Proposition 4 If η 2 = 0, for t > 0 FPT probability density (43) is expressed as: j,0 (t) + (1 − p) g (2) j,0 (t) where g (i) k,0 (t) is the FPT density given in (44).
Proof. Making use of (35) and (36) Due to Proposition 3, from (46) for j ∈ N it follows: By virtue of (39) and (44) one has µ i α j,0 (t) for i = 1, 2, so that (45) immediately follows from (47). 2 For j ∈ N, the 3 terms in the right-hand-side of the FPT density (45) can be interpreted as follows: -starting from (j, 1) at time 0, with probability p, the process reaches (0, 1) for the first time at time t, and no switches occurred up to time t; -starting from (j, 2) at time 0, with probability 1 − p, the process reaches (0, 2) for the first time at time t; -starting from (j, 1) at time 0, with probability p, the process reaches (k, 1), with k ∈ N, at time τ ∈ (0, t) without crossing (0, 1) in the interval (0, τ ), then a switch occurs at time t, and starting from (k, 2) the process reaches (0, 2) for the first time at time t.

Let
be the Laplace transform of the FPT density b j (t).

Diffusion approximation
This section is devoted to the construction of a heavy-traffic diffusion approximation for the process N(t). As customary, we adopt a scaling procedure that is usual in queueing theory and in other contexts (c.f. Di Crescenzo et al. [15] or Dharmaraja et al. [11], for instance). As a first step, we perform a different parameterization of the arrival and service rates of the stochastic model introduced in Section 2. Specifically, we set where λ * i > 0, µ * i > 0, ω 2 i > 0, for i = 1, 2, and > 0. We remark that is a positive parameter that has a relevant role in the scaling procedure indicated below. Let for n ∈ N 0 and i = 1, 2. In the limit as → 0 + , it can be shown that the scaled process N * (t) converges weakly to a two-dimensional stochastic process, say Note that X(t) may be viewed as a restricted Wiener process alternating between two environments, with switching rates η 1 and η 2 . For x ∈ R + 0 , t > 0 and i = 1, 2, let denote the probability densities of the process X(t), where the initial state is X(0) = (y, 1), with probability p, (y, 2), with probability 1 − p, with y ∈ R + 0 . Starting from the forward equations for N(t), given in Eqs. (4) and (5), the scaling procedure mentioned above yields that the densities (55) satisfy the following partial differential equations of Kolmogorov type, for i = 1, 2, x ∈ R + and t > 0: We note that the first 2 terms in the right-hand-side of (57) correspond to the classical diffusive operators of a Wiener process, whereas the last 2 terms express the joking between the two different environments, occurring with switching rates η 1 and η 2 . The first and second infinitesimal moments of the Wiener process in the i-th environment are respectively λ * i − µ * i and ω 2 i , i = 1, 2. It is worth pointing out that, due to the scaling procedure, the first equations of systems (4) and (5) lead to the following reflecting condition at 0: for t > 0 and i = 1, 2. Moreover, since for the process N(t) the initial condition is expressed by a Bernoulli trial, similarly as (3) we have the following dichotomous initial condition for densities (55): lim where δ(·) is the Dirac delta function. Furthermore, in analogy with (6), the normalization condition holds for all t ≥ 0. We remark that positions (53) express a heavy-traffic condition, since the rates λ i and µ i tend to infinity when → 0 + in the approximation procedure.

Steady-state density
Let us now investigate the steady-state densities of X(t). Let X = (X, E ) be the two-dimensional random variable of the system in the steady-state regime. We aim to determine the steady-state densities in the two environments, defined as From (57) and (58) one has the following differential equations: to be solved with the boundary conditions: Hence, denoting by the moment generating functions for the two environments in steady-state regime, one has: where P * (z) is the following third-degree polinomial in z: By taking into account the normalization condition M 1 (0) + M 2 (0) = 1, from (62) one obtains: Recalling that η 1 + η 2 > 0, Eq. (64) shows that the steady-state regime exists if and only if one of the following cases holds: (i) η 2 = 0 and λ * 2 /µ * 2 < 1, (ii) η 1 = 0 and λ * 1 /µ * 1 < 1, Hereafter, we consider separately the three cases.
Since the functions (70) are finite for all z in some interval containing the origin, the moment generating functions M 1 (z) and M 2 (z) determine the probability densities W 1 (x) and W 2 (x). Indeed, by inverting the moment generating functions, for x ∈ R + one obtains: from which (67) immediately follows. 2 In the continuous approximation, by virtue of (65), from (70) one has: which provides the same result given in (20) for the discrete model. Similarly to discrete case, we have that P(X < x|E = 1) and P(X < x|E = 2) are both generalized mixtures of two exponential distributions of means 1/ξ * 1 and 1/ξ * 2 , respectively. Making use of Proposition 6 and of (72), the conditional means immediately follow: Corollary 2 Under the assumptions of Proposition 6, for x ∈ R + one obtains the steady-state density of the process X: where A * 1 and A * 2 are provided in (68) and h 1 (x), h 2 (x) are exponential density with means 1/ξ * 1 and 1/ξ * 2 , respectively.
5 Analysis of the diffusion process for η 2 = 0 Let us now analyze the transient behaviour of the process X(t) = [X(t), E (t)] in the case η 2 = 0, with the initial state specified in (56).
Proof. It follows from (57), taking into account the boundary conditions (58) and the initial conditions (59). 2 The probabilistic interpretation of (77) and (78) is similar to the discrete queueing model.

First-passage time problem
We consider the first-passage time through (0, 1) or (0, 2) states when η 2 = 0. To this purpose, we define a two-dimensional stochastic process { X(t) = [ X(t), E (t)], t ≥ 0}, obtained from X(t) by removing all the transitions from (0, 1) and (0, 2). We assume that X(0) = (y, 1) with probability p and X(0) = (y, 2) with probability 1 − p, being y ∈ R + . Similarly to the discrete queueing model, only transitions from the first to the second environment are allowed. Hence, for y ∈ R + , denoting by the transition density of the process X(t), one has: with the absorbing boundary conditions and the initial conditions Hereafter we express the transition densities (79) in terms of the probability densities of the Wiener processes X (i) (t) in the presence of an absorbing boundary in the zero state for x, y ∈ R + , which is given by (cf. [9]) Proposition 8 If η 2 = 0, for y ∈ R + , x ∈ R + 0 and t > 0, the transition densities (79) can be expressed as: h 1 (x, t|y) = p e −η 1 t α (1) (x, t|y), h 2 (x, t|y) = (1 − p) α (2) (x, t|y) where α (i) (x, t|y) are provided in (83).
Hereafter we focus on the FPT probability density k(0, t|y) = d dt P(T y < t), t > 0, y ∈ R + .
We first get the steady-state distribution of the system, which is expressed via a generalized mixture of two geometric distributions. A remarkable result is that the system admits of a steady-state distribution even if one of the alternating environments does not possess a steady state. Hence, the switching between the environments can be used to stabilize a non stationary M/M/1 queue by means of the random alternation with a similar queue characterized by steady state.
Moreover, attention has been given to the transient distribution of the alternating queue, which can be expressed in a series form involving the queue-length distribution in absence of switching. A similar result is obtained also for the first-passage-time density through the zero state, in order to investigate the busy period.
The second part of the paper has been centered on a heavy-traffic approximation of the queue-length process, that leads to an alternating Wiener process restricted by a reflecting boundary at zero. The analysis of the approximating process has been devoted to the steadystate density, which is expressed as a generalized mixture of two exponential densities. Moreover, we determined the transition density when only one type of switch is allowed. Such density can be decomposed in an integral form involving the expressions of the Wiener process in the presence of a reflecting boundary at zero. Finally, we analyzed the first-passage-time density through the zero state, which gives a suitable approximation of the busy period density.