Combination of Site-Wide and Real-Time Optimization for the Control of Systems of Electrolyzers

The rapid expansion of renewable energy sources has introduced significant volatility and unpredictability in the energy supply chain, necessitating advanced control strategies to ensure grid stability and reliability. Green hydrogen production via electrolysis offers a viable solution for converting and storing this volatile renewable energy. However, the inherent fluctuations of renewable energy sources present challenges for consistent utilization and integration of green hydrogen. This work proposes a two-stage optimization approach, combining site-wide optimization and real-time optimization for managing systems of electrolyzers. By adapting an existing static optimization model, dual use is achieved in both site-wide optimization and real-time optimization. The hierarchical optimization structure, characterized by distinct temporal resolutions, enables effective responses to both dynamic changes and long-term trends. The side-wide optimization layer generates long-term plans based on forecast data, while the real-time optimization layer refines these plans in real-time, accommodating immediate fluctuations and ensuring efficient operation. The results from the case study on a system of electrolyzers demonstrate the method's effectiveness in aligning electrolyzer operation with actual availability of renewable energy. This approach offers a robust framework for optimizing the operation of electrolyzers but also other types of flexible energy resources, contributing to sustainable and economically viable energy management.


I. INTRODUCTION
The rapid expansion of renewable energy (RE) sources significantly increases the volatility and unpredictability in the energy supply chain [1], necessitating advanced control strategies to ensure grid stability and reliability [2].This emphasizes the crucial role of energy flexibility [3], which is the ability of a resource to modulate its power generation or consumption [4].
Green hydrogen, which can be produced by electrolysis, offers a viable solution for storing volatile RE [5].Hydrogen serves as a high-density energy carrier for production facilities and provides solutions for energy transportation and storage [6].However, leveraging the full potential of green hydrogen production presents challenges due to the inherent fluctuations of renewable energy sources [7].These fluctuations introduce uncertainties in the availability and predictability of RE supply, complicating the integration and consistent utilization of green hydrogen [7].
To fully capitalize on the benefits of green hydrogen and integrate it effectively into the energy system, advanced optimization strategies are crucial [8].The unpredictable nature of RE sources necessitates robust control mechanisms to handle these uncertainties [9].However, existing optimization approaches for control often disregard these uncertainties [10,11], and instead focus on economic optimization where coarse resolutions are sufficient [12].Yet this static optimization is inherently vulnerable to uncertainties [13], underscoring the need for finer resolutions to address both renewable integration and uncertainty management [14].Achieving such fine resolutions computationally, however, presents significant challenges regarding the timely generation of schedules [12].
Therefore, a multi-layered optimization approach, known for its scalability and adaptability, illustrated in Fig. 1, can be employed.Each layer within this hierarchical structure manages specific decision variables and monitors distinct parameters and variables from other layers.This hierarchical organization facilitates complexity abstraction and enables the provision of services to higher layers.For operational optimization purposes, these layers can be leveraged to achieve various optimization objectives.[15] A key feature of the hierarchical optimization structure is the distinct temporal resolution of each layer, enabling effective response to both dynamic changes and long-term trends.The Scheduling layer, which operates with the longest temporal resolution (weeks to days) [15], generates a schedule.Meanwhile, the Site-wide Optimization (SWO) layer, which encompasses a system of flexible energy resources, e.g., multiple electrolyzers, defines a plan.Long-term factors, such as market prices, can be integrated by these layers.A plan is typically generated for a timespan of hours to days.1: Control Hierarchy (adopted from [15]) The Real-Time Optimization (RTO) layer operates at an intermediate resolution, typically hours to minutes 1 , aligning operational execution with strategic directives [15].It defines a structured Set of Setpoints (SoS), whereby the current setpoint is transferred to the resource via the control layer.The RTO layer replans resource operation within one SWO time step, taking into account new data, such as short-term forecasts.Additionally, RTO, based on the concept of rolling planning or receding horizon, offers a promising approach to mitigate uncertainties.While traditional strategic optimization methods may disregard this technique, RTO enhances adaptability and resilience under uncertainty, making it a powerful tool for economic optimization and improved operational planning [16].
Forecasts, such as those for RE generation, are incorporated into these optimization processes.The uncertainty and therefore the accuracy of these forecasts correlates with the forecast horizon [17].Consequently, the schedule has the highest uncertainty, with decreasing uncertainty down to the RTO layer.
The bottom control layers have the shortest temporal resolution, responding to immediate changes within minutes to seconds [15].In these layers, the overall system is separated into resources, as each resource has its own controller.This layered approach in temporal resolution allows each layer to efficiently address specific tasks while ensuring a coordinated strategy that blends long-term planning with short-term reactions to changed contexts [15].
The prevailing focus on static optimization [14] often results in the isolated consideration of the depicted layers.Consequently, many publications disregard the interactions between RTO and SWO (grey layers in Fig. 1).Despite its potential for significant economic and energy-systemic benefits, the adoption of RTO in real-world applications has fallen short of expectations, leaving its potential largely untapped [13,16].One possible reason for this can be attributed to the high costs associated with the development and implementation of RTO solutions [18].
To exploit the untapped potential and ensure more efficient and economic resource operation, this work investigates the transformation of an existing static optimization model (e.g., from SWO) into a dynamic RTO model.As a result, a two-step optimization approach emerges, utilizing the same optimization model for both long-term and short-term optimization, thus addressing the isolated consideration of the individual layers (see Fig. 1).The adaptation of the automation pyramid by Skogestad [15] (as shown in Fig. 1) is applied in this work.Consequently, the approach is capable of responding to uncertainties and short-term deviations, tackling the issue that different optimization models across layers may lead to inconsistencies [16].The objectives on the SWO and RTO layer are somehow similar as both layers focus on, i.e., maximizing benefit, such as minimizing cost [16].Therefore the main difference between the two layers is their temporal resolution [16].Recently, Reinpold et al. [11], have demonstrated that static optimization models can accurately represent the real behavior of a resource, making the models suitable for dual usage in both long-term planning and short-term optimization.
This work is based on previous work by the authors which includes a reusable modular optimization model structure [19] and a methodology for its parameterization [20].
In summary, the contributions of this work are the following: • A method for adapting existing static optimization models for their dual use in SWO and RTO • An algorithm for continually solving the two-stage optimization problem incorporating updated forecast information • An evaluation and validation of the proposed method and algorithms through a case study • An assessment of the dynamic RTO model on power system performance and efficiency, highlighting improvements over static optimization in terms of cost, stability, flexibility, and energy usage This work is structured as follows: Sec.II provides an analysis of related work and describes the research gap.Sec.III describes the method for continually solving the two-stage optimization problem including the approach for adapting existing static optimization models.Sec.IV evaluates the method via a case study.The method and its evaluation are discussed in Sec.V. Sec.VI concludes this work.

