# Bacterial Foraging-Based Algorithm for Optimizing the Power Generation of an Isolated Microgrid
## 4 Normalized Two-Swim Modified Bacterial Foraging Optimization Algorithm (NTS-MBFOA)  
Normalization is the operation in which a set of values of a certain magnitude are transformed into another one, on a predetermined scale. In this work, normalization represents a change of magnitude at a fixed scale to map the search space of the TS-MBFOA to a range of \([-1,1]\), and so obtain a better performance of the algorithm solving the IMG problem [33]. We employ the following to normalize the bacterial population, as proposed in [34]:  
\[\theta_{x}^{i}(j,0)=\frac{\theta_{x}^{i}(j,0)}{U_{x}},x=1,\ldots,n \tag{27}\]  
where \(x^{i}\) is a decision variable, \(\theta_{x}^{i}(j,0)\) is the value to normalize the bacterium's current position, and \(U_{x}\) is the upper limit of the variable \(x_{i}\).  
Denormalization of results consists of the inverse operation, which is a simple multiplication as is defined in:  
\[\theta_{x}^{i}(j,G)=\theta_{x}^{i}(j,G)\times U_{x},x=1,\ldots,n \tag{28}\]  
The pseudocode of NTS-MBFOA is presented in Algorithm 2. The new bacterium generated in the elimination-dispersal process is also normalized using Equation (27). The best and worst bacterium are selected according to the feasibility rules of [PERSON] [14], using the objective function value and the sum of violated constraints. In this algorithm, bacteria are ordered from best to worst. First, bacteria are denormalized and evaluated both in the objective function and the problem constraints. Subsequently, bacteria are ordered. The set of ordered bacteria is again normalized to continue with the following algorithm processes. Figure 3 describes the TS-MBFOA operation.  
_Appl. Sci._**2019**, \(9\), 1261  
Figure 3: [Normalized] Two-Swim Modified BFOA.  
```
1 Create an initial population of random bacteria \(\theta^{i}(j,0)\)\(\forall i,i=1,\dots,S_{b}\)
2 Evaluate \(f(\theta^{i}(j,0))\)\(\forall i,i=1,\dots,S_{b}\)
3 Normalize \(\theta^{i}(j,0)\)\(\forall i,i=1,\dots,S_{b}\) between \([-1,1]\) using (27)
4 forG=1 toGMAXdo
5 fori=1 toS_bdo
6 forj=1 toN_cdo
7 Perform the chemotaxis process by interleaving swims using Equations (22) and (23).
8 Apply the swarming operator using Equation (26) and \(\sigma\) for the bacteria \(\theta^{i}(j,G)\).
9 end for
10
11 end for
12 ifG modRepCycle == 0 then
13 Perform the reproduction process by ordering the population according to the feasibility rules.
14 Duplicate the best bacteria \(S_{r}\) and the same number of worst bacteria are eliminated to maintain the size of the population.
15
16 end for
17 Perform the elimination-dispersal process eliminating the worst bacterium \(\theta^{av}(j,G)\) from the current population considering the technique of handling constraint. The new bacterium generated is normalized with Equation (27).
18 Update the step size vector using Equation (25).
19
20 end for
21 Denormalize \(\theta^{i}(j,0)\)\(\forall i,i=1,\dots,S_{b}\) between \([-1,1]\) using Equation (28).
```  
**Algorithm 2**NTS-MBFOA pseudocode. \(S_{b}\) is the number of bacteria, \(N_{c}\) is the number of chemotaxis cycles, \(\sigma\) is the scaling factor, \(R\) is the step size, \(S_{r}\) is the number of bacteria to reproduce, \(RepCycle\) is the reproduction frequency and \(GMAX\) is the number of generations.