Real-Time Flexibility Assessment for Power Systems with High Wind Energy Penetration

: To reduce the reliance on fossil fuel-based generation, many countries expand the use of renewable energy sources (RES) for electricity production. The stochastic and intermittent nature of such sources (i.e., wind and solar) poses challenges to the stable and reliable operation of the electric power system (EPS) and requires sufﬁcient operational ﬂexibility. With continuous and random changes in the EPS operational conditions, evaluating the system ﬂexibility in a standardized manner may improve the robustness of planning and operating procedures. Therefore, the development of fast algorithms for determining system ﬂexibility is a critical issue. In this paper, the ﬂexibility of the EPS with high wind energy penetration is calculated in real time. In this context, the EPS ﬂexibility is understood as the ability of the system to maintain a balance under irregular and short-term active power variations during a speciﬁed time by using the ﬂexibility resources. The EPS ﬂexibility calculation relies on a deterministic method developed to qualitatively and quantitatively assess the EPS readiness to changes in load. Accurate wind power forecasts and the observance of the electric circuit law when solving the optimization problem allow for determining the actual value of the EPS ﬂexibility during a considered time.


Introduction
With the government targets set to reduce the dependency on fossil fuel energy sources, there is a rapid increase in using renewable energy sources (RES) for electricity generation. The most abundant renewable energy sources, wind and solar, are well received for deployment in many existing power systems (for example, Denmark, Ireland, and Germany) [1]. These sources are stochastic and intermittent in nature, which implies that in addition to traditionally variable demand, the power systems have to deal with rising variabilities in the power supply [2].
For the efficient management of electric power systems, including those with RES, forecasting of electric demand and wind and solar power outputs is utilized. Based on such forecasts, scheduling of controllable and flexible sources of energy (e.g., conventional power plants, batteries, etc.) is performed. The actual operation of the system elements, however, differs from the predicted (planned) one due to forecast errors, which consist of errors in the forecasting method, an unexpected change in electric demand, and an unexpected change in the generation at a wind (solar) power output. Forecast errors cannot be predicted, therefore, they belong to the category of uncertainties in the form of irregular and short-term changes in active power. While increasing RES penetration, it is essential to take measures to improve the system flexibility and prevent future stability and reliability issues.
The stable and safe operation of the electric power system (EPS) is possible if there are reserves to maintain the power balance between the generation and consumption specified time at the expense of flexibility sources) is calculated in real time for n minutes ahead. Since the flexibility metric is assumed to be calculated in real time using the current state variables and very short-term forecast variables, there is no need to simulate any scenario. The focus is on forecasting the power generated by a wind farm. There is a whole host of studies on the creation of an ANN for wind power forecasting in the world [21]. This paper shows the significance of assessing the flexibility of an electric power system with a wind farm and a battery in real time for n minutes. The battery is one of the essential components for providing the flexibility of such power systems. The EPS flexibility calculation involves the development of a deterministic method to qualitatively and quantitatively assess the EPS readiness to the load variation. A criterion is proposed for determining the combination of imbalances arising from forecast errors (uncertainties), which, when exceeded, make the EPS incapable of maintaining the power balance (cause flexibility losses). This problem is solved as an optimization problem with equality and inequality constraints. To check if the constraints, which are the electrical circuit equations, are met, a load flow solution is found. The optimization parameters are the components of vector z, which are used for modeling a variety of loads.
The main contributions of this paper are as follows:

1.
A methodology for real-time flexibility assessment for a power system with high wind energy penetration is developed. This methodology uses measurements as input data, handles them, and then provides information about the EPS flexibility for n minutes ahead, taking into account the battery control strategy; 2.
Wind power forecasting integrated within the methodology is performed using state of the art forecasting method (variational mode decomposition and long short-term memory (VMD-LSTM)); 3.
A new term "operating state with minimum flexibility" is introduced.
The paper has the following structure. The second section presents the purpose and concept of the research. The third section focuses on the EPS flexibility calculation and describes the modeling of the EPS flexibility sources. This section also presents, in a general form, information related to the processing of measurement data (data collection system and state estimation); and makes a forecast of the active power at the wind farm. The same section gives the main idea of the method, presents the optimality criterion and the objective function for calculating the maximum loads, and sets the constraints. The fourth section discusses the research results. The conclusion contains the analysis of the work performed.