II. RELATED WORK
This section reviews related work in optimizing flexible energy resources, focusing on their control, with emphasis on handling uncertainties.
Sun and Leto [21] introduced a model for the bidding in energy markets for the integration of renewable energy sources and the operation of flexible energy resources.This approach aims to maximize profits and mitigate risks associated with the uncertainties of renewable energy production.The work by Sun and Leto [21] primarily addresses the upper layers of the control hierarchy shown in Fig. 1 -Scheduling and SWO -by proposing a joint bidding strategy for various distributed energy resources based on a predictive model that considers the uncertainties of renewable energy production.However, the model does not address RTO, which is crucial for immediate response to short term fluctuations.
Pazouki et al. [22] describe an optimization model for the operation of a system with energy generation from wind as well as the operation of flexible energy resources under uncertainty.Pazouki et al. [22] focus on the economic, emission, reliability, and efficiency aspects of the system operation in both certain and uncertain environments of wind, electricity demand, and real-time pricing markets.The authors utilize a stochastic optimization approach, incorporating Monte-Carlo simulations to generate scenario trees based on predicted realtime pricing, wind, and electricity demand.This method allows for the modeling of uncertainties and the identification of optimal operational strategies.Although the generated scenarios address uncertainties, the responsiveness in terms of RTO is lacking.This optimization is done on a sub-hourly resolution and cannot be considered as RTO, but rather SWO.
Vedullapalli et al. [9] proposed a model and an algorithm for the operational planning of battery and HVAC resources in buildings using RTO to minimize costs of electric energy.Vedullapalli et al. [9] also present a two-part forecasting model for short-term variations.This method only focuses on the short-term management for the control of resources without higher planning functions like SWO.This approach underscores the necessity of real-time control but lacks the integration with long-term strategic planning to market system flexibility.
Tsay et al. [23] proposed a framework for the energy flexible operation of industrial air separation units using RTO.Their work highlights the need to account for process dynamics in production optimization due to the variable nature of electricity prices, and addresses this with a dynamic optimization framework specifically designed for air separation units.Despite the mention of real-time electricity prices in the study, they are considered at an hourly resolution.Consequently, there is no reaction to short-term deviations, as the optimization primarily focuses on the strategic, longer-term SWO of air separation units.
Flamm et al. [8] presented a specialized optimization model for an electrolyzer.Through experimental analysis of an electrolyzer, detailed linearized models were created to capture the electrolyzer's conversion efficiency and thermal dynamics [8].This model informs an RTO controller that aims to minimize hydrogen production costs by adapting to fluctuating electricity prices and photovoltaic inflow.However, the study by Flamm et al. [8] uses deterministic forecasts, which raises questions about the appropriateness of the method in dealing with forecast uncertainties.Furthermore, Flamm et al. [8] describe their approach as "model predictive control", while Skogestad [15] highlights the limitations of single-layer optimization in dealing with uncertainty, as the uncertainty must be quantified a-priori.
Alabi et al. [24] introduced an optimization approach for a multi-energy system.Initially, the approach focuses on data management via clustering and scenario reduction to mitigate uncertainties.Subsequently, it employs multi-objective optimization to balance investment and operating costs.The integration of the Markowitz portfolio risk theory allows for managing operational uncertainties.As the approach primarily emphasizes long-term planning and cost optimization, it lacks consideration for real-time resource control to effectively respond to fluctuations, a crucial aspect addressed by RTO.Moreover, the hourly resolution used for renewable energy sources proves inadequate in capturing their fluctuations, thus rendering the system not capable of reacting to short-term variations.
Similar to Alabi et al. [24], Alirezazadeh et al. [25] presented a method for the optimization of flexible generation within a smart grid.The method employs linear and non-linear optimization models for solving unit commitment and smart grid scheduling problems, respectively.However, the method of Alirezazadeh et al. [25] does not consider RTO, which would be required for the adaptability to short-term variations, but is limited to static, SWO.
Yang et al. [26] focused on operational optimization for alkaline water electrolysis systems using a mixed-integer nonlinear programming approach.The optimization considers factors such as solar energy availability, electricity prices, and the resources' operational characteristics for scheduling the electrolysis system.While the optimization effectively plans the operation of the electrolyzers based on the availability of solar energy and electricity prices to increase profitability, it is limited to long-term planning in terms of static, SWO.This disregards the aspect of considering short-term fluctuations.As a result, the method cannot fully capture the dynamic nature of renewable energy sources, missing opportunities for further optimization and efficiency improvements in a realtime operational context.
Ireshika and Kepplinger [27] investigated the management of electric vehicle charging under uncertainty using a two stage optimization approach, thereby focusing on uncertainties such as non-elastic demand and electric vehicle usage behavior.
Dumas et al. [28] introduced a hierarchical optimization approach for microgrids, focusing on the coordination between operational planning and RTO.At the operational planning level, decisions are made based on day-ahead forecasts to optimize energy costs over one or several days.The RTO level adjusts operations based on actual conditions and forecast errors within the current market period.
Whereas Ireshika and Kepplinger [27] and Dumas et al. [28] each emphasize the benefits of a two-stage optimization approach for managing flexible energy resources under uncertainty.Instead of reusing existing approaches, both works specialize in applying dedicated optimization models for spe-cific problems within their domains, using different models for the different levels of optimization.However, this can lead to conflicts between the planning and RTO layers, potentially resulting in inconsistencies [16].
The analysis of related work reveals a gap in the integration of SWO and RTO into a unified framework, indicating a need for generalized methods to advance the field.Existing approaches focus on either SWO or RTO, with strategies to address short-term deviations rarely discussed [14].This underlines the need to go beyond the use of specific models for individual use cases to develop methods that provide a comprehensive and reusable solution for the dynamic adaptation of optimization strategies.

