A hybrid approach based on genetic algorithm and nearest neighbor heuristic for solving the capacitated vehicle routing problem

This work presents a hybrid approach called GA-NN for solving the Capacitated Vehicle Routing Problem (CVRP) using Genetic Algorithms (GA) and Nearest Neighbor heuristic (NN). The first technique was applied to determine the groups of customers to be served by the vehicles while the second is responsible to build the route of each vehicle. In addition, the heuristics of Gillett & Miller (GM) and Downhill (DH) were used, respectively, to generate the initial population of GA and to refine the solutions provided by GA. In the results section, we firstly present experiments demonstrating the performance of the NN heuristic for solving the Shortest Path and Traveling Salesman problems. The results obtained in such experiments constitute the main motivation for proposing the GA-NN. The second experimental study shows that the proposed hybrid approach achieved good solutions for instances of CVRP widely known in the literature, with low computational cost. It also allowed us to evidence that the use of GM and DH helped the hybrid GA-NN to converge on promising points in the search space, with a small number of generations.


Introduction
The Vehicle Routing Problem (VRP) consists in defining the routes that a set of vehicles must follow to supply the demand of certain customers, respecting the operational restrictions imposed by the context in which the problem is inserted (Laporte, Gendreaub, Potvinb, & Semetc, 2000).
In recent years, the VRP has attracted an increasing attention from researchers due to the great difficulty of its solution and its presence in various practical situations (Cordeau, Laporte, Potvin, & Savelsbergh, 2007).In consequence, there has been great effort to develop more robust, agile and flexible algorithms that can be modeled according to the scenario that describes the problem.
The VRP has several variants, which take into account the capacity (each vehicle has a specific capacity), time windows (customers are taken care of in time), vehicle fleet heterogeneous (distinct vehicles), and multiple depots (vehicles can come from different deposits (distribution centers) (Mandal, Pacciarelli, Lokketangen, & Hasle, 2015).
The Capacitated Vehicle Routing Problem (CVRP) is a variant of the VRP, and it consists, basically, in determining the routes to be followed by a fleet of homogeneous vehicles (in terms of capacity), to serve a given number of customers, without violating the capacities of the vehicles (Lee & Nazif, 2011).
The CVRP belongs to the class of NP-hard problems, which usually require non-polynomialtime algorithms for their solutions.In other words, the difficulty in finding the optimal solution for CVRP grows exponentially as the number of clients increases.Thus, the CVRP has been usually solved with the use of heuristic and metaheuristic algorithms such as Gillett & Miller (Gillett & Miller, 1974), Clarke and Wright (Laporte et al., 2000), Tabu Search, Particle Swarm Optimization, and Genetic Algorithms (Lu & Yu 2012).Reeves (1993) defines heuristic as a technique that although does not guarantee optimal solutions, it is able to find good solutions (sub-optimal in most cases) with feasible computational time.The metaheuristics, in turn, are characterized by guiding a set of heuristics and have been particularly useful in solving complex optimization problems.Heuristic and metaheuristic are more flexible than the exact algorithms to operate with more complicated and realistic objective functions and restrictions.
The choice of algorithm for solving VRP is a process of extreme importance, seeing that a welldefined algorithm can provide a better relation between the cost and benefit to define the routing.Thus, from all the existing techniques for solving the VRP, the Genetic Algorithms (GA) stand out by its versatility of construction, and the good results that it has been demonstrated in solving of complex problems, including VRP, as can be seen in Lee and Nazif, (2011); Tasan and Gen (2011); Ursani, Essam, Comforth, and Stocker (2011); Lu and Yu (2012); Kuo, Zulvia, and Suryadi (2012);Vidal, Crainic, Gendreau, Lahrichi, and Rei (2012); Reiter and Gutjahr (2012); Osaba, Diaz, and Oniera, (2014); Santiciolli et al. (2015).
For Laporte et al. (2000), a research trend is the development of simplest, fast and robust metaheuristics that even with some prejudice to the quality of the solutions, allowing their incorporation into commercial packages.
In this sense, this paper presents a hybrid approach to solve CVRP using Genetic Algorithms (GA) and the following heuristics: Nearest Neighbor (NN), Gillett & Miller (GM), and Downhill (DH).The NN heuristic consists of a greedy strategy that is coupled to GA for building the route of each vehicle in the solution.The second and third heuristics are employed, respectively, to: (i) generate solutions that are included in the initial population of GA, starting it with some feasible solutions, and (ii) refine the solutions generated by the GA-NN approach, after a certain number of generations without improvement.
In the experimental study, we demonstrated the efficiency of the NN for CVRP.It was applied it on the solution of Shortest Path Problem (SPP) and Traveling Salesman Problem (TSP).In these experiments, it was analyzed the influence of three complex networks coefficients (average clustering, average shortest path, network size) in the performance of NN, considering 2490 graphs.It was observed that NN performance improves as the average clustering coefficient of network (graph) increases.Thus, we could make sure that its use coupled to GA is a suitable alternative, since the all graphs of the instances from TSPLIB1 considered in this work have clustering coefficients with maximum value.
The obtained results, compared with the best results found in the literature, indicate that proposed approach achieved good solutions for CVRP, with low computational cost.In addition, it was evidenced that the use of GM and DH improved the hybrid GA-NN to converge quickly on promising points in the search space.

Material and methods
This section presents, firstly, a brief description on the considered problems (SPP, TSP, CVRP and Complex Networks) and techniques (GA, NN, GM and DH).After that, the methodology for conducting the experiments is presented.

Shortest Path Problem (SPP)
The SPP consists in determining a path between a pair of points (origin and a destination) with shortest distance (Cormen, Leiserson, & Stein, 2001).In general, this problem is represented by a graph with several paths to be evaluated, which represents a computational difficulty.Thus, many researches have focused on the development of efficient algorithms to solve it.SPP is present in several areas such as computer networks, games, water and gas distribution, transport logistic, among others.In computer networks, for example, the SPP consists of a routing task, in which information is transferred from a source to a destination following the shortest available path available (Cormen et al., 2001).There are many algorithms for SPP solution, many of them based on greedy strategies.
Traveling Salesman Problem (TSP) According to Helsgaun (2006), the TSP is one of the most well-known and intensely studied combinatorial optimization problem in history.It was one of the first types of routing problem to be studied.TSP consists of finding the smallest possible route, from the point of origin, in order to travel through a set of cities (points) and return to the origin, visiting each city exactly once.In other words, the objective of the TSP is to find in a graph G = (V, E), in which V are the set of vertices and E the set of edges, the path with the shortest cost so that all the vertices are visited only once.
To problems of this type, the optimal solution could be found by enumerating all possible solutions, but even with the technological advance in the last decades, it becomes unfeasible as the number of vertices increases.In this sense, to solve practical problems, where there is a high number of vertices, heuristic and metaheuristics algorithms are normally used to obtain good solutions in an acceptable computational time.In this paper, for example, Nearest Neighbor (NN) was used to solve it.

Capacitated Vehicle Routing Problem (CVRP)
According to Cunha (2000), routing problems can be seen as a problem of multiple traveling salesman with restriction of capacity (for example, each traveling salesman can only carry a limited capacity of objects).The CVRP is the classic version of VRP and consists of finding a set of routes, where each route is traveled by a vehicle, with the objective to minimize the total cost of determined routes, respecting the following restrictions: (1) Each route must start and finish at the distribution center; (2) Each customer must be visited just once; (3) The sum of the customers' demands included in a route cannot exceed the vehicle's capacity.
Let G = (V, E) be a graph in which V = 0,…,n is a set of vertices that represent the customers and E the set of edges that connects customers to each other and to distribution center.To each edge (v i , v j ) is associated a cost c ij .A set of K identical vehicles with capacity cv is allocated to the distribution center (v 0 ).Each customer v i has a demand d i and the demand of distribution center is defined as d 0 = 0. Mathematically the CVRP can be expressed as follows Equation 1 to 8: where: d i : demand of customer v i ; k: vehicle; K: set of vehicles; S: set of customers; nc: number of customers; m(S): minimum number of vehicles to attend S; cv: capacity of vehicles; c ij : cost of the path from the customer i to customer j; tc: total cost of the routes; x ijk : path from the customer i to customer j with vehicle k.
Equation 2 ensures that K vehicles will be used starting from the distribution center, while the Equation 3 guarantees that each route has its beginning and ending at the distribution center.Equation 4 defines that customers must be attended only once and the Equation 5 keeps the flow ensuring that the vehicle arrives at a customer and out of it, preventing the route ends prematurely.The Equation 6 prevents the formulation of routes which do not include the distribution center.In this restriction, m(S) represents the minimum number of vehicles required to attend a set of customers S.
To ensure that the number of vehicles used to attend the customers of set S is not less than m(S), the restriction 6 establishes, indirectly, that the capacity of vehicle is not exceeded.However, to let it explicit, the Equation 7 is used to formulate the capacity restriction.The Equation 9 is used to evaluate the solutions generated by the proposed approach.It reflects the value of the objective function (OF) and involves the number of vehicles used in the solution, violated restrictions (Equation 2 to 7) and the total cost of routes (Equation 1).
where: W v is the weight assigned to the number of vehicles used in the solution; nr is the Number of violated restrictions and W r is the weight given to the violated restrictions.

Complex networks
Many situations may be mathematically modeled by a network (or graph).Nodes that are connected by edges express a wide range of problems.For instance: the network formed by authors (nodes) and the works they published together (edges); computers (nodes) and network computers (edges); individuals (nodes) and the contact they make with each other during a certain period (edges).However, regular networks seem not to represent the dynamics of such problems, with complex networks, which have random characteristics, being used more frequently (Barabasi, 2003).
The approach proposed by Erdös and Rényi (1959) started with random networks: given N nodes, a fraction p of the possible edges link the nodes.Then, considering a regular network with all nodes connected to m nearest neighbors, a fraction p of the connections is rewired, allowing long-distance nodes being connected, but maintaining average small distances between nodes.This process forms networks called small-world, proposed by Watts andStrogatz, in 1998 (Watts &Strogatz, 1998).Topological parameters of small-world networks are similar to real networks formed by individuals in a population (Boccaletti, Latorab, Chavezf, & Hwanga, 2006).Moreover, some real networks also present a power law distribution in the degree (number of connections) distribution, that is, highly connected nodes are more likely to receive new edges.This is a scale-free network property (Bollobás, Riordan, Spencer, & Tusnády, 2001), also present in Barabási-Albert networks, whose formation is based on richer get richer rule (Albert & Barabási, 2002).
Usually, the most important topological parameters to analyze a network are: average clustering coefficient, which is the average percentage of connections between neighbors of each node; average shortest path, which is the average shortest path between any two nodes of the network; degree distribution and network size (Newman, 2010).

Genetic Algorithm (GA)
GA is a population-based optimization method on the Charles Darwin's theory of species evolution.
It is inspired by natural selection model and can be understood as a process where the most adapted individuals have a greater chance of surviving in an adverse environment (Goldberg, 1989).Each new generation is constituted from the most adapted individuals who pass on, consequently, their characteristics to their descendants, aiming at the preservation of acquired qualities.This process happens in a cyclical way so that each new generation is better than previous generation.Usually an objective function is used to calculate the aptitude (fitness) of an individual.
Thus, GA artificially applies the principles of the evolutional process proposed by Charles Darwin, with the objective of optimizing a search technique in the search space, seeking a solution of good quality.
In a GA population, an individual (or chromosome), represents a possible solution to the investigated optimization problem.The chromosome is usually represented by a bit string in which the genes (chromosome substrings) are associated with the decision variables of the problem and each bit represents an allele of the chromosome.In the beginning, the population is randomly generated and then it evolves by means of applying GA operators (selection, crossover, and mutation).In the selection operation, a percentage of best candidates are selected to be crossed, generating a new population.In other words, the genetic material of best chromosomes is mixed to generate the individuals of the next population.Several selection methods have been proposed in the literature.The most common are roulette wheel, tournament and ranking.In the latter, for example, only a portion of chromosomes with better fitness are selected to generate a new population.The mutation is responsible for randomly changing a small portion of the alleles (usually defined by a percentage) aiming to preserve the diversity of the population, that is, to avoid that individuals of population become too similar to each other (Goldberg, 1989).In fact, the mutation is the key point of the genetic algorithm to avoid local minimum (or maximum) points.
It is worth emphasizing that the great challenge in the use of GA is to choose well its configuration parameters, which include the selection method and the mutation rate.In addition, despite its good performance in solving optimization problems, there may be some difficulty for GA to find optimal or sub-optimal solutions, especially in more complex problems such as CVRP.In these cases, a good alternative is the use of a local search algorithm to refine the solutions found by the GA.

Nearest Neighbor heuristic (NN)
According to Cormen et al. (2001), the constructive heuristic of Nearest Neighbor works basically starting the solution from the origin vertex and adding to the route the vertex closest to the last vertex added, finalizing the algorithm when all the vertices are visited (in the case of TSP) or the destination vertex is found [in the case of (SPP)].
The NN algorithm is easy to implement and run quickly, but sometimes it may lose shorter routes, which are easily noticed by human vision because of its 'greedy' nature.As a general guide, if the last steps of the route are comparable in length to that of the first steps, the course is reasonable; but if they are much larger, it means that there are much better routes.

Downhill Heuristic (DH)
The Downhill algorithm is one of the most basic local search techniques (uses a heuristic function for making locally optimal choices).At each step of the algorithm, the solution generated by the current state is replaced by the solution represented by its best neighbor.If we consider, for example, a twodimensional solution space, the neighbors of a solution (x, y) could be (x+1, y), (x-1, y), (x, y+1) and (x, y-1).
The algorithm closes when it does not find a neighbor better than that represented by the current state (Russel & Norvig, 1995).Due to its characteristics of local search, DH is widely used to refine solutions generated by metaheuristic algorithms.
The use of a local search algorithm such as DH presupposes, in addition to an evaluation function, a methodology for generating the neighbors of a solution, which is important for the success of the approach.A methodology that generates many neighbors can lead to an excessive increase of the computational cost of the algorithm.
The GM algorithm (Gillett & Miller, 1974) is based on the notion of economies and is a two-stage heuristic (Cluster first, Route second) widely used for solving Vehicle Routing Problems.GM solves the VRP as follows: in the first stage, the vertices (costumers) are clustered using some criterion of proximity and performing the savings calculations.
Then, the sequence of visitation for each group of vertices is obtained by solving the TSP using, for example, the NN algorithm.

Methodology for conducting the experiments
In this work, two experiments were conducted.The first set of experiments consist of analyzing the influence of three complex networks coefficients (average clustering, average shortest path, network size) on the performance of NN applied to solve SPP and TSP, considering a total of 2,490 complex networks (graphs) with different topologies (Small Word, Barabasi Albert, Scale Free and Erdös & Rényi).We have considered the following intervals for the coefficients: average clustering (from 0.1 to 1.0), average shortest path (from 1.0 to 2.5) and network size (from 5 to 10).In order to allow the comparison of the results obtained by NN for SPP and TSP, the optimal solutions were obtained for each graph using, respectively, Dijkstra and exhaustive search algorithms.In addition, it was considered that a solution would be suboptimal when it had a gap of up to 10% in relation to the optimal solution.
The second set of experiments was conducted to evaluate the performance of proposed GA-NN approach for solving the CVRP, considering a set of 16 instances from Christofides 2 and TSPLIB 3 libraries, with up to 30 customers.The results obtained by GA-NN were compared with the best results found in the literature.
For the development of GA-NN approach, the programming language C/C++ and GAlib 4 library was employed.The GAlib is a free library widely used in solving combinatorial optimization problems.In all experiments we used a desktop computer with the following configuration: Intel Celeron 2955U−1.40GHz processor; 4 GB of RAM; Windows 7 Ultimate 32-bits operating system.

Results and discussion
Analysis of the influence of complex network coefficients on the performance of NN As we can be seen in Table 1, the performance of NN heuristic for both problems (SPP and TSP) improves as the clustering coefficient increases.Thus, it is possible to consider that the average clustering coefficient directly influences the performance of NN.This information was essential because we could make sure that the use of NN coupled to GA is a good alternative for solving CVRP, since the all graphs from Christofides and TSPLIB instances have average clustering coefficients equal to 1. Concerning to average shortest path and network size coefficients, the observed behavior indicates that the performance of NN is better in small graphs and/or small paths.
Proposed GA-NN In the proposed approach, the chromosome of GA (Figure 1) represents just the set of customers that must be attended by each vehicle, while the sequence or order of visits to customers (route) is solved by the NN algorithm.Concerning the mutation, 1% of the alleles from population, randomly selected, will have their values changed.The flip-bit operation means that if the original allele value is 1, it will be switched to zero, and vice versa.
In the refinement process by DH algorithm, the neighborhood of a current state (solution) is generated by shifting the elements of chromosome's matrix in a circular manner along the dimension M (left and right).Thus, at each iteration of DH algorithm, only two neighbor solutions are examined.
The sequence of techniques of proposed GA-NN approach is illustrated in Figure 2.
For evaluating the proposed approach, ten tests for each instance were conducted and the results obtained were compared with the best solutions found in the literature.
To evaluate the quality of the obtained solutions, we employed a measure called GAP, widely used in the literature to express how far the result obtained for a problem is from the best result reported in the literature for that problem.In our case, GAP = (OF * -OF_Best)/OF_Best, being OF * the best solution obtained by GA-NN and OF_Best the best solution reported in the literature.In addition, the average of the objective function (OF) values obtained in the 10 tests (OF_Med), the standard deviation of OF values (OF σ ), the computation time and the best solution (OF * ) obtained by GA-NN, for each instance, are also presented in Table 2.
From Table 2, we can observe that the approach enabled promising results.The maximum GAP has not exceeded 18 and 62.5% of the instances showed a GAP less than 5%.Regarding the stability, in 62.5% of instances the GA-NN presented the maximum standard deviation (OF σ ) up to 10, indicating its good performance.
With respect to computational cost, as can be seen in Table 2, the processing time is ranging from 27 s for smaller instance (Eil7) to 140 s for larger instance (E-Eil30 n30-k3).
Experiments considering GA-NN with and without the use of heuristics GM and DH were also performed as follows: GA-NN = Only Genetic Algorithm/Nearest Neighbor (without the use of heuristics

Figure 1 .
Figure 1.Chromosome representation of the GA.As illustrated in Figure 1, the chromosome consists of a binary matrix of N rows by M columns, where n represents the number of vehicles and M the number of costumes.So, alleles (array elements) with a value of 1 in each line indicate the customers that will be attended by a vehicle.The configuration parameters of GA were defined empirically as follows: Chromosome encoding = Binary Matrix; Population Size = 1200; Population subset for refinement (R) = 1/3 of the population; Number of generations without improvement (gw) = 30; Number of Generations (used as stop criterion) = 5000; Population rate of replacement = 80%; Elitism (%) = 20; Crossover rate (%) = 80; Selection Method = Roulette; Rate Neighbor + Downhill; GA-NN/GM = Genetic Algorithm/Nearest Neighbor + Gillett & Miller; GM = only Gillett & Miller; GA-NN/DH/GM = Genetic Algorithm/Nearest Neighbor + Gillett & Miller + Downhill; These results are presented in Table3 and Figure 2.Acta Scientiarum.Technology, v. 40, e36708, 2018

Figure 2 .
Figure 2. Sequence of techniques employed in the proposed approach.

Table 1 .
Percentage of optimal and sub-optimal solutions obtained by NN with relation to network coefficients.

Table 2 .
Results of experiments with the proposed approach.of the GA, such as Clarke & Wright algorithm; to investigate other types of neighborhood structures for the refinement of solutions, for example the 2-Opt and 3-Opt operators and, finally, to apply the GA-NN in other instances from the literature, well as in real scenarios, aiming to evaluate its applicability in a commercial software. population