Purpose and Concept of the Research
The flexibility assessment is one of the most significant issues in the operational dispatch control of an EPS with renewable energy sources. Current information on the EPS flexibility can become critical when making a decision on adjusting the operating states in unforeseen situations of the EPS functioning.
This research proposes calculating the flexibility with a method based on the statement that the EPS has flexibility if the power balance is maintained during the considered time under uncertainties on the part of power consumers and producers. First, we determine the combinations of loads for the given values of generating capacities (dispatch solution), in which the balance is ensured by putting into operation the entire power reserve intended to smooth out the uncertainties. This EPS operating state is characterized by the minimum flexibility (hereinafter referred to as the operating state with minimum flexibility) since an insignificant excess of load at a node will lead to a power shortage in the EPS or to the use of an emergency reserve. The latter is unacceptable as it will pose a threat to the EPS's safe operation. Then the flexibility metric is calculated.
The power system flexibility in a normal operating state at the time t + n moment, with known information about the configuration and parameters of the EPS equivalent circuit (in Figure 1. EPS description), is calculated according to the following methodology ( Figure 1):

•
Collect information about the operating parameters, perform a state estimation (blocks I, II); •  Specify the scheduled operating state according to the measurement information  (blocks III, IV). To do this, forecast the power at the wind farm using an ANN and find a load flow solution; • Calculate the flexibility of the refined planned operating state (blocks V, VI). First, determine the operating state with minimum flexibility. This means calculating the steady-state variables (SSV) that include the largest loads for a given generation. This is an optimization problem with equality and inequality constraints.
Mathematics 2021, 9, x FOR PEER REVIEW 4 of 16 circuit (in Figure 1. EPS description), is calculated according to the following methodology ( Figure 1): • Collect information about the operating parameters, perform a state estimation (blocks I, II); •  Specify the scheduled operating state according to the measurement information  (blocks III, IV). To do this, forecast the power at the wind farm using an ANN and find a load flow solution; • Calculate the flexibility of the refined planned operating state (blocks V, VI). First, determine the operating state with minimum flexibility. This means calculating the steady-state variables (SSV) that include the largest loads for a given generation. This is an optimization problem with equality and inequality constraints. Further, the process of operating a state flexibility assessment at the considered time (t: t + n) is described in detail using the developed algorithm.

Data Acquisition
Traditionally, electricity is generated by large power plants and delivered to the end user via transmission and distribution networks [22]. These networks are equipped with measurement devices (e.g., remote terminal units (RTUs), intelligent electronic devices (IEDs), and phasor measurement units (PMUs)) connected to a local area network (LAN) along with supervisory control and data acquisition (SCADA) systems [23].
There are several sources of measurements in the EPS ( Figure 2): • SCADA systems, IEDs, PMUs, and RTUs provide real-time voltage, current, and power flows measurements; • Meter data management systems (MDMS) along with a customer information system (CIS) are used to monitor the network consumption and distributed energy resources (DER) output. In case of insufficient data redundancy, a pseudo measurement generator is used; • Automated mapping and facility management (AM/FM) systems along with geographic information and outage management systems (GIS and OMS, respectively) monitor the equipment connectivity status. Further, the process of operating a state flexibility assessment at the considered time (t: t + n) is described in detail using the developed algorithm.

