*Article* **Bacterial Foraging-Based Algorithm for Optimizing the Power Generation of an Isolated Microgrid**

#### **Betania Hernández-Ocaña 1, José Hernández-Torruco 1, Oscar Chávez-Bosquez 1,\*, Maria B. Calva-Yáñez <sup>2</sup> and Edgar A. Portilla-Flores 2,\***


Received: 10 February 2019; Accepted: 18 March 2019; Published: 26 March 2019

**Abstract:** An Isolated Microgrid (IMG) is an electrical distribution network combined with modern information technologies aiming at reducing costs and pollution to the environment. In this article, we implement the Bacterial Foraging Optimization Algorithm (BFOA) to optimize an IMG model, which includes renewable energy sources, such as wind and solar, as well as a conventional generation unit based on diesel fuel. Two novel versions of the BFOA were implemented and tested: Two-Swim Modified BFOA (TS-MBFOA), and Normalized TS-MBFOA (NTS-MBFOA). In a first experiment, the TS-MBFOA parameters were calibrated through a set of 87 independent runs. In a second experiment, 30 independent runs of both TS-MBFOA and NTS-MBFOA were conducted to compare their performance on minimizing the IMG using the best parameter tuning. Results showed that TS-MBFOA obtained better numerical solutions compared to NTS-MBFOA and LSHADE-CV, an Evolutionary Algorithm, found in the literature. However, the best solution found by NTS-MBFOA is better from a mechatronic point of view because it favors the lifetime of the IMG, resulting in economic savings in the long term.

**Keywords:** optimization; Bacterial Foraging algorithm; Swarm Intelligence algorithm; Isolated Microgrid

#### **1. Introduction**

Currently, one of the most critical issues is the efficient use of available energy sources. Therefore, in rural or remote geographic locations, the generation and distribution of energy is a significant challenge for many areas of engineering such as control, power electronics or planning, among others. In recent years, microgrids (MGs) have been a reliable solution for the power supply in separate areas, provided that there is adequate operational planning of the MG energy sources [1].

In general, an MG is composed of energy storage systems (ESS),hybrid power generation systems (HPGS) from renewable energy sources (RES) and conventional generation systems (CGS); with all elements working in a coordinated way for the power generation. It is important to highlight that CGSs have a high operating cost due to the materials and transportation logistics. Moreover, ESSs are integrated by costly devices requiring a safe manner operation, thus guaranteeing a long service life. Finally, uncertainty in the appropriate operation of the RES due to the origin of wind and sunlight must take into account. These theoretical considerations are some of the reasons why optimal management of power generation resources for the appropriate operation of the MG is required.

In isolated microgrids (IMGs), a hybrid power generation system (HPGS) is responsible for the generation of reliable energy. This is done by integrating into the IMG at least one of the RES, CGS, and ESS systems such as a wind turbine generator, solar generator, diesel generator, or battery storage systems. However, due to the RES generation intermittency, the ESS become the main factor in the steady performance of the IMGs [2–4]. When a steady state is reached, the best performance of the whole system is obtained. HPGSs have been studied by several authors [5–7], describing conditions of remote localities having variable demand and power dispatch by generators minimizing the cost of generation, while maintaining a balance between the generation of energy and the load.

Usually, the power supply to the load in an IMG can be calculated as an economic dispatch function for generators at a large-scale power level [8]. This cost function should be minimized, subject to constraints related to the generator's capacity and the energy balance between generation and load demand. The load demand must be computed for a 24 h period in an IMG, and several scenarios can be presented in the HPGS such as: (1) RESs cannot produce energy for 24 h; (2) all the RES in the IMG can always dispatch energy, but not the total demand capacity of the load; (3) the main costs are the fuel costs and the generation of the diesel generator; and (4) the operation cost of the HPGSs are non-linear, generally due to the cost of the diesel generator.

On the other hand, there is a kind of problems, specifically in real-world applications, where it is impossible to find an optimal solution using a viable amount of resources employing traditional techniques such as numerical methods or graphic analysis. These cases correspond to the hard optimization category and have a similar nature to the NP (nondeterministic polynomial time) decision problems since they can not be solved in an optimal way or up to a guaranteed point using deterministic methods in polynomial time.

Metaheuristics are an alternative to find feasible and optimal solutions to NP problems, where any problem modeled as a constrained numerical optimization problem (CNOP) can have at least one optimal feasible solution. A CNOP also known as a general problem of non-linear programming can be defined as: minimize *f*(*x*) subject to: *gi*(*x*) ≤ 0, *i* = 1, ... , *m* or *hj*(*x*) = 0, *j* = 1, ... , *p*. Here, *<sup>x</sup>* <sup>∈</sup> <sup>R</sup>*<sup>n</sup>* such that *n* ≥ 1, is the solution vector *x* = [*x*1, *x*2, ... , *xn*] *<sup>T</sup>*, where each *xi*, *i* = 1, ... , *n* is delimited by the lower and upper limit *Li* ≤ *xi* ≤ *Ui*; *m* is the number of inequality constraints and *p* is the number of equality constraints (in both cases, the constraints can be linear or non-linear). If we denote by *F* the feasible region (where all the solutions that satisfy the problem are found) and by *S* the entire search space, then *F* ⊆ *S*.

Metaheuristics are well-known algorithms, most of them are inspired by nature, that have successfully solved CNOPs. Metaheuristics are divided into two broad groups: (1) evolutionary algorithms (EAs), whose operation is based on emulating the process of natural evolution and survival of the fittest [9], and (2) swarm intelligence algorithms (SIAs) that base their operation on social and cooperative behaviors of simple organisms such as insects, birds, and bacteria [10].

