## 5 Optimal Scheduling Model of BIPV Microgrid
### The Objective Function  
This article aims at the minimum daily operating cost of the system, meanwhile, it also considers the comfort of the staff in the building. Therefore, the objective function contains three parts; the first is the economic cost, including the cost of power purchase from the main grid and the maintenance cost of each equipment in the system, the second is the penalty caused by the comfort decrease of the staff, the last is the revenue of selling electricity to the main grid. In summary, the objective function of the system is developed as:  
\[C=\min\sum_{t=1}^{N}\left(C_{1}+C_{2}+C_{3}-C_{4}\right) \tag{14}\]  
where \(C_{1}\) is the cost of purchasing power. When \(P_{\text{grid}}\geq 0\), \(C_{1}=c_{\text{grid}}\times\left|P_{\text{grid},t}\right|\times\Delta t\). When \(P_{\text{grid}}<0\), \(C_{1}=0\). \(c_{\text{grid}}\) is the real-time electricity price. \(C_{2}=c_{\text{pv}}\times P_{\text{pv},t}+c_{\text{b}}\times\left|P_{\text{b}, t}\right|+c_{\text{ec}}\times P_{\text{ec},t}+c_{\text{h}}\times P_{\text{h},t}\), which is the maintenance cost of each device in the system. \(c_{\text{pv}}\), \(c_{\text{b}}\), \(c_{\text{ec}}\) and \(c_{\text{h}}\) is the operating and maintenance cost of PV, battery, AC, and EWH per hour per kilowatt, respectively. \(C_{3}=\gamma\times\left|T_{\text{in},t}-T_{\text{set},t}\right|\), which is the penalty term of staff comfort. \(\gamma\) is the penalty factor. \(T_{\text{set},t}\) is the temperature setting of AC without VES. \(C_{4}\) is the revenue from selling electricity to the main grid. When \(P_{\text{grid}}<0\), \(C_{4}=0.2\times c_{\text{grid}}\times\left|P_{\text{grid},t}\right|\times \Delta t\). When \(P_{\text{grid}}\geq 0\), \(C_{4}=0\). Set the price of electricity sold to main grid at 0.2 times the real-time price.  
In this paper, we first establish the mathematical model of each unit in the system according to its working principle and describe its operating state. For example, the mathematical model of a battery accurately describes the charging/discharging process of the battery, and ACVES accurately describes the heat transfer process inside and outside the building. These models precisely describe the changes in their state and provide an approximate simulation of their actual operation. Each unit in the microgrid has physical operating limits, such as the maximum capacity of the battery. At the same time, the operation of the system also has various constraints, such as the power balance constraints, heat transfer balance constraints inside and outside the building, and comfort constraints for indoor staff. The system has to operate within these constraints and achieve its optimization goals. For this purpose, this paper develops an optimal scheduling model of the system, which contains a set of constraints and an economic objective function. It should be noted that the optimization model proposed in this paper can also be applied and modified by similar studies. For example, the VES model and control strategy can also be applied to a hybrid AC/DC microgrid that contains more dispatchable loads and distributed generators. Furthermore, the ancillary services, such as fast frequency response, can also be provided through proper control of the VES in an AC microgrid.