Data Acquisition
Traditionally, electricity is generated by large power plants and delivered to the end user via transmission and distribution networks [22]. These networks are equipped with measurement devices (e.g., remote terminal units (RTUs), intelligent electronic devices (IEDs), and phasor measurement units (PMUs)) connected to a local area network (LAN) along with supervisory control and data acquisition (SCADA) systems [23].
There are several sources of measurements in the EPS ( Figure 2): • SCADA systems, IEDs, PMUs, and RTUs provide real-time voltage, current, and power flows measurements; • Meter data management systems (MDMS) along with a customer information system (CIS) are used to monitor the network consumption and distributed energy resources (DER) output. In case of insufficient data redundancy, a pseudo measurement generator is used; • Automated mapping and facility management (AM/FM) systems along with geographic information and outage management systems (GIS and OMS, respectively) monitor the equipment connectivity status. The measurement set used by the state estimator looks as follows: where = ( ) + ( ) , = ( ) + ( ) , is the magnitudes of nodal voltages; ( ) , ( ) are the active and reactive power generation at the nodes; ( ) , ( ) are the active and reactive power load at the nodes; , are power flows in the transformers and the lines; is the voltage phases at the nodes. The objective function used in the traditional state estimation is as follows: where is a covariance matrix of measurement errors (diagonal matrix), = ( , ) is the state vector (a part of the state variables, which is used to find the load flow solution).
The state vector calculation involves the minimization of criterion Equation (2) with respect to the voltage phase and magnitude.
The derivative ( )/ is set to zero, and the system of non-linear equations is solved: subject to ( , 1) = 0, where = / is a Jacobi matrix, ( , 1) = 0 represents the equations of the electric circuit connecting the measured (y) and unmeasured (y1) variables.
The system Equation (4) is linearized at each iteration i. The system of linear equations is solved, where the correction vector is calculated by the equation: The components of the state vector are calculated by the equation:

State Estimation
The state estimator is the data processing algorithm used to filter raw measurements from noise, detect and eliminate gross errors, and determine the optimal estimates for the system state. It includes topology processing, an observability analysis, a state estimation, and bad data detection [24,25].
The measurement set used by the state estimator looks as follows: where , U i is the magnitudes of nodal voltages; P g(i) , Q g(i) are the active and reactive power generation at the nodes; P l(i) , Q l(i) are the active and reactive power load at the nodes; P ij , Q ij are power flows in the transformers and the lines; δ i is the voltage phases at the nodes. The objective function used in the traditional state estimation is as follows: where R y is a covariance matrix of measurement errors (diagonal matrix), x = (U, δ) is the state vector (a part of the state variables, which is used to find the load flow solution). The state vector calculation involves the minimization of criterion Equation (2) with respect to the voltage phase and magnitude.
The derivative ∂J(x)/∂x is set to zero, and the system of non-linear equations is solved: where H = ∂y/∂x is a Jacobi matrix, w(y, y1) = 0 represents the equations of the electric circuit connecting the measured (y) and unmeasured (y1) variables.
The system Equation (4) is linearized at each iteration i. The system of linear equations is solved, where the correction vector is calculated by the equation: Mathematics 2021, 9, 2056 6 of 16 The components of the state vector are calculated by the equation: If ∆x < ε x , the iteration process converges, where ε x is the accuracy of the iterative process. Then, a load flow solution is obtained using the state vector.

Wind Power Forecasting Using VMD-LSTM
The wind farms power outputs have both fluctuating and random components. Therefore, forecasting of the future wind energy production might be a challenging task. To adequately determine the EPS flexibility, it is particularly important for system operators to have as accurate forecasts of power outputs as possible.
The forecasting technique used in this paper is based on the hybrid variational mode decomposition and long short-term memory (VMD-LSTM) artificial neural network [26]. Hybrid models can recognize hidden signal features in time series (including wind power time series) and learn from them. The original wind power time-series signal is decomposed into multiple sub-series, which are less chaotic and, consequently, more predictable. For this purpose, variational mode decomposition (further VMD method) is used. The VMD method is described in detail in [27]. To implement this method, the following mathematical functions are used: Wiener filtering, Hilbert transform and frequency mixing, and heterodyne demodulation.
The wind power time series are decomposed according to the physical signal properties. With such a decomposition, the original wind power signal is divided into three components: the long-term trend, short-term fluctuation, and ultra-short randomness.
The algorithm for forecasting wind power consists of five steps, described below.