From the initial ideas of Bremermann [11], in 2002 Passino proposed a novel SIA called Bacterial Foraging Optimization Algorithm (BFOA) [12], based on E.Coli bacteria foraging. In BFOA, each bacterium *E. Coli* tries to maximize the energy obtained per unit of time spent on the foraging process, while avoiding harmful substances. Moreover, bacteria can communicate with each other by segregating certain substances. There are four main processes in BFOA: (1) chemotaxis (swim-tumble movements), (2) swarming (communication between bacteria), (3) reproduction (cloning of the best bacteria), and (4) elimination-dispersal (replacement of the worst bacteria). Bacteria are potential solutions to the problem and their location represents the values of the problem decision variables. Bacteria can move (generate new solutions) through the chemotaxis cycle; additionally, a movement through the attraction of solutions in promising areas of the search space is generated (as it allows the reproduction of the best solutions). Finally, those bacteria located in areas of low quality are deleted.

In 2009, a simplified BFOA version was proposed, called modified bacterial foraging optimization algorithm (MBFOA) [13], which implements fewer parameters with respect to the original BFOA. MBFOA includes a mechanism for the management of constraints based on feasibility rules, consisting of (a) between two feasible solutions, that with the best value in the objective function is selected, (b) between a feasible solution and a non-feasible solution, the feasible one is selected, and (c) between

two non-feasible solutions, the one with the smallest amount of constraint violations is selected [14]. MBFOA has been used to solve a number of problems of a different nature. For example, solving a set of chemical and mechanical engineering design problems, obtaining competitive results [13], and the solution of a bi-objective mechanical design problem with constraints [15].

In 2016, a recent algorithm based on MBFOA, called two-swim MBFOA (TS-MBFOA) [16], was proposed. This version includes an operation similar to the mutation operator, used in EAs, as a swimming operator within the chemotaxis process. It also implements a random swim in the chemotaxis process, along with a skew mechanism for the initial population based on the variables range. TS-MBFOA has been used to solve real-world problems of mechatronic design and also in the nutrition field by generating successful healthy menus [17].

There is a number of proposals in the specialized literature using metaheuristics algorithms to optimize particular mathematical models minimizing or maximizing an MG. Some of the EAs employed are Differential Evolution and Genetic Algorithms. SIAs employed are limited to particle swarm optimization (PSO) and BFOA. Other paradigms such as artificial neural networks, harmony search, and hybridizations between harmony search and differential evolution have also been used [18–20]. A common factor in this works is the management of constraints using the penalty technique, which implies adding more parameters to be defined by the end user.

In Table 1, main proposals based on BFOA were grouped according to particular characteristics. Moreover, other proposals were added—each proposal derived in several contributions. In the first row, representing this work, BFOA is implemented in order to optimize a mathematical model minimizing an IMG, including renewable energy sources such as wind and solar, as well as a conventional generation unit based on diesel fuel. Two novel versions of the BFOA are implemented and tested: TS-MBFOA, and a new proposal called NTS-MBFOA. Results showed that TS-MBFOA obtained better numerical solutions compared to NTS-MBFOA and compared to LSHADE-CV, an EA found in the literature solving the same problem. However, the best solution found by NTS-MBFOA is better from a mechatronic point of view because it favors the lifetime of the IMG and therefore resulting in economic savings in the long term.

In the second row of Table 1, Ahmad and others [21] proposed the bacterial foraging tabu search (BFTS) technique, a hybridization of BFOA and tabu search (TS) using different operational time interval (OTI) to schedule appliances while balancing user comfort (UC). His goal was to reduce both the waiting time and electricity cost simultaneously. Real-time pricing (RTP) scheme was used to get the total cost of electricity consumed. For simulations, they studied an average size modern home with 11 appliances. The simulation results of BFTS-based scheduled clearly shows that the proposed technique is better as compared to BFOA, TS, and unscheduled electricity consumption. The electricity cost and waiting time were minimized thus increasing UC.

In the third row of Table 1, Hasan and others [22] implemented two algorithms aimed at minimizing electricity cost and peak to average ratio (PAR) in a smartgrid by using BFOA and strawberry algorithm (SBA). Real-time pricing (RTP) pricing scheme was used to calculate the electricity cost. A single home with three types of appliances; fixed, shiftable and elastic appliances composed the simulated model. Authors found that these optimization schemes reduce the total electricity cost and peak to the average ratio by shifting the load from on-peak hours to off-peak hours. BFOA performed better than SBA regarding electricity cost minimization. However, the authors concluded that trade-off always exists between cost and user comfort.

In the fourth row of Table 1, Saadia and others [23] gained electricity cost reduction up to 40% in a home energy management system (HEMS) with a single home using BFOA and pigeon inspired optimization (PIO). Cost, PAR and waiting time of the appliances were calculated on the bases of a 120 h time slot. Two types of appliances were used: interruptible and non-interruptible. Critical peak pricing (CPP) was used as a pricing signal to calculate the electricity bills. Simulation results showed that PIO was identified as the best technique as it performs well in reducing cost. PIO gives 37% more waiting time than BFOA; it has 60% less cost by BFOA and PAR is 3% less by BFOA.



