# Structural Topology Design Optimization Using the Binary Bat Algorithm
## 3 Binary Bat Algorithm  
In nature, bats use sonar to navigate and hunt. They tend to increase the rate and decrease the loudness of emitted ultrasonic sounds when they chase prey. In the BA, virtual bats (possible designs) have the same two main characteristics. Namely, an artificial bat has a position vector, velocity vector, and frequency. The algorithm starts by initially generating a set of random designs from the design domain. Then, in every iteration, new designs are generated and analyzed. Mathematically, an artificial bat's location vector, velocity vector, and frequency are updated as follows [32]:  
\[\mathbf{X}_{i}(Iter+1)=\mathbf{X}_{i}(Iter)+\mathbf{V}_{i}(Iter+1) \tag{11}\]  
\[\mathbf{V}_{i}(Iter+1)=\mathbf{V}_{i}(Iter)+(\mathbf{X}_{i}(Iter)-\mathbf{X}_{best})f_{i} \tag{12}\]  
\[f_{i}=f_{min}+(f_{max}-f_{min})\beta \tag{13}\]  
where \(\mathbf{X}_{i}\) is the \(i\)-th virtual bat's location (the \(i\)-th design vector), \(\mathbf{V}_{i}\) is the \(i\)-th virtual bat's velocity, \(\mathbf{X}_{best}\) is the best design obtained so far, \(f_{i}\) is the frequency of the \(i\)-th virtual bat, \(f_{min}\) and \(f_{max}\) are the minimum and maximum frequencies respectively, and \(\beta\) is a random number of a uniform distribution \([0,1]\). Initially, each bat is randomly assigned a frequency which is drawn uniformly from \([f_{min},f_{max}]\). \(f_{min}\) and \(f_{max}\) are algorithmic parameters that set depending on the problem. Equations (11)-(13) guarantee the exploitability phase of the algorithm. However, the exploitation phase is performed by randomly selecting a solution among the current best solutions to perform a random wall as follows:  
\[\mathbf{X}_{new}=\mathbf{X}_{old}+\varepsilon A(\textit{Iter}) \tag{14}\]  
where \(\varepsilon\) is a random number of a uniform distribution \([0,1]\), and \(A\) is the average loudness of emitted sound that bats use to perform exploration at the current step. The pseudocode of BA is shown in Algorithm 1. ```
Inputs: The population size, maximum number of iterations, minimum and maximum pulse frequencies, loudness, and pulse rate. Initialize the bat population \(\mathbf{X}_{i}(i=1,2,\ldots n)\) positions and velocities. Define pulse frequency. Outputs: The location of the best bat (design) and its fitness value. whileIter < maxIter  Generate new designs by adjusting frequencies, updated velocities, and locations (Equations (11)-(13)). if\(rand_{1}>r_{i}\)  Select a solution among the best solutions randomly. Generate a local solution around the selected best design. endif  Generate a new solution by flying randomly. if\(rand_{2}<A_{i}\) and \(C(\mathbf{X}_{i})<C(\mathbf{X}_{best})\)  Accept the new solution. Reduce \(A_{i}\) and increase \(r_{i}\) endif  Rank the bats and find the current best design (\(X_{best}\)) endwhile
```  
**Algorithm 1** Pseudocode of BA [21]. In Algorithm 1, note that \(rand_{1}\) and \(rand_{2}\) are random numbers of a uniform distribution \([0,1]\), and \(C\) is the compliance (Equation (8)). \(A_{i}\) and \(r_{i}\) (if they are not set to constant) are updated as follows:  
\[A_{i}(\textit{Iter}+1)=\alpha A_{i}(\textit{Iter}) \tag{15}\]  
\[r_{i}(\textit{Iter}+1)=r_{i}(0)[1-\exp(-\gamma\textit{Iter})] \tag{16}\]  
where \(\alpha\) and \(\gamma\) are constants. For any \(0<\alpha<1\) and \(\gamma>0\), in the end, \(A_{i}\) and \(r_{i}\) converge to zero and \(r_{i}(0)\), respectively [21]. \(\alpha\) and \(\gamma\) are algorithmic parameters that set depending on the problem. In the BBA, the search space is considered a hypercube. That is, artificial bats can shift to the nearer and farther corners of this hypercube by flipping bits (i.e., switching between \"0\" or \"1\" values). Therefore, the velocity and position updating expressions (Equations (11) and (12)) must be modified to be consistent with the bit representation.