1.
Select an ANN type. This study uses an LSTM ANN. It is a kind of recurrent neural network that overcomes the memory limitations by adding particular cells aimed at filtering new information (preserve or ignore); 2.
Form a data set for training, validation, and testing. In this study, historical wind power measurements are used as a data set; 3.
Initialize LSTM. Determine the LSTM starting parameters. The starting parameters are as follows: σ s and σ t are activation functions (σ s denotes the state (sigmoid), and σ t denotes the gate (hyperbolic tangent)); W, M, and b are input weights, the recurrent weights, and the bias of each component, respectively; and c t is the cell memory state, h t is the hidden state, x t is a time-series vector. 4.
Train LSTM. Use the method of backpropagation for training LSTM. The key element of LSTM is a cell state. During the LSTM training, the memory cell state changes. LSTM is considered to be trained if the memory cell stops changing. The following equations describe the forward pass of an LSTM unit with the input, output, and forget gates and with the memory cells at each time step t ( Figure 3): The sigmoid layer of the LSTM cell determines what information should be removed from the cell of state The input gate determines what part of the new information needs to be added to the The tanh layer creates the cell candidate The new information is added The output gate defines the extent to which the existing part of the memory contributes to the output The hidden state is: 5. Test LSTM.
The hidden state is: 5. Test LSTM.   The wind power forecasting process may be divided into several steps.
Step 1. Select the input data. Use several previous measurements (two in Figure 4) to predict the wind power output t + 1 min ahead.
Step 2. Perform the VMD to decompose each input datum into three features. These features are as follows: the long-term trend ( , ), short-term fluctuation ( , ), and ultra-short randomness ( , ).
Step 3. Forecast wind power. Three components of wind power are predicted using an LSTM artificial neural network.
Step 4. Build the predicted point from , , and .
The hidden state is: 5. Test LSTM.   The wind power forecasting process may be divided into several steps.
Step 1. Select the input data. Use several previous measurements (two in Figure 4) to predict the wind power output t + 1 min ahead.
Step 2. Perform the VMD to decompose each input datum into three features. These features are as follows: the long-term trend ( , ), short-term fluctuation ( , ), and ultra-short randomness ( , ).
Step 3. Forecast wind power. Three components of wind power are predicted using an LSTM artificial neural network.
Step 4. Build the predicted point from , , and . The wind power forecasting process may be divided into several steps.
Step 1. Select the input data. Use several previous measurements (two in Figure 4) to predict the wind power output t + 1 min ahead.
Step 2. Perform the VMD to decompose each input datum into three features. These features are as follows: the long-term trend (P rand t−1 , P rand t ), short-term fluctuation (P f luc t−1 , P f luc t ), and ultra-short randomness (P trand t−1 , P trand t ).
Step 3. Forecast wind power. Three components of wind power are predicted using an LSTM artificial neural network.

Computing Load Flow Solution t + n Minute Ahead
The load flow calculation aims to clarify the scheduled state variables at time t + n according to the information available at time t. In this case, the scheduled state variables are referred to as the load patterns and generation profiles (unit commitment solutions), to which the time instant t + n belongs. In the load flow calculation, injections of active and reactive power at all the nodes, except for the slack one, are used as independent state variables. The variables are refined in the following order:

•
The wind farm injections are predicted for n minutes ahead; • The capacity values for the load and generator units are taken from the data of the scheduled operating state; • The battery power is calculated according to the control strategy for the battery energy storage system (BESS) based on the forecast data on the wind farm power and the scheduled load data. The BESS control strategy can vary. For example, the strategy can suggest the use of a BESS to maximize the renewable energy penetration or to smooth a profile of power output from the wind and solar power plants. This study uses the former [28]; • The reactive power values are calculated based on the rule of maintaining the proportion between active and reactive power; • The initial voltage approximations are set. The initial approximations are the voltages calculated with the state estimation at time t; • Based on the known active and reactive injections at the nodes, the load flow solution is computed.

