Comparative Study of Algorithms Metaheuristics Based Applied to the Solution of the Capacitated Vehicle Routing Problem

This chapter presents the best-known heuristics and metaheuristics that are applied to solve the capacitated vehicle routing problem (CVRP), which is the generalization of the TSP, in which the nodes are visited by more than one route. To find out which algorithm obtains better results, there are 30 test instances used, which are grouped into 3 sets of problems according to the position of the nodes. The study begins with an economic impact analysis of the transportation sector in companies, which represents up to 20% of the final cost of the product. This case study focuses on the CVRP for its acronym capacitated vehicle routing problem, analyzing the best-known heuristics such as Clarke & Wright and sweep, and the algorithms GRASP and simulated annealing metaheuristics based.


Introduction
Logistics as a science has its origins in the military area; the transportation of weapons, food, and men at the service was coordinated through it. With the passage of time, the concept began to be applied in the business field, and for a long period of time, the logistics function was considered as a habitual, operational, and necessary activity to take the products from the seller to the buyer (Ballou, 2004). A little later, starting in the 1950s, a cycle of growth and constant demand increase was experienced throughout the world, which caused the production and sales capacity to exceed the companies' ability to distribute products. Thus, in those years, delivering orders on time became a problem due to poor compliance. Then, in 1980, the concept of response time was created, which is the union between the concept of physical distribution and material management; specialists realized that the faster the response time to the customer, the more the profitability of the company increased.
As the concepts were changing, the methods as well and the companies looked for ways to become efficient; in this way they expanded the activities related to logistics and determined that one of the heaviest items is transportation costs, representing on average, between 10% and 20% of the final cost of the product or service (Toth and Vigo, 2002).
Although transport decisions are expressed in a variety of ways, the main ones are mode selection, route design, vehicle programming, and shipment consolidation (Ballou, 2004). In relation to the route design problem, the problem is commonly known as vehicle routing problem (VRP). Both the companies that own the transport service as part of their processes and the companies that provide the service seek to optimize resources within the route selection, since a good selection brings savings in time, resources such as fuel, maintenance of the fleet, salaries, and improvements, among others, in service indicators as a promise of product delivery.
The VRP can be considered as the natural extension of the TSP, in the sense that unlike the TSP, in the VRP we consider that the vehicles, or the agents in charge of providing a service to the nodes, have a limited capacity; therefore, most likely the entire route cannot be made through a single route, with a single vehicle that leaves and returns to the storage, traveling all the nodes, but to respect the restriction of the limited capacity of the vehicles so. In general, several routes are required, or what is the same, the solution of the VRP will be a set of Hamiltonian cycles that start from the deposit and such that each node is traveled only once.

Vehicle routing problem
The vehicle routing problem (VRP) consists in determining a set of routes for a fleet of vehicles that depart from one or more warehouses to meet the demand of several geographically dispersed customers [1].
The VRP objective is to meet the demand of the customers, optimizing some objective, which is generally the total cost involved in the routes, which is affected by the vehicular congestion of large cities, the high-energy consumption of cargo vehicles, and other factors.
Since the VRP problem is a generalization of the TSP, and knowing that the TSP is of the NP-hard problem class [2], it is concluded that the VRP is also a difficult problem of the NP-hard class.
The VRP model has many classifications by the different characteristics that can be included or considered in it. The most basic version is reflected with the CVRP capability (for the acronym of capacitated vehicle routing problem). The CVRP has the following assumptions: The fleet of vehicles is homogeneous, that is to say all cargo vehicles have the same characteristics: I. The demand is known in advance, that is, the quantity to be delivered for each client is known; this means that the demand is deterministic.
II. Each vehicle will carry the entire delivery to customers, prohibiting the distribution of fractional or partial loads that would later be completed by another vehicle.
III. All vehicles in the fleet have exactly the same load capacity.
IV. The starting point of the vehicles is only one and is considered a central warehouse.
V. Vehicles have capacity restrictions that are known in advance.