In the fifth row of Table 1, Wang and others [24] implemented a genetic algorithm to optimize a micro-grid operation considering distributed generation, environmental factors and demand response (DR). Experiments were conducted on a smart micro-grid from Tianjin, China. The building micro-grid system mainly includes distributed generation, energy storage device, electric vehicle, and various load resources. Two prices mechanisms were used, fixed price and DR prices. The main finding of this model is to optimize the cost in the context of considering demand response and system operation without reducing user comfort. Also, the authors found that the natural gas price dramatically influences both the operation cost of the micro-grid and demand response.

In the sixth row of Table 1, Ma and others [25] focus on minimizing the overall system generating cost, including the depreciation cost, the operation cost, the pollutant emission cost, and economic subsidies available for renewable energy source (RES) over the entire dispatch period of an IMG. For experimentation, they use an actual IMG in Dongao Island, China. Authors applied a modified PSO algorithm to solve this optimization problem. Results showed that this algorithm was able to minimize both the fuel consumption cost and pollution emission cost.

In the seventh row of Table 1, Wang and others [26] proposed a distributed locational marginal pricing (DLMP)-based unified energy management system (uEMS) model, which considers both increasing profit benefits for distribution generations (DGs) and increasing stability of the distributed power system (DPS). The model contains two parts: (1) a game theory-based loss reduction allocation (LRA); and (2) a load feedback control (LFC) with price elasticity. Simulation results based on a modified IEEE 37-bus system show that uEMS can lead to a more fairly competitive environment for DGs, where the model can increase DGs' benefits, reduce system losses, and improve stability.

In the last row of Table 1, Zhu and others [27] aimed to find the optimal placement and control parameter settings of multiple battery energy storage System (BESS) units to improve oscillation damping in a power transmission system. They formulated a mixed-integer optimization problem and solved it using PSO. Experiments were conducted on two power systems, the New England 39-bus system, and a Nordic test system. This optimization design can be adapted to seasonal load changes and the minimum number of BESS units to be placed. The superiority of the proposed model was validated with another typical type of controllers in the existing literature.

On the other hand, Aziz and others [28] investigated the techno-economic and environmental performance of a hybrid energy system (HES) under the load following (LF) and cycle charging (CC) strategies using HOMER software as a tool for optimization analysis. Experiments were conducted in a photovoltaic (PV)–diesel–battery configuration. Results show that variations in critical parameters, such as battery minimum state of charge, time step, solar radiation, diesel price, and load growth have considerable effects on the performance of the proposed system.

In summary, the problem of optimal management of energy sources in an IMG can be solved as a dispatch control problem, which deals with the energy flow management from the various sources to load for cost minimization.

This document is organized as follows: Section 2 presents the mathematical modeling of the Isolated Microgrid proposed. Sections 3 and 4 briefly describe TS-MBFOA and the normalized version called NTS-MBFOA. In Section 5, results obtained and the discussion of these are presented. Finally, in Section 6, the conclusions and future works are presented.

#### **2. Description of the Isolated MicroGrid**

An IMG is composed of a set of AC loads and an HPGS. In this work, the HPGS is integrated by a solar photovoltaic generator (PV), a wind turbine generator (WT), a diesel generator (DG) and a battery storage system (BS), as shown in Figure 1.

**Figure 1.** Hybrid power generation system components.

The aim of the optimal management of energy sources in an IMG is to assign the load demands among its distributed generation units securely and reliably, to minimize the overall system generating cost, subject to a set of constraints. Thus, it is essential to compute the operation cost of each of such generation units. In this work, the cost function and data for the BS, PV and WT generators were taken from [29] (2014 prices). In that work, the authors computed the corresponding cost function of the BS, PV, and WT considering the rate of return of the initial investment using a factor of capital recovery in a regular series of equal annual payments. Figure 2 depicts the overall optimization process proposed.

#### *2.1. DG Generation Cost*

The mathematical relationship associated with this kind of systems is related to the generator power. Without loss of generality, we established the cost function as:

$$F\_i(P\_i) = \alpha\_i + \beta\_i P\_i + \gamma\_i P\_i^2 \tag{1}$$

where *Fi* and *Pi* are the *i*-th generation source and its output power, respectively. Also, *α*, *β* and *γ* are the cost coefficients. Therefore, in this work the cost function for the DG systems is given by:

$$F\_1(P\_1) = 1488 + 0.3P\_1 + 0.000435P\_1^2 \tag{2}$$

**Figure 2.** Isolated microgrid optimization process.

#### *2.2. BS Generation Cost*

The general cost function, proposed in [29], is given by:

$$F(P) = aI^pP + G^EP\tag{3}$$

where *P* is the generator output power, *a* is the rate of return of the initial investment, *I <sup>p</sup>* is the inversion cost per installed unit and *G<sup>E</sup>* is the operation and maintenance costs per unit of generated power.

Also, the rate of return of the initial investment is computed by:

$$a = \frac{r}{1 - (1 + r)^{-N}}\tag{4}$$

where *r* the interest rate (we set a value of 0.09 for the base case) and *N* the useful life (we propose 20 years), respectively.

In this work, we set a 2 kWh battery storage bank as the ESS system of the IMG. Therefore, the inversion cost per storage unit installed is established as [*I <sup>p</sup>* = 1000 \$/kW]. Also, the operation and maintenance costs per unit is given by [*G<sup>E</sup>* =¢1.6/kW]. Finally, the cost function is given by:

$$F\_2(P\_2) = 119P\_2\tag{5}$$

#### *2.3. PV Generation Cost*

The PV generation cost was computed using a inversion cost per installed unit of [*I <sup>p</sup>* = 5000 \$/kW] and the operation and maintenance costs per unit given by [*G<sup>E</sup>* =¢1.6/kW]. Therefore, the PV generation cost is computed by:

