# CoSimulating Communication Networks and Electrical System for Performance Evaluation in Smart Grid
## 4 Modeling of Smart Grid Application  
In this section, we explain how the applications of the distribution and customer domains can be modeled with the demand response (DR) application. We considered a scenario in which DR application is used with a deployment of renewable energy generator.  
The main problem of employing a renewable energy generator is its inherent characteristic that an environmental factor like clouds can affect its output power. This can influence on efficiency and stability of the distribution system. Therefore, in DR application, the real-time pricing is introduced to solve the problem. By providing electricity with high price when the power availability is low, the DR application tries to reduce energy consumption of each customer. To perform the DR application, we deploy the energy management system which perform rescheduling of the electricity demand of customers in the dynamics of renewable energy generation. However, in perspective of peak load distribution, an entity is required to collect all the power generation and consumption information and to determine proper electricity load of each customer since peak load distribution cannot be performed at each energy management system. Therefore, we devise the concept of gateway energy management system which can be mapped onto a service provider in the smart grid. The gateway energy management system is placed in the distribution domain and supervises the energy management of the distribution domain.  
The most important point of the DR application is how to decide the electricity consumption of each customer according to the real time price. The function needs to minimize the electricity consumption cost and distributes the peak load of the distribution domain. To achieve the goal of the DR application, we simply modeled the application as follow [28]:  
\[\begin{split}\text{minimize }&\sum_{i=1}^{N}C(t) \cdot P_{L,i}(t)+\\ &\sum_{k=1}^{T-t}\sum_{i=1}^{N}C^{forecasted}(t+k)\cdot P_{L,i}( t+k)\\ \text{subject to }& L_{i}^{min}\leq\sum_{l=0}^{t}P_{L,i}(l)+ \sum_{l=t+1}^{T}P_{L,i}(l)\leq L_{i}^{max},\\ &\text{for }i\in 1,\ldots,N\\ & P_{L,i}^{min}(l)\leq P_{L,j}(l)\leq P_{L,i}^{max}(l),\\ &\text{for }i\in 1,\ldots,N\text{ and }l\in 1,\ldots,T\\ &\sum_{l=0}^{t}C(l)\cdot P_{L,i}(l)+\sum_{l=t+1}^{T}C^{forecasted }(l)\cdot P_{L,i}(l)\leq B_{i}^{total},\\ &\text{for }i\in 1,\ldots,N,\end{split} \tag{3}\]  
where \(C(t)\) and \(C^{forecasted}(t+k)\) represent the real time electricity price at time \(t\) and forecasted electricity price at time \(t+k\), \(P_{L,i}(t)\) and \(P_{L,i}(t+k)\) are decision variables which represent the power demand of customer \(i\) at time \(t\) and \(t+k\), \(B^{total}\) represents the total daily budget of each customer for electricity, \(T\) is the size of scheduling window, and \(N\) is the number of customer. The objective function indicates that the energy management system tries to minimize the electricity consumption cost by rescheduling the electricity demand of each customer. The first and second constraints represent that enough daily and instant energy consumption should be guaranteed for each customer to perform basic home tasks. The third constraint represents that the energy management system tries to find the minimum electricity consumption cost which is lower than predefined (or customer defined) budget. Totally, Equation (3) tries to minimize total energy consumption cost while consuming predefined amount of energy demand.  
In our application model, when the real time and forecasted electricity prices are given, the gateway energy management system solves Equation (3) according to the given cost. Then, the optimal value of electricity load is distributed to each energy management system to control their electricity. In the next section, we will present how this DR application model can be modeled into OOCoSim and can be simulated through OOCoSim. Moreover, we will precisely investigate whether OOCoSim can produce the proper simulation results.