Classic heuristics to solve VRP
Heuristics are simple processes that perform a limited space search and generate acceptable solutions in moderate calculation times; an important characteristic of these methods is that they are designed to solve a specific optimization problem, and in general they cannot be used to solve other optimization problems. A more advanced class are the so-called metaheuristics, which are considered more advanced methods than heuristics, in the sense that they guide their construction and, therefore, are general purpose [3].
There are many advantages, and also disadvantages, when using heuristic algorithm methods to solve optimization problems, as described [4] within the reasons to use heuristic methods which are as follows: I. The problem is that no exact method for its resolution is known.
II. Although there is an exact method to solve the problem, its execution is computationally very expensive.

III.
A heuristic method is more flexible than an exact method, that is, difficult modeling conditions can be incorporated.
IV. The heuristic method is used as part of a global process that certifies an optimal solution. There are two possibilities: a. The heuristic method provides a good initial starting solution.
b. The heuristic method participates in an intermediate step of the procedure, such as the selection rules of the variable to enter the base in the simplex method.

Savings based heuristics
There are several types of heuristic methods to solve the VRP, which are addressed extensively in Braekers et al. []4, trying to generate broad, nonexclusive categories, where the best-known heuristics are located to solve this problem; among them one of the most used and popular algorithms is the one of Clarke & Wright, and that has had contributions from different authors [5].
This algorithm is based on successively combining subtours until a Hamiltonian cycle is obtained, of which the subtours have a common node or vertex called base or initial.
• The distance savings obtained by the union is • An initial solution is started in this algorithm, and the unions that give greater savings are made as long as they do not violate the restrictions of the problem.
• When the maximum saving is negative, the combinations of the routes will increase the distance traveled, but the amount of routes in the solution will decrease; depending on the characteristics of each problem, this can generate circular or radial routes that can be avoided by placing a reference value λ, which penalizes the union routes with distant customers. Saving is proposed as In Eq. (2) s ij represents penalized savings with the weight λ in the total distance traveled if the two routes 0, … , i, 0 ð Þand 0, j, … , 0 ð Þare joined, which prevents when possible, merging routes with nodes far apart.

Application of savings algorithm
Step 1: With the coordinates of each client or city, prepare the distance matrix.
Step 2: Calculate the s ij savings table for each pair of nodes.
Step 3: For each client or city i, build the route 0, i, 0 ð Þ.
Step 4: Order savings from highest to lowest.
Step 5: Starting with the greatest savings, join the corresponding nodes, so that s ij ¼ max s ij , where the maximum is taken between the savings that have not yet been considered; the route, r i * j * , will be created, if i * is the last customer of de r i * ; and j * is the first customer of r j * . Remove s i * j * from future considerations. Repeat step 5 until there are no more combinations of savings (Olivera, 2004; Pacheco, 2005).

Example of application of the savings algorithm
A company wants to solve the problem of routing and design of the fleet of its product x to its 10 customers in the city and has a homogeneous fleet of trucks with capacity for 100 units of x product, with locations and demand shown in Table 1.
There are details in the Cartesian coordinates of the warehouse and each customer with the demand, while in Figure 1, the position of each customer and the warehouse is shown.
Step 1: The matrix of Euclidean distances between each pair of nodes is calculated: Table 2 shows the distance matrix between all customers along with the warehouse. This matrix is symmetrical, that is, it has the same distance to go from client i to client j and vice versa. Point 0 has been considered for the warehouse (whs).
Step 2: Once the distance matrix is obtained, the savings are calculated. For the savings matrix, no row or column is placed for the warehouse. For example, the savings between customer 1 and customer 2 is s 12 ¼ 25:46 þ 19:80 À 5:66 ¼ 39 In Table 3 all the savings are shown; in the same way the matrix is symmetric.
Step 3: The route 0, i, 0 ð Þis built for each client. In Figure 2 each route is shown from the warehouse to each customer and back to the warehouse.
Step 4: Savings are organized from the highest to lowest. In the list of savings to choose, only the savings that can be chosen are considered.
When the list is prepared with all the savings, those savings that one or both clients have already considered in a previous route are discarded.
Step 5: To assemble the routes, the restrictions are considered; for this example the only restriction is the capacity of the truck that does not exceed 100 units of the product x. For the first route, the highest savings are chosen and placed in the form 0, i, 0 ð Þ; in this case 0 is the warehouse (whs), as the savings are chosen to add them to the existing route or create a new one; the demands of each client are added, and the route is closed when the sum of the demands is equal to or less than the capacity of the truck 100 units, but when adding one more client, the demand exceeds the capacity, and you can no longer choose that customer.
The composition of the routes is displayed step by step in Figure 3, and the complete route diagram is shown in Figure 4. Below is the composition of the routes with the demands. Consequently, Clarke & Wright algorithm determines a solution for the routing problem in which the distance traveled is 204.20 units in length.