III. METHOD FOR SOLVING TWO-STAGE OPTIMIZATION
This section introduces the method for continually solving SWO and RTO models for the subsequent control of systems of flexible energy resources.The concept for a two-stage optimization approach using existing optimization models is outlined in Sec.III-A.Necessary adjustments for transforming an existing optimization model into a model compatible with both SWO and RTO are explained in Sec.III-B.The approach for continually solving the two-stage optimization problem is elaborated in Sec.III-C.

A. Concept for Two-Stage Optimization
The concept, illustrated in Fig. 2, utilizes the SWO to devise a plan for the entire optimization horizon T , e.g., a full day, segmented into intervals Δ .Individual time steps are denoted as .To achieve this, long-term forecast data is incorporated, ensuring the plan reflects anticipated future conditions or demands.The results from this planning phase set starting points for RTO, i.e., defining starting conditions like resource system states for each time step .This approach is executed cyclically, with new, updated forecasts being taken into account for each optimization.Following this initial phase, RTO refines the optimization at a higher resolution Δ , such as on a per-minute basis, denoted as time steps , over an optimization horizon .The length of the RTO horizon | | is equivalent to one time step of the SWO Δ .This finer granularity allows for the accommodation of immediate fluctuations and guarantees that operations can quickly adjust to evolving scenarios.Any changes detected during the RTO phase, such as the failure of resources, are then fed back into the SWO, ensuring that the behavior of the real system is reflected in the subsequent planning periods of the SWO.This cyclical process creates a dynamic and responsive optimization framework that seamlessly integrates long-term strategic planning with immediate operational adjustments, significantly improving both efficiency and adaptability.