The Flexibility Assessment
The power system flexibility is characterized by the following three indices: ramping limit (∆R), power capacity (P), and energy capacity (E). Each index is a time derivative of the previous index [3].
The calculation of the flexibility of the EPS resources: • Assumes that the ramping limit of the flexible source (∆R) is equal to the lead time for which the flexibility is calculated; • Factors in the maximum and minimum generation (P) index; • Takes into account that the final energy capacity of the battery (E) limits its capabilities.

Modeling the Flexibility of EPS Components
Model of generator flexibility of a conventional power plant The flexibility available from each generator F g is determined by the power that can be additionally generated over the time under consideration and is calculated using the equation: where P g(per) is the regulating reserve (employed in normal condition), P g(c) is the active power of the generator at the moment in question.

Model of battery flexibility
The flexibility available from the battery F B is determined by the state of charge and the current power. If the battery is charged within the specified limits: then the power output is calculated using the equation: otherwise, where SoC is the state of charge, SoC min is the minimum level of charge, SoC max is the maximum level of charge, P B(c) is the active power of the battery at the moment in question.

Model of system flexibility at the time in question
The power system flexibility at the time in question (F Sys ) is determined as a sum of flexibilities of all the facilities in the system. When two kinds of flexibility are available in the system, F Sys is calculated by the equation: where n1 is the number of generators at conventional plants, n2 is the number of batteries.

Metric of Flexibility
Whether the power system is flexible or not during the time [t: t + n] is determined by calculating a flexibility metric: where P max calc is the largest active loads when the power system can remain flexible, P L is the active powers in a scheduled operating state.
where P i (z i ) is the maximum load at node i, at a set loading of generators (at a given dispatch solution), n 3 is the number of load nodes. If F S > 0, then the considered EPS is flexible (during the time [t: t + n]). The value F S is the largest range of uncertainty, within which there is no danger for the power system. F S shows how much flexibility the power system has.

Determination of Operating State with Minimum Flexibility. Objective Function
The operating state with the minimum flexibility is calculated as a problem of nonlinear optimization (we have non-linear constraints). The optimality criterion is the maximum difference between the values of active powers at nodes with uncertainty in the scheduled operating state and in the operating state with minimum flexibility. The optimization parameters are the components of vector z, which are responsible for modeling the load value at load nodes from the minimum to maximum values.
The objective function, i.e., the maximum sum of differences between the modeled and scheduled powers at nodes with uncertainty, is written as follows: where r is the number of nodes with uncertainty. In this case, these are the load nodes, nodes where control actions are performed, and a slack node, P i (z i ) is calculated as follows [10]: A distinctive feature of the research is the method of forecasting the active power of a wind farm, which gives more accurate results in comparison with load forecasts. Therefore, wind farm power is considered to be an exact value and is not entered into the objective function. The predicted battery power value calculated based on the predetermined battery control strategy is also not input to the objective function. The uncertainties associated with an error in a forecast of power at the wind farm and battery are compensated for at the balancing power plant.
Each component Equation (21), given Equation (22), can be represented as follows: When all the values independent of the optimization parameters are excluded, the objective function has the form: In Equations (23) and (24), i is the number of a node with uncertainty, P i is the value of active power at node i in the scheduled operating state; P i (z i ) is the relationship between active power and value z responsible for the variation in values of power at node i, P max i , P min i are the maximum (minimum) values of consumed (generated) power at node i. The maximum generated power is the maximum power that can be used in the normal operating state, in particular, to compensate for the uncertainties.
The search for optimal parameters is performed given the equality and inequality constraints. The equality constraints are the balance of active power in system Equation (25) and the equation that controls the implementation of the electric circuit laws Equation (26). The inequality constraints are introduced to control the transfer capability of the lines and the power limits at nodes with uncertainty Equations (27)-(29).
The constraints have the following form: where n is the number of nodes in the grid; ∆P s is the active power balance in the system; P i (z i ) is the node i power value obtained from solving the optimization problem; P i (U i , δ i ) are state variables at node i; U i , δ i are the voltage magnitude and phase at node i; P max l−j is the transfer capability limit of the transmission line limited by nodes l, j; P are the maximum and minimum active power at the controlled and slack nodes, respectively.
The power balance in system Equation (25), given Equation (22) and after some transformations, is written as follows: where n is the number of nodes in the system, π is the system active power losses calculated in the operating state. Equation (26) guarantees the observance of Ohm's and Kirchhoff's laws since it includes the steady-state variables. To calculate the steady-state variables, a system of nodal equations is built in the form of power balances: Mathematics 2021, 9, 2056 11 of 16 where G l , D l are the active and reactive conductivity of the shunt at node l; P l−j , Q l−j are the active and reactive power in the lines limited by nodes l, j; m is the number of adjacent nodes. This system of equations is solved by Newton's iterative method, where ξ P , ξ Q is the accuracy of the iteration process. The achieved accuracy of Equations (31) and (32) means the end of the iterative process.

