# Hybrid Energy Routing Approach for Energy Internet
## 4 Subscriber Matching Mechanism  
The subscriber matching mechanism constructs the producer (seller)-consumer (buyer) pairs based on the proposed peer-to-peer trading architecture. We assume that, here, the broker stores producers/consumers profiles such as: the electricity price, transmission time and the amount (\(P\)) of available/needed power, as shown in Table 4.  
As mentioned in the subscriber-matching mechanism sequence diagram (shown in Figure 4): \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Device** & **Consumer/ Prosumer** & \(P\) **(Kw)** & \
\begin{tabular}{c} **Electricity Price** \\ **(USD/Kw.h)** \\ \end{tabular} &
\begin{tabular}{c} **Transmission Time (hm)** \\ \end{tabular} \\ \hline \(D1\) & Consumer & \(-22\) & - & 13:00–13:15 \\ \(D2\) & Prosumer & \(15\) & 0.068 & 09:45–14:00 \\ \(D3\) & Consumer & \(-9\) & - & 10:00–12:00 \\ \(D4\) & Prosumer & \(25\) & 0.048 & 09:00–12:00 \\ \(D5\) & Prosumer & \(10\) & 0.056 & 12:00–13:30 \\ \(D6\) & Prosumer & \(18\) & 0.043 & 12:30–14:00 \\ \(D7\) & Consumer & \(-12\) & - & 10:00–12:00 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Producers’ and consumers’ energy information. Figure 4: Energy routing approach sequence diagram. 1. Each consumer creates an energy request message with the amount of needed energy, then sends it to their connected ER. 2. The ER transfers this energy request to the broker. 3. The broker treats the energy demands according to their requesting time and determines for each demand a list of all producers/prosumers that can provide the consumer energy demand in the corresponding time. If there is no single producer/prosumer capable of providing the consumer required energy, then the consumer is a heavy load. In this case, the broker constructs a list of all the producers/prosumers available in the consumer transmission time;
4. The broker sends the constructed list to the consumer energy router. 5. After receiving the possible producers' list, the consumer ER runs the subscriber matching mechanism as illustrated in Algorithm 1,  
As illustrated in Algorithm 1, there are two cases:  
```
Input:\(c\) // the identify of consumer \(P_{c}\)// the demand energy of consumer \(L\) // the list of possible producers Output:\(Fitness\)// the Fitness value /* check if the consumer is a heavy load */ \(Fitness\gets 0\) if(IheavyLoad(c)then /* case 1: Mono-source consumer */ for\(i\gets 0\)to\(1\)do // l:the number of producers in list \(L\) \(cost_{p}\gets calculatedcost(L(i),P_{c})\) \(w_{c\gets p}\gets IACObasedERP(L(i),c,P_{c})\) \(Fitness_{p}(i)\leftarrow\alpha\times w_{c\gets p}+(1-\alpha)\times Cost_{p}\) /* Select the best producer with min Fitness */ \(Fitness=min(Fitness_{p})\) else /* case 2: Heavy load (consumer) */ \(C_{c}^{n}\gets createCombination(P_{c},L)\) for\(i\gets 1\)to\(m\)do /* Determine the power amount to get from each set to achieve the minimum Fitness */ \(Fitness_{s}(i)\gets EPSOA(C_{c}^{n}(i),c,P_{c})\) /* Select the best producers set with the min Fitness */ \(Fitness\gets min(Fitness_{s})\)
```  
**Algorithm 1**Subscriber Matching Mechanism  
_Case 1: A mono-source consumer_  
Here, one or multiple producers can provide the requested energy. Here, ER uses Equation (3) to calculate the fitness value (\(Fitness_{p}\)) to each producer (\(p\)) in the received list. \[Fitness_{p}=\alpha\times w_{c\gets p}+(1-\alpha)\times Cost_{p} \tag{3}\]  
\[Cost_{p}=electricityPrice\times P_{c}\times Time \tag{4}\]  
where \(cost_{p}\) and \(w_{c\gets p}\) represent, respectively, the cost of energy and the power transmission loss of the best path between the consumer and producer generated by IACO-based energy routing protocol (described in detail in Section 5). As mentioned in Equation (3), it is evident that the objective function combines two opposing objectives to be minimized: cost and power loss. To make the problem simpler, we connected these two objectives together by an \(\alpha\) factor reflecting the degree of importance or weight of each objective, based on the preference of the broker.