B. Dual Use of Optimization Models
To facilitate the transformation of static optimization models into dynamic RTO models, some preliminary steps must be performed.The basic prerequisite, however, is that a static, feasible optimization model of a system of flexible energy resources is available.The static optimization model requires modification to enable differentiation between its application in SWO and RTO.Specifically for RTO use, it is necessary to fix historic values of variables, including the states of resources or initial setpoints for the RTO time steps.This is achieved by equating the respective decision variable to the respective value.These values are derived from the outcomes of the SWO or results of previous RTO time steps.Furthermore, the energy amount procured for any time step must be set as a target for the corresponding RTO horizon starting at ,0 .This is ensured by means of the constraint shown in Eq. 1, wherein the energy in one SWO time step must be equal to the sum of the energy sourced from the grid in all corresponding RTO time steps .
This is particularly significant in the context of ancillary services, as the costs for these services are allocated to the parties responsible for deviations from the plan.
Furthermore, the objective function could be modified to ensure the full integration of RE, such as maximizing the output of the system.

C. Solving the Two-Stage Optimization Model
The process for solving the two-stage optimization model is depicted in Fig. 3. First, initial parameter settings are defined, such as the system state at the start of SWO (Step 1).
Subsequently, long-term forecast information, such as electricity data from spot markets or RE generation, is imported (Step 2) and utilized to solve the static optimization model for the time steps 0 , | T | (Step 3).The results obtained from this operational planning for the time step are stored (Step 4) and subsequently adopted as initial values for the RTO model ( = ,0 , Step 5).
To enable appropriate responses, short-term forecasts with a high resolution, as those from RE sources, are incorporated (Step 6).Subsequently, the RTO model is solved based on the specified RTO horizon , allowing for suitable adjustments to short-term fluctuations (Step 7).Subsequently, the system Upon reaching the end of the RTO horizon with = | | , the system checks if the end of the planning interval T has been reached as well.If so, the process terminates.However, this process is typically executed in a continual manner, meaning that in most cases, the end is never reached.Instead, new starting values for the subsequent planning time step are obtained from the static optimization, and the RTO process recommences (Step 5).Both stages are always solved for the entire length of the respective optimization horizon T / incorporating newly available information, such as forecasts for future time steps, and historic values.Hence, each model is solved times, with corresponding to T Δ or Δ , respectively for SWO and RTO.
Applying the method outlined in this section generates plans for the control of a system of resources.At the availability of new data, such as forecasts, an updated SoS or plan for the remaining time steps of the respective optimization horizon is generated.

IV. EVALUATION OF THE METHOD
The case study assesses the effectiveness of the proposed method by applying it to a system of electrolyzers, which draws power from both the grid and a wind farm.For this purpose, this section describes the setup of the validation (Sec.IV-A) as well as the results (Sec.IV-B & Sec.IV-C).