Description of a Scheme and a Scenario
The developed method is applied to calculate the power system flexibility in the normal operating state and is verified using the test scheme shown in Figure 5: 9, x FOR PEER REVIEW 11 of 16 nodes. This system of equations is solved by Newton's iterative method, where , is the accuracy of the iteration process. The achieved accuracy of Equations (31) and (32) means the end of the iterative process.

Description of a Scheme and a Scenario
The developed method is applied to calculate the power system flexibility in the normal operating state and is verified using the test scheme shown in Figure 5: The scheme consists of six tie lines and six nodes, including a wind farm (node 1), a battery (node 5), conventional plants (nodes 2 and 6), and loads (nodes 3 and 4). Nodes 2, 3, 4, and 6 are assigned to be the nodes with uncertainty. Nodes 1 and 5 are considered to be the nodes without uncertainties since the uncertainties associated with the wind farm and the battery are assumed to be compensated for at the balancing power plant (node 6).
The calculations are performed according to the scenario: calculate the power system flexibility in two normal operating states 10 min ahead. The operating states differ from each other by the power of the battery. The load uncertainties are compensated for at the controlled plant. The uncertainties exceeding the permissible size of the control action are compensated for by the power at the balancing power plant.
The ramping limit (ΔR) is assumed to be 10 min. This means that in 10 min, the entire reserve available at a conventional plant, designed to compensate for uncertainties, is turned on, and the battery delivers the maximum power. The maximum and minimum values of active power at nodes with uncertainty and the active powers of two operating states are shown in Table 1. The powers are taken from the operating state scheduled 10 min ahead.

Flexibility Calculation for a Six-Node System
This problem-solving process can be represented by several steps.
Step 1. Acquire the data. Perform the state estimation. The scheme consists of six tie lines and six nodes, including a wind farm (node 1), a battery (node 5), conventional plants (nodes 2 and 6), and loads (nodes 3 and 4). Nodes 2, 3, 4, and 6 are assigned to be the nodes with uncertainty. Nodes 1 and 5 are considered to be the nodes without uncertainties since the uncertainties associated with the wind farm and the battery are assumed to be compensated for at the balancing power plant (node 6).
The calculations are performed according to the scenario: calculate the power system flexibility in two normal operating states 10 min ahead. The operating states differ from each other by the power of the battery. The load uncertainties are compensated for at the controlled plant. The uncertainties exceeding the permissible size of the control action are compensated for by the power at the balancing power plant.
The ramping limit (∆R) is assumed to be 10 min. This means that in 10 min, the entire reserve available at a conventional plant, designed to compensate for uncertainties, is turned on, and the battery delivers the maximum power. The maximum and minimum values of active power at nodes with uncertainty and the active powers of two operating states are shown in Table 1. The powers are taken from the operating state scheduled 10 min ahead.

