## 3 Risk Assessment of Technical Constraints Violation
By assuming a duration of the investment of \(n\) years, equivalent to the lifespan of the BESS, and a constant interest rate (\(r\)), \(AF\) is evaluated as:  
\[AF=\frac{1-\left(1+r\right)^{-n}}{r} \tag{12}\]  
The factor \(R_{b,h}\) is the risk component calculated with the flowchart of Figure 3 and it is used to estimate the annual recourse to flexibility services and, consequently, its energy remuneration. The extension of the optimization to multiple time-steps simultaneously (\(T>1\)) is motivated by the potential presence of multiple contingency events during the same network operating conditions (\(b\)) and, consequently, the need to correctly assess the capacity remuneration and the BESS sizing. Indeed, the resort to a flexibility resource may have different energy requests for different time-steps within the same time-interval \(T\) but it must have the same capacity bid. Also, if two time-steps with \(R_{b,h}>0\) are close or one next to the other, the BESS must be sized for solving sequentially both the contingencies. In summary, the new problem statement (11) will define the optimal compromise between the investment in BESS (finding number, site, and size of storage devices) and the purchase of flexibility services from existing DERs (in terms of capacity available and energy used). A further improvement of the economic model has been obtained by fixing a cap in the annual budget available for the DSO (\(B_{cap}\)). This cap can be fixed arbitrarily, or it can derive from the conventional planning alternative of network refuishment. In other words, it can be used to compare the investments in network solutions, needed to solve the technical issues, with the expenditures in flexibility services (e.g., DR actions) and in innovative solutions (BESS). Obviously, also \(B_{cap}\) is assessed by applying a suitable annuity factor to each network upgrade. This new constraint increases the possibility that the LP problem becomes unfeasible due to the lack of sufficient resources to solve all the contingencies. It is important to note that these defective situations have not to be disregarded but they are still useful in a general planning procedure. Indeed, even if the risk of constraints violation is not nullified, it is reduced (residual risk) so contributing to the achievement of the planning goal of \(R_{T}<R_{A}\). To overcome this limitation and allow the optimization to provide always a solution, \"slack\" variables have been introduced in the objective function and in the nodal voltage and line current inequality constraints (\(s_{i}^{V^{min}},\ s_{i}^{V^{max}},\ s_{j}^{V^{max}}\)). Dimensionally, they represent the residual gaps in nodal voltages or in line currents that the available DERs are not able to close for satisfying the corresponding technical constraints. In the objective function, they are weighted by a very large cost, to avoid that they could be used needlessly, i.e., when flexibility resources are still available below the budget cap. When returned (\(\
eq\)0) by the LP optimization, they allow assessing the residual risk through  
\(Fmax_{g}^{RES}\) and \(Fmax_{d}^{DR}\)). It has not been considered a minimum size for the BESS power, in order to optimize also the location and not only the size of the storage. Indeed, when \(Pn_{k}^{B}=0\), no BESS is in the \(k\)th node. If a minimum size needs to be fixed preserving on the same time the siting optimization, a Mixed Integer Linear Programming formulation should be implemented. As aforementioned, this LP formulation is deterministic, in the sense that all data are exactly known, and the operation of each resource is certain. However, this is a weak assumption, and several uncertainties still affect this model, because the active management of DER is not yet implemented in the actual distribution system (only few pilot projects have been founded in the last years), and local ancillary services markets does not exist.