**2. Genetic algorithm for route planning problems**

#### **2.1 Traveling salesman problem**

The Traveling Salesman Problem (TSP) represents the scenario of a salesperson who must visit each place within a set of cities or towns. This must be performed with the following considerations: the salesperson starts and ends the whole journey at a single location (i.e., the main office) and must visit each place only once [3]. Although this is the basic understanding of the TSP, the main feature of finding a single route, or sequence of minimum distance or cost, is shared by other real-world applications such as vehicle routing [4], production planning [5], service time [6], and design of computer networks [7]. **Figure 3** presents an overview of the TSP model with *n* = 12 cities.

Note that each single route that complies with the previous restrictions represents a candidate solution, and there are as much as *n*! candidate solutions if brute search were to be considered as solving method to find the optimal or best solution. Just for the example presented in **Figure 3**, there are up to 12! = 479′001,600 or

#### **Figure 3.**

*Example of a feasible TSP solution with n = 12 cities.*

479.00e+006 feasible solutions to visit all 12 cities. This number increases exponentially as *n* increases linearly. Thus, if just a single city is added to the TSP problem, the number of feasible solutions can increase to 13! = 6.23e+009.

This leads to a problem with an infinite solution space if large sets of cities are considered. This classifies the TSP as an NP-hard problem, which is very difficult to solve within reasonable time, even with the most advanced computational systems. Thus, different meta-heuristics have been developed to provide fast near-tooptimal solutions. Among these meta-heuristics the following can be mentioned [8]: Nearest Neighbor (NN), Simulated Annealing (SA), Tabu Search (TS), Genetic Algorithm (GA), Ant Colony Optimization (ACO), Particle Swarm Optimization (PSO) and Tree Physiology Optimization (TPO).

As presented in [8] GA and SA are among the most suitable heuristics, achieving error gaps from best known solutions within the 10% mark for small (*n* < 100), moderate (100 < *n* < 150) and large (150 < *n* < 450) TSP instances. However, within the context of TSP solutions, it is always recommended to test the solving methods with very large instances (i.e., n > 500) to corroborate their performance.

Thus, the developed GA considers TSP instances with *n* ≈ 1000. For this purpose, the GA considers the structure presented in **Figure 2** with the settings and reproduction operators presented in **Table 1** and described in **Figure 4**.


**Table 1.** *GA settings for the TSP.*

### *Search Algorithms on Logistic and Manufacturing Problems DOI: http://dx.doi.org/10.5772/intechopen.96554*

**Figure 4.**

*Partially-matched crossover, and swap/inversion mutation operators for the TSP.*

Implementation of the GA was performed in MATLAB with an Intel Core i7–5500 CPU at 2.40 GHz and 8GB RAM. Testing was performed with a set of TSP instances from the TSPLIB95 database [9]. The details of these instances, including the GA's population size *N* used for each case, are presented in **Table 2**. The results of the tests can be observed in **Figure 5** and **Figure 6**.

As presented in **Figure 5**, the mean error gap through all instances begins to decrease as the selection and reproduction mechanisms of the GA start to operate on the initial and updated populations. By the 300th generation the mean error gap decreases under the 10% mark to finally reach an approximate of 7% by the 1000th generation. This corroborates the performance reported in [8].

Finally, **Figure 6** presents the performance of the GA based on the size of the test instances (*n*). With the settings reported in **Table 1**, as *n* increases, the GA takes more time to converge to a local optimum which, in some cases, it is slightly over the 10% mark. Also, the size of the population (*N*) must be increased to improve the search performance.

Based on these findings, particularly for the TSP with *n* ≈ 1000, the following recommendations can be made:


As an example of hybridization, **Figures 5** and **6** present the performance of the revised GA (hybrid-GA) with a much smaller *N* (= 50 for all instances) and a Greedy algorithm to improve four offspring (two by crossover, one by flip mutation, one by swap mutation) which are included within the updated population. This increases the speed of the GA, reaching the 10% by the 100th generation, with


a final mean error gap of 5% by the 1000th generation. Also, improvement of the large instances (*n* > 500) is observed, achieving error gaps under the 10% mark.

#### **Table 2.** *TSPLIB instances for GA testing.*

#### **2.2 Capacitated vehicle routing problem**

The Capacitated Vehicle Routing Problem (CVRP) represents an extension on the TSP. As shown in **Figure 7**, the CVRP determines a set of routes that start and end at a specific place or location (e.g., a distribution center). These routes must visit or serve a finite number of locations and meet their demand requirements. Each route must be served by a single vehicle (e.g., a salesperson) with finite capacity, and only one vehicle can serve a location. Thus, the CVRP can be understood as a variant of the multiple-TSP with capacity restrictions [11].

As in the case of the TSP, the CVRP is a combinatorial problem of NP-hard complexity which cannot be solved within a reasonable polynomial time [12]. Due to this, the CVRP has been addressed by different meta-heuristics such as Tabu -Search (TS) [13, 14], GA [15], SA [16, 17], and Particle Swarm Optimization (PSO) [18].

*Search Algorithms on Logistic and Manufacturing Problems DOI: http://dx.doi.org/10.5772/intechopen.96554*

*Mean error gap across all TSP test instances with (a) the GA, and (b) the revised hybrid-GA.*

**Figure 6.**

*Error gap across all TSP test instances with (a) the GA, and (b) the revised hybrid-GA.*

For this case, the GA presented in **Figure 2** was modified to solve the CVRP. The GA and its configuration settings are presented in **Figure 8** and **Table 3** respectively. Note that the reproduction operators remain the same as considered for the TSP. Testing was performed with a set of instances from the CVRPLIB database [19, 20]. **Table 4** presents the details of the selected instances.

As presented in **Figure 9**, the mean error gap reaches the 10% mark by the 200th generation, with an approximate of 8.5% by the 1000th generation. In contrast to the patterns observed in **Figure 6**, in **Figure 10** there is not a clear relationship between the size of the instance (*n*) and the error gap. Thus, there are large instances with very small error gaps (approximately 6%) and medium instances with large error gaps (over 10%). This however is expected because there are more tasks to be performed on the CVRP such as route segmenting and capacity restriction compliance. This leads to frequently consider GAs for small CVRP instances (*n* < 200) [15, 21].

#### **Figure 8.**

*Modified structure of the GA for the CVRP.*


#### **Table 3.** *GA settings for the CVRP.*


#### *Search Algorithms on Logistic and Manufacturing Problems DOI: http://dx.doi.org/10.5772/intechopen.96554*


#### **Table 4.**

*CVRPLIB instances for GA testing.*

**Figure 9.** *Mean error gap across all CVRP test instances with the GA.*

#### **Figure 10.**

*Error gap across all CVRP test instances with the GA.*

Based on these findings, particularly for the CVRP with *n* ≈ 1000, the following recommendations can be made:

• Due to the size of the population and the additional tasks, faster processes are needed for diversification of solutions. In example, Tabu Search (TS)

#### *Search Algorithms on Logistic and Manufacturing Problems DOI: http://dx.doi.org/10.5772/intechopen.96554*

uses small sets of candidate solutions (neighbors) through the consideration of movements (or moves). Also, convergence to a local optimum can be minimized by forbidding certain moves (e.g., make them *tabu*) which would make the algorithm to revisit a region within the solution space. This is an advantage when compared to GA, which requires full-candidate solution populations, and avoidance of previously obtained solutions may require additional tasks.