Flexibility Calculation for a Six-Node System
This problem-solving process can be represented by several steps.
Step 1. Acquire the data. Perform the state estimation.
Step 2. Forecast the wind power. Make a very short-term forecast (10 min ahead). Use the historical wind power measurements as a training data set. The answers of trained LSTM are 16.14 and 15.12. (The real values of wind power output are 16.04 and 15.0).
Step 3. Determine the state variables 10 min ahead. The results are shown in Table 1, columns 4 and 5. The real values of wind power output are shown in brackets.
Step 4. Describe the objective function and constraints following the requirements for the input data of the software programs used.
The objective function is written as follows: max where B i = P max i − P min i , i = 2, 3, 4, 6. The power balance in the system is written in the following way: The constraints that control the power balances at the nodes have the form where z 2 , z 3 , z 4 , z 6 are optimization parameters, P 2 (U 2 , δ 2 ), P 3 (U 3 , δ 3 ), P 4 (U 4 , δ 4 ), P 6 (U 6 , δ 6 ) are active powers at the nodes, which are the steady-state variables. The constraints (31) and (32) are factored in in the load flow calculation. The constraints of the form Equations (27)-(29) are built relying on the data from Table 1. Step 5. Solve the optimization problem considering the set constraints. The Matlab environment is employed with the function fmincon. The result of the optimization problem is z 2 , z 3 , z 4 , z 6 . Equation (22) is then used to compute the optimal steady-state variables, which are the variables of the operating state with minimum flexibility.
Step 6. Assess the flexibility. Equation (18) is used to measure the flexibility of the power system for 10 min.