$$F\_3(P\_3) = 545.016 P\_3 \tag{6}$$

#### *2.4. WT Generation Cost*

To compute the cost function of the WT generator we use an inversion cost per installed unit given by [*I <sup>p</sup>* = 5000 \$/kW], and an operation and maintenance costs per unit given by [*G<sup>E</sup>* =¢1.6/kW]. Thus, the cost function is computed by:

$$F\_4(P\_4) = 152.616 P\_4\tag{7}$$

#### *2.5. Optimization Strategy*

In order to obtain an optimal power generation in an IMG, an economic dispatch problem must be solved. In this problem, the output power of each one of the IMG's sources must be computed at every hour of the day, so that the generation cost is the lowest possible. In this study, the vector of design variables is related to the sources, therefore:

$$
\vec{p} = \begin{bmatrix} P\_1, P\_2, P\_3, P\_4 \end{bmatrix} \tag{8}
$$

where *Pi* with *i* = 1, . . . , 4 is the output power of the *i*-th generation source.

#### *2.6. Objective Function*

The classical economic dispatch problem is established with:

$$\min F = \sum\_{i=1}^{n} F\_i(P\_i) \tag{9}$$

subject to the following constraints:

$$\sum\_{i=1}^{n} P\_i = P\_L \tag{10}$$

$$P\_i^{\min} \le P\_i \le P\_i^{\max} \tag{11}$$

where *n* is the number of generation sources, *Pmin <sup>i</sup>* and *<sup>P</sup>max <sup>i</sup>* are the minimum and maximum values of the output power of the *i*-th generation source, *PL* is the total load demanded by the system, and *Fi* is the generation cost of the *i*-th generation source.

In this work, the objective function at *τ*-hour is given by:

$$\begin{aligned} F(\vec{p^\tau}) &= \omega\_1 \mathbb{C}\_f F\_1(P\_1(\tau)) + \omega\_2 F\_2(P\_2(\tau)) \\ &- \omega\_3 F\_3(P\_3(\tau)) - \omega\_4 F\_4(P\_4(\tau)) \end{aligned} \tag{12}$$

where *ω*1, *ω*2, *ω*<sup>3</sup> and *ω*<sup>4</sup> are the weights related with each one of the sources generation. These weights were fixed to 0.25 while the fuel cost was set to USD \$1.

Finally, considering that the generation cost must be computed at every hour of the day, the total objective function for all the day is:

$$\Phi = \sum\_{\tau=1}^{24} F(\vec{p}(\tau)) \tag{13}$$

#### *2.7. Design Constraints*

In order to produce a proper management of the power generation in the IMG, we considered some design constraints.

• Power Balance: The sum of the generation power of all sources must be equal to the total load demanded by the system:

$$P\_1 + P\_2 + P\_3 + P\_4 = P\_L \tag{14}$$

• BS Model: The output power of the solar PV generator and the load demanded at time *t* by the system, determine the state of charge (SOC) of the battery storage system BS. On the other hand, the SOC of the BS system at hour *t*, SOC(*t*), is related to the previous hour SOC, SOC(*t* − 1) [6]:

$$\text{SOC}(t) = \text{SOC}(t-1) - a\_D P\_2(t) + a\_C P\_3(t) + a\_C P\_4(t) \tag{15}$$

where *α<sup>D</sup>* = *ηD*/*Bmax <sup>C</sup>* and *<sup>α</sup><sup>C</sup>* = *<sup>η</sup>C*/*Bmax <sup>C</sup>* , in which *η<sup>D</sup>* and *η<sup>D</sup>* are the battery charging efficiency and the battery discharging efficiency, respectively. Also, *Bmax <sup>C</sup>* is the maximum battery capacity. Using Equation (15), a general mathematical equation by the battery dynamics can be established as:

$$\begin{aligned} SOC(t) = SOC(0) - a\_D \sum\_{\tau=1}^t P\_2(\tau) + a\_C \sum\_{\tau=1}^t P\_3(\tau) \\ + a\_C \sum\_{\tau=1}^t P\_4(\tau) \end{aligned} \tag{16}$$

where *SOC*(0) is the initial state of charge of the battery, *α<sup>C</sup>* ∑*<sup>t</sup> <sup>τ</sup>*=<sup>1</sup> *<sup>P</sup>*3(*τ*) + *<sup>α</sup><sup>C</sup>* <sup>∑</sup>*<sup>t</sup> <sup>τ</sup>*=<sup>1</sup> *P*4(*τ*) is the input power by the battery and *α<sup>D</sup>* ∑*<sup>t</sup> <sup>τ</sup>*=<sup>1</sup> *P*2(*τ*) is the power discharged by the battery at time *t*, respectively.

Finally, at time *t* the state of charge of the battery must be between the minimum (*SOCmin*) and maximum (*SOCmax*) possible capacity:

$$\text{SOC}^{\text{min}} \le \text{SOC}(t) \le \text{SOC}^{\text{max}} \tag{17}$$

In this work, the BS parameters are shown in Table 2.

**Table 2.** Energy Storage System parameters.


*Appl. Sci.* **2019**, *9*, 1261

#### *2.8. Optimization Problem*

We defined the mono-objective optimization problem associated with the optimal power generation as:

$$\min \Phi = \sum\_{\tau=1}^{24} F(\vec{p}(\tau)) \qquad \vec{p}(\tau) \in \mathbb{R}^4 \tag{18}$$

subject to the constraints:

$$\begin{array}{rcl}h\_1(\vec{p}(\tau)) &=& P\_1(\tau) + P\_2(\tau) + P\_3(\tau) + P\_4(\tau) = P\_L\\ \mathcal{g}\_1(\vec{p}(\tau)) &=& \mathcal{SOC}^{\text{min}} - \mathcal{SOC}(\tau) \le 0\\ \mathcal{g}\_2(\vec{p}(\tau)) &=& \mathcal{SOC}(\tau) - \mathcal{SOC}^{\text{max}} \le 0\end{array} \tag{19}$$

with the bounds:

$$\begin{aligned} 0 &\le \quad P\_1(\tau) \le D G\_{\text{nominal}} \\ 0 &\le \quad P\_2(\tau) \le S \text{OC}(0) \times B\_{\text{cmax}} - S \text{OC}^{\text{min}} \times B\_{\text{cmax}} \\ 0 &\le \quad P\_3(\tau) \le P\_{pv}(\tau) \\ 0 &\le \quad P\_4(\tau) \le P\_{\text{wind}}(\tau) \end{aligned} \tag{20}$$

where *DGnominal* is the nominal capacity of the DG system and *Bcmax* is the maximum capacity of the battery system; with proposed values of 5000 kW and 2000 kW, respectively. Values of *Ppv* and *Pwind* were taken from [30]. Indeed, values of *Ppv*(*τ*) and *Pwind*(*τ*) (where *Ppv* is the photovoltaic output power and *Pwind* is the wind output power) are based on studies conducted on real data. For the photovoltaic resource, two-day solar irradiation data collected in Celestún (México) was used. For the wind resource, data collected in Celestún (México), Ambewela (Sri Lanka), and Madrid (Spain) for several heights was used. In this study, these ranks are used as input values for the TS-MBFOA and NTS-MBFOA at each run to find the minimum value optimizing the IMG.

Table 3 summarizes the initial power in Watts (W) and percentages (for the ESS) of each resource in the IMG per hour.

**Table 3.** Starting conditions (in Watts and percentages) of the resources included in the IMG. *LP* = Load power, *P*<sup>1</sup> = Diesel power, *P*<sup>2</sup> = ESS, *P*<sup>3</sup> = Solar power and *P*<sup>4</sup> = Wind power.



**Table 3.** *Cont*.

#### **3. Two-Swim Modified Bacterial Foraging Optimization Algorithm (TS- MBFOA)**

TS-MBFOA is an algorithm derived from MBFOA proposed to solve CNOPs [16]. In this metaheuristic, a bacterium *i* represents a potential solution to the CNOP (i.e., a n-dimensional real-value vector identified as *x*), and it is defined as *θ<sup>i</sup>* (*j*, *G*), into a population of bacteria (*Sb*), where *j* is the chemotaxis loop (*Nc*). *G* is the generational loop that ends up reaching a maximum number of generations (*GMAX*) or using a number of evaluations, defined by the user, calculated as:

$$GMAX = \frac{Number\ of\ evaluations}{S\_b \times N\_c} \,\tag{21}$$

A generation includes the following processes: (1) a chemotaxis process with *Nc* loops; (2) a swarming towards the best bacterium of the swarm *θB*(*G*); (3) a reproduction process, if the frequency parameter *RepCycle* (defined by the user) allows it, with the best bacteria of the swarm *Sr*; and finally (4) an elimination-dispersal process that eliminates the worst bacterium of the swarm.

**Chemotaxis:** In this process, two swims are interleaved in each generation: either the exploitation swim or exploration swim is performed. The process starts with the exploitation swim (classical swim). Yet, a bacterium will not necessarily interleave exploration and exploitation swims, because if the new position of a given swim *θ<sup>i</sup>* (*j* + 1, *G*) has better fitness (based on the feasibility rules) than the original position *θ<sup>i</sup>* (*j*, *G*), another swim at the same direction will take place in the next loop. Otherwise, a new tumble is computed. The process stops after *Nc* attempts.

The exploration swim uses the mutation between bacteria and is calculated by:

$$
\theta^i(j+1, G) = \theta^i(j, G) + (\sigma)(\theta\_1^r(j, G) - \theta\_2^r(j, G))\tag{22}
$$

where *θ<sup>r</sup>* <sup>1</sup>(*j*, *<sup>G</sup>*) and *<sup>θ</sup><sup>r</sup>* <sup>2</sup>(*j*, *G*) are two different randomly selected bacteria from the population. Additionally, *σ* is a parameter defined by the user used in the swarming operator, which defines the proximity of the new position of a bacterium with respect to the position of the best bacteria in the population *θB*(*G*). In this operator, *σ* is a positive control parameter for scaling the different vectors in (0,1), i.e., scales of the area where a bacterium can move.

The exploitation swim is calculated as:

$$
\theta^l(j+1, G) = \theta^l(j, G) + \mathbb{C}(i, G)\phi(i) \tag{23}
$$

where *φ*(*i*) is calculated with the original tumble operator of BFOA:

$$\phi(i) = \frac{\Delta(i)}{\sqrt{\Delta(i)^T \Delta(i)}}\tag{24}$$

where <sup>Δ</sup>(*i*)*<sup>T</sup>* is a random vector with elements within the range [−1, 1].

*C*(*i*, *G*) is the random step size of each bacterium updated by:

$$\mathbb{C}(i, G) = \mathbb{R} \* \mathbb{S}(i) \tag{25}$$