Heuristic method of assigning first, routing after
Sweep heuristics are the best-known method of assigning first, routing later. This method is solved in two phases. First, groups of customers called clusters are created considering the capacity constraints of the vehicles, and second for each cluster, a route is generated that visits all customers.
In sweep heuristic, clusters are created by turning a half-straight in the central tank from the horizontal counterclockwise; after that the customers are incorporated into the mentioned group until the maximum capacity restriction of the vehicles is met.
This heuristic is used to find solutions to geographical problems, that is to say in which the nodes or vertices correspond to a point in the plane. It is assumed that the  Table 3. Savings matrix.
location of each client i can be represented through its polar coordinates r i , θ i ð Þ having a single central deposit. It defines

Steps for sweep heuristics
Step 1: Prepare the table of the location of the nodes in polar coordinates.
Step 2: Customers or cities are sorted in ascending order by θ; if two clients or cities have the same θ value, the one with the lowest r value is chosen first. Then a customer or city w is selected to start and make k ¼ 1 y C k ¼ w f g.
Step 3: If all clients or cities are in a cluster, go to step 4. Otherwise, a client or city is selected; w i and w i are added to C k if you do not exceed the capacity restrictions; if you exceed them, create a new cluster for which, k ¼ k þ 1 and C k ¼ w i f g. Repeat step 2 until there are no clients or cities without a cluster.
Step 4: For each cluster C k for t ¼ 1, … , k, solve traveling salesman problem (TSP) with its clients and a solution that can be a local optimum is obtained until not checking otherwise.
Step 5: Return to step 2 to reorder customers where the first becomes the last, the second the first, and so on until the original sorting. For each change, steps 3 and 4 are performed again, and the best of the solutions obtained is taken (Olivera, 2004; Pacheco, 2005).

Example of sweep heuristics
We will take the example of the savings algorithm.
Step 1: Formula (5) is used to obtain the polar coordinate table, where θ i is expressed in radians and r i is the directed distance. Table 4 shows the polar coordinates for each client i. The change of polar coordinates is displayed ( Figure 5).
Step 2: It is sorted by θ i from least to greatest, as seen in Table 5.
Step 3: To elaborate the routes, it is done in two phases, the first one where the clients are grouped by the sweep method and the second one where a TSP is resolved (step 4). For the sweep method, the angles from the smallest to the largest are chosen, and it moves counterclockwise.
As can be seen in Table 5, customers are already sorted in ascending order by their angular polar coordinate, and customers are chosen until they fail to comply with the capacity restriction of the truck that is 100 units of product x. Considering this the routes are as follows: In Figure 6, the sweeps are visualized starting with client 9 that has the greatest angle, thus grouping them in zones in this case by colors and within each one for their best distance. The sweep groups customers do not violate the restriction of the truck.
In Figure 7, the solution is shown with three routes before the TSP is applied.
Step 4: In the second phase to each route already generated in the first, it is resolved by TSP, for this case with the nearest node.  The routes are as follows: Thus, the sweep algorithm has a local solution for the routing problem in which the distance traveled is 222.36 units in length.
In Figure 8, the route diagram is displayed.
Step 5: Repeat step 2 where the customers already ordered from Table 5, continue to rotate the position until the first returns to be first, and for each rotation, steps 3 and 4 are performed, and after all iterations, the best is selected. Below is the iteration that had the best result. Table 6 shows the fifth iteration of nine where you start with client six (Figure 9).
After performing step 3 in Figure 10, the grouping of customers is appreciated to not violate the restriction of the truck's capacity.  Table 5.
Ascending ordering of customers.    In step 4, each grouping is resolved with a TSP, and the following routes are obtained: In Figure 10, the diagram of the routes of the fifth iteration is displayed, which obtained the best response.
The sweep algorithm determines a solution for the routing problem in which the distance traveled is 205.96 units in length, that is, a solution of lower quality than that obtained by the Clarke & Wright algorithm with 204.20 units in length.

