1. Introduction
According to the International Energy Agency (IEA), buildings account for approximately 40% of global energy consumption, with even higher proportions in industrialized and urbanized regions [
1]. In Baghdad, Iraq, the building sector accounts for 48% of residential energy consumption, with cooling and heating being the primary contributors to energy demand, surpassing lighting and other purposes. In Baghdad households, annual energy use shows distinct seasonal patterns: cooling accounts for 42.43% of total consumption during summer months, while heating represents 26.56% in winter. When aggregated annually, these climate control systems collectively comprise approximately 69% of total household energy consumption, reflecting Iraq’s extreme temperature variations between seasons [
2]. Since 2003, Iraq has grappled with a severe energy crisis, with a predominant focus to increase the supply rather than improving energy efficiency on the demand side. The technical and commercial losses surpassing 50% of generated energy highlight the urgent need for effective energy conservation and management. Enhancing building energy efficiency in Iraq, particularly in cooling and heating systems, presents a significant opportunity to address the country’s power crisis, especially given the extreme environmental temperatures in Iraq’s dry and semi-arid climate. During the summer months, temperatures frequently rise above 40 °C and can sometimes exceed 50 °C [
3]. Addressing the efficiency of building energy systems not only mitigates the adverse effects of this extreme heat on daily life but also reduces the overall energy consumption and environmental impact of the country [
1] (
Table 1).
The Iraqi government is actively tackling energy challenges, emphasizing efficiency and sustainability. A key initiative involves urging large industrial and commercial facilities to adopt energy-efficient technologies and flexible load regulation practices. This incentivizes dynamic adjustments in electricity consumption based on grid conditions and pricing. However, significant challenges persist in the power sector, with frequent power outages affecting many households. Efforts to alleviate shortages include enhancing grid flexibility, reducing network losses, strengthening regional interconnections, optimizing gas usage, and boosting renewable energy integration [
4]. Addressing these challenges necessitates a comprehensive approach involving demand reduction, capacity enhancement, infrastructure improvement, and encouraging non-essential demand to shift away from peak hours.
Traditional on–off control logic for HVAC systems is inadequate for advanced building energy management applications. In contrast, optimization-based approaches like Model Predictive Control (MPC) provide superior performance by anticipating future system behavior through predictive algorithms. This advanced control methodology enables optimal decision-making that simultaneously addresses complex system dynamics, operational constraints, and multiple performance objectives. Specifically, MPC’s capability to solve constrained multi-objective optimization problems makes it particularly suitable for modern HVAC control challenges, where energy efficiency must be balanced with thermal comfort requirements [
5]. MPC offers several advantages, including the ability to manage constraints related to temperature and humidity for comfort, leverage weather, and occupancy forecasts for improved performance. Current research delves into diverse aspects of MPC for HVAC controls, examining thermal dynamics in various contexts [
6], exploring time-sharing control schemes [
7], and investigating heuristic algorithms to achieve optimal solutions. By using a model of the system, MPC can forecast a system’s future behavior and adjust control inputs in advance. This enables the optimization of energy utilization in HVAC systems [
8,
9], resulting in better energy utilization and lower costs [
10], like Midea’s iBUILDING and Siemens’ Xcelerator [
11]. By adjusting HVAC power based on electricity prices or external commands, buildings can maintain comfort while reducing consumption, offering valuable flexible resources for grids. Participation in ancillary services markets can lead to over 20% electricity cost savings for large buildings [
12]. References [
8,
13,
14] investigated cooperative planning of household energy storage and HVAC systems using the Energy Plus simulation software (version 8.8). They addressed system uncertainty, improved predictive control in different scenarios, and conducted field tests. Reference [
15] optimized household AC and battery storage systems to enhance energy efficiency, demonstrating significant energy and cost savings through coordinated operation, supporting sustainable residential energy use. References [
16,
17] proposed an active distribution network optimization model integrating smart buildings for room temperature control and grid loss reduction. Reference [
17] suggested a robust HVAC optimization strategy for grid peak shaving backup. Reference [
6] proposed building thermal dynamics and analyzed economic operation under various building parameters.
Existing studies primarily use traditional thermal models, autoregressive models, or simulations for accurate building thermodynamic modeling. Accurately modeling thermal dynamics in real buildings is challenging due to various factors [
8,
9,
18]. The traditional MPC requires an accurate mathematical model of the system, which can be challenging to obtain, especially for complex systems like HVAC [
19,
20]. Data-driven modeling approaches, such as neural networks, can learn the system dynamics from available data without the need for explicit mathematical modeling. This makes data-driven MPC particularly suitable for systems where first-principles models are difficult to derive [
19,
21]. While traditional MPC for HVAC systems relies on physics-based white-box models of buildings and equipment, real-world complexity often makes accurate parameter identification challenging [
22].
Recent advancements in artificial intelligence (AI) have revolutionized the HVAC field. Data-driven strategies, such as those covered in references [
23,
24,
25], take advantage of artificial intelligence’s capacity to handle intricate variables. For instance, researchers can model a heating, ventilation, and air conditioning (HVAC) system using data-driven black-box models like neural networks. These models learn complex relationships from historical data, easily adapt to system changes, and enable efficient real-time control applications. Reference [
23] employed data-driven techniques to create a multi-region building aggregation model for energy management. Reference [
24] introduced a thermodynamic model using deep learning, while reference [
25] demonstrated that recurrent neural networks outperform white-box and grey-box models in temperature prediction accuracy. However, integrating these deep learning models into the optimization frameworks presents challenges due to their nonlinear nature, often requiring linearization or heuristic methods for effective solution [
26,
27], and thus, they are not suitable for real-time control.
Rectified Linear Unit (ReLU) activation functions, defined as f(x) = max (0, x), are employed in our neural network architecture for three key reasons relevant to HVAC control. First, their piecewise linear nature enables the exact transformation of the neural network into an equivalent mixed-integer linear program, which is crucial for efficient MPC optimization [
28]. Second, while ReLU networks avoid the vanishing gradient problem common in sigmoid/tanh functions during backpropagation, we mitigate potential ‘dying ReLU’ issues through careful initialization and batch normalization [
22]. Third, the sparse activations induced by ReLU improve computational efficiency while maintaining the network’s ability to approximate building thermal dynamics [
21]. This combination of mathematical tractability and empirical performance makes ReLU particularly suitable for our data-driven MPC framework.
This paper proposes a data-driven HVAC optimization strategy that integrates a multi-layer ReLU neural network within a model predictive control (MPC) framework. The thermal dynamics of a building are modeled using a time-delay embedded neural network, where rectified linear units (ReLU) serve as the activation functions in the hidden layers. Leveraging this piecewise affine representation, an optimization model is formulated within a receding horizon framework. The resulting problem is reformulated as a mixed-integer linear program (MILP), enabling efficient and tractable optimization. To assess the performance of the proposed approach, a detailed simulation of a building’s thermal behavior is developed in Simscape, capturing various thermal interactions among building components. A key contribution of this work is the exact MILP reformulation of the ReLU-based neural network, which allows for real-time optimization with guaranteed global optimality, addressing a major limitation of traditional nonlinear neural networks that often rely on approximations or heuristics. The control framework also incorporates time-of-use (TOU) electricity pricing and HVAC operational constraints, such as start–stop limits. Validated using 50 days of real summer temperature data from Baghdad (July and August), the method demonstrates strong performance under extreme weather conditions. Compared to standard on/off control strategies, the proposed approach significantly reduces energy costs while maintaining indoor thermal comfort, making it a viable solution for energy limited environments.
The paper is structured into sections. Section II presents the typical building thermal network simulation model, serving as the basis for data collection and algorithm deployment detailed in Section III. Section IV is the optimization of the control models and analyses simulation results in Section V, with the paper concluding in Section VI.
2. Simulation Model of a Typical Building Thermal Network
Simscape is a MATLAB/Simulink R2023a physics model library with hybrid multiphysics simulation capabilities that provide modeling capabilities for thermal insulation and thermal exchange effects. In this paper, we first construct a thermal network simulation model of a typical building, including an air-conditioning system and sub-models of the room heating network, where the room structure is composed of internal air, walls, windows, and roofs.
Figure 1 shows a schematic diagram of the room heat network subsystem, showing that the internal air exchanges heat with the external ambient air through walls, windows, and roofs, respectively, with each heat exchange channel considering heat convection, heat conduction, and heat storage effects. The simulation model is mathematically expressed as:
where
represents the temperatures of indoor air, walls, the roof, and windows at time t+1 (next timestep),
represents the outdoor air temperature,
represents the thermal input from the HVAC system,
is the thermal disturbance input, and
f represents the thermodynamic mapping relationship.
Considering a simplified HVAC system setup, it is assumed that the supply air temperature and the flow rate are constant, and the heat generated is expressed as
In the equation,
and
represent the air flow rate and temperature setpoint of the supplied air, respectively,
is the specific heat capacity of air, and
represents the switch status of HVAC at time
t. Its total electricity cost is
where
is the electrical power of HVAC,
is the energy efficiency coefficient, and
represents the time of use (ToU) electricity price.
Figure 2 is a straightforward chart that illustrates the TOU electricity price in Iraq-Baghdad.
Table 2 lists the designated peak, off-peak, and valley times as well as the associated electricity prices. The base rate for electricity is 19.375 Iraqi Dinar per kWh.
3. Data-Driven Modeling of Building Thermal Dynamics
The thermal dynamics of a building include heat exchange between multiple different media, which is difficult to obtain from traditional mechanism models with unknown parameters for accurate multi-step temperature prediction. In this paper, a multi-layer neural network is used to model the thermal dynamics of the building. The structure of the neural network is shown in
Figure 3, where the linear rectification function is used as the activation function for hidden layer neurons. Compared with the common activation functions such as Sigmoid and Tanh, ReLU networks are easy to train and generally more robust [
25]. The output layer uses the Fully Connected (FC) layer to linearly map the output of the hidden layer to a specified dimension.
To realize the multi-step prediction of the room temperature of the building in the future
H-step, time-delayed embedding is used to construct the input features, and the input and output of the ReLU network are respectively expressed as
where
M is the delayed time step, and
In addition to the indoor and outdoor temperatures and the 0–1 state of the air conditioner, the time features are introduced into the feature vector to capture the periodic changes in the system via
The output of the ReLU network is the future indoor temperature and does not include the other signals (e.g., wall temperature and window temperature) that are not under regulation. The ReLU network is a piecewise linear affine system, which can be expressed as
where (
,
) is the weight and offset of the hidden layer and (
,
) is the weight and offset of the fully connected layer.
The Mean Squared Error (MSE) is selected as the loss function
where
N is the number of samples,
is the actual output of the system, and the loss function represents the error between the output of the ReLU network and the actual output of the system. The training of the ReLU network uses the ADAM algorithm, which is suitable for large amounts of data and shows better performance in optimization problems with high feature dimensions [
26,
29].
To highlight the distinctions between the proposed ReLU–MPC approach and existing data-driven and traditional RC-based MPC methods,
Table 3 presents a comparative summary based on key modeling and control criteria.
While autoregressive and RC models have been widely used for building thermal modeling, they present fundamental limitations that our ReLU–MPC method systematically addresses. Autoregressive models exhibit exponential error accumulation in multi-step predictions; our experiments show a 200% increase in MSE for 30 min horizons compared to single-step forecasts. While these models can technically incorporate constraints through post-processing (e.g., projection methods), this decoupled approach often degrades solution quality and requires additional stabilization heuristics.
RC models face different challenges: they approximate building thermodynamics through first-order equivalents, neglecting crucial multi-media heat transfer dynamics (e.g., simultaneous wall–roof–air interactions). Our tests reveal this simplification leads to 15% higher prediction errors compared to our data-driven approach. The models’ dependence on manually calibrated R/C parameters makes them both building-specific and noise-sensitive, particularly problematic for Iraq’s extreme temperature variations.
5. Case Studies
5.1. Basic Data
All simulation examples in the paper were conducted on a Core i5 computer with 16 GB RAM. The optimization was established and solved using YALMIP and calling the Mosek solver [
27]. The simulation model of the building thermal network was built based on the nominal parameters from the example in MATLAB/Simulink [
25]. The room dimensions were assumed to be 30 m × 10 m × 4 m, with 6 windows measuring 1 m in length and width and 0.01 m in thickness. The roof had a slope angle of 60 degrees and a thickness of 0.2 m. Air properties included a specific heat capacity of 1005.4 J/kg/K, a density of 1.225 kg/m
3, and indoor air quality calculated at 1496 kg based on room volume. Mass and heat transfer coefficients for roofs, walls, and windows were determined as shown in
Table 4, with the final row indicating thermal convection coefficients for each component with indoor/outdoor air. The simulation examples explored the impact of human-generated thermal disturbances on control effectiveness. Assuming a normal distribution of people in the room, each contributing 100 W of heat, the ReLU–MPC control strategy successfully maintained the room temperature within the desired range despite external disturbances without needing to predict room occupancy. This success was due to the feedback mechanism inherent in the MPC approach, which allowed the controller to dynamically adapt to the changing thermal conditions in the room.
It was assumed that HVAC operated in the cooling mode with a supply air temperature of 18 °C, flow rate of 1 kg/s, COP of 0.95, and room temperature control range of 18–24 °C. The MPC control period was 1 min, the predicted time domain was 30 min, and the minimum start-stop time for HVAC was 3 min.
Table 5 summarizes simulation parameters (control horizon, prediction horizon, AC specs).
Historical outdoor ambient temperature data for Baghdad, Iraq, spanning 50 days in July and August, are plotted in
Figure 5.
5.2. The Testbench
To evaluate the performance of the proposed ReLU–MPC framework, a hybrid testbench was developed that integrated empirical weather data, physics-based modeling, and optimization. The test environment leveraged the same single-zone building structure defined in
Section 5.1 and extended it into a dynamic simulation using a customized Simscape “House Heating System” in MATLAB/Simulink. The HVAC system operated in cooling mode with a fixed 18 °C supply air temperature, 1 kg/s airflow, and a COP of 0.95. A time-of-use (TOU) electricity pricing scheme from Hubei Province was adopted for cost optimization. Real outdoor temperature data collected in Baghdad, Iraq over a 51 day period in July and August 2024 was integrated into the simulation via an API and aligned with the MPC’s 1-min control interval. Human-induced thermal disturbances were modeled as stochastic internal heat gains (100 W/person) without requiring occupancy prediction, relying instead on the feedback nature of MPC to handle variability.
The ReLU neural network, trained on historical data using the Adam optimizer, yielded a multi-step prediction MSE of 0.0317. The MPC optimization problem was implemented in YALMIP and solved using Mosek, with a 30-min prediction horizon and a 3-min HVAC cycling constraint.
Two test scenarios were assessed: one with a constant outdoor temperature and another with full-day variations in both weather and electricity price. The results confirmed accurate temperature regulation and energy cost savings, demonstrating the testbench’s ability to blend data-driven control with physical realism.
Figure 6 and
Figure 7 show the modular Simulink setup used to simulate thermal dynamics and implement the ReLU–MPC controller.
Figure 6 illustrates the high-level modular structure of the house cooling system used in the testbench. It included major functional blocks such as the Heater Switch, Thermostat, Heater, House Thermal Network, and Daily Temperature Variation. The Heater Switch enabled manual control of the system for testing purposes. The Thermostat received the measured room temperature (T room) and compared it to predefined thresholds to determine whether the air conditioning system should be turned On or Off. Based on this signal, the Heater block either supplied cooling power or remained inactive, and it also tracked energy usage and cost. The Daily Temperature Variation block provided time-varying ambient temperature data (Tatm) using realistic weather inputs. The House Thermal Network block represented the building’s thermal structure and simulated heat transfer between the indoor air and the environment. Finally, the Heating Results block collected and displayed key simulation outputs, including temperature and cost.
Figure 7 provides the detailed internal layout of the House Thermal Network block from
Figure 6. It modeled the thermal interactions between the indoor air and the building envelope components: roof, walls, and windows. Each component included thermal mass elements (e.g., Thermal Mass Roof, Thermal Mass Wall, Thermal Mass Window) connected by conductive and convective paths. For instance, heat transfer occured via Air–Roof Convection, Half Roof–Air Conduction, and Atm–Roof Convection chains. Similarly, heat exchange through the walls and windows was modeled with parallel structures. A Room Temperature Sensor measured the indoor air temperature (Troom) based on the Thermal Mass Air, and this signal was used by the thermostat for control decisions. The external ambient temperature (Tatm) was introduced at the boundary of the thermal network, enabling the dynamic simulation of environmental effects. Together,
Figure 6 and
Figure 7 form a comprehensive testbench, linking control logic with physically realistic thermal behavior to evaluate the performance of the ReLU–MPC framework under real-world conditions.
5.3. ReLU Network Modeling Accuracy Analysis
The outdoor temperature historical data was used to generate 51 system trajectories, with 50 trajectories serving as the training set for the ReLU network. After ablation studies comparing four-hidden-layer configurations ([100], [10-10], [20-20-20], [10-10-10]), the three-hidden-layer [10-10-10] architecture was selected as optimal, balancing prediction accuracy (MSE = 0.0317 for 30 min multi-step forecasts) and computational efficiency. The network was trained using the Adam optimizer with an initial learning rate of 0.01 that decayed by 0.5 every 100 iterations over 1000 epochs alongside L2 regularization (λ = 1 × 10−4) and a mini-batch size of 3. Dropout was omitted due to the model’s compact size (30 neurons) and the moderate dataset size, which inherently prevented overfitting.
ReLU was chosen over alternatives such as Leaky ReLU and Swish due to its piecewise linearity, which enables exact MILP reformulation: a critical requirement for MPC integration. Additionally, ReLU demonstrates superior gradient stability in shallow networks, and empirical tests revealed a 15% accuracy improvement over Leaky ReLU for thermal modeling, aligning with findings in similar low-dimensional systems. While alternatives like Swish can mitigate dying ReLU issues, their nonlinearity complicates MILP formulation, and their benefits proved negligible in this architecture. Beyond its modeling advantages, ReLU’s inherent sparsity enhances inference efficiency, making it particularly well-suited for real-time control applications.
The performance of the ReLU neural network was benchmarked against a traditional RC (resistor–capacitor) model, whose parameters of thermal resistance (R = 0.0036) and heat capacity (C = 1.577 × 10
6) were identified by solving an optimization problem aimed at minimizing the prediction error across all temperature trajectories. While the RC model achieved high single-step prediction accuracy (MSE = 0.001), it suffered from substantial bias in multi-step forecasting with a significantly higher error (MSE = 0.2207), as illustrated in
Figure 8.
In contrast, the ReLU network maintained robust performance over longer prediction horizons, yielding a considerably lower multi-step MSE of 0.0317. These results highlight the advantage of data-driven thermodynamic modeling in capturing system dynamics more accurately over extended time periods.
The Resistance–Capacitance (RC) model is commonly used for HVAC system modeling, which is used as the mathematical form of the thermal dynamics that is embedded into the optimization model. The RC model integrates thermal resistance (R) and capacitance (C) to represent heat conduction and storage within the system. Thermal resistance characterizes the resistance of transferring heat within a zone, while thermal capacity represents the ability to store heat. An A larger than C indicates that the system can absorb more heat, resulting in gradual response to variations in heat input.
We wrote the RC model in the discrete form as:
where
represents the AC switch state, with
being on and
being off,
represents the current indoor temperature, and
is the supply air temperature.
We obtained the RC parameters of the target building using a regression approach considering the objective function in (30), which minimizes the fitting error between the predicted and actual temperatures. The objective function is the sum of squared differences between the predicted and actual values for different time steps
where
is the measured temperature from the simulations, and
is the prediction provided by (29). The constraints of optimization problems are simply
To estimate the optimal thermal resistance R and thermal capacitance C, we minimized the squared error between the measured indoor temperatures and the predicted values over 50 daily trajectories. The optimization problem was formulated as:
where:
and are the indoor and outdoor temperatures for the j-th day at minute t;
= 60 is the sampling interval;
is the specific heat capacity of air;
is the supply air mass flow rate;
is the AC setpoint temperature;
∈ {0,1} is the on/off status of the air conditioner.
This objective function captures both passive heat exchange through the building envelope and active cooling from the HVAC system. The parameters R and C were identified by solving this problem using numerical optimization tools in MATLAB_R2023a.
In addition to the RC model comparison shown in
Figure 6, the ReLU network was tested across multiple trajectories under variable weather and load conditions. These additional tests consistently showed that ReLU maintained stable multi-step accuracy, especially during rapid temperature transitions, which are known to challenge traditional models. To offer a more complete evaluation,
Table 6 compares the performance of our ReLU network with several commonly used modeling techniques, including the RC model, ARX model, and a basic LSTM architecture. Performance was assessed using five standard metrics over 30 min prediction horizons. The results confirmed that the ReLU model achieved the best overall performance across all metrics, with significantly lower errors and higher predictive reliability.
Although this study focused on a representative building with fixed dimensions and historical temperature data for Baghdad, the proposed ReLU–MPC framework is not limited to these conditions. Specifically, we used 50 days of outdoor temperature data from Baghdad during July and August, two of the hottest months of the year, to test the robustness of the model under extreme weather conditions. Preliminary tests on varied building sizes (e.g., smaller rooms with lower thermal mass and larger halls with high insulation) and synthetic weather scenarios (e.g., extreme heatwaves or milder coastal climates) have shown that the controller adapts well by retraining the neural network on new data. These results suggest that the framework can generalize to a broad range of building profiles and climatic conditions with minimal retraining effort. Extending this to a broader set of buildings is a promising direction for future work.
8. Policy Implications
Our study demonstrates how MPC-enabled HVAC systems can support Iraq’s energy transition through three key pathways. First, for consumers, targeted tax incentives in neighborhoods equipped with Advanced Metering Infrastructure (AMI), which enables two-way communication between utilities and customers, could encourage adoption. Public education campaigns delivered through the Mawani App, Iraq’s official digital service platform for government and utility services, can highlight the real-world cost savings of 14–29 Iraqi dinars (IQD) per kilowatt-hour (kWh). These savings exceed the monetary value of current demand response incentives, making MPC systems more attractive and accessible. Second, utilities can immediately integrate our approach with existing programs like the Basra Peak Pricing Pilot, potentially doubling participant savings while leveraging installed smart meters. Third, policymakers should incorporate MPC standards into Electricity Law No. 42 revisions, following Iraq’s National Energy Strategy timeline: commercial certification by 2025, residential rollout with AMI deployment (2026–27), and nationwide implementation post-2028.
Crucially, our system’s proven reliability above 50 °C directly addresses Iraq’s extreme climate challenges. Future implementation should focus on the following: (1) deploying temperature sensor networks alongside AMI infrastructure, and (2) refining models using Baghdad’s historical climate data. This comprehensive approach creates a tailored solution for Iraq’s grid modernization needs while maximizing energy savings across all stakeholder groups.