**5.1 Genetic algorithm**

GA is a search heuristic that is inspired by Charles Darwin's theory of survival of the fittest, which explains inferior creatures pass away and superior creatures remain [28]. In GA, sets of design variables are codified by sequences with fixed or variable lengths, similar to chromosomes or individuals in biological systems. Each chromosome is formed of several design variables, which are known as genes. In repetitive processes such as GA, each repetitive stage is a generation and a collection of solutions associated with each generation is a population. Generally, the initial population is generated randomly [29]. In GA statistical methods are used to achieve optimum points. In the process of natural selection, populations are selected based on their fitness. A new population is formed using genetic operations containing selection, crossover, mutation, etc. This cycle continues until a certain result is achieved or the stop criterion is satisfied [30]. **Figure 7** shows the flowchart of GA and the steps of binary GA are discussed below [32].

#### **Step 1: Initialization of population**

The initial population of GA includes binary numbers generated randomly which are chromosomes or GA strings, consisting of bits called genes. Actually, the initial population is the probable solution to the optimization problem. The number of gens (*ng*) assigned to represent a variable in the chromosome depends on the precision ϵ and the range of the variable [*xmin, xmax*], and is given by

$$n\_{\rm g} = \log\_2\left(\frac{\varkappa\_{\rm min} - \varkappa\_{\rm max}}{\Xi}\right) \tag{66}$$

### **Step 2: Fitness evaluation**

The fitness value of each GA string is examined by first determining the decoded values of the variables *D*, and next the corresponding real values are obtained as follows:

$$
\boldsymbol{\mathfrak{x}} = \boldsymbol{\mathfrak{x}\_{\min}} + \frac{\boldsymbol{\mathfrak{x}\_{\max}} - \boldsymbol{\mathfrak{x}\_{\min}}}{\mathbf{2}^{n\_{\mathrm{f}}} - \mathbf{1}} \tag{67}
$$

$$
\underbrace{\boxed{\mathbf{s}\_{\max}}}\_{\text{(}\boldsymbol{\mathfrak{x}\_{\max}}\text{ limit)}}
$$

**Figure 7.** *Flow chart of GA [31].*

The fitness function values are then computed knowing the real values of design variables.

#### **Step 3: Reproduction/selection**

In this step, chromosomes with better fitness values to participate in the crossover are selected. Several selection modes such as roulette wheel selection or proportionate selection, rank-based selection, and tournament selection can be used in this step [33]. In proportionate selection, the probability of a chromosome to be selected is directly proportional to its fitness value. Hence, the chromosome having a better fitness value has a higher chance of selection for reproduction. This may result in premature convergence of the solution because there is a chance of losing diversity. The tournament selection is faster compared with the other two selection methods. In this method, *n* chromosomes are randomly picked from the population of solutions, where n represents the tournament size. The chromosome having the best fitness value is copied to the mating pool and all the n GA strings are returned to the population. This process is repeated for obtaining all the individuals of the mating pool.

#### **Step 4: Crossover**

The genes are exchanged between two-parent chromosomes in the crossover step, which leads to a new set of solutions, called children. The crossover operation represents the selection pressure or exploitation of fit chromosomes for even better solutions. The crossover probability (*Pc*) specifies the number of individuals taking part in the crossover operation, and this control parameter value is optimally chosen as nearly equal to 1.0. Several schemes of crossover such as single-point crossover, two-point crossover, multipoint crossover, and uniform crossover can be used in this step. A comparison of these methods is given in the literature [34].

#### **Step 5: Mutation**

Mutation means the change of a bit from 0 to 1 and from 1 to 0 in the solution chromosome, which is used for the exploration of new solutions. It helps to come out of the local basin and search for a global solution. The mutation probability *Pm* specifies the number of mutations and is commonly kept very low. Because if its value is high, the qualified solutions may be lost. The range of *Pm* is given as

$$\frac{0.1}{l} \le P\_m \le \frac{1}{l} \tag{68}$$

