# Hybrid Energy Routing Approach for Energy Internet
## 6 Algorithms Complexity  
Algorithm complexity is one of the metrics used to measure the performance of any given algorithm. In our proposed approach, we have used ACO and PSO algorithms to obtain the best optimal solution. ACO is exploited to find the efficient paths between consumers and their producers. PSO is used to determine the best producers for a heavy load consumer. Despite the fact that the ACO algorithm presents limitations in large-scale combinatorial problems because they require huge processing time, in our case, it outperformed the greedy search algorithm used in [20] to solve the same problem. In what follows, we computed the used algorithms complexity.  
We can compute the subscriber matching's complexity in two cases: heavy loaded network (ComplexHeavy) and light loaded network (ComplexNotHeavy). Since the IACO algorithm is invoked in both cases, let us compute its complexity first. Assume n is the number of ER nodes, m is the number of ants, and the maximum number of iteration is maxit. Then, the time complexity analysis of IACO algorithm is: \(O(n\times(n-1)\times m\times maxit/2)\)(1) The time complexity of the light-loaded network is (see Table 7):  
\[ComplexNotHeavy=1+np\times(1+comIACO+1)+1\] \[=2+2\times np+np\times comIACO\] \[=2+2\times np+np\times O(n\times(n-1)\times m\times maxit/2)\] \[=O(n^{2}\times m\times maxit/2)\] \[because\quad 2+2\times np\quad\text{is}\quad\text{less}\quad \text{than}\quad comIACO.\]  
where \(np\) is the number of possible producers.  
(2) The time complexity of the heavy loaded network is (the worst scenario (see Table 8)):  
\[ComplexHeavy=comp(C(c,n))+\] \[m\times comp(EPSOA)+\] \[comp(EPSOA)+\] \[=O(n^{min(c,c-n)})+m\times O(maxit\times k\times np)+O(n^{2} \times m\times maxit/2)+1\]  
where:  
* \(comp(C(c,n))=O(n^{min(c,c-k)})\) is the combination complexity.
* \(comp(EPSOA)\) is the \(EPSOA\) algorithm complexity. The\(EPSOA\) algorithm contains several elementary instructions, two nested loops and three nested loops. Then, its complexity is \(O(maxit\times k\times np)\) (see Table 9):  
\[comp(EPSOA)=1+O(k\times n)+O(k)+4+5\times O(maxit)+\] \[3\times O(k\times maxit)+2\times O(maxit\times k\times np)\] \[=O(maxit\times k\times np)\]  
where \(k\) is the number of particles.
* \(\text{comp}(EPSOA\) objective function) is the same as the complexity of the light loaded network case, previously computed as: \(comp(EPSOAobjective function)=O(n^{2}\times m\times maxit/2)\)  
\begin{table}
\begin{tabular}{l l l} \hline \hline
**Instruction** & **Complexity** & **Explanations** \\ \hline \(Fitness\gets 0\) & O(1) & Elementary instruction \\ \(cost_{p}\gets calculatecost(L(i),P_{c})\) & O(1) & Repeated np times \\ \(w_{c\gets p}\gets IACObasedERP(L(i),c,P_{c})\) & comIACO & Repeated np times \\ \(Fitness_{p}(i)\leftarrow\alpha\times w_{c\gets p}+(1-\alpha)\times Cost_{p}\) & O(1) & Repeated np times \\ \(Fitness=min(Fitness_{p})\) & O(1) & Elementary instruction \\ \hline \hline \end{tabular}
\end{table}
Table 7: Light-loaded network case.  
\begin{table}
\begin{tabular}{l l l} \hline \hline
**Instruction** & **Complexity** & **Explanations** \\ \hline \(C_{n}^{c}\gets createCombination(P_{c},L)\) & \(O(n^{min(c,c-k)})\) & Combination \\ \(Fitness_{i}(i)\gets EPSOA(C_{c}^{n}(i),c,P_{c})\) & \(comp(EPSOA)\) & Repeated m times \\ \(Fitness\leftarrow min(Fitness_{s})\) & O(1) & Elementary instruction \\ comp(EPSOA objective function) & \(O(n^{2}*m*maxit/2)\) & The same as compIACO \\ \hline \hline \end{tabular}
\end{table}
Table 8: Heavy loaded network case.