Analysis of Results and Discussion
The results are summarized in Table 2. Columns 2 and 4 contain the active power values determined in accordance with Equation (22), where z is the result of optimization. Columns 3 and 5 show flexibility F S(i) . The last line indicates the total EPS flexibility calculated according to Equation (18). Figure 6 shows the maximum power values (Table 1, column 2) and the optimization results ( Table 2, columns 2 and 4).   The analysis of the results presented in Table 2 and Figure 6 shows that: • A comparison of the preset maximum loads (Table 1, italics) with the maximum possible loads ( The flexibility of the considered system is equal to 7.02 MW and 11.32 MW for operating state 1 and operating state 2, respectively. This means that when the battery delivers the maximum power, the highest load deviation, provided that the balance can be restored, is 11.32 MW; when the battery supplies the minimum power, the maximum load deviation is 7.02 MW. The flexibility was calculated for 25 snapshots (sets of measurements taken simultaneously). In this case, the measurements were taken 25 times every 10 min. Figure 7 shows the active power at all the nodes in 25 normal operating states. Figure 8 shows the active power at all the nodes in the operating states with minimum flexibility. Figure 9 shows the difference between two operating states, where the difference between the active power at nodes 3 and 4 is used to calculate the flexibility ( ). The analysis of the results, presented in Figures 7-9, shows how the EPS flexibility differs at different time. The analysis of the results presented in Table 2 and Figure 6 shows that:

•
A comparison of the preset maximum loads (Table 1, italics) with the maximum possible loads ( The flexibility of the considered system is equal to 7.02 MW and 11.32 MW for operating state 1 and operating state 2, respectively. This means that when the battery delivers the maximum power, the highest load deviation, provided that the balance can be restored, is 11.32 MW; when the battery supplies the minimum power, the maximum load deviation is 7.02 MW. The flexibility was calculated for 25 snapshots (sets of measurements taken simultaneously). In this case, the measurements were taken 25 times every 10 min. Figure 7 shows the active power at all the nodes in 25 normal operating states. Figure 8 shows the active power at all the nodes in the operating states with minimum flexibility. Figure 9 shows the difference between two operating states, where the difference between the active power at nodes 3 and 4 is used to calculate the flexibility (F s ). The analysis of the results, presented in Figures 7-9, shows how the EPS flexibility differs at different time.   The developed methodology provides information about the upward flexib some cases, it is important for system operators to have the knowledge of the dow flexibility, which can be a subject of further research.
In this work, the utilized BESS control strategy was used for illustrative purpo determine the effect of implementing different control strategies on the EPS fle further research is needed.

Conclusions
The paper presents a method for the real-time calculation of the flexibility of tric power system with a wind farm. An optimality criterion has been developed tify the combination of loads that are the maximum for the planned generating ca in the period at issue. The problem of flexibility calculation is solved as an optim   The developed methodology provides information about the upward flexib some cases, it is important for system operators to have the knowledge of the dow flexibility, which can be a subject of further research.
In this work, the utilized BESS control strategy was used for illustrative purp determine the effect of implementing different control strategies on the EPS fle further research is needed.

Conclusions
The paper presents a method for the real-time calculation of the flexibility of tric power system with a wind farm. An optimality criterion has been developed tify the combination of loads that are the maximum for the planned generating ca in the period at issue. The problem of flexibility calculation is solved as an optim problem with a linear objective function and equality and inequality constraints.   The developed methodology provides information about the upward flexib some cases, it is important for system operators to have the knowledge of the dow flexibility, which can be a subject of further research.
In this work, the utilized BESS control strategy was used for illustrative purpo determine the effect of implementing different control strategies on the EPS fle further research is needed.

Conclusions
The paper presents a method for the real-time calculation of the flexibilit electric power system with a wind farm. An optimality criterion has been devel identify the combination of loads that are the maximum for the planned gen capacities in the period at issue. The problem of flexibility calculation is solve optimization problem with a linear objective function and equality and ine constraints. The developed method enables a quantitative metric of flexibilit The developed methodology provides information about the upward flexibility. In some cases, it is important for system operators to have the knowledge of the downward flexibility, which can be a subject of further research.
In this work, the utilized BESS control strategy was used for illustrative purposes. To determine the effect of implementing different control strategies on the EPS flexibility, further research is needed.

Conclusions
The paper presents a method for the real-time calculation of the flexibility of an electric power system with a wind farm. An optimality criterion has been developed to identify the combination of loads that are the maximum for the planned generating capacities in the period at issue. The problem of flexibility calculation is solved as an optimization problem with a linear objective function and equality and inequality constraints. The developed method enables a quantitative metric of flexibility to be calculated.
When solving the optimization problem, the observance of Ohm's and Kirchhoff's laws is guaranteed by introducing a constraint as a function representing the load flow solution. The calculation of the steady-state variables involves the construction of a system of nodal equations, which is solved by Newton's method. The state variables are maintained within the specified limits by introducing inequality constraints.
The size of flexibility is calculated for the normal operating state disregarding emergencies in the EPS. At the same time, when using the obtained information to adjust the state variables, the system is guaranteed not to be exposed to the threat of a system failure during the considered time. The active power balance is maintained at the expense of the flexibility sources. The emergency reserve remains unchanged, which is achieved by correctly set power constraints at the slack node (the available power is reduced by the emergency reserve magnitude).
The wind farm active power has been forecast. The developed method for its forecasting is sufficiently accurate (the error of 0.6% in the first operating state, and 0.8% in second (Table 1)). The ability of the forecasting system to predict wind power has been improved by decomposing the original wind power measurements into three components: the long-term trend, fluctuation component, and signal randomness.
The flexibility of a six-node system, which includes a wind power plant, a storage battery, two loads, and two generating plants, has been calculated. A comparative analysis of the flexibility values calculated for the different operating states shows that the EPS flexibility value depends on the state variables at the considered time instant. This confirms the need to determine flexibility in real time for some time in advance.