## 4 BILSTM-Transformer Based Bems Model
### Microgrid Optimization Method Based on Cognitive Control  
After applying the Transformer-BiLSTM network, the building-energy management system (BEMS) can effectively predict the \(P_{\text{gird}}\) and control the charging and discharging power in most cases, but due to the increasing demand for EV charging and the increasing complexity of the system, the BEMS faces the problem of unstable communication or data loss in data transmission.  
On the one hand, the delay or loss of data in communication will make it impossible for the charging pile to obtain the latest status of the central system and the electric vehicle in time, thus affecting the charging and discharging scheduling decisions of the electric vehicle. This uncertainty can directly affect the energy management of the system, leading to an imbalance in the load on the grid and potentially additional energy losses.  
On the other hand, the forecasting results of the Transformer-BiLSTM network built into the charging pile depend on the integrity and stability of the data. In the case of missing data or transmission failure, the model may output inaccurate \(P_{\text{gird}}\) forecastings, causing the charging and discharging schedule of electric vehicles to deviate from the optimal scheme and increase the scheduling error of the power grid. In particular, when a large number of electric vehicles are connected to a central system at the same time, the accumulated forecasting error will further amplify the scheduling bias and affect the overall energy efficiency of the system.  
Therefore, the communication delay and the acquisition of incomplete information will directly or indirectly affect the real-time monitoring ability of the BEMS system for electric vehicles, resulting in the charging and discharging needs of some electric vehicles cannot be met in time, which further reduces the response speed and scheduling efficiency of the system.  
Figure 2: Network structure.  
In order to solve the above problems, a cognitive control model was introduced to optimize the performance of BEMS, enhance the robustness of the control system, and reduce the impact of data uncertainty. Cognitive control models are a model-free adaptive learning method that can learn and speculate in response to data loss, latency, or missing information in an environment where wireless communication is unstable. The specific implementation steps are divided into the following three parts: in the first part, user-side cognitive control (UACC) is introduced to help the system autonomously adjust the charging and discharging behavior of electric vehicles in the case of unstable wireless communication or data loss. In the second part, the system is globally scheduled and optimized by the building-energy management center (MCC), which addresses the problem of data loss by estimating deviations in user demand. In the third part, the information gap quantification will be used to measure the data information uncertainty caused by communication instability, the Q learning algorithm will be used as the core learning mechanism to help the system find the optimal scheduling strategy in the case of incomplete data, and finally the joint cost function will be used to help the system achieve a balance between energy management and information uncertainty.  
In the BEMS of this study, the implementation of the cognitive control model is mainly achieved through user-side cognitive control (UACC), building-energy management center (MCC)-side cognitive control (MACC), and the quantification of information gaps. Each of these directions takes on different levels of tasks, and their synergy optimizes the performance of BEMS in environments of data loss and unstable communications. The following is a description of the implementation steps and formulas of the model.