A. Setup of the Evaluation
The optimization model used for the validation of the method is built using the validated optimization model structure developed by Wagner et al. [19] (see Optimization Model 1).Therein, a set of constraints for the representation of flexibility features was developed [19].This includes constraints for operational boundaries (min./max.values for flows), input-output relationships, as well as system states and related constraints [19].The objective function aims at minimizing the cost of electric energy procured from the European intra-day market (Eq.2).
min Total cost of energy procured from European intraday market (Eq.2) subject to • Power balance to include grid and renewable power and connect electrolyzers • Operational boundaries of the system (Eq.3) • Operational boundaries of each resource (Eq. 3) • Input-Output relationships (Eq.4-7) • Target for energy input (Eq.8) • System states (Eq.9-11) • Follower states (Eq.12) • Holding durations (Eq.[13][14] • Ramp limits (Eq.[15][16] Optimization Model 1: Electrolyzer model used for the case study.Based on model structure developed by Wagner et al. [19] The parameters for each electrolyzer were determined by employing the methodology for parameterizing optimization models developed by Wagner and Fay [20].This creates a data model for the parameterization of the optimization model, based on operational data [20].The mathematical modeling and the parameter set are described in the Appendix in detail. Optimization Model 2 shows how the existing, feasible Optimization Model 1 is extended for its use in RTO as described in Sec.III-B.Feasibility is ensured through a) a validated model structure [19] and b) a systematic derivation of suitable parameters [20].

max hydrogen output subject to
• Constraints of Optimization Model 1 • Target to avoid penalty costs (Eq. 1) • Fixed Values for past periods (see Fig. 3) Optimization Model 2: Model used for RTO For forecasts of future RE generation, this work utilizes data from a real wind farm published by Anvari et al. [17], available at a resolution of 1 Hz.From this dataset, both |T | longterm (see Fig. 4a) and | | corresponding short-term forecasts to each time step ∈ T (see Fig. 4b) were generated.These forecasts were generated in an iterative manner at each time step, retaining data points for past time steps.To address the issue of prediction uncertainties, greater uncertainty for time steps further in the future was introduced.This can be exemplary seen in deviations of values at time step 1 of the forecasts generated at 0 and 1 , respectively, in Fig. 4a (grey circle).There, the forecast generated at time step 0 (blue) overestimated the renewable generation at 1 and necessitated a correction in forecast for 1 (red).A similar interpretation can be applied to the short-term forecasts shown in Fig. 4b.The method has been implemented in Java utilizing an optimization model based on IBM ILOG CPLEX 2 .

B. Results of the Evaluation
The method outlined in Sec.III is applied utilizing optimization models 1 and 2, with all models solved as depicted in Fig. 3. Prices sourced from the European intra-day market are employed [29], as illustrated in Fig. 5.The calculations were performed on Windows 10 with an Intel Core i7-11700 processor and 16 GB RAM with an optimality gap of 10 −3 .The method for the two stage optimization approach was applied for |T | = 10 SWO time steps and | | = 10 time steps of RTO each.The calculation time for each time step including its corresponding RTO time steps was approx.10 s in total using temporal resolutions of 0.25 h for SWO and 0.025 h for RTO.
Moreover, the optimized SoS generated by RTO is transmitted to a simulation model of electrolyzers, as described in [30], 2 Implementation: https://github.com/lukas-wagner/TwoStageOptutilizing OPC-UA (Steps 9 & 10 in Fig. 3).For this purpose, the method devised by Reinpold et al. [11] is employed.This process was carried out successfully and the recorded values are analyzed below.
1) Results of Site-wide Optimization: Fig. 6 shows the plan generated by the SWO, taking into account the forecasts shown in Fig. 4a.For clarity, only the first time step 0 and the final, realized SoS generated at 9 , taking into account all past decisions, are shown.Fig. 6a illustrates that the plan generated at 0 aligns with the realized plan ( 9 ) up to and including time step 4 .This initial plan is generated assuming perfect foresight it benefits from the most flexibility potential.
Starting from 5 , a significant share of time steps has already been executed, thereby constraining the ability to respond to updated forecast data during the remaining time steps of SWO due to the constraints imposed.Consequently, this results in deviations between the optimized plan at 0 and realized plan from this juncture onwards as the flexibility potential decreases.This limitation reflects in a decrease of 0.5 % in hydrogen produced between the initial stage at 0 and the final step 9 .The main driver is the uncertainty of the forecasts, with 1.5 % less realized RE than initially forecasted.This also results in a lower overall efficiency of 62.3 %, compared to the initial plan of 62.6 % at 0 .The comparison of efficiencies at 0 and 9 is depicted in Fig. 6b, illustrating the impact of the aforementioned uncertainties on the overall efficiency of the electrolyzer system.
2) Results of Real-Time Optimization: Fig. 7 shows the results of RTO for one exemplary time step 4 .In Fig. 7a, the prediction for the RE output under the SWO for time step 4 , as well as the deviating forecast at 4 ,9 , are depicted.Notably, the output of RE sources consistently surpasses the long-term prediction of the SWO.Consequently, this leads to an increase in hydrogen production.The realized SoS at 4 ,9 yields 0.66 kWh of hydrogen energy instead of the planned amount of 0.62 kWh at 4 capitalizing on the increased availability of RE (see Fig. 7b).
Furthermore, as shown in in Fig. 7b, a significant drop in power can be observed at 7 .This is attributed to the increase in the forecast for RE from 8 to 9 compared to previous forecasts (see 4 ,7 ).Consequently, the hydrogen production has been shifted to later time steps 8 and 9 resulting in a decrease of power input at 7 .

