# Demand-Response Control in Smart Grids
## 5 Fair Energy-Scheduling Method
### Phase I: Proportional Division-Based Energy Scheduling  
The auctioneer agent receives information on the amount of excess energy (\(E_{s(i)}\)) and the deficit energy (\(E_{rsq(i)}\)) from the provider and consumer agents, respectively, in the first phase. For the multi-agent system, the auctioneer agent calculates the total extra energy available and total required energy load as follows:  
\[E_{req}=\sum_{i=1}^{NbConsumers}\left(L_{i}-G_{i}\right)=\sum_{i=1}^{NbConsumers }E_{req(i)} \tag{14}\]  
\[E_{total}=\sum_{i=1}^{NbPraducers}\left(G_{i}-L_{i}\right)=\sum_{i=1}^{NbPraducers }E_{s(i)} \tag{15}\]  
where \(G_{i}\) represents the produced energy by the agent \(i\). Because the suggested energy-scheduling methodology is non-priority based, it performs fair energy-scheduling among all consumer agents during Phase I, utilizing the proportionate division method. As a result, the auctioneer agent divides \(E_{total}\) into \(N\) equal portions, as seen below:  
\[E_{eq}=E_{total}/NbC\text{Consumers} \tag{16}\]  
The auctioneer agent attempts to disperse the \(E_{eq}\) among all consumer agents. The energy requirements of the consumer agent can be less than or greater than \(E_{eq}\). If the energy requirement of the consumer agent (\(E_{req(i)}\)) is less than \(E_{eq}\), the total energy purchased by the consumer agent during phase I is (\(E_{b(i)}\)). If (\(E_{req(i)}\leq E_{eq}\)),  
\[E_{b(i)}=\ E_{req(i)}\]  
Because the consumer agent's energy requirement is met during phase I, its remaining energy requirement is zero, i.e.,\[E_{rem-req(i)}=0\]  
However, if the consumer agent's demand exceeds \(E_{eq}\), the consumer will receive energy equal to \(E_{eq}\) in phase I; i.e., if (\(E_{req(i)}>E_{eq}\)),  
\[E_{b(i)}=E_{eq}\]  
Because the consumer agent's energy requirements were not met during phase I's internal trade, the remaining energy requirements are computed as  
\[E_{rem-req(i)}=E_{req(i)}-E_{eq}\]  
As a result, the first phase focuses on lowering the cost of energy for each consumer agent, as all consumers receive at least some of their entire energy requirements through internal trading and do not need to acquire all their energy from the utility grid at a higher cost. After executing energy scheduling during Phase I, the \(E_{total}\) is the left-over energy with the auctioneer agent. The \(E_{total}\) is calculated as follows:  
\[E_{total}=E_{total}-\sum_{i=1}^{NbConsumers}E_{b(i)}\]  
Running Example  
From Table 3, there are some agents which play the role of provider or consumer depending on the difference between the electricity generated, as well as its requirement. If the difference is positive (resp. negative), it is considered as a provider (resp. consumer). Using Equation (14), \(E_{req}=40+235+410+232+500=1417\) KWh. Using Equation (15), \(E_{total}=395+685+170=1250\) KWh. Using Equation (16), \(E_{eq}=1250/5=250\) KWh. Therefore, the total energy becomes \(E_{total}=1250-(40+235+250+232+250)=243\) KWh. Table 4 presents the requested energy of the five consumers along with the energy scheduling done during Phase I of Algorithm 3. The consumers whose energy requirement is greater than 250 kWh; that is, the consumers with IDs 5 and 8 receive 250 kWh in the first phase. The other consumers (IDs 1, 4, and 7) will receive the electricity that they require. Therefore, the remaining energy requirement of these three agents becomes 0 after Phase I, and these three consumers will not participate in Phase II. The other consumers (IDs 5 and 8) will participate in Phase II auctioning for buying the remaining energy requirement.