Metaheuristics
The term metaheuristics first appeared in the seminal article about taboo search (Glover, 1987). The term metaheuristics is obtained by putting the suffix "meta" before the word heuristic, which means "beyond" or "at a higher level."  Metaheuristics are generic procedures that, through approximate algorithms, guide a subordinate heuristic by combining the exploration of the solution space for optimization problems, obtaining better results than classical heuristics in a longer period; however, this time is less than if the exact methods are used.
Metaheuristics that have been considered for this comparative study are shown below, which correspond to constructive and local search procedures [4].

GRASP
GRASP methods had their origins at the end of the 1980s in order to find a solution to problems of joint coverings, and in 1995 by Feo and Resende, this metaheuristic is of general purpose [6].
The word GRASP comes from the acronym of greedy randomized adaptive search procedures that would be something like search procedures based on voracious adaptive random functions.
GRASP has a multistart process in which each step has a construction and an improvement phase. In the construction phase, the constructive heuristic process obtains a good initial solution, which is improved in the second phase by a local search algorithm. The best of all solutions examined is saved as the final result.
There are many implementations of GRASP metaheuristics, including variants and hybridizations with other procedures such as variable neighborhood search or path relinking, with which this metaheuristic has proven to work very well in practice as demonstrated in Marti and Sandoya [7]. A simple scheme to represent the operation of this algorithm is as follows: While (stop condition) Construction phase: • Choose a list of candidate elements.
• Have a restricted list with the best candidates.
• Select an item randomly from the restricted list.
Improvement phase: • Perform a local search process based on the solution built until it can no longer be improved. Update: • If the solution obtained improves to the best stored, update it.
In the construction phase, a possible solution is built iteratively, considering an element in each step. In each iteration the choice of the next element to be added to the partial solution is determined by a greedy function, which examines the benefit of adding each of the elements according to the objective function and choosing the best one.
This metaheuristic works with a restricted list of the best candidates, which makes the best candidate randomly selected for each iteration of the construction phase.
In the improvement phase, the results that are obtained from the construction phase are not usually local optimal; therefore, a local search procedure is applied as post-processing to perfect the solution obtained.
Performing several iterations is a way of sampling the solution space.

Simulated annealing
The simulated annealing metaheuristics was introduced in the 1950s by Metropolis Hastings to be used in the field of statistical thermodynamics simulating cooling processes of a material.
In 1983 the method was refocused to solve combinatorial optimization problems of great complexity by Scott Kirkpatrick, C. Daniel Gelatt and Mario P. Vecchi, and independently in 1985 by Vlado Cerny. For its implementation ease, this metaheuristic had a great boom in the 1980s.
Simulated annealing has its procedure based on local search by environments that is characterized by an acceptance criterion of neighboring solutions that are adapted throughout its execution.
A temperature variable is used, T, that determines the extent to which neighboring solutions, worse than the current n, can be accepted. This variable is about starting it with a high value, which is called the initial temperature, T 0 , which generates a high probability of accepting a nonimprovement movement. In each iteration the temperature decreases through a temperature cooling mechanism, α, having a smaller probability until approaching the optimal solution and reaching a final temperature, T f . Costs also decrease as the temperature decreases, making it increasingly difficult to accept bad movements in search of the solution.
In each iteration a specific number of neighbors is generated, which can be fixed for the entire execution or depend on each iteration.
Each time a neighbor is generated, the acceptance criterion is applied to see if it replaces the current solution: • If the neighboring solution is better than the current one, it is automatically accepted, as it would be done in the classic local search.
• If the neighboring solution is worse than the current one, there is still a chance that the neighbor will replace the current solution. This allows the algorithm to exit from local optimum, in which the classic local search would be trapped.
This model is given by the following structure: Take an initial solution x Take an initial temperature T While (not frozen) The following parameters are determined: I. Initial temperature: it is established by doing a series of tests to reach a certain fraction of accepted movements.
II. Cooling speed r.
III. Length L that must be proportional to the expected size of N x ð Þ.
IV. When the cooling sequence ends, it is frozen cont ¼ cont þ 1 when a temperature is completed and the percentage of movements accepted is less than MinPercent:cont ¼ 0 when the best stored solution is improved.