Where *l* represents the length of the GA string. Steps 2, 3, 4, and 5 are repeated until the termination criterion (maximum number of generations or desired precision of solution) is met.

#### **5.2 Particle swarm optimization**

The PSO is inspired by the way fish and birds swarm search for food [35]. In this method, each particle represents one solution to a problem and they aim to find optimum points in a search space. This method is also based on the behavior of birds that they use to find their orientation. Based on this direction, the collective location of the swarm and the best individual location of particles per time are calculated and a new search orientation is composed of these two orientations and the previous orientation. In a search space of the D dimension, the best individual location of a particle and the best location of the overall particle are defined as Eqs. (69) and (70), respectively.

$$
\overrightarrow{P}\_1 = C\_1 \begin{pmatrix} \overrightarrow{P}\_{i1}, \ \overrightarrow{P}\_{i2}, \ \dots, \ \overrightarrow{P}\_{iD} \end{pmatrix} \tag{69}
$$

*Heat Exchanger Design and Optimization DOI: http://dx.doi.org/10.5772/intechopen.100450*

$$\vec{\mathbf{g}}\_1 = \mathbf{C}\_1 \begin{pmatrix} \vec{\mathbf{g}}\_1, \ \vec{\mathbf{g}}\_2, \ \dots, \ \vec{\mathbf{g}}\_D \end{pmatrix} \tag{70}$$

The best location in the vicinity of each particle is given as below:

$$
\overrightarrow{n} = \begin{pmatrix} \overrightarrow{n}\_{i1}, \ \overrightarrow{n}\_{i2}, \ \dots, \ \overrightarrow{n}\_{iD} \end{pmatrix} \tag{71}
$$

Displacement of particles after determination their velocity is as follows:

$$
\overrightarrow{\mathbf{x}}(t) = \overrightarrow{\mathbf{x}}(t-\mathbf{1}) + \overrightarrow{\nu}(t) \tag{72}
$$

$$
\overrightarrow{\boldsymbol{\nu}}(t) = \overrightarrow{\boldsymbol{\nu}}(t-\mathbf{1}) + \overrightarrow{\boldsymbol{F}}(t-\mathbf{1})\tag{73}
$$

The best individual location of the particle and the best collective location of particles as two springs connected to the particle are used to model the force entered in the particle. The first spring is directed to the best individual experience and the second spring is directed to the best swarm experience. Eq. (74) shows the force entered in the particle.

$$
\overrightarrow{F}\_{i-1} = \mathbf{C}\_1 \left( \overrightarrow{P}\_{i-1} - \overrightarrow{\mathbf{x}}\_{i-1} \right) + \mathbf{C}\_2 \left( \overrightarrow{\mathbf{g}}\_{i-1} - \overrightarrow{\mathbf{x}}\_{i-1} \right) \tag{74}
$$

Where *C1* and *C2* are acceleration coefficients. The particle velocity at dimension *d (νid)* and the next repetition can be obtained as follows [35]:

$$\begin{split} \nu\_{id}(t) &= \alpha \nu\_{id}(t-1) + \mathcal{C}\_1 \text{rand}\_1(P\_{id}(t-1) - \boldsymbol{\varpi}\_{id}(t-1)) \\ &+ \mathcal{C}\_2 \text{rand}\_2(n\_{id}(t-1) - \boldsymbol{\varpi}\_{id}(t-1)) \end{split} \tag{75}$$

This shows the velocity of particle i at the star topology or global best. The rand1 and rand2 are random numbers that have a constant distribution in the range 0–1. **Figure 8** shows the flowchart of PSO and the steps of PSO are discussed below [32].

**Figure 8.** *Flow chart of PSO [31].*

### **Step 1: Initialization**

The swarm of potential solutions is generated with random positions and velocities. The i*th* particle in D-dimensional space may be denoted as *Xi = (xi1, xi2,...., xid)* and *i = 1, 2,..., N*, where *N* denotes the size of the swarm.
