# Flexibility Based Day-Ahead Generation-Reserve Bilevel Decision Model
## 3 Flexibility Based Reserve Decision Method
### Universal Generating Function Model for Wind Power  
The wind power prediction error is formulated as a normal distribution model [28], and the modeling method is also applicable to other distribution forms. The output of wind farm \(P^{\text{w}}(t)\) at the time \(t\) obeys normal distribution \(N(\overline{P}_{\text{w}}(t),\,\sigma_{\text{w}}(t))\), where \(\overline{P}_{\text{w}}(t)\) is the wind farm output predictive value at time \(t\), \(\sigma_{\text{w}}(t)\) is the standard deviation. Same as load, the study was limited in the range of \([\overline{P}_{\text{w}}(t)-3\sigma_{\text{w}}(t),\,\overline{P}_{\text{w}}(t )+3\sigma_{\text{w}}(t)]\) for efficiency. The output of wind farm is divided into \(N_{\text{w}}\) states, the power value of state \(i\) is \(p^{\text{w}}_{i}(t)\), the prediction error is \(\Delta P^{\text{w}}_{i}(t)\), then the corresponding probability \(p^{\text{w}}_{i}(t)\):\[\begin{array}{ll}p_{i}^{\rm w}(t)&={\rm Pr}\Big{[}p_{i}^{\rm w}(t)-\frac{p_{\rm inv }}{2}<P_{\rm w}(t)<P_{\rm w}^{\rm w}(t)+\frac{p_{\rm inv}}{2}\Big{\}}\\ &=\Phi\Big{(}\frac{2\Delta p_{i}^{\rm w}(t)+P_{\rm inv}}{2\alpha_{\rm w}(t)} \Big{)}-\Phi\Big{(}\frac{2\Delta p_{i}^{\rm w}(t)-p_{\rm inv}}{2\alpha_{\rm w}( t)}\Big{)}\end{array} \tag{20}\]  
The transition probability \(p_{ij}^{\rm w1}(t)\) from the output state \(i\) at time \(t\) to the output state \(j\) at time \(t+1\) is obtained through the historical data statistics of wind farm W1. The difference in output from the next moment to the current moment is the wind power ramping state of current moments. From this, the conditional probability of wind power ramping on output is obtained. While the output of W1 is in state \(i\), the conditional probability of the ramping state \(k\) can be described as \(p_{kij}^{\rm w1}(t)\):  
\[\begin{array}{ll}p_{kij}^{\rm w1}(t)&={\rm Pr}\Big{[}R_{k}^{\rm w1}(t)\Big{|} p_{i}^{\rm w1}(t)\Big{\}}\\ &=p_{ij}^{\rm w1}(t)\Big{|}R_{k}^{\rm w1}(t)=P_{j}^{\rm w1}(t+1)-P_{i}^{\rm w1 }(t)\end{array} \tag{21}\]  
According to conditional probability formula, the probability \(p_{k}^{\rm w1}(t)\) of ramping state \(k\) is:  
\[p_{k}^{\rm w1}(t)=\sum_{i=1}^{N_{\rm w1}}\Big{(}p_{kij}^{\rm w1}(t)p_{i,t}^{ \rm w1}(t)\Big{)}=\sum_{i,j\in\Pi_{k}}\Big{(}p_{ij}^{\rm w1}(t)p_{i,t}^{\rm w1 }(t)\Big{)} \tag{22}\]  
where \(N_{\rm w1}\) is the total number of output states of wind farm W1; \(\Pi_{k}\) is the state set that satisfy \(R_{k}^{\rm w1}(t)\)\(=P_{j}^{\rm W1}(t+1)-P_{i}^{\rm W1}(t)\). In formula (22), the ramping probability distribution of wind farm W1 is established on the basis of predicted output and ramping state transition distribution, then the ramping UGF model for wind farm W1 at time \(t\) is as follows:  
\[u_{\rm w1}(z,t)=\sum_{k=1}^{S_{\rm w1}}p_{k}^{\rm w1}(t)z^{R_{k}^{\rm w1}(t)} \tag{23}\]  
where \(S_{\rm w1}\) is the total number of ramping states. Repeat the process listed above until the ramping probability distribution of all wind farms is obtained.  
If wind farms are independent, then the total ramping probability distribution of wind farms is:  
\[u_{\rm W}(z,t)=u_{\rm w1}(z,t)\otimes_{+}u_{\rm w2}(z,t)\otimes_{+}\ldots u_ {\rm wN^{w}}(z,t)=\sum_{j=1}^{S_{\rm w}}p_{j}^{\rm W}\cdot z^{R_{j}^{\rm w}(t)} \tag{24}\]  
where \(\otimes_{+}\) is the summation operator of the UGF method, \(N^{\rm w}\) refers to the total number of wind farms, \(S_{\rm w}\) is the total number of wind farm total ramping states, \(R_{j}^{\rm W}(t)\) and \(p_{j}^{\rm W}(t)\) are the ramping value and probability of the \(j^{th}\) ramping state of total wind farms at time \(t\).