Test instances
The cases to be evaluated are divided into three groups classified by the type of client with 10 examples each. Next, some tables will be presented, which have the name of instance, the truck's capacity in column cap, the number of customers in column n, the number of vehicles to be used in column k, and the optimal solution in column opt. Table 7, belong to the Augerat B set in 1995 [8] and specify that the coordinates are points between [0,100] Â [0,100] in the grid that are chosen to form neighborhood groups (NC) closest, where k ≤ NC À 1. The demands have a uniform distribution U 1, 30 ð Þ; however, n=10 was multiplied by 3.

Results
The results for the 30 selected test cases are shown below, applying the heuristics and metaheuristics studied in Chapter 3 and 4 to know which one has a response that is closer or equal to the optimum by group of client positioning.
To define which has a better quality solution, the gap analysis or difference analysis is used, which consists in calculating the difference between the optimal solution and the solution obtained, divided for the solution obtained and expressed as a percentage.
The solution of the real case is also presented through the heuristics and metaheuristics that offer the best solution given the characteristic of the clients' positions.

Test cases resolved by heuristics
Clarke & Wright heuristics have better quality solutions, solving problems where customers with a small n are grouped.   10 shows that for the group of clients with gathered positions, the gap is 3.63%; for the positions of random clients, the gap is 5.18%; and in less effective way for customers with grouped and random positions, it has a gap of 6.55%. It also compares the number of vehicles k ð Þ that were obtained when solving each case against the optimal solution, and it was obtained that 12 cases had a vehicle more than the optimum B-n41-k6, B-n45-k6, A-n33-k6, A-n34-k5, A-n38-k5, A-n44-k6, X-n106-k14, X-n115-k10, X-n134-k13, and X-n139-k10, and two cases had three more than the optimal vehicles X-n101-k25 and X-n125-k30.
Sweep heuristics are more effective in solving problems where customers with a small n are grouped together. However, the difference in the average gap between random and grouped customers is short. Table 11 shows that for the group of customers with grouped positions, the gap is 8.68%; for random customer positions; the gap is 8.85%; and in a less effective way for customers with grouped and random positions, it has a gap of 17.00%.
It also compares the number of vehicle numbers k ð Þ that were obtained when solving each case against the optimal solution, and it was obtained that seven cases had a vehicle more than the optimal B-n45-k6, A-n38-k5, A-n39-k5, X-n115-k10, X-n129-k18, X-n134-k13, and X-n139-k10; one case had five more vehicles than the optimum X-n101-k25, and one case had six more vehicles than the optimal X-n125-k30.
In each group of clients, the sweep heuristic obtained better answers than the Clarke & Wright heuristics with 30% in the group of clients with a grouped position, 30% in the group of clients with a random position, and 20% in the group of clients with grouped and random position. In other words, Clarke & Wright heuristics are superior with 70% in the first two groups of clients and with 80% in the last group of clients.
A comparison among the values of the Distance traveled in the solution found by the heuristic, the optimal solution and the GAP for each one of the considered test instances is shown in Table 12.
On the other hand, Table 13 shows a summary of the minimum, maximum and average gap for each of the three classes of problems considered: Clustered, Random and Clustered, and Random.

