AC load flow model
AC load flow algorithm is performed to calculate the voltage magnitudes of the buses and branch currents of the system. Traditional backward/forward sweepbased load flow has taken as a load flow algorithm.
AC microgrid with N_{AC} number of buses, ith bus current \(I_{{i,{\text{AC}}}}\) is given by
$$I_{{i,{\text{AC}}}} = {\text{conj}}\left( {\frac{{P_{{{\rm Li,AC}}} + jQ_{{{\rm Li,AC}}} }}{{V_{{i, {\text{AC}}}} }}} \right)\quad i = 1,2, \ldots ,N_{{{\text{AC}}}}$$
(1)
where \(P_{{{\rm Li,AC}}}\), \(Q_{{{\rm Li,AC}}}\) are the active and reactive power demand at ith bus and \(V_{{i, {\text{AC}}}}\) is the voltage magnitude of an ith bus.
During backward sweep of the backward/forward based load flow, the branch currents are obtained with the help of businjections to branch currents matrix (BIBC) as follows
$$J_{{k,{\text{AC}}}} = {\text{BIBC}}*I_{i}\quad k = 1,2, \ldots ,N_{{{\text{AC}}}}  1$$
(2)
During forward sweep of the backward/forward based load flow, the bus voltages are calculated with the help of branch current to bus voltage matrix (BCBV) as follows:
$$V_{{i,{\text{AC}}}} = V_{0}  \left( {{\text{BCBV}}} \right)*J_{{k,{\text{AC}}}}\quad i = 2,3, \ldots ,N_{{{\text{AC}}}}$$
(3)
Repeat Eqs. (2) and (3) until the difference between the voltages of two adjacent iterations is less than the tolerance value (ε).
$$\left {V_{{i,{\text{AC}}}}^{{{\text{itr}} + 1}}  V_{{i,{\text{AC}}}}^{{{\text{itr}}}} } \right < \varepsilon$$
(4)
DC load flow model
DC microgrid with N_{DC} number of buses, ith bus current \(I_{{i,{\text{DC}}}}\) is given by
$$I_{{i,{\text{DC}}}} = {\text{conj}}\left( {\frac{{P_{{{\rm Li,DCeff}}} }}{{V_{{i,{\text{DC}}}} }}} \right)\quad i = 1,2, \ldots ,N_{{{\text{DC}}}}$$
(5)
$$P_{{{\rm Li,DCeff}}} = P_{{{\rm Li,DC}}}  P_{{{\text{REDG}}}}$$
(6)
where \(P_{{{\rm Li,DC}}}\), \(P_{{{\text{REDG}}}} ,P_{{{\rm Li,DCeff}}}\) are the active power demand, REDG active power and effective active power demand at ith bus, respectively, and \(V_{{i,{\text{DC}}}}\) is the voltage magnitude of an ith bus.
During backward sweep of the backward/forward based load flow, the branch currents are obtained with the help of businjections to branch currents matrix (BIBC) as follows:
$$J_{{k,{\text{DC}}}} = {\text{BIBC}}*I_{{i,{\text{DC}}}}\quad k = 1,2, \ldots ,N_{{{\text{DC}}}}  1$$
(7)
During forward sweep of the backward/forward based load flow, the bus voltages are calculated with the help of branch current to bus voltage matrix (BCBV) as follows:
$$V_{{i,{\text{DC}}}} = V_{0}  \left( {{\text{BCBV}}} \right)*J_{{k,{\text{DC}}}}\quad i = 2,3, \ldots ,N_{{{\text{DC}}}}$$
(8)
Repeat Eqs. (7) and (8) until the difference between the voltages of two adjacent iterations is less than the tolerance value (ε).
$$\left {V_{{i,{\text{DC}}}}^{{{\text{itr}} + 1}}  V_{{i,{\text{DC}}}}^{{{\text{itr}}}} } \right < \varepsilon$$
(9)
Highpower converter (VSC) model
The active (\(P_{{{\text{AC}}}}\)) and reactive (\(Q_{{{\text{AC}}}}\)) power absorbed by HPC from the AC grid with ignored converter losses can be expressed as follows
$$P_{{{\text{AC}}}} = \frac{{V_{{{\text{AC}}}} V_{{{\rm C}}} }}{{X_{{{\text{HPC}}}} }}\sin \delta$$
(10)
$$Q_{{{\text{AC}}}} = \frac{{V_{{{\text{AC}}}} \left( {V_{{{\text{AC}}}}  V_{{{\rm C}}} \cos \delta } \right)}}{{X_{{{\text{HPC}}}} }}$$
(11)
\(V_{{{\text{AC}}}}\) is the amplitude of AC grid voltage, \(V_{{{\rm C}}}\) is converter output voltage, \(X_{{{\text{HPC}}}}\) is equivalent reactance of converter, and \(\delta\) converter modulation angle. However, the converter loss is ignored so that the active power is equal on the AC and DC side. Then the active power can be expressed as
$$P_{{{\text{AC}}}} = V_{{{\text{DC}}}} I_{{{\text{DC}} }} \quad \therefore V_{{{\rm C}}} = \frac{M}{\sqrt 2 }V_{{{\text{DC}}}}$$
(12)
\(V_{{{\text{DC}}}}\) is voltage on the DC side and M is a modulation index of the converter. Since the power supply on the DC side of the network is poor inactivity, the losses of the converter can be expressed by the current and resistance of the converter as follows
$$P_{{C{\text{, Loss}}}} = \frac{{P_{{{\text{AC}}}}^{2} + Q_{{{\text{AC}}}}^{2} }}{{V_{{{\text{AC}}}}^{2} }}R = I^{2} R$$
(13)
where \(P_{{C{\text{,Loss}}}}\) is power lost in the converter and R is the resistance offered by HPC.
Problem formation
Optimal allocation of REDG units in a hybrid AC/DC microgrid system is to find the best location as well as the size of REDG units that gives minimum power loss as an objective function with the area required by REDG units as variables while satisfying various operating constraints. The objective function minimization of power loss is described as follows:
$${\text{OF}} = {\text{Min}}\left( {P_{{T,{\text{Loss}}}} \left( {A_{{{\text{PV}}}} ,A_{{{\text{FC}}}} } \right)} \right)$$
(14)
$$P_{{T,{\text{Loss}}}} = \mathop \sum \limits_{k = 1}^{{N_{{{\text{AC}}}} }} J_{{K,{\text{AC}}}}^{2} *R_{K} + \mathop \sum \limits_{k = 1}^{{N_{{{\text{DC}}}} }} J_{{K,{\text{DC}}}}^{2} *R_{K} + P_{{C,{\text{Loss}}}}$$
(15)
$$P_{{{\text{REDG}}}} = \left( {n_{{{\text{PV}}}} *I_{{{\text{PV}}}} *V_{{{\text{PV}}}} *A_{{{\text{PV}}}} } \right) + \left( {n_{{{\text{FC}}}} *V_{{{\text{FC}}}} *A_{{{\text{FC}}}} *J} \right)$$
(16)
Constraints
Power balance constraint
$$P_{{{\text{Slack}}}} + \mathop \sum \limits_{k = 1}^{{N_{{{\text{DG}}}} }} P_{{{\text{REDG}}}} = \mathop \sum \limits_{i = 1}^{N} P_{D,i} + \mathop \sum \limits_{k = 1}^{{{\text{NB}}}} P_{{{\text{Loss}},k}}$$
(17)
Inequality constraints
$$V_{\min } \le V_{i} \le V_{\max } \quad {\text{where}},\quad V_{\min } = 0.95\;{\hbox{p.u and}}\, V_{\max } = 1.05\;{\text{p.u}}$$
(18)
$$S_{k} \le S_{k,\max } \quad {\text{where}},\quad S_{k,\max } \;{\text{is maximum apperent power admissible for the branch}}$$
(19)
\(\sum\nolimits_{k = 1k = 1}^{{N_{{{\text{AC}}}} }} {J_{{K,{\text{AC}}}}^{2} *R_{K} }\) is power loss in AC microgrid system, \(\sum\nolimits_{k = 1}^{{N_{{{\text{DC}}}} }} {J_{{K,{\text{DC}}}}^{2} *R_{K} }\) is power loss in DC microgrid system, \(P_{{{\text{REDG}}}}\) is power injected by REDG units in DC microgrid system, NB is number of branches in the system, N_{DG} is number of REDG units connected, N is number of buses in the system, i is bus number, k is branch number, \(A_{{{\text{PV}}}} ,A_{{{\text{FC}}}}\) are area required by PV and FC units, \(n_{{{\text{PV}}}} ,n_{{{\text{FC}}}}\) are the number of PV and FC units connected, \(I_{{{\text{PV}}}} ,\eta_{{{\text{PV}}}} , A_{{{\text{PV}}}}\) are solar insolation (W/m^{2}), the efficiency of solar PV, the area required by PV unit (m^{2}) and \(V_{{{\text{FC}}}} ,A_{{{\text{FC}}}} ,J\) are the output voltage of FC, area required by FC unit (m^{2}), current density (A/m^{2}), \(P_{{{\text{Slack}}}}\) is slack (substation) bus power, and \(P_{D}\) is the real power load connected at ith bus.
Butterfly optimization algorithm
Butterfly optimization is based on the ability of the butterflies to locate the source of fragrance accurately. They can also differentiate various fragrances and sense their intensities. In BO algorithm, butterflies are the searching agents. Fitness is correlated with the intensity of fragrance that can be generated by the butterfly. The movement of butterflies in search space will change its fitness. The sharing of information between butterflies is established through the propagation of fragrance. The searching ability of a butterfly depends on the sensing capability of the fragrance. This property will decide the movement of the butterfly towards a global search or local search (random). In BOA, the fragrance is formulated as a function of the physical intensity of stimulus as follows:
where f is the perceived magnitude of the fragrance, i.e., fragrance receiving property by other butterflies, c is the sensory modality, I is the stimulus intensity, and a is the power exponent dependent on modality, which accounts the varying degree of absorption. Most of the cases \(a \& c \in \left[ {0, 1} \right]\). If a = 1, it means there is no absorption of fragrance, i.e., the amount of fragrance emitted by a particular butterfly is sensed in the same capacity by the other butterflies (fragrance propagation in an idealized environment). Thus, a butterfly emitting fragrance can be sensed from anywhere in the domain which in turn helps to reach the global optimum easily. On the other hand, if a = 0, it means that the fragrance emitted by any butterfly cannot be sensed by the other butterflies at all. Another important parameter \(c \in \left[ {0, \infty } \right]\) determines the convergence speed. The values of a and c crucially affect the convergence speed of the algorithm. For the maximization problem, the intensity can be proportional to the objective function [29].
In BO algorithm, the characteristics of butterflies are idealized as follows:

1.
Every butterfly is supposed to emit some fragrance which enables the butterflies to attract each other (propagation of information).

2.
Every butterfly will move randomly or toward the best butterfly emitting more fragrance.

3.
The stimulus intensity of a butterfly is affected or determined by the topography of the objective function.
The detailed steps for implementation of BO algorithm are as follows.
Step 1: Initialize algorithm parameters such as the number of agents N, the dimension of the problem d, the maximum number of iterations Iter_{max}, probability switch P, power exponent PE and sensor modality SM.
Step 2: Generate initial random solution \(x_{i}^{j}\)
$$x_{i}^{j} = x_{\min ,j} + \left( {x_{\max ,j}  x_{\min ,j} } \right)*{\text{rand}};\quad i = 1:N\quad {\text{and}}\quad j = 1:d$$
(21)
$$x = \left[ {\begin{array}{*{20}c} {x_{1}^{1} } & {x_{1}^{2} } & \cdots & {x_{1}^{d  1} } & {x_{1}^{d} } \\ {x_{2}^{1} } & {x_{2}^{2} } & \cdots & {x_{2}^{d  1} } & {x_{2}^{d} } \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ {x_{N  1}^{1} } & {x_{N  1}^{2} } & \cdots & {x_{N  1}^{d  1} } & {x_{N  1}^{d} } \\ {x_{N}^{1} } & {x_{N}^{2} } & \cdots & {x_{N}^{d  1} } & {x_{N}^{d} } \\ \end{array} } \right]$$
(22)
where N is the number of agents and d is the number of decision variables,\(x_{i }^{j}\) represents the position of the ith agent in jth dimension generated randomly between the limits as \(x_{\max ,d}\) and \(x_{\min ,d}\) and rand() is a random number between 0 and 1.
$${\text{Case 1:}}\;x_{i}^{j} = \left[ {A_{{{\text{PV}}i}}^{1,1} ,A_{{{\text{FC}}i}}^{2,1} \cdots A_{{{\text{PV}}i}}^{j  1,k} ,A_{{{\text{FC}}i}}^{j,k} \cdots A_{{{\text{PV}}i}}^{d  1,k} ,A_{{{\text{FC}}i}}^{d,k} } \right]$$
(23)
$${\text{Case 2:}}\;x_{i}^{j} = \left[ {L_{i}^{1,1} ,A_{{{\text{PV}}i}}^{2,1} ,A_{{{\text{FC}}i}}^{3,1} \cdots L_{i}^{j  2,1} ,A_{{{\text{PV}}i}}^{j  1,k} ,A_{{{\text{FC}}i}}^{J,k} \cdots L_{i}^{d  2,1} ,A_{{{\text{PV}}i}}^{d  1,k} ,A_{{{\text{FC}}i}}^{d,k} } \right]$$
(24)
where k = 1: N_{DCMG}, N_{DCMG} is number of DC microgrids, L, A_{PV} and A_{FC} represents location of REDG, area of PV and area of FC, respectively.
Step 3: Evaluate the fitness (objective functions) of agents using Eq. 14. Record the gbest solution so far and set iteration count t as zero.
Step 4: Calculate the fragrance \(f_{N}\) for each agent or butterfly using Eq. 20.
Step 5: Perform a global search using Eq. 25 if \({\text{rand}} < {\text{probability}}\;P\) or local search using Eq. 26 if \(d > P\).
$$x_{N}^{d} \left( {t + 1} \right) = x_{N}^{d} \left( t \right) + \left( {r^{2} *gbest  x_{N}^{d} \left( t \right)} \right)*f_{N}$$
(25)
$$x_{N}^{d} \left( {t + 1} \right) = x_{N}^{d} \left( t \right) + \left( {r^{2} *x_{j}^{d} \left( t \right)  x_{k}^{d} \left( t \right)} \right)*f_{N}$$
(26)
where \(x_{j}^{d} \left( t \right)\) and \(x_{k}^{d} \left( t \right)\) are jth and kth butterflies from the solution space which belongs to the same swarm and r is a random number in [0, 1] and then Eq. 27 becomes a local random walk.
Step 6: Evaluate the fitness of each agent in the new population using Eq. 14.
Step 7: Update the gbest vector.
Compare each new solution with the previous solution, if the new solution is better than the previous solution, record the gbest; otherwise, discard the new solution and preserve the previous solution as it is.
Step 8: Stopping criterion.
If the maximum number of iterations has reached (iter_{max}), computation is terminated. Otherwise, Step 4 to Step 7 are repeated.
The implementation flowchart for the BO algorithm is illustrated in Fig. 1.