C. Validation of the Method for Two-Stage Optimization
Fig. 8 shows the realized hydrogen output in each time step for the SWO as well as the sum of all hydrogen outputs in the last RTO time step of each SWO time step ,9 .Therein, it can be seen, that robust results have already been achieved through SWO, with an average deviation of +2 % between the optimized plan and the realized SoS across all time steps , encompassing a range of -3.5 % to +15 %.Although the SWO generally yields favorable results, deviations exceeding +15 % in periods of high RE uncertainty underscore the importance of RTO.However, these inherent uncertainties in RE, which resist further quantification and are dependend on the quality of the forecast, can be effectively addressed by RTO, providing a valuable tool for appropriate responses.
The approach outlined in Sec.III for implementing a twostage optimization strategy is especially advantageous for hybrid energy resources that integrate both RE sources and the electricity grid.Initially, the SWO determines the required energy procurement from the energy market with manageable computational effort and a long-term planning horizon.The second optimization stage, RTO, then utilizes the predetermined energy procurement from the energy market and the existing resource states established by the SWO to respond to short-term fluctuations or deviations within optimized, defined framework conditions.
Utilizing one optimization model could not have accounted for continually updated forecasts as as this would have necessitated the continuous solving of the model for the entire horizon equal to at the availability of new forecasts.The computational times of one model at a high temporal resolution, e.g., 1.5 min, would have been too large to be useful (timely availability of the plan) [12].Such an approach is also unsuitable considering the high level of uncertainty in forecasts for the distant future, rendering a resolution of 1.5 min.unjustified, which emphasizes the application of the two-stage optimization approach presented.
In summary, the findings demonstrate the efficacy of the method presented in Sec.III and affirm that the two-stage optimization approach can be successfully applied based on an existing static optimization model.This approach optimizes the procurement of energy from a spot market in parallel while facilitating the simultaneous integration of variable RE sources.This is especially important given the increasing expansion of RE and the imperative of decarbonization.
Moreover, it becomes evident that existing optimization models of SWO can be adapted for this two-stage optimization approach without requiring significant adjustments (see Sec. III-B).This facilitates the transition from pure planning to real time operation, accommodating short-term fluctuations.