Test cases resolved through metaheuristics
The GRASP metaheuristics are based on a previous solution for which Clarke & Wright heuristic responses were selected since their responses are of better quality than the sweep heuristics.
The following parameters were considered for its implementation: • α = 0.5 • Number of iterations = 10,000 GRASP's metaheuristics are more effective in solving problems where customers with a small n are grouped together.  Table 14 shows that for the clients with grouped positions; the gap is 3.09%; for the positions of random clients, the gap is 4.38%; and less effectively for customers with grouped and random positions, it has a gap of 5.97%. On average metaheuristic GRASP based is better than Clarke & Wright heuristics by 0.53%, 0.77%, and 0.38% in the solutions of the positions of the grouped, random, and grouped and random clients, the group of clients with random positions being those that obtained a greater improvement in the quality of the solutions. The simulated annealing metaheuristics start from a previous solution for which Clarke & Wright heuristic responses were selected since their responses are of better quality than the sweep heuristics.
The following parameters were considered for its implementation: • Current temperature = 250 • Final temperature = 10 • Cooling coefficient = 0.8 • Number of iterations = 10,000 The simulated annealing metaheuristic is more effective in solving problems where customers with a small n are grouped together. Table 15 and 17 shows that for clients with grouped positions, the gap is 3.13%; for the positions of random clients, the gap is 4.41%; and less effectively for clients with grouped and random positions, it has a gap of 6.26%.
On average simulated annealing heuristics based is better than Clarke & Wright heuristics by 0.52%, 0.71%, and 0.21% in the solutions of grouped, random, and grouped and random clients' positions, the group of clients with random positions being those that obtained a greater improvement in the solutions quality.
Within each group of clients, the simulated annealing metaheuristics obtained better answers than the GRASP metaheuristics with 30% in the group of clients with a grouped position, 50% in the group of clients with a random position, and 40% in the group of clients with grouped and random position. That is, the GRASP metaheuristic is superior with 70% in the first group and with 60% in the third group of clients and is equal with 50% in the second group of clients.
A comparison between the minimum and maximum gap within each group is established in Table 16 test results with clustered clients have better results. Therefore, obtaining a minimum gap of 0%, that is, in the case of B-n34-k5, the GRASP metaheuristic obtained the optimal solution (

Conclusions
The results obtained by solving the test cases by heuristics and metaheuristics show both generate better quality solutions when solving cases where customers are grouped together and had their worst result in the group of clients with a grouped and random position since they had large n with reference to the other groups of clients. Between the heuristics, Clarke & Wright heuristics generated better quality results than sweep heuristics, having a big difference in the maximum gaps of each one for each group of clients. However, the numbers of vehicles obtained in the solutions of both heuristics were compared with the optimal solution, and the sweep heuristics had more solutions in which it reached the optimum. This is a very important contribution, since Clarke & Wright heuristics get solutions with shorter distances than the sweep heuristic, but this gets greater distances with fewer vehicle units. For some companies it will be more important to reduce the units to buy than the distance traveled.
Analyzing the metaheuristics, the GRASP metaheuristics generated better quality results than simulated annealing metaheuristics, with minimal differences in average gap for each group of clients, and both metaheuristics obtained greater improvements in relation to the initial solutions of Clarke & Wright heuristics in the test cases of randomized clients. Also GRASP algorithm with B-n34-k5 case of grouped customers reached the optimal solution, being the only test instance of the thirty that were done.
It is recommended that for future studies, each group of clients by positioning has a number of clients n ð Þ with greater variability to be able to deduce exactly if heuristics and metaheuristics have better or worse solutions when n are larger or smaller.

Author details
Fernando Francisco Sandoya Sánchez, Carmen Andrea Letamendi Lazo* and Fanny Yamel Sanabria Quiñónez Escuela Superior Politécnica del Litoral (ESPOL), Guayaquil, Ecuador *Address all correspondence to: cletamendi@gmail.com © 2020 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/ by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.