## 2 Queue Model  
### Mathematical Formulation of Queue  
This section presents the queuing analysis used to control EV's charging load. Figure 1 shows the schematic diagram for a population of EVs connected to the network to start the charging process. From the network point of view, the process is a queueing system consisting of three main parts:  
* Arrivals of EVs characterized by a statistical distribution with an arrival rate which is represented by a number \(N_{EV}\) of the EV connected to the grid at a specific time T (see Figure 1)
* EVs queue includes several EVs waiting in a line to charge. It should be mentioned here that the line represents EVs connected to the network and all vehicles are connected to the network and are either charging or not. * The charging service includes several servers (charging points NCP) subject to a statistical distribution of service times (charging time). Hence, the DSM for EVs charging can be defined as a multi-servers (M/M/s) queue with identical server number (charging points) \(N_{CP}\). Each charging point has an operating process with an exponential Poisson service rate \(T_{full}\). The most important parameters for any queue are: the average time spent in the queue, average queue length, and the overall average time spent in the system [47]. To obtain these parameters, a Markov chain is used in the queueing analysis [48]. A sequence of random variables \(X_{1},\ X_{2},X_{3},\dots\ X_{n}\) is defined as a Markov chain for \(n\) steps, where the transition probability to the following state only depends on the current state. \[Pr(X_{n+1}=j|X_{n}=i,\ X_{n-1}=x_{n-1},\dots\dots\dots X_{0}=x_{0})=Pr(X_{n+1} =j|X_{n}=i) \tag{1}\]  
where \(Pr\) is the probability. The transition probability \(P_{ij}^{(n)}\) between two state \(i\) and \(j\) in \(n\) steps can be expressed as:  
\[P_{ij}^{(n)}=Pr(X_{n+1}=j|X_{n}=i) \tag{2}\]  
where the transition matrix \(Q\) can be expressed as:  
\[Q=\left[P_{ij}\right] \tag{3}\]In this work, the arranged EVs in the queue is considered the state of the chain, where the state transition occurs when an EV arrived, or a connected EV reached its full charge state \(T_{full}\), hence it is virtually unplugged viz., idle state, or to depart physically. A birth-death is applied as a stochastic model to represent the evolving process of the system, wherein the queuing model \"birth\" denotes the customer arrival while \"death\" denotes the customer departure. The transition rate diagram is exhibited in Figure 2. The figure shows the transition for \(N_{EV}\) states when all states have an arrival rate \(\lambda\) but there are two different service rates. In case of the number of EV less than the charging point \(N_{CP}\) number (\(N_{EV}<N_{CP}\)) the service rate is \(N_{EV}\)\(T_{full}\) otherwise, in case of the number of EV greater than the charging point number (\(N_{EV}>N_{CP}\)) in which all charging points have occupied, the rate is \(N_{CP}\)\(T_{full}\). By applying the Markov chain using the transition rate diagram shown in Figure 2 the transition probability matrix can be written as in (4). Figure 1: The schematic diagram for EVs charging process with a dynamic queue model. Figure 2: Transition rate diagram. \[Q=\left[ \begin{array}{cccccccc}-\lambda&\lambda&0&0&0\\ T_{full}&-\left(\lambda+T_{full}\right)&\lambda&0&0&\cdots\\ 0&2T_{full}&-\left(\lambda+2T_{full}\right)&\lambda&0\\ 0&0&3T_{full}&-\left(\lambda+3T_{full}\right)&\lambda&\\ &&&&&\ddots\\ &&\cdots&&&N_{CP}\ T_{full}&-\left(\lambda+N_{CP}\ T_{full}\right)&\lambda&0\\ &&&&0&N_{CP}\ T_{full}&-\left(\lambda+N_{CP}\ T_{full}\right)&\lambda\\ \end{array} \right] \tag{4}\]  
The stationary condition which describes the steady-state condition is expressed by the following equation:  
\[[\pi][Q]=0 \tag{5}\]  
where \(\pi\) is the stationary vector \(\pi=\left[\pi_{0}\ \pi_{1}\ \pi_{2}\ \ldots\ \pi_{N_{EV}}\right]\). The general formula for the stationary distribution at any state \(n\) can be written as:  
\[\pi_{N_{EV}}=\left\{