# Sustainable Operation of Active Distribution Networks
## 3 Agents' Modeling
### Local Agents
#### 3.1.3 Plug-in Electric Vehicle Agent (PEV/A)  
PEV/A calculates the boundaries of each PEV's state of charge and the active and reactive power it trades with the distribution network. According to these characteristics, the area the PEV is permitted to operate is derived [16], and is shown in Figure 2.  
The time that the EV is plugged to the network and unplugged from it is denoted with \(t_{0}\) and \(t_{f}\), respectively. \(SoC_{max}\) and \(SoC_{min}\) are the maximum and the minimum values of the PEV's battery state of charge. \(SoC_{0}\) is the initial state of charge (kWh) of each PEV.  
Figure 2: Bounds of the PEV’s stored energy.  
and \(P_{min}\) (kW) are the maximum and minimum power that the PEV's battery can exchange with the network, respectively. \(SoC_{target}\) (kWh) is the stored energy target that the driver has defined the PEV should reach at its disconnection time. The dynamic lower and upper bounds of the PEV's SoC, SoC\({}_{low}\), and SoC\({}_{high}\) are generally defined by 4 points where they start to decrease or increase with a constant rate of change \(P_{min}\) or \(P_{max}\), respectively. These points are (\(t_{0}\), \(SoC_{0}\)), (\(t_{L_{1}}\), \(SoC_{min}\)), (\(t_{L_{2}}\), \(SoC_{min}\)), and (\(t_{f}\), \(SoC_{target}\)) for SoC\({}_{low}\) and (\(t_{0}\), \(SoC_{0}\)), (\(t_{H_{1}}\), \(SoC_{max}\)), (\(t_{H_{2}}\), \(SoC_{max}\)), (\(t_{f}\), \(SoC_{target}\)) for SoC\({}_{high}\).  
\(t_{L_{1}}\), \(t_{H_{1}}\), \(t_{L_{2}}\) and \(t_{H_{2}}\) are estimated as in the following:  
\[t_{L_{1}}(i)=t_{0}(i)+\frac{SoC_{min}(i)-SoC_{0}(i)}{P_{min}(i)} \tag{9}\]  
\[t_{H_{1}}(i)=t_{0}(i)+\frac{SoC_{max}(i)-SoC_{0}(i)}{P_{max}(i)} \tag{10}\]  
\[t_{L_{2}}(i)=t_{f}(i)+\frac{SoC_{target}(i)-SoC_{min}(i)}{P_{min}(i)} \tag{11}\]  
\[t_{H_{2}}(i)=t_{f}(i)+\frac{SoC_{target}(i)-SoC_{max}(i)}{P_{max}(i)} \tag{12}\]  
Moreover, PEV/A determines the flexibility of each individual PEV to adjust its power, \(flex_{PEV}(i,t)\)[25]. These quantities are forwarded to the CPEV/A that supervises the cluster of PEVs.  
\[flex_{PEV}(i,t)=t^{\prime}(i,t)-t \tag{13}\]  
where \(t^{\prime}(i,t)\) is the time point at which the SoC trajectory crosses the SoC\({}_{high}\) or SoC\({}_{low}\) limits provided that the \(i\)th PEV absorbs or injects active power \(P_{min}(i)\) or \(P_{max}(i)\), respectively, as described in [25].  
According to Equation (13), the flexibility of the \(i\)th PEV to increase (reduce) its active power at a certain time point is the time required to reach the SoC\({}_{high(low)}\) limit if it absorbs (injects) the maximum active power, respectively.  
If \(P(i,t)\geq 0\), then \(t^{\prime}(i,t)\) is calculated in Equation (14).  
\[t^{\prime}(i,t)=min\left\{\begin{array}{l}\frac{SoC_{max}(i)-SoC(i(t+\Delta t ))}{P_{max}(i)-P_{min}(i)}+\frac{P_{max}(i)\cdot t_{H_{2}}(i)-P_{min}(i)\cdot t }{P_{max}(i)-P_{min}(i)}\\ t+\frac{SoC(i(t+\Delta t)-SoC_{max}(i))}{P_{min}(i)}\end{array}\right. \tag{14}\]  
If \(P(i,t)<0\), then \(t^{\prime}(i,t)\) is calculated in Equation (15).  
\[t^{\prime}(i,t)=min\left\{\begin{array}{l}\frac{SoC_{max}(i)-SoC(i(t+\Delta t ))}{P_{max}(i)-P_{min}(i)}+\frac{P_{max}(i)\cdot t_{H_{2}}(i)-P_{min}(i)\cdot t }{P_{max}(i)-P_{min}(i)}\\ t+\frac{SoC(i(t+\Delta t)-SoC_{max}(i))}{P_{min}(i)}\end{array}\right. \tag{15}\]  
If \(P(i,t)\) is the optimal active power of the \(i\)th PEV (generator convention) and the \(n_{ch}\), \(n_{dis}\) charging and discharging efficiencies, then the SoC (kWh) of the \(i\)th PEV at the end of the next time interval is estimated according to Equation (16).  
\[SoC(i,t+\Delta t)=\left\{\begin{array}{l}SoC(i,t)-P(i,t)\cdot n_{ch}\cdot \Delta t,\quad P_{PEV}^{*}(i,t)<0\\ SoC(i,t)-\frac{P(i,t)}{n_{dis}}\cdot\Delta t,\quad\quad\quad P_{PEV}^{*}(i,t) \geq 0\end{array}\right. \tag{16}\]  
The state of charge calculated in Equation (16) is used in Equations (13)-(15) to estimate the flexibility of the \(i\)th PEV, \(flex_{PEV}(i,t+\Delta t)\), at time \(t+\Delta t\).