V. DISCUSSION
The method as well as the results of the evaluation, are discussed in this section.
The presented research demonstrates the potential of transforming static optimization models into dynamic, RTO models for managing flexible energy resources such as electrolyzers.Specifically, the work employs a two-stage optimization strategy that integrates both site-wide and real-time optimization techniques to improve operational flexibility.The method involves a hierarchical approach where long-term forecasts are used for SWO, and short-term adjustments are made through RTO.This allows the system to adapt dynamically to fluctuations in RE generation and accurately reflect the actual behavior of the resource as well as the actual availability of RE. Results from the case study of a system of electrolyzers validate the effectiveness of this approach.
The proposed method ensures a stable power grid by matching energy consumption with RE generation and demonstrates the practical benefits of integrating real-time adjustments into long-term planning.This dynamic capability is crucial for handling the variability and unpredictability associated with RE sources.
The implications of this study are relevant to the future of energy management and the integration of RE sources.The two-stage optimization method developed in this work provides a robust framework for RTO of flexible energy resources, such as electrolyzers.This method, by combining SWO with RTO, enhances the alignment of energy consumption with RE generation.This alignment is important for sustainable energy practices, as it allows for more efficient use of RE resources and minimizes waste and mismatch.This method makes it possible not to assume perfect foresight during the determination of a SoS for subsequent control and rather continually use reliable values in RTO in a short time gap to realization.This however leads to deviations from the initially generated plan by SWO.
Such deviations, initially, are not problematic and are expected given the forecast uncertainties.In fact, if RTO did not account for these deviations and instead strictly adhered to the SWO plan generated under the assumption of perfect foresight, unplanned adjustments would eventually become necessary.This is because either not all available RE would be integrated or the grid supply would have to be adjusted in an unplanned and ad-hoc manner.Therefore, the ability of the RTO to adapt to real-time data ensures more efficient and reliable integration of RE, preventing the need for reactive measures and supporting overall grid stability.
Despite the promising outcomes, the work recognizes limitations.One notable limitation is the dependency on the accuracy of RE generation forecasts.While the optimization models perform well with accurate forecasts, deviations from predicted values can influence the optimality of the SoS.Additionally, the initial setup and computational requirements, although manageable, might present some challenges for largescale implementation.The necessity for high-resolution data and computational resources could potentially impact the scalability of this approach.Future research should aim to enhance forecast accuracy, streamline computational processes, and explore decentralized optimization approaches to further improve the method's practicality and scalability.
Even though the case study showed the applicability of the method to a system of electrolyzers, the SWO and RTO of other types of flexible energy resources are also possible, as the underlying optimization model structure is generically applicable [11,19].

VI. CONCLUSION
In this work, a novel two-stage optimization method was developed that bridges the gap between SWO and RTO, allowing for dynamic adjustments in response to the unpredictable nature of RE sources.By leveraging existing static optimization models and transforming them for use in RTO, a seamless integration of RE into a system of electrolyzers is achieved, enhancing both grid reliability and operational efficiency.This method stands out for its adaptability, ensuring optimal resource utilization in near real-time and reducing the energy procurement costs from the intra-day market.
The case study on a system of electrolyzers, utilizing a hybrid energy supply from both the grid and a wind farm, validated the effectiveness of the method.The results demonstrated not only a more sustainable operation through the optimized use of renewable resources but also highlighted the potential for economic benefits as updated forecasts can be included in the operational planning.
As the deployment of RE sources continues to expand, the importance of such dynamic optimization methods will increase.With higher shares of RE in the power grid, the variability and unpredictability of the energy supply will become more pronounced.The proposed method is particularly relevant in this context, as it offers an adaptable solution to integrate increasing amounts of RE while maintaining grid stability and optimizing resource utilization.
In conclusion, the developed two-stage optimization strategy offers a robust and flexible framework for energy management, paving the way for more sustainable and economically viable energy control of flexible energy resources in the face of growing RE integration.
Future work can focus on the transfer of the method to decentralized optimization approaches employing multi-agent systems, as they are inherently suited for the representation of resources under uncertainty and the handling thereof.

APPENDIX
This appendix describes the mathematical modeling of Optimization Model 1.For a detailed explanation please refer to Wagner et al. [19].Additionally, the parameter set is presented.
Operational boundaries are modeled as shown in Eq. 3 [19].
The piecewise linear approximation of the input-output relationship is realized by means of binary variables for each segment ∈ K and time step / (Eq.4-6).Only one segment can be active per time step (Eq.7).The total energy output over the optimization horizon is set by Eq. 8. [19] output, = lb input , ≤ ub • , ∀ , System states ∈ S are characterized by lower and upper flow limits (Eq. 10 and 11), follower states S , (Eq.12), holding durations of each state (Eq.13 and 14), and ramp limits (Eq.15 and 16) [19].
The parameter set used for the case study has been derived from measurement data [20].Tab.I shows the parameters for the input-output relationship whereas Tab.II shows parameters for system states and related constraints.These parameters are used for all electrolyzers.

Figure 2 :
Figure 2: Schematic Representation of the Concept

Figure 3 :
Figure 3: Flowchart for the use of an existing optimization model in RTO

Figure 8 :
Figure 8: Optimization results for entire horizon

Table I :
Parameters of the input-output relationship