where Θ(*i*) is a randomly generated vector of size *n* with elements within the range of each decision variable: [*Ux*, *Lx*], *x* = 1, ... , *n*, and *R* is a user-defined parameter for scaling the step size (this value must be close to zero, for example 5.00E-04). The initial *C*(*i*, 0) is generated using *θ*(*i*). This random step size allows bacteria to move in different directions within the search space and prevents premature convergence, as suggested in [31]. Step size *R* can be randomly, statically, and dynamically adjusted [32].

**Swarming:** At the half number of the chemotaxis process, the swarming operator is applied with (where *σ* is a user-defined positive parameter between (0,1)):

$$\theta^{i}(j+1,\mathcal{G}) = \theta^{i}(j,\mathcal{G}) + \sigma(\theta^{B}(\mathcal{G}) - \theta^{i}(j,\mathcal{G})) \tag{26}$$

where *θ<sup>i</sup>* (*j* + 1, *G*) is the new position of the bacterium *i*, *θB*(*G*) is the current position of the best generational bacterium and *σ*, is a parameter called scaling factor, which regulates how close the bacterium *i* will be from the best bacterium *θB*. In this proposal, if a solution violates the boundary of decision variables then a new solution of *xi* is randomly generated between the lower and upper limits *Li* ≤ *xi* ≤ *Ui* of the decision variables. The swarming operator movement applies twice in a chemotaxis loop, while in the remaining steps the tumble-swim movement is carried out.

**Reproduction:** In this process, bacteria are ordered based on the handling constraint technique, duplicating the best bacteria *Sr*, and eliminating the same number of worst bacteria to maintain the size of the population. The process is carried out once every certain number of cycles which is a user-defined parameter 1 ≤ *RepCycle* ≤ *GMAX*, it aims to allow the diversity in the swarm.

**Elimination-dispersal:** Finally, the worst bacterium of the population *θw*(*j*, *G*) is eliminated based on the feasibility rules, and a new one is randomly generated.

The original proposal of TS-MBFOA includes a skew mechanism to generate the random initial population and a local search engine. However, in this study we did not include this mechanism in order to reduce computational cost. The pseudocode of TS-MBFOA is presented in Algorithm 1.

**Algorithm 1:** TS-MBFOA pseudocode. *Sb* is the number of bacteria, *Nc* is the number of chemotaxis cycles, *σ* is the scaling factor, *R* is the stepsize, *Sr* is the number of bacteria to reproduce, *Repcycle* is the reproduction frequency and *GMAX* is the number of generations.

**<sup>1</sup>** Create an initial population of random bacteria *θ<sup>i</sup>* (*j*, 0) ∀*i*, *i* = 1, . . . , *Sb* **<sup>2</sup>** Evaluate *f*(*θ<sup>i</sup>* (*j*, 0)) ∀*i*, *i* = 1, . . . , *Sb* **<sup>3</sup> for** *G=1 to GMAX* **do <sup>4</sup> for** *i=1 to Sb* **do <sup>5</sup> for** *j=1 to Nc* **do <sup>6</sup>** Perform the chemotaxis process by interleaving swims using Equations (22) and (23). **<sup>7</sup>** Apply the swarming operator using Equation (26) and *σ* for the bacteria *θ<sup>i</sup>* (*j*, *G*). **<sup>8</sup> end <sup>9</sup> end <sup>10</sup> if** *G mod RepCycle == 0* **then <sup>11</sup>** Perform the reproduction process by ordering the population according to the feasibility rules. **<sup>12</sup>** Duplicate the best bacteria *Sr* and the same number of worst bacteria are eliminated to maintain the size of the population. **<sup>13</sup> end <sup>14</sup>** Perform the elimination-dispersal process eliminating the worst bacterium *θw*(*j*, *G*) from the current population considering the technique of handling constraint. **<sup>15</sup> Update the step size vector** using Equation (25). **<sup>16</sup> end**

#### **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\_\prime 0) = \frac{\theta\_x^i(j\_\prime 0)}{\mathcal{U}\_x}, \mathbf{x} = 1, \dots, n \tag{27}$$

