## 2 Problem Formulation  
The distribution network includes wind generators, an energy storage system, conventional generators, and a load demand. The energy storage system is utilized to satisfy the load demands that exceed the available capacity of distributed generations (DGs). The configuration of the energy storage system is an optimization problem to identify its optimal installation capacity and location. The objective of this paper is to provide an optimization allocation scheme of battery energy storage systems for distribution networks integrated with renewable energy. The objective problem includes two items, the capacity configuration and the location configuration of energy storage. The capacity configuration model identifies the installed capacity of energy storage to maintain a certain system reliability. On this basis, the location configuration model improves the contribution of energy storage by optimizing the energy storage installation location. The optimization problem has the following two characteristics: (1) the two optimization objectives, the installation capacity and location of the energy storage system, have their own control variables, and the control variables may vary to achieve the optimization objective; (2) the optimization objective of the installation capacity of the energy storage system has a higher priority, and the optimization of the installation position of the energy storage system can be adjusted for the optimization. Moreover, the installation position of the energy storage system will influence the results of the capacity optimization. In this paper, bi-level programming is applied to the optimization problem of the installation position and capacity allocation of energy storage in distribution networks. Bi-level programming was first proposed by McGill and Bracken in 1973 [28]. Bi-level programming has been widely applied in the field of economic management [29; 30; 31] and engineering technology [28]. In power system research, bi-level optimization has also been widely applied in research on the pricing and profit problem of power systems [32; 33; 34; 35; 36], reactive power optimization [28; 37] and transmission capability evaluation. Figure 1 shows the structure of the distribution network studied in this paper. There are wind generators, energy storage devices and loads in the distribution networks. The load demand includes residential, commercial and industrial loads. Figure 1: Diagram of a distribution network integrated with an energy storage system. The allocation of an energy storage system is characterized in terms of the dual variables of the installation location and installation capacity of an energy storage system. In other words, the installation capacity of an energy storage system considering the distribution reliability requirement is an optimization problem in itself. This optimization includes linear constraints terms and provides the optimal installation capacity associated with the reliability level. Therefore, since the allocation of an energy storage system is dependent on both the installation capacity and location variables, the above-described practical procedure to obtain the pricing and profit optimization is also suitable for the energy storage system allocation considering sizing and siting. Hence, based on the above analysis, the proposed reliability constrained energy storage system allocation planning can be formulated as the following linear bilevel programming problem:  
\[\min_{C_{ES},N_{ES}}F(N_{ES},C_{ES}) \tag{1}\]  
\[\mathrm{F}:R^{m}\times R^{n}\to R^{l} \tag{2}\]  
subject to  
\[\left\{ \begin{array}{l}G(N_{ES},C_{ES})\geq 0,\;G:R^{m}\times R^{n}\to R^{p}\\ J(N_{ES},C_{ES})=0,\;J:R^{m}\times R^{n}\to R^{q}\end{array} \right. \tag{3}\]  
where \(C_{ES}\) resolves  
\[\min_{C_{ES},N_{ES}}f(N_{ES},C_{ES}) \tag{4}\]  
\[f:R^{m}\times R^{n}\to R^{l} \tag{5}\]  
subject to  
\[\left\{ \begin{array}{l}g(N_{ES},C_{ES})\geq 0,\;g:R^{m}\times R^{n}\to R^{w}\\ j(N_{ES},C_{ES})=0,\;j:R^{m}\times R^{n}\to R^{2}\end{array} \right.