1. Introduction
The management of microgrids (MGs) is a crucial challenge of the energy transition, in the context of the complexity of decentralized networks and the intermittency of renewable sources. To address these challenges, bio-inspired algorithms are emerging as a promising approach. The T-Cell algorithm is inspired by the immune system and offers an innovative energy distribution optimization method.
The strength of the algorithm is in adaptively responding to disturbances and grid variations in order to realize a stable energy balance. Integrated into an EMS, it optimizes local distribution and minimizes interchanges with the main grid. Its efficacy has been experimentally verified using real-time simulation on an OPAL-RT by accurately replicating operational conditions. Combined with a multi-agent system structure to allow efficient microgrid component coordination. Localized agent interactions locally optimize energy distribution and enhance grid robustness.
Recent research has proposed a set of advanced Energy Management System (EMS) for microgrids, including Model Predictive Control (MPC), Mixed-Integer Linear Programming (MILP), decentralized methods like droop control, as well as metaheuristics such as ACO (Ant Colony Optimization), ABC (Artificial Bee Colony), PSO (Particle Swarm Optimization), and GA (Genetic Algorithm), approaches to reinforcement learning and fuzzy logic-based approaches. The usage of MPC is to balance and regulate voltages by predicting choices and improving electrical stability in dynamic scenarios [
1,
2,
3]. Similarly, the usage of the ABC algorithm decreases operational costs in some scenarios of load and solar irradiance [
4]. The usage of a super-twisting sliding mode control (ST-SMC) strategy has been experimented with in the paper [
5] and confirmed in real time by using OPAL-RT to ensure robust voltage regulation. Moreover, the usage of a hybrid adaptive fuzzy approach to powers in [
6] attained real-time voltage regulation on OPAL-RT and demonstrated high robustness in algorithmic behavior. Additionally, a microgrid-based MILP (Mixed-Integer Linear Programming) framework has been proposed and shows reductions in operational costs and improves the integration of renewable sources and system stability [
7]. Other studies have applied EMS implementations through metaheuristics, e.g., PSO has been used to balance the load and generation while using a communication system to ensure coordination and reliability [
8]. Additionally, CPSO-MPC-based EMS has been used and has been able to minimize costs and optimize storage used compared to classical methods [
9].
Furthermore, several recent studies have focused on integrating distributed energy management techniques with hybrid onboard power generation systems (HESPS) that face major challenges, including variable power demand, limited onboard space, and the need for functional reliability under variable navigation conditions. In this context, significant advancements have been made in optimizing HESPS, such as [
10], which proposes an original methodology that combines waste heat recovery with thermal energy storage, where the application of the advanced DMAO algorithm offers considerable potential for optimizing hybrid marine energy systems by optimizing fuel consumption, reducing emissions, and improving energy quality. Moreover, another study [
11], based on the NSGA-II algorithm, has also demonstrated promising results, confirming the effectiveness of this method for the concurrent optimization of fuel consumption, emissions, and overall energy performance. At the same time, ref. [
12] studied a deep reinforcement learning–based EMS with prioritized replay for residential microgrids, providing better adaptability in highly dynamic conditions. Similarly, ref. [
13] studied an IoT-oriented stochastic EMS scheduled through multi-agent systems, highlighting the future-oriented shift in the direction of decentralized, data-driven control systems.
Despite these advances, these strategies still have significant limitations. MPC offers anticipatory decision-taking but requires accurate models and high computational power requirements, constraining real-time applications [
1,
2,
3,
14]. Swarm methods such as PSO are simple to implement, but are adversely impacted by premature convergence, parameter sensitivity, and scalability [
15,
16,
17]. ACO offers an interesting degree of flexibility but suffers from slow convergence and strong heuristic dependencies [
18,
19]. Reinforcement learning [
12,
20,
21] and IoT–MAS enable adaptability in uncertain scenarios but necessitate huge computational resources, large training data sets, and complex infrastructures. Moreover, fuzzy logic strategies [
6,
22,
23] enhance robustness against nonlinearities but struggle to maintain high levels of accuracy in highly dynamic scenarios. Overall, these strategies involve compromises between robustness, computational intensity, scalability, and reliability in real-time scenarios.
For this aim, our contribution is to embed a bio-inspired T-Cell algorithm [
24] in a multi-agent distributed architecture developed on the JADE platform, to enable local closed-loop decision-making. The framework is capable of dynamic adaptivity to disturbances and ensures, at the same time, optimization of economic performance and of voltage stability, tested experimentally on an OPAL-RT hardware platform in real-time.
The important contributions of this study are summarised as follows:
- (i).
Our work extends the bio-inspired T-Cell optimization algorithm [
24] by introducing a voltage deviation penalty term in its objective function. This modification enables power distribution and maintains the voltage levels within an acceptable range (0.95–1.05 pu as defined by EN50160). A feedback system based on real-time measurements (OPAL-RT platform) triggers dynamic adjustments when deviations are detected, creating an innovative synergy between bio-inspired decision-making and technical grid constraints.
- (ii).
The paper emphasizes time-constrained execution and interoperability by validating the overall operation of the EMS in real-world conditions with communication latency and time-constrained execution.
- (iii).
The system is tested under a variety of power imbalances and voltage fluctuations scenarios and demonstrates the ability of the MAS-T-Cell approach to achieve dynamic balance and voltage stability in uncertain scenarios.
- (iv).
The results confirm that the proposed EMS can complete optimization cycles in approximately 210 ms, confirming its suitability for advanced and responsive microgrid energy management in practice.
This paper aims to achieve the following objectives:
To propose a hierarchical energy management framework integrating a bio-inspired T-Cell optimization approach and a MAS for distributed energy resources coordination.
To derive the optimization problem, including cost and voltage stability constraints, ensuring that the proposed T-Cell algorithm is suitable for real-time usage.
To implement the EMS in a real-time system via OPAL-RT, Raspberry Pi, and conventional communication protocols (MQTT/Modbus).
To validate the framework through hardware-in-the-loop (HIL) experiments under different scenarios, demonstrating voltage profile improvements, reduced grid dependency, and effective agent interactions.
The remainder of the paper is organized as follows.
Section 2 presents the materials and methods, including the formulation of the optimization problem, the proposed T-Cell algorithm, and the multi-agent system architecture.
Section 3 describes the real-time simulation setup and presents the results obtained using the OPAL-RT platform.
Section 4 discusses the results and analyzes their implications for microgrid operation. Finally,
Section 5 concludes the paper by summarizing the main contributions and suggesting directions for future research.
2. Materials and Methods
2.1. Energy Management Systems (EMS)
In the area of Energy Management Systems (EMS) [
25,
26,
27], the knowledge of the control levels that control the system should be acquired. Three principal hierarchical controls include the primary level, secondary level, and tertiary control level [
28].
Primary Level: The most basic form of hierarchical control operates at the local power level. It is in charge of local measurements, which are regulated based on a predetermined set point defined in the higher hierarchical control. Proper management and manipulation of these measurements at this level are key to keeping the stability of the system intact.
Secondary Level: This layer ensures reliable and economically feasible operation, handling power exchange and synchronization within the microgrid. It optimizes the system to meet reliability and economic goals.
Tertiary Control: This is the intelligence of the overall system. The main goal is the optimization of the microgrid operation itself, helped by benefits such as efficiency and economy. Advanced techniques used in this level include optimization algorithms and communication strategies. It collects information from the microgrid and the network and optimizes the operation of the system, which improves performance.
Our work integrates tertiary control, improving EMS efficiency and reliability by introducing intelligence and system-wide optimization. Leveraging advanced algorithms and communication strategies, we optimize microgrid operations using real-time data from both the microgrid and main grid.
Most research [
6,
22,
23,
29] on microgrid EMS focuses on optimization techniques for integrating renewable sources and storage systems. These studies employ advanced EMS strategies and real-time simulation tools to validate and refine their approaches, ensuring effectiveness under diverse conditions.
Our EMS relies on detailed OPAL-RT microgrid simulations. Set points calculated by the T-Cell algorithm are transmitted to the simulator for implementation. The tool simulates power distribution and monitors voltage levels across the microgrid’s three buses. OPAL-RT feeds power and voltage measurements back to the algorithm for analysis, enabling performance assessment. If imbalances (e.g., production-consumption mismatches or voltage deviations) are detected, the algorithm recalculates set points to restore equilibrium.
Unlike conventional EMS studies focused solely on power distribution, our approach combines comprehensive simulation with closed-loop voltage and load balancing. This directly addresses the growing operational challenges of modern grids, where renewable variability and decentralized generation demand more adaptive solutions. Our T-Cell algorithm’s biological inspiration provides inherent adaptability for real-world conditions, while OPAL-RT validation ensures practical deployability beyond theoretical scenarios.
The method’s dual voltage-power optimization fills a critical gap in microgrid control, offering implementable solutions for the dynamic, unpredictable environments characteristic of today’s energy transition.
2.2. System Architecture
Figure 1 illustrates the complete architecture of the system, showing the set-point flow from T-Cell algorithm in Java to the OPAL-RT platform via MQTT and Modbus protocols, as well as the closed-loop feed-back mechanism. The figure is composed of four numbered blocks, and it is clarified as follows.
- (1)
T-Cell Algorithm (Java Environment)
In the optimization layer, the T-Cell algorithm in Java computes the optimal power dispatch considering renewable generation, storage dynamics, and load demand. The environment in this layer also gets feedback data transmitted by the simulator in order to detect anomalies such as voltage deviation or power imbalance.
- (2)
Raspberry Pi Gateway.
To transmit the computed set points, Java interfaces with a Raspberry Pi via the lightweight MQTT protocol, chosen because of its efficacy as well as robustness under limited bandwidth. The Raspberry Pi then serves as a gateway, ensuring interoperability between the software environment and the real-time hardware simulator.
- (3)
OPAL-RT Simulator.
The Raspberry Pi then communicates the set points to OPAL-RT through Modbus, a widely adopted industrial communication standard. OPAL-RT applies the set points in a simulated microgrid model, made up of renewables, storage, and load-controllable equipment. During execution, OPAL-RT continually provides measurements such as bus voltages, active power flow, and battery state of charge.
- (4)
Real-Time Simulation and Feedback.
The measurement data are sent back to the Java environment, where the T-Cell algorithm calculates the performance of systems. Once deviation of nominal operating ranges (e.g., non-0.95 to non-1.05 pu voltages) is detected, new set points are recalculated and transmitted, thus closing the real-time feedback loop. The block offers safe closed-loop control under real-time constraints.
This Java–Raspberry Pi–MQTT–Modbus–OPAL-RT architecture ensures efficient communication, robust closed-loop control, and practical validation of the proposed EMS. This modular design supports low computational latency, adaptability, and suitability for real-time energy management in microgrids.
2.2.1. OPAL-RT
Real-time simulation nowadays has become an indispensable alternative to traditional testing of hardware for developing complex systems, such as electrical grids. These used to involve physical prototype construction and bench tests for new component testing. Although this can be a reliable method, it often means very high costs and a quite complicated setup process.
With the development of digital simulation tools and real-time technologies, it would be possible to perform the test of the systems in a virtual environment while respecting the temporal constraints of the real world. As illustrated in
Figure 2, the experimental setup integrates three main elements: the OPAL-RT real-time simulator, the Raspberry Pi gateway, and the laptop running the T-Cell algorithm. The OPAL-RT simulator executes the detailed microgrid model and provides real-time measurements of voltages, currents, and power flows. The Raspberry Pi acts as a lightweight gateway, ensuring interoperability between the Java environment and OPAL-RT through MQTT and Modbus protocols. Finally, the T-Cell algorithm, implemented in Java on a laptop, computes the optimal set points for distributed resources. Together, these components enable a closed-loop cycle where set points are applied, feedback is collected, and re-optimization is triggered when deviations occur, thereby validating the proposed EMS under realistic operating conditions.
This approach provides several advantages; it strongly reduces the costs and development time needed because no complex physical prototypes are required anymore. Besides, real-time simulation allows fast validation of control strategies and interaction between all components before field deployment. This enables the ability to perform parameter tuning on the fly and to test a variety of scenarios without the risk of damaging actual equipment, thus making the development process far safer and much more flexible.
Real-time simulation is basically dependent on the quality of the simulated model and its capability to represent the behavior of a real system precisely. The widely used OPAL-RT in energy, automotive, and aerospace allows one to test and validate high-fidelity models in conditions representative of reality. It allows for interfacing with the simulation and dynamic interaction through the adjustment of parameters in real-time. Many works illustrate the effectiveness of OPAL-RT for the validation of EMS. A study in [
30], for example, validates an EMS optimized by the Parasitism-Predation Algorithm (PPOA) using a simulator, OPAL-RT 5700. It achieved a maximum efficiency of 93.17%, higher than that achieved with conventional methods. Another work in [
31] tested a new EMS for a hybrid wind and photovoltaic power plant on an OPAL-RT OP4510 simulator. The latter approach has identified the effectiveness of EMS under different conditions of power variations, such as wind and irradiation, for adequate response to active and reactive power demands.
Besides, it was shown in the study [
32] that OPAL-RT can be used to validate the model of a DC microgrid feeding fast-charging electric vehicle EV stations. An intelligent energy management strategy, SEMS, has thus been developed to predict the requirements for EV charging and optimize the energy flow to overcome solar intermittency problems.
These studies show the increasing relevance of real-time simulations in both cost and time savings of development while ensuring reliability and optimization of results in the field of energy management systems.
2.2.2. Complete Workflow for Integrating MATLAB Models into RT-LAB
Figure 3 illustrates the workflow of integrating a MATLAB/Simulink (R2022b) model into the RT-LAB environment for execution on OPAL-RT hardware. The workflow starts with initial modeling generation in MATLAB/Simulink, which is then imported into RT-LAB for real-time implementation. Next, the model is divided into a Master Subsystem (SM) responsible for numerical computations and communication, and a Slave Subsystem (SC) that manages component-specific tasks. Communication between the subsystems and the hardware is enabled by virtue of OpComm blocks. Following this, the OPAL-RT target platform is defined, and the model is compiled automatically to C code for high-speed execution. Then the subsystems are assigned to processors to share calculation load, loaded on the test bench to test connectivity, and executed in real time. During execution, the system continuously monitors for overruns, which occur when computational time exceeds the real-time step. If overruns are detected, the process loops back to the partitioning step to optimize subsystem distribution and improve performance. Otherwise, the simulation continues and the results are generated.
Figure 4 shows the development chain of a Simulink model running in real time on OPAL-RT. The SM, acting as the computational core, receives as input distributed energy loads and resource states: wind1 (turbine wind generation), pv1 (solar photovoltaic production), batt (batteries charging/discharging, and State of Charge (SOC)), vl (bus voltage), as well as cl (controllable load). From these inputs, it determines aggregate outputs such as P_production (aggregate generation output), P_grid (grid interchange output), P_load (aggregate load output), and voltage (aggregate bus measurements). These outputs are subsequently sent to SC for acquisition and visualization (acquisition_production, acquisition_grid, acquisition_load, acquisition_voltage), while the Ras_Meas signal preserves synchronism of both subsystems. Together, these mechanisms define how inputs and outputs flow in the architecture, linking physical system variables to the real-time optimization and monitoring framework.
2.3. Problem Formulation and Constraints
The goal of this work is to optimize energy production in the face of fluctuating demands, considering ways to enhance renewable source usage for cost reduction and increased sustainability. Therefore, an algorithm has been developed that finds the perfect combinations between generators and loads, considering the constraints imposed by the systems on production capacity, battery charging, and more. The main objective is to minimize production costs with a balanced energy supply/demand ratio.
The optimization problem will be well-defined and formulated with consideration of the objective function and constraints. We seek an optimal solution that reduces the cost of production while satisfying all system constraints for a sustainable economic energy distribution. We adopt advanced optimization techniques to search for the best configuration of system variables with due consideration of efficient and effective balancing between the produced and consumed energy.
Objectif function
The objective function represents a mathematical criterion that guides the optimization process by setting the goal to be achieved, which, in our case, is the minimization of production costs. It incorporates various system parameters and variables, such as the variable costs of production units, resource availability, battery state of charge and voltage deviation, to create a model for evaluating the effectiveness of different potential solutions. The objective function is employed as a criterion to define the optimum configuration adhering to all the limitations and optimizing the system’s economic and operational functioning.
Constraints are the essential requirements to be met in the optimization procedure. They incorporate various factors such as resource limitations, production units capacities, state of charge, energy demand, and voltage requirements. These elements ensure that the optimization model operates under realistic conditions by guaranteeing the feasibility and effectiveness of the proposed solutions.
Power Balance Constraint: The power generated shall be equal to the required power demand.
Renewable generation constraints:
For clarity in the optimization modeling, all parameters, variables, and constants of the objective function and the constraints are presented in
Table 1. This table specifies the specifications, units, and admissible limits of each notation to facilitate reproducibility and prevent ambiguity in the problem optimization. These formulations define the feasible space and optimization criterion used by the T-Cell optimization algorithm (
Section 2.4).
2.4. Proposed Algorithm for the Real-Time Optimization of T-Cell
Optimizing energy management in microgrids is one of the major challenges in the energy transition. The increasing complexity of these systems, characterized by the intermittency of renewable energy sources and the diversity of consumers, requires efficient and adaptive optimization tools. Many researchers have applied artificial intelligence algorithms such as genetic algorithms (GA) [
33,
34], ant colony optimization (ACO) [
18,
19], particle swarm optimization (PSO) [
15,
16], neural networks, and artificial immune systems. This work is focused on the T-Cell algorithm, based on immune system adaptation mechanisms, and suggests a novel approach to address this challenge.
The T-Cell algorithm is a metaheuristic to simulate immune T-Cell behavior. Candidate solutions (as “cells”) are microgrid decision variables (generation, storage, loads). The population is evolved by three mechanisms: (i) Proliferation, where the best solutions generate their copies to enhance search intensity; (ii) Differentiation, where the copies are subjected to controlled variations to explore new regions; and (iii) Mutation, with random perturbations added to ensure diversity and avoid premature convergence.
The optimization objective is twofold: (i) minimize microgrid operating costs, and (ii) maintain voltage stability in EN50160 restrictions (0.95–1.05 pu). The objective function is the sum of production costs (PV, wind, battery, grid, controllable loads) and has a penalty on voltage deviations. The algorithm is embedded in a closed-loop EMS: after each run, the set points are sent in real time through OPAL-RT. If bus voltage deviations are beyond acceptable limitations, the algorithm is reexecuted with new conditions to ensure adaptability and grid code compliance.
The population size was fixed at 5 candidate solutions, a value chosen to match the number of core decision variables (PV, wind, battery, grid, and controllable load) while minimizing computational overhead. This size ensures sufficient diversity for convergence while maintaining compatibility with real-time requirements. The stopping criterion employed was 10,000 evaluations to converge within the required iterations. The mutation rate (ε = 0.2) preserves diversity while avoiding system instabilities, and the proliferation and differentiation factors (each = 2) allow limited cloning and variation to ensure real-time convenience of execution. The voltage penalty coefficient (λ) was set at 0.045 to be consistent with values cited in recent optimization literature (typically in the range of 0.0045 and 0.046 USD/p.u.) [
35]. The voltage limits were at [0.95–1.05 pu], consistent with EN50160 standards.
The algorithm was executed on a Dell Latitude E5570 workstation (Intel® Core™ i7-6600U processor, 16 GB RAM, Windows 10 Pro 64-bit). The mean time to execute was 210 ms per cycle, which demonstrates suitability for real-time microgrid management compared to more computationally intensive methods such as MPC.
For clarity and reproducibility, the code implementing the T-Cell algorithm (Algorithm 1) in the EMS framework is presented in the following pseudocode:
Algorithm 1. The T-Cell algorithm in the EMS framework |
- 1.
Input: - -
System data (PV, Wind, Battery, Grid, Loads) - -
Parameters: populationSize = 5, maxEvaluations = 10,000,
- i.
epsilon = 0.2, prolif = 2, difer = 2, - ii.
voltageBand = [0.95, 1.05] pu
- 2.
Initialize population of cells - 3.
For each cell: - -
Generate random decision variables - -
Evaluate feasibility (power balance, SOC, constraints) - -
Compute objective (cost + voltage penalty)
- 4.
While (nbEvaluations < maxEvaluations): - 5.
For each cell: - -
Proliferate into ‘prolif’ clones - -
Differentiate clones by varying decision variables - -
Mutate subset with probability epsilon - -
Evaluate feasibility and objective
- 6.
Update population: retain best feasible cells - 7.
Select the current best solution - 8.
Closed-Loop Monitoring: - 9.
Send best set points to OPAL-RT - 10.
Receive bus voltage feedback - 11.
If (any voltage < 0.95 pu OR > 1.05 pu):
- -
Re-run optimization with updated conditions
- 12.
Return: - 13.
Optimal set points {Ppv, Pwind, Pbat, Pgrid, Pload} - 14.
Best objective value (cost minimization + voltage stability) - 15.
Execution time
|
This pseudocode provides a structured representation of the algorithm, emphasizing both the exploration of feasible solutions (via proliferation and differentiation) and the continuous enforcement of voltage stability through closed-loop monitoring.
Finally,
Table 2 shows a comparative analysis of MPC, PSO, and T-Cell on the basis of relative strengths and weaknesses. Since MPC provides predictive capabilities, it is highly computation-intensive and highly model-dependent; PSO is highly adaptable but highly sensitive to tuning and initialization; whereas the T-Cell algorithm is highly robust, low in terms of dependency on the model, and highly responsive to dynamic environments.
A thorough comparison among the MPC, PSO, and immune-inspired T-Cell algorithm highlights greater clarity on their strengths and limitations in their application to microgrid energy management (
Table 2). The MPC is defined by its ability to anticipate system changes through strict predictive models; however, it suffers from major limitations, including strong reliance on model accuracy, high computational load, and sensitivity to uncertainties and real-time implementation difficulty in embedded or distributively implemented systems [
3,
14]. The PSO, as a heuristic method, is defined by strong system flexibility and moderate over-reliance on system modeling, but is highly sensitive to parameter tuning (swarm size, inertia weight, acceleration coefficients) and initialization effectiveness. The PSO is vulnerable to local convergence problems and higher resource usage with an increase in population [
17]. The T-Cell algorithm, inspired by adaptive immune processes, demonstrates excellent robustness to disturbances, low over-reliance on mathematical modeling, and strong adaptability to dynamic environments.
2.5. Multi-Agent-Based Distributed Control Architecture for Microgrid Energy Management and Optimization (MAS)
For the management of microgrids, multi-agent systems (MAS) introduce a decentralized and intelligent control structure allowing dynamic coordination of distributed sources and real-time adaptation to variations in demand and generation. Numerous contributions reflect the effectiveness of MAS in energy management systems. For example, ref. [
13] offers a coordination method based on MAS among multi-microgrids to enhance their stability and reduce their costs. Ref. [
36] presents a hybrid PV–small hydro system governed by a MAS achieving enhanced real-time balancing of supply and demand. Ref. [
37] presents an application to the distributed resources of green buildings by an MAS to demonstrate its appropriateness to enhance demand response. Several other contributions, such as [
38,
39], reassert the adaptability and reliability of an MAS when it is used in decentralized and real-time controlling scenarios.
Building on these previous studies, the proposed architecture is deployed on the JADE platform, which is FIPA-compliant and ensures standardized services for agent lifecycle management, registration, and communication. In our implementation, the Agent Management System (AMS) handled the creation and termination of the six agents during optimization cycles, while the Directory Facilitator (DF) enabled service discovery and ensured coordination between the Supervisor (MGS) and Optimization Agent (MGO) during re-optimization requests. The Remote Management Agent (RMA) supported scalability by monitoring distributed containers and supervising experimental runs, which ensures the system’s flexibility and robustness under real-time conditions.
The MAS includes six functional agents:
PV Agent: Models photovoltaic generation and provides real-time data.
Wind Agent: Represents wind turbine production.
Battery Agent: Supervises the state of charge and manages charging/discharging commands.
Controllable Load Agent: Governs the activation and deactivation of flexible loads.
MGO (Optimization Agent): Executes the T-Cell algorithm to compute optimal set points for distributed resources.
MGS (Supervisor Agent): Monitors busbar voltages and system states; in case of deviations outside [0.95–1.05 pu], it triggers re-optimization by the MGO.
The coordination between agents relies on ACL messages as specified in JADE. Each optimization cycle requires approximately 10 to 15 inter-agent messages, covering data requests, replies, and dissemination of new set points. The average message exchange latency was consistently below 20 ms, ensuring that communication overhead does not compromise system reactivity.
Performance analysis confirmed that the average execution time of the T-Cell optimization cycle is approximately 210, and includes inter-agent communication exchanges and input/output operations. This response time remains well within the requirements of real-time microgrid management.
Finally, the MAS is integrated with the OPAL-RT real-time simulation platform through a Raspberry Pi gateway. Optimized set points are transmitted via MQTT to the gateway and then forwarded to OPAL-RT using Modbus. Measurements of voltages and power flows are sent back along the same channel, enabling the MAS to continuously adapt control actions. This closed-loop configuration ensures both economic efficiency and compliance with operational voltage standards, while supporting the effective integration of renewable energy sources.
2.6. Implementation and Simulation Environment
In order to evaluate the presented T-Cell optimization algorithm and multi-agent system within realistic operating scenarios, a comprehensive implementation and simulation environment has been developed. This environment is composed by software-based modeling through MATLAB/Simulink, real-time simulation by RT-LAB and OPAL-RT, and hardware communication through a Raspberry Pi gateway using the MQTT and Modbus protocols. The motivation of this setup is to represent the dynamic behavior of the microgrid in real time to ensure that the EMS can be tested within scenarios resembling real-world deployment cases in a close manner. The microgrid architecture, measurement system, data acquisition chain, and real-time interface employed in this environment are given in
Figure 5,
Figure 6,
Figure 7 and
Figure 8.
The microgrid under study comprises renewable energy sources, an energy storage unit, and both variable and controllable loads, all interconnected by distribution buses. The photovoltaic array and the wind turbine, both of which are modelled by a PQ model, supply renewable power, and the storage unit offsets production and consumption. The entire system is interconnected with transmission lines and fed into the main grid through a transformer and distribution buses (Bus A0, A1, and B1). The topology creates a hybrid system where renewable resources, storage units, and loads interact with the main grid dynamically. The overall system architecture is depicted in
Figure 5.
The microgrid’s measurement system offers continuous monitoring and acquisition of the key electrical and power signals. The input is received from wind and solar photovoltaic generation, battery state charge, and variable and controllable loads. The signals are processed and aggregated into key indicators such as total production power (Pproduction), grid power exchange (Pgrid), and load demand (Pload). In addition, voltage measurements at the main grid and at the different buses (Vgrid, VbusA1, VbusB1) are made for stable monitoring of system conditions and stability. All the data are exported to be analyzed further, allowing accurate real-time evaluation of energy flow in the microgrid. The full configuration of the measurement system is illustrated in
Figure 6.
The control set point structure used for real-time control of the microgrid is shown in
Figure 7. They include photovoltaic set point (PVset), wind generation set point (Windset), dump load activation, charge and discharge directives of the battery, and load set points for variable and controllable loads. These instructions are aggregated and forwarded through the communication block to the RT-LAB environment, maintaining the optimization algorithm and hardware-in-the-loop simulation in sync. It aims to manage distributed energy resources and loads dynamically based on predictions and real-time system conditions.
The integration of the microgrid model into the RT-LAB environment enables real-time Hardware-in-the-Loop (HIL) validation. The acquisition channels are renewable generation, grid interaction, load demand, and bus voltages, which are aggregated and transferred to the RT-LAB interface to be displayed and supervisory controlled. The interface provides direct access to prime variables such as photovoltaic and wind generation, battery operation, dump load activation, and total load consumption. This setup provides real-time monitoring of the system and supports testing and verification of control strategies during dynamic and changing operating conditions.
Figure 8 shows the real-time interface developed in RT-LAB. This implementation and simulation environment forms the basis for the experimental validation presented in
Section 3, where the effectiveness of the proposed EMS is evaluated under different operating scenarios.
3. Results
This section displays the outcome from the real-time modeling and verification of the microgrid that is under study. After describing the global structure and the measurement system that is applied, the supervision interfaces and control signals are described so as to illustrate the integration of the T-Cell algorithm as well as the multi-agent approach into the OPAL-RT setup. The simulation results indicate the potential of the proposed system to achieve production–consumption balance, bus voltage stability, and autonomous adjustment to disturbances and loading changes.
3.1. Scenario 1
Figure 9 shows the simulation results of the MG’s behavior within one simulated day executed in the OPAL-RT real-time simulation platform. The described simulation results demonstrate that the algorithm used is efficient and robust for its purpose since it managed to maintain a power balance among the different components of the microgrid.
The algorithm’s performance and robustness are also demonstrated through the stable and coordinated behavior of all the microgrid components over the simulated period. The bus voltage levels are coordinated and stable, with minimal variations, providing balanced power transmission and load-sharing in the system. Moreover, the optimized power dispatch shows minimal interaction with the main grid, enhancing the autonomy of the microgrid. Such results confirm the capability of the algorithm for real-time adaptation to fluctuating generation and demand conditions, for continuous equilibrium through iterative changes in the control set points. This closed-loop operation, facilitated by OPAL-RT feedback, confirms the in-practice applicability of the developed methodology for reliable and intelligent energy management.
Moreover, the algorithm keeps the voltage within its allowable range to prevent any risks of harming the system due to overvoltage and Undervoltage conditions. Another important factor is that it minimizes the power exchange with the main grid, enhancing the autonomy of the microgrid.
This ability to effectively manage the available energy resources while ensuring system stability underscores the importance of intelligent and adaptive management in modern microgrids. The T-Cell algorithm plays a key role in this management. By enabling continuous optimization and rapid response to variations in system conditions, it ensures that each energy source is used optimally. This not only improves energy efficiency but also contributes to the resilience of the microgrid against disturbances, thereby strengthening the transition toward more sustainable and autonomous energy systems.
3.2. Scenario 2
In
Figure 10, the algorithm optimizes and sends a set of points to each energy source that is connected to the microgrid, such as a PV, wind turbine, and battery storage units. Hence, each of these sources will receive a nominal value of power it has to generate based on the set points created, while feedback signals are received from each of these sources to check the real amount of energy each of them produces.
If, after sending a production set point to a source, a zero signal is returned, that means it is no longer in a state of producing power. Then, under voltage feedback, the MGS may receive an anomaly such as overvoltage or undervoltage and ask the MGO to recalculate the optimization, changing the set points to the new system conditions.
This operating principle is illustrated in the following scenarios (2), where different disturbances and resource variations are managed in real time by the proposed framework.
T1 (01:25): Wind generation (1200 W) supplies the load (1000 W). A simulated wind turbine outage instantly decreases its output to 0 W; the battery instantly takes over and supplies 1000 W. No controllable load is activated, and the voltage is in the acceptable range [0.95–1.05 p.u.].
T2 (05:40): The load (900 W) is supplied by wind generation (3000 W). The excess is divided into charging the battery (900 W) and activating the controllable load (1200 W) with zero support from the grid. The measured voltage is maintained stable at 222 V with 0.965 p.u., well within the authorized range [0.95–1.05 p.u.].
T3 (07:30): The photovoltaic generation supplies initially the base load and then sequentially switches on controllable loads (1200 → 2400 → 3600 W). The excess remaining is stored in the battery to ensure an optimal use of available renewable energy sources. The voltage recorded is 224 V, or approximately 0.974 p.u., well within the acceptable range [0.95–1.05 p.u.].
T4 (12:00): The failure in the photovoltaic generator (3000 W → 0 W) initially causes a reduction in voltage to 217 V and hence causes a transient disturbance visible as an under-voltage in the microgrid buses. The MGS detects this aberration and reports the same to the MGO using the T-Cell algorithm. Based on this signal input, the optimization process computes a new set point, enabling the deficit to be balanced by the wind turbine (500 W) and supported by the battery (2000 W) to meet the load demand (2500 W). The voltage is stabilized at 227 V with reconfiguration measurement (~0.987 p.u.), proving the re-establishment of microgrid stability in response to the disturbance.
T5 (17:00): with the reduction in the PV generation to 0 W, the non-controllable load (3700 W) is covered by the wind generation (3000 W) and by the battery (700 W). The measured voltage is 223 V (0.969 p.u.), demonstrating the microgrid autonomy and robustness in the presence of variable renewable sources.
This result confirms effective management of energy distribution in a microgrid and smooth integration of photovoltaic production, wind production, battery storage, controllable loads, and total load. System stability is also guaranteed by maintaining the bus voltages within the optimum value range, which provides stability in the system. The algorithm will also minimize the exchanges with the main grid and improve its autonomy by promoting energy effectiveness in the microgrid.
The test scenarios in our experiment were designed to simulate a series of critical scenarios, possible in an operational microgrid, like sudden production losses (wind faults, photovoltaic faults), rapid load fluctuations, overload/underproduction scenarios, and voltage fluctuations among buses. For each event, the exact time of occurrence, the amplitude of the power variation, and the respective voltage fluctuations were specified explicitly, to ensure reproducibility and strict experimental conditions. Those phenomena were artificially induced in order to test our proposed control system. The innovation in our method is in the combination of a bio-inspired closed-loop algorithm and a multi-agent system (MGO/MGS) on an integrated hardware testbed (Raspberry Pi + OPAL-RT), in order to offer a distributed, autonomous perturbation detection with dynamic recalculation of the control commands. This integration constitutes an advanced experimental investigation, verified in real time, to perfectly simulate operational conditions in a microgrid in an uncertain variable environment.
The results confirm that the integration of the T-Cell algorithm into the multi-agent system (MAS) enables the following:
- (i).
Considerable reduction in principal grid interactions, improving the microgrid’s autonomy;
- (ii).
Simultaneous deployment of storage and renewables (wind, PV, battery) ensures maximum local use and effective supply of controllable and non-controllable loads at all hours, even during faults or resource fluctuations;
- (iii).
Strong voltage regulation at all operating points, with values consistently maintained within the allowable [0.95–1.05 p.u.] range to ensure robust and stable operation.
3.3. Comparison of the Voltage Profile Before and After Optimization
Figure 11 shows the voltage profile of the microgrid before and after applying the proposed T-cell optimization algorithm. In the uncontrolled case, bus voltages achieved a fluctuation of ±9 V around the nominal 230 V, which exceeds the limits set by EN50160. When the T-cell algorithm is applied, these deviations are reduced to ±5 V, which represents about a 44% improvement in voltage stability. This highlights the algorithm’s effectiveness in meeting voltage quality standards and enhancing overall system reliability.
The quantitative benefits are detailed in
Table 3, which outlines key performance metrics. Compared with the uncontrolled scenario, grid energy imports are decreased from 30.07 kWh to 5.13 kWh (an 83% reduction), while the self-consumption rate increases to 84%. Together,
Figure 11 and
Table 3 demonstrate the dual advantage of the T-cell strategy: stabilizing bus voltages while reinforcing microgrid autonomy by maximizing the local renewable generation use.
To compare these results with established references,
Table 4 compares the proposed T-cell algorithm with other methods reported in the literature. For instance, ref. [
2] found that cooperative MPC strategies reduced external resource use by an average of 46.18% in a community microgrid while keeping voltage variations within ±10 V. In [
40], a hybrid UT–ECOA (Unscented Transformation combined with the Enhanced Cheetah Optimization Algorithm) achieved a 10% reduction in voltage deviations and a 10.63% decrease in power losses for a grid-connected microgrid. Meanwhile, ref. [
41] reviewed heuristic methods such as PSO, which typically cut grid reliance by 50–70%, though these approaches often face challenges with convergence and parameter sensitivity.
Although direct comparisons are difficult due to differences in testbeds, scenarios, and configurations, the T-cell algorithm demonstrates significantly higher grid independence (−83% versus 46–70% reported in the literature) and tighter voltage stability (±5 V compared with the more common ±10 V). Moreover, the proposed algorithm achieves these results with low computational complexity, such that an average cycle time is 210 ms, which makes it highly suitable for real-time embedded control among microgrids.
3.4. Description of the Interaction of Different Agents in the Platform Jade
This section describes the supervisory mechanism of the microgrid (MG). The T-Cell algorithm is embedded within the MGO agent (MG1), where optimization is carried out, after which set points are sent to the various MG agents. Additionally, an MGS agent has been implemented to oversee the system and detect any potential anomalies. Based on voltage feedback from the microgrid buses, if the MGS detects a significant discrepancy, it requests the MGO to recalculate and issue updated set points.
Figure 12 shows the Interaction between agents in the JADE platform. The PV, Wind, Battery, and Load agents communicate system states to the Microgrid Manager. The MGS is supervising voltage feedback and, in case of anomalies, requesting recalculated set points from the MGO. Arrows represent ACL message exchanges for data requests, responses, and set point dissemination. At line 223 in
Figure 12, we observe that the MGS detects a voltage variation between the buses, indicating a significant fluctuation, either in the load or in power generation. In this case, the MGS requests from DF the MGO agent address. Once the address is acquired, it requires the MGO to recalculate the set points to ensure power balance and maintain bus voltage within an optimal range.
4. Discussion
Experimental results in real-time for Scenario 1 and Scenario 2 demonstrate the effectiveness of the developed T-Cell algorithm to maintain power balance together with voltage stability despite dynamic and uncertain operational conditions. Embedded with a closed-loop multi-agent system, the T-Cell algorithm detects disturbances (such as unexpected generator faults or voltage deviations) and adjusts set points to restore stability. This demonstrates flexibility as well as resilience for an environment with high noise and high uncertainty, and highlights its potential for real-time energy management.
Beyond these encouraging results, several aspects define the current scope of validation and suggest promising directions for further investigation. The algorithm achieves a fast optimization cycle of 210 ms, which is well-suited to real-time control. Extending the framework to larger-scale systems with additional agents and decision variables would provide valuable insights into scalability and may motivate the use of parallelization or hardware acceleration to preserve rapid responsiveness.
Additionally, while the present paper cited literature-reported data for MPC, PSO, and UT–ECOA, a direct benchmarking under strictly identical test conditions was not part of the present scope; Conducting such comparative analyses under standardized operating conditions would enrich the understanding of relative performance, particularly in terms of convergence behavior, robustness under uncertainty, and control effort.
The OPAL-RT platform usage played a critical role in verifying the EMS under real-time restrictions. Unlike simulation-only studies, the hardware-in-the-loop (HIL) setting facilitated by OPAL-RT exposed the true timing behavior of the system, comprising communicative delays, processing latencies, and violation of real-time constraints. This allows the verification of the EMS’s responsiveness to rapid perturbations as well as evaluating its practical feasibility for implementation within real microgrids. Verification highlighted not only optimization algorithm robustness but also end-to-end JADE agent integration, MQTT communication stack, and Raspberry Pi hardware integration, thereby verifying operational readiness.
In summary, the proposed T-Cell algorithm demonstrates strong real-time performance and adaptability within a microgrid environment. Its rapid response and robustness position it as a valuable candidate for advanced energy management, while opportunities remain to further validate and generalize the approach across more complex scenarios and standardized benchmarks.
5. Conclusions
This study introduced an innovative energy management optimization method for microgrids by combining a bio-inspired algorithm, T-Cell, into a multi-agent system (MAS) and validated it in real time on the OPAL-RT platform. This approach directly addresses the energy supply–demand imbalances that arise from renewable variability.Quantitative results confirm the effectiveness of the proposed EMS: by reducing the energy imports from the grid by 83% (from 30.07 kWh to 5.13 kWh), regulating voltage fluctuations to ±5 V (a 44% improvement compared with the uncontrolled case), and ensuring a self-consumption ratio of 84%. Additionally, the algorithm achieved an end-to-end closed-loop response time of ~210 ms, which demonstrates its suitability for real-time applications.
Beyond these results, integration with OPAL-RT and Raspberry Pi hardware also validates the optimization performance, the complete communication chain, and time-constrained execution, confirming the system’s readiness for real-world deployment.As future work, we will extend the study to larger-scale microgrids (and multi-microgrid settings) and integrate deep-learning-based forecasting models for photovoltaic generation, wind power, and load demand, to enhance predictive capability and further improve the performance and robustness of the EMS.
In summary, the MAS–T-Cell approach provides a robust, adaptive, and computationally efficient EMS solution, positioning it as a strong candidate for next-generation microgrid management under dynamic and uncertain operating conditions.