where *x<sup>i</sup>* is a decision variable, *θ<sup>i</sup> <sup>x</sup>*(*j*, 0) is the value to normalize the bacterium's current position, and *Ux* is the upper limit of the variable *xi*.

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 lL\_x, \mathfrak{x} = 1, \dots, 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 Deb [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.

**Figure 3.** [Normalized] Two-Swim Modified BFOA.

**Algorithm 2:** NTS-MBFOA pseudocode. *Sb* is the number of bacteria, *Nc* is the number of chemotaxis cycles, *σ* is the scaling factor, *R* is the step size, *Sr* is the number of bacteria to reproduce, *Repcycle* is the reproduction frequency and *GMAX* is the number of generations.


#### **5. Results**

We implemented TS-BFOA and NTS-MBFOA to solve the IMG problem on three computers with the following characteristics: a PC with 4 GB RAM, 2.3 Ghz processor; and two PCs with 8.0 GB RAM, 2.4 GHz processor. We use the Matlab R2018b development platform over a 64 bit Windows operating system.

#### *5.1. First Experiment*

First, we calibrate the parameters for TSM-BFOA and NTS-MBFOA via 87 independent runs with a diverse combination of parameters and 15,000 generations. The ranges tested for each parameter were: *Sb* between [10, 200], *Nc* between [5,100], *Sr* between [1, *Sb*/2], *RepCycle* between [10, 200], *R*, *B* between [0,1] and *GMAX* between [5000,15,000]. The best result obtained from all the independent runs was the value −564,959.112. During the calibration phase, we noticed that the higher the number of bacteria and chemotaxis cycles, the execution time of both algorithms increased from an order of seconds to minutes, due to the number of evaluations needed (number of times that a solution is evaluated in the objective function and constraints), which is calculated by *Sb* × *Nc* × *GMAX*. TS-MBFOA takes ∼14 min, on average, using the best combination of parameters. In the case of NTS-MBFOA, the algorithm takes ∼16 min on average. This time can be improved using a computer with a better processor.

We found that, by increasing the reproduction frequency (*RepCycle*) to values greater than 60, the results quality of the algorithm decreased, that is, the population of bacteria loses diversity. Therefore, a lower number of bacteria *Sr* favors the performance of the algorithm.

Finally, values close to zero for the step size *R* and scaling factor *B* allow a better balance between exploitation and exploration of the search space and have a positive impact on the performance of the algorithm when generating higher quality solutions according to the objective function.

From these experiments, the best parameter calibration is presented in Table 4.


**Table 4.** Parameters of TS-MBFOA and NTS-MBFOA.

#### *5.2. Second Experiment*

We ran independently both TS-MBFOA and NTS-MBFOA 30 times with the parameter configuration obtained in the previous experiment. The statistical results of both algorithms are shown in Table 5. The standard deviation is calculated using the best solution found in each of the 30 independent runs, where the best solution is the sum of the 24 objective functions in a run.

**Table 5.** Basic Statistics of the results obtained by TS-MBFOA and NTS-MBFOA compared against an Evolutionary Algorithm. Std is the standard deviation.


TS-MBFOA obtained the best solution with a value of −551,960.121 followed by NTS-MBFOA with a value −549,369.785 in the objective function. Values are negative because they represent an economic saving when operating with RES, instead of using only the diesel generator and the ESS (battery). The more energy supplied by the RES and the less supplied by the DG and the ESS, the higher the savings.

A convergence graph was generated for TS-MBFOA and NTS-MBFOA using the data of the independent run number 15 (representing the median). In Figure 4, we can observe the behavior of each algorithm during the 24 h, both algorithms starting with infeasible solutions. For the NTS-MBFOA, feasible solutions arise in the first ∼10 generations, except for hours 16:00, 17:00, and 23:00, where the algorithm requires more generations. For the TS-MBFOA, solutions are found beyond 200 generations. As can be observed in Figure 4, the NTS-MBFOA converges more quickly on feasible solutions, which indicates a lower computational cost than TS-BFOA.

With respect to the quality of the solutions found by the algorithms in each of the 24 h, the convergence graphs indicate that both algorithms behave differently along the day, but in hours 00:00, 02:00–04:00, 06:00–07:00, 13:00–14:00, 16:00–18:00 and 22:00–23:00 the TS-MBFOA algorithm generates better feasible solutions. In the rest of the hours, NTS-MBFOA generates a better solution to the objective function. In run number 15, the TS-MBFOA obtained a value of −525,869.49 in the objective function, in the case of NTS-MBFOA the value found was −422,989.41.

**Figure 4.** Convergence graph of TS-MBFOA and NTS-MBFOA in the independent run number 15.

Results of bacterial foraging-based algorithms are better when compared against the LSHADE-CV algorithm. However, a higher number of evaluations is required. Parameters reported by the authors of LSHADE-CV algorithm are presented in Table 6. LSHADE-CV dynamically tuned the parameters using operators such as parameter memory and linear population reduction [35]. The best numeric solution was −532,508.057. Besides, BFOAs obtained a better median, average, standard deviation and the worst value found is close to the average.

**Table 6.** Parameters of LSHADE-CV. D is the number of decision variables of the problem, in this case D = 4.


Analyzing the results of the TS-MBFOA and the NTS-MBFOA, we observed that NTS-MBFOA has a lower standard deviation than the TS-MBFOA because it finds the better among the worst results, that is, results closer to the average. To know if there is a significant difference between the NTS-MBFOA and TS-MBFOA algorithms, we conducted the non-parametric Wilcoxon Signed Rank Test, with a confidence level of 95% to the set of the 30 best solutions obtained of the 30 independent runs of each algorithm. The result obtained by this test was a *p* value of 0.00112, which implies that there is a significant difference between the results of both algorithms.

To analyze results from the mechatronic point of view, we used the values of the best solution generated by TS-MBFOA, NTS-MBFOA, and LSHADE-CV, respectively, for the IMG during the 24 h. Values presented in Tables 7–9 were used to generate the IMG behavior graphs shown in Figure 5, respectively. In these graphs, each resource is marked with different lines. In the case of the BFOAs, it is important to highlight that the conditions established for the use of solar and wind energy favor the high demand for diesel consumption (see Table 3).

**Figure 5.** Visualization of the power supply during the 24 h of the day for the operation of the NIR-MG, obtained by the TS-MBFOA, NTS-MBFOA and LSHADE-CV.


**Table 7.** Details of the best solution found by the TS-MBFOA.

**Table 8.** Details of the best solution found by the NTS-MBFOA.



**Table 9.** Details of the best solution found by LSHADE-CV.

Analyzing the behavior graphs of the TS-MBFOA and the NTS-MBFOA, we can observe that both algorithms produce similar results, i.e., both allow the consumption of solar and wind energy while decreasing the use of the diesel generator and the intervention of the battery (ESS).

Specifically, the use of solar power increases from 07:00 h onwards and decreases after 17:00 h, when the sun begins to hide. Concerning the wind power, both graphs show variations of peaks in the first hours, reaching a maximum production of energy close to 1250 watts between the 13:00 and 19:00 h. The ESS operates in a considerable and constant way between 13:00 h and 18:00 h. However, in the early hours of the day, the solution generated by TS-MBFOA presents several peaks (state transitions of the battery operation) that fall and rise abruptly, which decreases the battery's lifetime.

The behavior of the solar and wind power, as well as ESS, tends to reduce the diesel demand from 12:00 h. Moreover, diesel is even not used for one hour, between 14:00 and 15:00 h, in both algorithms. However, when solar power is depleted, diesel power begins to rapidly increase. Analyzing the behavior of the use of diesel in the early hours of the day, it is evident that the NTS-MBFOA solution allows less diesel generator starts by having fewer peaks during the first hours of the day, which increases the lifetime of the diesel generator.

TS-MBFOA obtained a better solution in numbers, with −551 960.121 in the objective function value, compared to NTS-MBFOA, that obtained a value of −549, 369.785 in the objective function. The behavior of the graph lines, which correspond to the resources used in the IMG, favors the NTS-MBFOA because this solution increases the useful lifetime of the ESS and the DG, allowing economic savings on the long term.

Comparing the behavior graphs of the NTS-MBFOA and LSHADE-CV, we observe similar behavior in all the components of the IMG. Only from the hour 15:00 to 16:00 h it is evident how the EA delays the start of the diesel generator. On the other hand, from the hour 21:00 to 22:00 h, this algorithm starts the diesel generator slightly, something that does not happen in NTS-MBFOA. Since the graphs are very similar, we can take the numerical values as a point of comparison, where the best results of both algorithms were −549,369.785 and 532,508.057, respectively. We can conclude that

both algorithms are competitive, but NTS-MBFOA obtains better results. However, the competitiveness of the evolutionary algorithm is evident, even with fewer generations than our proposal.

#### **6. Conclusions**

Two algorithms, TS-MBFOA and NTS-MBFOA, based on the foraging of the *E. Coli* bacteria were implemented to solve a CNOP minimizing an isolated microGrid (IMG). An IMG is an intelligent energy network that uses distributed generators allowing the exploitation of renewable energy sources, such as wind and solar, as well as fuels (e.g., diesel, petrol). The CNOP is based on a mathematical model, wherein the optimum values of a network of power generation devices are computed to supply a load during 24 h. In essence, every hour an optimization problem is solved, according to the conditions and operation restrictions of the network. As a result, we generate behavior graphs of the optimal powers, i.e., the sum of the 24 objective functions, which represents the best solution.

Two experiments were designed to monitor the behavior of the algorithms while minimizing the IMG. In the first experiment, 87 independent runs were conducted with different values to the parameters of the TS-MBFOA algorithm in order to obtain the best configuration of parameters that allows the optimal performance of the algorithm. As a result of this experiment, we obtained that the best performance of the algorithm was using a population of 10 bacteria, eight chemotaxis cycles, five bacteria to reproduce every 60 generations with a step size of 0.015 and a scaling factor of 0.040. We also noticed that, the higher the number of bacteria and chemotaxis cycles, the longer the execution time required by the algorithm.

In the second experiment, 30 independent runs of both TS-MBFOA and NTS-MBFOA were conducted, using the parameter tuning obtained in the previous experiment. The best solution obtained by TS-MBFOA was −551,960.121 and by NTS-MBFOA was −549,369.785, where a lower value is better, meaning economic savings. Both results are the sum of the 24 objective functions.

A non-parametric Wilcoxon signed rank test was conducted for the 30 best solutions of each of the algorithms, resulting in a significant difference between both algorithms.

Results obtained by TS-MBFOA and NTS-MBFOA were compared against the LSHADE-CV algorithm, where the best solution found by our proposals were better, although at a higher computational cost.

According to results, TS-MBFOA found a better *numerical* solution to the problem. From the mechatronic point of view, however, it is important to notice that NTS-MBFOA obtained a better result because it favors the useful life both of the diesel generator and the energy storage system (battery). This conclusion arises from a behavior analysis of each resource used by the IMG during the 24 h of a day.

As future work, more experiments will be conducted on TS-MBFOA and NTS-MBFOA to reduce the number of evaluations and find highly competitive solutions against other state-of-the-art algorithms. We are motivated in advance in the study of IMG for a real implementation in a low-consumption energy housing.

**Author Contributions:** Conceptualization, B.H.-O. and E.A.P.-F.; Data curation, B.H.-O.; Formal analysis, B.H.-O. and M.B.C.-Y.; Funding acquisition, B.H.-O. and E.A.P.-F.; Investigation, B.H.-O., J.H.-T., O.C.-B. and M.B.C.-Y.; Methodology, B.H.-O., O.C.-B., M.B.C.-Y. and E.A.P.-F.; Project administration, B.H.-O. and E.A.P.-F.; Resources, B.H.-O. and E.A.P.-F.; Software, B.H.-O.; Supervision, B.H.-O. and E.A.P.-F.; Validation, B.H.-O., M.B.C.-Y. and E.A.P.-F.; Visualization, B.H.-O., J.H.-T. and O.C.-B.; Writing—original draft, B.H.-O., J.H.-T. and O.C.-B.; Writing—review & editing, B.H.-O. and O.C.-B.

**Funding:** This work was supported by the COFAA and SIP of the Instituto Politécnico Nacional, México for the publication.

**Acknowledgments:** To CONACYT (Ministry of Science and Technology of México) for supporting the National System of Researchers.

**Conflicts of Interest:** The authors declare no conflict of interest.

#### **Abbreviations**

The following abbreviations are used in this manuscript:


#### **References**


#### [CrossRef]


© 2019 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
