1. Introduction
South Africa is endowed with substantial renewable energy (RE) potential, particularly in wind and solar resources [
1]. Yet, the country relies heavily on coal-fired power plants, which account for approximately 80% of its electricity generation [
2,
3]. Renewable energy resources offer a transformative opportunity to enhance the sustainability of the nation’s energy system, reducing reliance on fossil fuels and mitigating environmental impacts [
4]. Despite these benefits, the integration of RE sources into the national grid remains limited, primarily due to their intermittent and stochastic nature [
5,
6]. Wind power varies with weather conditions, and photovoltaic (PV) generation is unavailable at night, which creates significant challenges for grid stability and operational cost management. In isolated power grids, such as those in small island systems, these issues are exacerbated, as mismanaged RE resources, particularly wind turbines, can destabilize the grid, affecting power storage, frequency stabilization, and overall system reliability [
7].
Furthermore, the integration of RE sources into power grids introduces challenges related to grid inertia [
8], a property inherent in traditional non-renewable generators but often absent in RE systems [
9]. Wind turbines, for instance, are typically not directly coupled to the grid and use inverters to manage frequency stability, which limits their ability to provide inertia [
10]. Similarly, PV panels, being static devices, cannot generate rotational inertia. Grid inertia is critical in mitigating frequency drops by enabling the system to respond to sudden increases in load demand [
10].
Thus, highly accurate models are needed to predict sudden load increases.
Figure 1 illustrates a schematic of a centrally controlled national grid that integrates RE sources. The Grid Control Center (GCC) serves as the core authority that dispatches energy and makes real-time operational decisions. It coordinates conventional power plants, renewable sources, energy storage systems, and national electricity demand [
11]. The GCC ensures optimal power flow, preserves system reliability, and maintains equilibrium between supply and demand despite fluctuations in generation. In essence, integrating RE into the grid necessitates that operators anticipate sudden demand spikes to prevent frequency deviations and rapidly adjust system operations to maintain grid stability. Addressing these challenges demands advanced optimization strategies capable of handling uncertainty in both renewable generation and electricity consumption. These methods must also optimize storage use, reduce operational costs, and support stable and cost-effective use of renewable resources [
12,
13].
Ramadan et al. [
14] proposed a framework for the optimal planning of distribution systems, incorporating renewable-based distributed generators (DGs) while addressing uncertainties in load and generation. The model employed a multi-objective formulation to minimize expected power loss, voltage deviation, system cost, and emissions, while enhancing overall voltage stability. The Equilibrium Optimizer (EO) algorithm was used to determine optimal DG sizes and locations, with validation performed on IEEE 69-bus and 94-bus practical distribution systems. Although this framework demonstrated notable performance improvements, such as a 70.66% emission reduction and a 48.73% increase in voltage stability on the 69-bus system, it was focused on long-term planning and static optimization. Niknami et al. [
15] introduced a two-step optimization model, Robust Day-Ahead Scheduling for Enhanced Resilience, to manage microgrid energy amidst renewable integration, uncertain demand, and diverse equipment like batteries and electric vehicles, achieving an 8% cost reduction over existing methods by optimizing energy use, battery management, and distributed generation dispatch using a Column-and-Constraint Generation (C&CG) algorithm. Additionally, Li et al. [
16] proposed a two-stage stochastic optimization framework for multi-energy microgrids using CVaR to address risk from renewable and load uncertainties, with scenario generation via Monte Carlo simulation and improved K-means clustering. While their approach was effective at the microgrid scale, it failed to account for constraints peculiar to a national grid, such as reserve adequacy, the startup/shutdown dynamics of generators, large-scale curtailment management, and system-wide load shedding penalties, all of which are crucial for ensuring grid-wide reliability and operational feasibility.
Mathur et al. [
17] developed a priority-based cost optimization framework for hybrid PV–wind-controllable distributed generator microgrids, addressing the intermittent nature of RE sources through a stochastic day-ahead scheduling strategy that minimizes costs using the Grey Wolf Optimization (GWO) algorithm. Their work outperformed the Jaya and Particle Swarm Optimization (PSO) algorithms with optimal costs of USD 3754 (best case) versus USD 4222 for Jaya on the CIGRE test network, though costs increased in isolated mode due to load curtailment. Zhang et al. [
18] introduced a stochastic optimization framework for integrated energy microgrid operations using a time-divided scenario generation method based on forecasting errors in PV and load. Their methodology, applied to a microgrid in Changzhou, Jiangsu Province, China, constructed probabilistic models using nonparametric kernel density estimation (KDE) to capture distribution characteristics and time correlation of uncertainties. While Zhang et al.’s method is based on synthetic error modeling, our work applies real empirical energy data from the South African grid to derive more context-specific insights into renewable uncertainty. Other research efforts in renewable uncertainty and their mitigation techniques for grid integration can be found in [
19,
20,
21,
22]
Despite growing research in RE integration, current approaches often fall short in three critical areas: (i) many focus on microgrid or small-scale systems and do not address the operational complexities of national grids; (ii) forecasting and dispatch are often treated as separate, decoupled tasks; and (iii) uncertainty quantification is either absent or insufficiently integrated into decision making. As detailed in our literature review, existing models, such as those by Ramadan et al. [
14], Niknami et al. [
15], Li et al. [
16], Mathur et al. [
17], and Zhang et al. [
18], have demonstrated valuable contributions in distribution system planning, microgrid scheduling, and risk-aware optimization. However, most of these works rely on synthetic data, focus on isolated systems, or neglect key reliability metrics like curtailment and load shedding under uncertainty.
To address these gaps, this study proposes a unified, scenario-based stochastic optimization framework that integrates machine learning-based forecasting, probabilistic scenario generation, and dispatch optimization under uncertainty. We apply the proposed framework to five years of real-world data from the South African power grid to benchmark four dispatch strategies—stochastic, deterministic, rule-based, and perfect information. The objective is to demonstrate the practical benefits of our approach in enhancing cost efficiency, system resilience, and RE integration in high-variability power systems. In essence, the primary contributions of this work are threefold:
Hybrid forecasting with uncertainty quantification: We develop an LSTM–XGBoost hybrid model for forecasting wind, PV power, concentrated solar power (CSP) generation, and electricity demand that integrates Monte Carlo dropout and quantile regression to capture predictive uncertainty. This is crucial for informed scenario generation in stochastic planning.
Physically and statistically grounded scenario generation and reduction: We introduce a distribution-based sampling framework using Weibull (wind), Beta (solar), and Lognormal (demand) distributions combined with turbine power curves and diurnal constraints to generate realistic input scenarios and reduced via a Temporal-Aware K-Means Scenario Reduction process for computational efficiency.
Stochastic optimization and real data evaluation: A two-stage stochastic optimization framework is developed and evaluated using five years of national grid data from South Africa.
The remainder of this paper is organized as follows:
Section 2 outlines the problem description and data overview.
Section 3 details the methodology, while
Section 4 presents the results and key findings. Finally,
Section 5 concludes the paper and offers recommendations for future research.
3. Methodology
This research employs a scenario-based stochastic optimization framework that integrates machine learning-based forecasting with uncertainty modeling to enhance power dispatch planning. As illustrated in
Figure 4, the method comprises two main phases: (1) A hybrid LSTM–XGBoost model generates forecasts and prediction intervals for PV, wind, CSP, and demand, with uncertainty quantified through Monte Carlo dropout and quantile regression. These probabilistic forecasts are used to produce multiple scenarios, which are reduced using Temporal-Aware K-Means clustering to ensure computational efficiency. (2) A two-stage stochastic MILP model is then used for dispatch optimization, where the first stage determines day-ahead unit commitment and storage operations, and the second stage optimizes real-time dispatch across all scenarios. This end-to-end framework is designed to enable robust and cost-effective decision making under renewable generation uncertainty.
Figure 4 presents an overview of the proposed framework.
3.1. Hybrid LSTM–XGBoost Model
The forecasting component of the framework utilizes a hybrid model that combines Long Short-Term Memory (LSTM) networks with Extreme Gradient Boosting (XGBoost) to predict energy generation from wind, PV, and CSP, as well as total energy demand. LSTM, a form of recurrent neural network, is well suited for capturing temporal dependencies and sequential patterns [
28,
29,
30], making it ideal for modeling the daily and seasonal fluctuations inherent in RE data [
31]. Its ability to retain long-range dependencies enables accurate forecasting of time series behavior over extended horizons [
32,
33]. To improve the model’s overall robustness and accuracy, XGBoost is integrated to capture complex non-linear relationships and interactions across multiple features. The hybrid approach is deliberately designed to leverage LSTM’s sequential learning capabilities alongside XGBoost’s gradient-boosting efficiency in order to ensure more reliable and precise forecasts [
34]. This dual-model strategy plays a critical role in the downstream optimization process, with improved energy scheduling and greater grid resilience under RE variability.
In this architecture, the Long Short-Term Memory (LSTM) network is tasked with modeling the sequential behavior of RE generation (wind, PV, and CSP), relevant weather parameters (e.g., time, wind speed, temperature, and solar radiation), and electricity demand. These input variables exhibit diurnal and seasonal patterns that the LSTM captures through its recurrent connections and memory cell, enabling it to learn long-term dependencies. For example, the model learns how patterns in wind speed affect wind energy production over time or how solar radiation impacts PV output throughout the day.
The LSTM’s learned representations, which encapsulate both short-term fluctuations and long-range dependencies, are then passed as input features to the XGBoost model. XGBoost further refines the predictions by modeling complex, non-linear interactions that may not be fully captured by the LSTM alone, thereby enhancing overall forecasting accuracy. LSTM’s internal operations are governed by a set of gating mechanisms that regulate the flow of information through time. Specifically, the memory cell is updated using Equations (18)–(22) [
35].
where
,
, and
are the forget, input, and output gates;
is the memory cell; and
is the hidden state.
XGBoost, a gradient-boosting framework, refines the LSTM predictions by incorporating additional features and capturing non-linear interactions that the LSTM might miss. For instance, XGBoost can model the interaction between wind degree and temperature to improve WIND predictions or use radiation and humidity to enhance PV forecasts. The hybrid model is trained on historical data, with the LSTM handling the temporal dynamics and XGBoost optimizing the final predictions. To provide probabilistic forecasts, Monte Carlo dropout is applied in the LSTM layer to generate a distribution of predictions, and XGBoost’s quantile regression capabilities are used to estimate uncertainty bounds (e.g., 10th, 50th, and 90th percentiles). This results in a range of scenarios for RE generation and demand, such as high, medium, and low WIND output, which are critical for the stochastic optimization stage. XGBoost minimizes the objective defined in (7) as follows [
36]:
where
=
is the squared error, and
=
is a regularization term used to avoid overfitting.
The combined prediction is defined as
3.2. Scenario Generation Process
To effectively address the uncertainties associated with RE generation and demand forecasting, we formulate a scenario generation process (SGP) that creates a diverse set of future trajectories for wind, PV, CSP, and total demand over a predefined forecast horizon. The SGP is controlled by four primary inputs: N, the number of scenarios per target; S, the start date of the forecast window; L, the length of the forecast window; and F, a scaling factor to control uncertainty spread. These inputs define the temporal and probabilistic structure of the scenarios used within the optimization framework.
The SGP begins with a Long Short-Term Memory (LSTM) network, which is trained on historical energy and weather datasets to capture underlying temporal dependencies. Given an input sequence
, where
l denotes the lookback window and
d the number of features, the LSTM generates multiple Monte Carlo samples
through stochastic forward passes. These samples are used to compute both the mean prediction
and the standard deviation
which quantifies forecast uncertainty [
37].
To increase variability, the standard deviation is scaled by a factor
s, i.e.,
Next, the mean prediction
is concatenated with relevant exogenous features
to form the input vector
for an XGBoost model:
To improve the realism of scenario generation for the optimization process, we model uncertainties in wind, solar (PV and CSP), and total demand using distributions that reflect their physical and statistical characteristics. Wind power is modeled using the Weibull distribution, solar generation via the Beta distribution with diurnal constraints, and total demand using the Lognormal distribution to capture positive skewness.
3.2.1. Wind Scenario Sampling (Weibull Distribution)
Wind speeds are sampled from a Weibull distribution characterized by the shape parameter
k and scale parameter
λ [
38] derived from the mean
μ and standard deviation
σ:
Wind speeds
are then converted into power output P(
v) using a turbine power curve characterized by cut-in, rated, and cut-out wind speeds.
where
,
,
and
, which reflects the total installed wind capacity in the South African grid as of 2024. This value is used to scale the normalized wind power outputs simulated using the Weibull distribution, ensuring physical realism in the generation scenarios.
3.2.2. PV and CSP Scenario Sampling (Beta Distribution)
Solar power (PV and CSP) scenarios are modeled using the Beta distribution [
39] after normalizing by the respective maximum capacities
(PV: 2287 MW, CSP: 500 MW).
These values represent the maximum recorded or registered generation capacities of grid-connected systems in South Africa during the study period and are critical for scaling stochastic forecasts to realistic operational levels. The Beta distribution is parameterized using the empirical mean μ and standard deviation σ derived from the historical generation data.
Given the mean
μ and standard deviation
σ [
40],
The variance is
, and the parameters are estimated as follows [
40]:
Samples
are then scaled back:
Nighttime hours (20:00–04:00) are set to zero to reflect solar unavailability, i.e.,
3.2.3. Total Demand Scenario Sampling (Lognormal Distribution)
Total demand uncertainty is modeled using the Lognormal distribution to account for positive skewness. The Lognormal distribution is parameterized by
and
[
41]. Given mean
μ and standard deviation
, both
0.1,
Scenarios are generated and then clipped to realistic system demand limits.
3.3. Temporal-Aware K-Means Scenario Reduction
While generating a large number of scenarios enhances robustness, it significantly increases the computational burden of stochastic optimization [
42]. To address this, we propose a Temporal-Aware K-Means Scenario Reduction (TAKSR) method that balances representativeness with computational efficiency while enforcing physical constraints. TAKSR reduces the original scenario set by clustering based on extracted statistical and temporal features and selecting representative scenarios from each cluster.
3.3.1. Feature Extraction
For each scenario
i, TAKSR extracts a 28-dimensional feature vector
capturing key statistical and temporal characteristics:
where
is the time series of scenario
i,
is the corresponding forecast,
is the mean during 06:00–18:00 minus the mean during 18:00–06:00, and the mean deviation is the average deviation from the forecast mean.
The features are then standardized using z-score normalization [
43] to ensure comparability across dimensions:
3.3.2. Clustering and Scenario Selection
The standardized feature vectors
are clustered using K-Means with
K clusters. The optimal number of clusters is selected by maximizing the silhouette score [
44]:
where
is the intra-cluster distance for point
i, and
is the nearest-cluster distance. Once clustering is completed, the representative scenario
for each cluster
k is selected as the closest to the cluster centroid
[
45]:
The full forecast, scenario selection, and reduction process are summarized in Algorithm 1.
Algorithm 1: Hybrid Forecasting and Scenario Reduction Process |
Input: X → Historical multivariate time series data, → Exogenous features at time t, l → Lookback window, k → Number of scenarios, n → Number of LSTM stochastic passes, α → Confidence level (e.g., 90%), S → Start date of forecast window, L → Length of forecast horizon, F → Uncertainty scaling factor |
Outputs: , , , : Prediction Interval |
Train an LSTM on historical data to capture temporal dynamics For each time step t in the forecast horizon, do
- a.
Perform n Monte Carlo forward passes to obtain stochastic forecasts: Append to S - b.
Compute mean prediction: - c.
Compute standard deviation: - d.
Apply uncertainty scaling:
- a.
Form input vector: - b.
For each target variable (wind, PV, CSP, demand) do
Sample N stochastic scenario trajectories across all forecast steps. Post-process samples (e.g., clip negatives, enforce zero generation at night for solar)
For each generated scenario i, do
- a.
Extract descriptive features = [mean, std, range, day-night delta, mean deviation]
Standardize all feature vectors = StandardScaler() Apply TAKSR on {, …, } For each cluster k = 1 to K, do
- a.
Return the reduced representative scenario set:
|
3.3.3. Temporal and Physical Constraints
To ensure physical realism, especially for solar resources like PV and CSP, TAKSR re-applies temporal constraints after representative scenario selection. Although such constraints are already imposed during scenario generation, reapplying them serves as a safeguard. Specifically, clustering may occasionally select scenarios where noise or forecast deviations push nighttime values slightly above zero. Re-imposing these constraints ensures such anomalies are corrected. Additional constraints include ramping limits during dawn and dusk to reflect realistic solar behavior and clipping to predefined capacity limits for feasibility.
Figure 5 presents the workflow from the forecasting model to the scenario generation process.
3.4. Stochastic Optimization Model
We employ a two-stage stochastic programming framework to optimize energy scheduling in both day-ahead and real-time operations. This model incorporates probabilistic scenarios derived from hybrid LSTM–XGBoost forecasts to represent uncertainty in RE generation and electricity demand.
3.4.1. First Stage (Day-Ahead Scheduling)
In the first stage, the model determines the optimal unit commitment of non-RE resources and the preliminary dispatch of renewable resources based on forecasted scenarios. The objective is to minimize the expected cost, which comprises fuel costs for non-renewable generation, startup and shutdown costs, and penalties for potential demand shortfalls. Constraints ensure that the total supply meets forecasted total demand while respecting system capacities (e.g., wind install and PV install). The key decision variables include the binary unit commitment status
, startup indicators
, and shutdown indicators
. The first stage cost is calculated as
3.4.2. Second Stage (Real-Time Scheduling and Recourse Decisions)
The second stage of the two-stage stochastic optimization model addresses real-time operational adjustments in response to forecast deviations in RE generation and load demand. For each scenario,
, the model activates scenario-dependent variables that include non-renewable generation levels
,
,
,
. These variables allow the model to implement corrective actions that maintain grid balance under uncertainty. For instance, if wind generation underperforms due to low wind speed, the model compensates by increasing non-renewable generation or invoking demand-side adjustments such as load shedding:
The model is formulated as a mixed-integer linear program (MILP) and implemented in Python using Gurobi [
46], a high-performance solver capable of handling the combinatorial complexity of large-scale scheduling problems. The optimization spans a 7-day horizon and incorporates operational constraints such as generator capacity limits, minimum up/down times, ramping limits, and storage dynamics. This architecture ensures that anticipatory (first-stage) decisions are made with awareness of potential real-time (second-stage) adjustments, enabling a cost-effective and resilient energy dispatch strategy under RE uncertainty.
3.4.3. Performance Metrics and System Parameters
The model’s performance under forecast uncertainty is evaluated using system-level indicators, as summarized in
Table 4.
Table 5 outlines the operational parameters used for dispatch simulations. These parameter values are drawn from publicly available sources, including planning documents from Eskom [
47] and reports by the Department of Mineral Resources and Energy (DMRE) [
48]. Where precise values were not available, reasonable estimates were adopted based on similar studies. All parameters are configurable and can be adjusted to reflect the operational preferences or constraints of specific system operators.
3.5. Technical Implementation and Computational Setup
The framework was implemented using Python v3.10, with TensorFlow v2.19 and Scikit-learn libraries v1.6 supporting the hybrid LSTM–XGBoost model’s development. The optimization component was developed using Pyomo v6.9 and solved with Gurobi 12.0. The training and simulations were executed on a workstation equipped with an Intel Core i7 processor, 16 GB RAM, and an NVIDIA RTX 3090 GPU. Training the hybrid forecasting model took approximately 3.2 h across all four targets. The stochastic optimization solver runtime for a full 7-day dispatch problem (across 50 scenarios) averaged 18–22 min per instance.
5. Conclusions
This study presents an optimization framework aimed at enhancing renewable integration by optimizing dispatch under RE uncertainty using South Africa’s power system as a representative case study. A scenario-based stochastic optimization approach is proposed, which integrates machine learning-based forecasting with uncertainty quantification to support more resilient and cost-effective operational planning. Specifically, a hybrid LSTM–XGBoost model is developed to forecast wind, PV, concentrated solar power (CSP), and electricity demand. Monte Carlo dropout and quantile regression techniques are employed to capture uncertainty, and scenarios are generated using appropriate probability distribution models. The optimization framework evaluates four dispatch strategies—Perfect Information, Stochastic, Deterministic, and Rule-Based—under realistic operational constraints and cost penalties for curtailment and load shedding. The Perfect Information model served as a benchmark for ideal system performance with zero load shedding and curtailment. Among the implemented strategies, the Stochastic model demonstrated the highest effectiveness by incorporating multiple future scenarios, thus enabling more balanced and stable system operations. It significantly reduced reliance on non-renewable generation while also minimizing curtailment and load shedding. In contrast, the Deterministic and Rule-Based models were hindered by rigid planning and poor adaptability to uncertainty, resulting in high operational penalties and inefficiencies. This study demonstrates that forecast-informed, probabilistic optimization strategies are critical to managing the complexities of renewable-integrated power systems. With modest increases in computational overhead, such strategies can significantly enhance system resilience, reduce dependence on fossil-based generation, and support a more flexible and cost-effective energy transition. Future research will extend validation across multi-seasonal and multi-year horizons to assess long-term performance. The framework may also be expanded to incorporate DC or AC power flow models, enabling spatially aware dispatch decisions and ensuring voltage stability across the transmission network.