Abstract

The traveling salesman problem (TSP) is one of the most famous problems. Many applications and programming tools have been developed to handle TSP. However, it seems to be essential to provide easy programming tools according to state-of-the-art algorithms. Therefore, we have collected and programmed new easy tools by the three object-oriented languages. In this paper, we present ADT (abstract data type) of developed tools at first; then we analyze their performance by experiments. We also design a hybrid genetic algorithm (HGA) by developed tools. Experimental results show that the proposed HGA is comparable with the recent state-of-the-art applications.

1. Introduction

The objective of TSP is to find the shortest tour among a set of cites. Given the distance matrix where stands for distance between the city and , the problem is called symmetric TSP (STSP) when and, otherwise, it is named asymmetric TSP (ATSP).

Since TSP is NP-Complete, there is no exact algorithm with time complexity better than an exponential time. It means that exact algorithms are not practical for the large-scale instances in reasonable running times, so we have to use approximate algorithms to find the semioptimal solutions in acceptable running times. Recently, many approximate algorithms have been developed to handle TSP instances [14]. The types of metaheuristics like genetic algorithms (GA) [57], simulated annealing [8], swarm based algorithm [9], artificial bee colony algorithm [10], ant colony algorithms [11, 12], and combination of these algorithms have been applied to the TSP [13, 14]. However, if we consider the experiment sections of these references, we observe that almost all of these algorithms have not been applied to the instances with size of more than 1000. Among these metaheuristics, surly, Lin-Kernighan (LK) which is a type of local search algorithms (LSAs) (in this paper, LS points to the local search) is one of the best algorithms in which its extended types have been successfully applied to the large-scale instances with size of more than 85000 nodes [3, 15]. In addition, in many cases, these algorithms have been used in other metaheuristics and have increased their performance [2, 11, 16].

LSAs include 2- and 3-opt and Lin-Kernighan (LK) algorithms have been based on edges exchange process [1, 3, 15, 17]. GAs are population-based and their efficiency depends on their operators [4]. To easily use these algorithms, we have programmed objective tools by three object-oriented languages which include C++, C#, and Java. These tools allow the researchers or developers to exploit these metaheuristics easily and create their own hybrid algorithms (these tools will be available via email request to [email protected] (subject: TSP_Tools)).

Developed tools in this paper mainly focus on types of genetic operators and LSAs; however, types of ant colony optimization (ACO) have been implemented separately and will be available. The implementation of LSAs has been based on LKH implementation [1, 15, 18] which is one of the most famous and effective implementations of LK. In addition, some famous initial-solution constructors like Quick-Boruvka and nearest neighbor (NN) strategy have been included in these tools. The genetic operators have been selected from literature. These operators include the PMX [19], EPMX [20], VGX [21], IGX [5], GX (description of this operator and its versions can be found in [5, 19, 21, 22]), GSX-0, GSX-1, GSX-2, DPX [16], and OX [23]. The implementations of these operators are effective. Experimental results show that, in almost all cases, the performance (in the terms of running time and accuracy) of developed operators is even better than reported results in their references.

This paper is not limited to the developed tools only. A type of hybrid GA which is proposed in this paper and uses a two-storey strategy is fast and accurate. Experimental results show that performance of proposed hybrid algorithm outperforms one of the recent state-of-the-art algorithms.

With these descriptions, this paper is organized as follows: in the rest of this paper, we briefly describe LSAs and the ADT of their programming pack. We review GA, its operators, and the ADT of their class in the third section. In Section 4, we combine the LK into the GA and design a hybrid GA. We put forward experimental results of these algorithms in Section 5 and finally summarize the paper in Section 6.

2. LSAs

Majority of LSAs for TSP have been based on the edges exchange process. The 2-opt, 3-opt, and LK are three important algorithms that are categorized in LSAs. We have programmed these heuristics by C++, C#, and Java. In this section, we review their algorithms briefly, and then we state ADTs of their programming tools.

2.1. The Opt

The 2-opt is a special case of the -OPT. A tour is named -OPT, if it is impossible to decrease the cost of tour by changing number of edges. The 2-opt converts an input tour to its possible 2-opt case. Algorithm 1 shows the general algorithm for the 2-opt.

Suppose tour with edges that is defined on graph G(V, E):
 (1) Suppose direction for .
 (2) If there are not nodes like A, B, C and D with below conditions then go to end.
  (i) AB, CD
   (a) In supposed direction, B and D are right nodes of A and C respectively.
  (ii) Cost(AB) + cost(CD) > cost(AC) + cost(BD)
 (3) Remove AB and CD form and add AC and BD to it (2-opt-move).
 (4) Go to (2).
 (5) End.

Instruction 3 in Algorithm 1 is named 2-opt-move or 2-change that is shown in Figure 1. In the 2-opt algorithm the 2-opt-move occurs when conditions in instruction 2 are satisfied. Time complexity of running exact 2-opt is high, so, to improve speed of the 2-opt algorithm, researchers usually use two important rules which have been proposed by Bentley.(1)For each node A in line 2, we only consider its candidate nodes. Usually the five nearest neighbors are selected to make a candidate set of each node. These sets can be approximately calculated by k-d-tree [25] in ( ).(2)In the instruction 2, only the active nodes are considered. The nodes which have participated in tour cost reduction in previous iteration are activated for the next iteration. This heuristic is known as “do not-look bits” [26].

2.2. OPt

The 3-opt operates like the 2-opt but its conditions to exchanging edges is rather complicated (see [27]). Algorithm for the 3-opt in each step probes 3 edges to exchanging, so when three edges are deleted, six considerable cases appear and probing these cases increases time complexity and algorithm becomes more complicated to implement.

2.3. LK

The types of LK may be the best heuristics that have been successfully applied to TSP. Furthermore, other metaheuristics like GAs widely use variant versions of this heuristic to improve their solutions. For more description about LK, we recommend readers to refer to [15, 17] but here we present this algorithm in brief. The LK can be introduced by the three words: “break,” “link,” and “condition test”. The LK algorithm is done in some iterations. In each iteration, it exchanges some edges by another to reduce tour cost. Appendix A shows a simple algorithm for LK.

2.4. Review ADT of Class for LSAs

To implement LSAs, we need to define some primitive data structure like graph and tour at first, because these data structure definitions are necessary for other parts of program and classes. In the rest of this subsection, we define class for graph and tour at first; then, we present class for heuristic methods.

2.4.1. Graph Class

Our graph implementation has been packed in Graph class. It can read  .tsp files and compute distance between nodes. It supports all known TSP formats like GEO, GEOM, ATT, EU-2D, and CEIL-2D. Algorithm 2 shows Graph ADT. Graph class object should read TSP file by its constructor as soon as it is created (line 4).

//nodes indexes start at 0 and go up to  graph dimenion    1
(1)  class Graph
(2)  {
(3)  public:
(4)  Graph(char    path);
(5)  ~Graph();
(6)  int D(int node1,int node2);
(7)  int D(int x1,int y1,int x2,int y2);
(8)  int Dimension();
(9)  double X(int node);
(10)double Y(int node);
(11)};

2.4.2. Tour Class

Tour ADT is shown in Algorithm 3. Tour object is created to belong to Graph object. Tour object is completed after adding (= dimension) nodes, either adding to the right (by using function in line 6) or adding to the left (by using function in line 7).

(1)  class Tour
2  {
3  public:
4  Tour(Graph    graph);//tour constructor gives a gaph object pointer as argument
5  ~Tour();
6  int Add_Right(int node); //exends uncomlete tour from right
7  int Add_Left(int node); //exends uncomlete tour from left
8  int Right(int node); // return right neighbour of node in complete tour
9  int Left(int node); //return left neighbour of node in complete tour
10unsigned long long Cost(); //computes and returns cost
11void InitiateRandomly();//forms tour by sequence: 0,  1,  …,  dimenion    1
12Tour    Copy();
13short IsComplete();//if tour is complet, this function returns 1 otherwise 0.
14void reset();
15};

2.4.3. Heuristics Class

We have packed 2-opt, 3-opt, LK, Quick-Boruvka, and double-bridge into the Heuristics class. To manipulate the candidate sets, we have also added some functions into the Heuristics class. Quick-Boruvka is effective tour constructor algorithm. Double-bridge is usually used to mutate. Algorithm 4 shows Heuristics class ADT. The LK method in Heuristics class has been based on latest version of LKH, so-called LKH-2, and its source code is in C language and free for academic use [18].

/  We implement this class function according to LKH  [18]  that is free for academic use./
1    class Heuristics
2  {
3  public:
  /  Heuristic object compute candidate sets as soon as created, second argument in
       constructor is the number of candidates in each set./
4  Heuristics(Graph    graph, int NumberOfCandidates);
5  ~Heuristics();
  /  Both of lines  6  and  7  shows the 2-OPT but function in line  6  consider all of nodes
      as active but function  7  supposes only nodes in ActiveNodes array are active /
6  void TwoOpt(Tour    tour);
7  void TwoOpt (Tour    tour, int    ActiveNodes, int NumberOfActiveNodes);
       /  Both of lines  8  and  9  shows the 3-OPT but function in line  8  consider all of nodes
      as active but function  9  supposes only nodes in ActiveNodes array are active /
8  void ThreeOpt(Tour    tour);
9  void ThreeOpt (Tour    tour, int    ActiveNodes, int NumberOfActiveNodes);
    /  Both of lines  10  and  11  shows the LK but function in line  10  consider all of nodes
        as active but function  11  supposes only nodes in ActiveNodes array are active /
10void LinKernighan(Tour    tour);
11void LinKernighan(Tour    tour, int   ActiveNodes, int NumberOfActiveNodes);
12void DoubleBridge(Tour    tour);
13Tour    Q_Boruvka();
14int SetCandidates(int node, int candidate, int index);
15int GetCandidates(int node, int index);
16void SetBestTour(Tour    best_tour);
17};

3. Genetic Algorithm

Genetic algorithm is one of the search algorithms that is inspired by evolutionary process of nature. In recent years, researchers have solved many NP-Complete problems by GA, scheduling [28, 29], routing [30], and assignment [31, 32] and many other problems have been solved by GA effectively in recent years. GA works with population of solutions and, in each step, new solution is created by the crossover operator, or one or more solutions are changed by the mutation operator. The crossover operators usually get two solutions from the population. These two solutions are so-called parents (or the father and mother). The crossover creates new solution(s) based on the parents. The new solution is called child or offspring. There is question in which solutions are suitable to submit to mutation or crossover operators. There are some papers answering this question [33, 34]. Crossover and mutation are two operators of GA which play an important role in evolution of solutions of GA. Generally, LSAs include LK extensions such as iterated LK (ILK) [3] and LKH versions [1, 15] are very powerful in dealing with TSP. However, there are some effective GA or extensions like Nagata’s one [4] that uses very efficient crossover operator, so-called edge assembly crossover (EAX). In this section, we review some of these crossover operators which have been included in the developed tools.

3.1. Genetic Operators Review

Many GA crossover operators have been invented by researchers because the performance of GA depends on an ability of these operators. PMX [19] is one of the first crossovers which have been proposed by Goldberg and Lingle in 1985. Reference [20] states some shortcomings for PMX and to overcome them, proposing extended PMX (EPMX). DPX [16] is another crossover that produces child with greedy reconnect of common edges in two parents. Greedy subtour crossovers (GSXs) [24, 35, 36] family is another group of crossovers that operate fast. GSX-2 [36] is improved version of GSX-0 [35] and GSX-1 [24]. Order crossover (OX) proposed by Davis is another one in which its extensions not only have been applied on TSP [23] but also solved many other NP-Completes [32, 37].

In this subsection, we represent some of the recent GA crossovers and introduce them by examples. In these examples, we use the graph with eight nodes as this set: , 2, 3, 4, 5, 6, 7, that its edges weight is as shown in Table 1.

3.1.1. PMX Crossover

Partially mapped crossover (PMX) is one of the first genetic operators. It produces two children according to two parents by exchanging nodes between two arbitrary points.

PMX is unable to detect the same nodes from mapped areas. In Figure 2, it can be easily seen that PMX cannot determine that node 7 is common in both mapped areas. PMX is double point crossover and these crossovers are not suitable to solve TSP. These defects can cause repetitive children production by this crossover [20].

3.1.2. EPMX Crossover

Reference [20] tries to overcome PMX’s shortcomings and proposes extended PMX (EPMX). It selects one arbitrary point and exchanges unique nodes before this arbitrary point and produces two children. As example of EPMX, given father = 1-2-3-4-5-6-7-8 and mother = 1-4-8-6-2-3-5-7, suppose that arbitrary point = 4 so father = 1-2-3-4|5-6-7-8 and mother = 1-4-8-6|2-3-5-7 are divided to two sublists. Nodes 2 and 3 from first sublist of father are not repeated in first sublist of mother and nodes 8 and 6 from first sublist of mother are not repeated in first sublist of father so form exchanges so children are produced as child1 = 1-4-8-6-5-3-7-2 and child2 = 1-2-3-4-8-6-5-7.

3.1.3. Greedy Crossovers (GXs)

Some versions of GX like very greedy crossover (VGX) [21] and improved greedy crossover [5] have been proposed by researchers in recent years. To review these crossovers, readers can refer to [5].

3.1.4. Improved Greedy Subtour Crossover (GSX-2)

GSX-2 [36] is improved version of GSX-0 [35] and GSX-1 [24]. GSX-0 is first version of GSX family. Algorithm 5 shows GSX-0 algorithm.

1  Node X    select random node;
2  Copy X to child;
3  Node R    X;
4  Node L    X;
5  while(true)
6  {
7  R    right neighbor of R in father tour;
8  L    left neighbor of L in mother tour;
9  if R is in child then break while loop;
10if L is in child then break while loop;
11Add node R to child right side;
12Add node L to child left side;
13}
14Complete child by remaining nodes (nodes havent been copied to child tour yet) in random;
15return child;

Figure 3(a) shows GSX-0 example. In this example, after node 5 that has been included in child is met again, GSX-0 fills remaining places with random nodes but, same as Figure 3(b) that shows GSX-1 example, it fills remaining nodes in order of one of parents.

In general, GSX-1 operates better than GSX-1 because it can preserve order of remaining nodes but, in some cases, it produces repetitive tours; same as Figure 3(b), child tour is the same as father tour. Reference [36] states some shortcomings of GSX-0 and GSX-1 and, to overcome these shortages, proposes GSX-2.

3.1.5. Distance Preserving Operator (DPX)

DPX   [16] operates as follows: it detects common subpaths of two parents at first and then reconnects them greedily and produces child. Figure 4 shows DPX example that uses presented edges weight of graph in Table 1.

3.2. ADT of Class for Crossovers

We have packed crossover operators into the Crossover class. Algorithm 6 shows ADT of Crossover class. Lines 5 to 14 show definitions of crossovers functions. Functions in lines 5 to 12 show crossovers which take two tours as father and mother and produce only one child, so their functions take three tour-pointers as the input arguments. The first two arguments are to point to the parent tours and third argument points to the child tour. Lines 12, 13, and 14 show OX, PMX, and EPMX which produces two children so their functions take four arguments. The first two arguments point to the parent tours and the second two arguments point to the two children tours.

1  class Crossovers
2  {
3  public:
4  CrossoversGraph(Graph  );
  //Original greedy crossovers function definition.
5  void GX(Tour  , Tour  , Tour  );
  //Another version of greedy crossovers function definition [17, 21].
6  void GX_4(Tour  , Tour  , Tour  );
  //Function definition of another version of GX [17, 21].
7  void GX_4_Pool(Tour  , Tour  , Tour  );
  /  lines  8  to  15  show proposed function definitions of crossovers that proposed in
  [3, 5, 16, 20, 21, 23, 24]  respectively./
8  void VGX(Tour  , Tour  , Tour  );
9  void IGX(Tour  , Tour  , Tour  );
10void DPX(Tour  , Tour  , Tour  );
11void GSX(Tour  , Tour  , Tour  );
12void OX(Tour  , Tour  , Tour  , Tour  );
13void PMX(Tour  , Tour  , Tour  , Tour  );
14void EPMX(Tour  , Tour  , Tour  , Tour  );
15};

The performance of these crossovers, which are based on speed and accuracy, has been analyzed in [5]. Results in [5] show that heuristic crossovers like IGX and DPX have more accuracy than others. These results also show that the crossovers like GSX family have more diversity than others which mean that these crossovers can produce wide range of different solutions.

3.3. Types of Genetic Algorithm

There are two major models for GA: generational and steady-state GA. The main deference between generational and steady-state GA is that, in generational GA, new solutions are added to population and, after some steps, population size is normalized by removing worse individuals but, in steady-state GA, the new solution is replaced by one of old solution of population. In both algorithms, mutation operation may be applied on one or more solutions of population periodically.

Recently, researchers add solution improvement function such as 2- opt, 3-opt, and LK into their GA. These functions usually are applied to new solutions after they are created or changed by the crossover or mutation operations. These GAs are called memetic or hybrid GA (HGA). Memetic is general concept and points to the all evolutionary algorithms that incorporate local searches to improve their solutions.

4. Developing HGA by the Developed Objective Tools

To show applicability of proposed objective tools, we develop new model of HGA which differs with another versions in two main cases (See Appendices).(1)The proposed HGA is two-storey GA. It means that the proposed HGA has been formed from two storeys of GA. First storey of GA uses heuristic genetic operator such as GX versions. This storey increases quality of population, so LSA can operate quickly in second storey. It should be tended that LSAs can operate quickly on high quality solutions. Therefore, this storey affects the second storey where LK is utilized. The LK operates quickly when it is applied to high quality tour.(2)The second storey of the HGA is also HGA itself. Like other HGA algorithms that incorporate LSA to increase tours quality, proposed HGA also does and exploits LK as its LSA but (I)it is updating LK candidates’ sets periodically while these instructions of storey are executing; (II)in order to produce wide variety of solutions it should use quick crossover operator with high diversity same as classical PMX, GSX-1, or EPMX instead of heuristic crossovers that are usually slow. Notice that LK guarantees solutions’ quality so it is not reasonable to use time consumer heuristic crossovers.

5. Experiments

In this section, we show objective tools performance. We divide this section to three subsections. In first subsection, we focus on LSAs tools, in second subsection, we put forward experimental results for the crossovers, and, finally, we exhibit experimental results of HGA designated by developed objective tools.

5.1. Performance of the Developed Tools

To test developed LS tools including 2-opt, 3-opt, and LK, we apply them on fifteen TSPLIB instances twenty times. Users may need to be informed about accuracy and speed of LS tools, so here we report best, worst, average, and standard deviation of recorded costs and runtimes for LS tools per each instance in each of the twenty runs. Table 2 shows average, best, worst, and standard deviation of twenty solution costs for each instance achieved by each of the stated heuristics. Moreover, this table shows error percent of best, average, and worst solution costs which is calculated by . Please consider that optimum cost for usa115475 is unknown so we have used best solution cost (6283142) that is obtained by LK tool.

Table 3 presents runtime information of each heuristic applying to each instance in twenty runs. The minimum, average, maximum, and standard deviation of required runtimes have been listed in this table.

To make comparison among heuristic tools easy, we have introduced average error percent column of  Table 2 and average time column of  Table 3 by diagrams in Figure 5.

5.2. Performance of the Developed Crossovers’ Tools

To present crossover performance, we should show effect of crossover in GA accuracy, convergence speed, and ability of crossover in generating wide range of various solutions. To achieve these goals, we have to use generational GA because, in steady-state GA, generation size is constant but, in generational GA, the total generated solutions depend on ability of crossover in generating various solutions; if crossover can generate different solutions, so it delays generational GA convergence; then total generations increase. On the other hand, when generated solutions count is high, it shows that crossover diversity is high and it can produce wide range of various solutions. We used each of stated crossovers in generational GA to solve some instances from TSPLIB twenty times and Table 4 shows results of this experiment.

Table 4 shows information about best, worst, average, and standard deviation of solution costs for each of the twenty runs by each crossover when solving each instance. Figure 6 summarizes average error percent and STDV columns of Table 4.

In Figure 6 it can be easily seen that IGX has better performance in both average error percent and standard deviation. In average error percent and for kroA100, a280, lin318, rat783, and pr1002, IGX has first best rank and, only in att532, it has second minimum error percent. For standard deviation, also IGX has minimum in dealing with kroA100, a280, lin318, rat783, and pr1002. In solving att532, IGX has second minimum STDEV.

Tables 5 and 6 show experimental results information about required runtime and total generations count in each of the twenty runs. These tables list best, average, worst, and standard deviation of required runtime and minimum, average, maximum, and standard deviation of total generations count. Average and STDEV columns of both tables have been introduced in Figure 7.

5.3. HGA Performance Analysis

Comparing developed HGA with other state-of-the-art methods is not our purpose here but we want to show that it is possible to design and develop new memetic algorithms by our objective tools. Therefore, to achieve this goal we compare HGA with latest windows based version of LKH in period of 100000 seconds in solving pla85900 that is the largest problem in TSPLIB. Diagram in Figure 8 shows result of this competition. This diagram shows that HGA produces better tours than LKH during 100000(s) and its prominence is noticeable.

6. Conclusion

In this paper, we present highlight of our TSP programming tools that have been based on LKH implementation. In fact, these tools are source codes in three object-oriented languages: C++, C#, and JAVA. These tools can help engineers, researchers, and those who are dealing with TSP to write and develop their TSP applications more easily by one of the stated programming languages arbitrarily. Here, we tried to show our tools’ performance by experiments. In order to show their applicability, we designed a hybrid algorithm that was effective and beat the LKH-2 software in dealing with largest TSPLIB instance.

Appendices

A.

See Algorithm 7.

1     List<Node> ActiveNodes;// to implement dont-look bits
2     void LK(Tour tour)
3     {
4     for each node X
5     Add X to ActiveNodes List;
6     while(active node is existed)
7     {
8     Node N = remove and return first node in ActiveNodes;
9     if(inner-LK(tour, X) <= 0)
10  inactive X;
11  }
12  }
1     int inner-LK(Tour tour, Node x)
2     {
3     Y    neighbor of X;
4     int partial-gain = |XY|;
5     break XY from tour;
6     Add Y to ActiveNodes List;
7     for each Z    candidate set of X
8     {
9     add YZ to tour;
10  Add Z to ActiveNodes List;
11  partial-gain = partial-gain + |YZ|;
12  if tour is feasible (tour closing up by one edge is possible)
13  {
14  if (partial-gain    last added edge cost > 0 then)
15  {
16  close up tour;
17  return  partial-gain    last added edge cost;
18  }
19  else
20  {
21  int g = inner-LK(tour, x);
22  if (g < 0)
23  {
24  break YZ; //test another.
25  }
26  else
27  {
28  return g;
29  }
30  }
31  }
32  }
33  add XY to tour; //breaking XY was unsuccessful.
(34)  remove Y from ActiveNodes List;
(35)  return 0;
(36)  }

B.

See Algorithms 8 and 9.

1    while (some conditions are satisfied)
2    {
3    for (i = 0; i < gen-size; i++)
4    {
5    Get father and mother from population;
6    Child(s)  <-  crossover(father,  mother);
7    LS may be apply on child tour(s);
8    Add child to population;
9    }
10  Normalized population size by removing some solutions;
11  }

1for (i = 0; i < gen-size; i++)
2{
3Get father and mother from population;
4Child(s)  <-  crossover(father,mother);
5LS may be apply on child tour(s);
6index  <-  get_inddex();
7population[index]  <-  child;
9}

C.

See Algorithm 10.

1  Create population of random tours;
     //First storey is GA and increases tours  quality. It uses IGX as its crossover [5].
2  Use steady-state GA by heuristic crossover to improve population;
3  Sort population according to cost in ascendant order;
4  Tour    best-so-far    population0;
     //Second storey is HGA and uses GSX as its crossover, Double-Bridge as its mutation and LK
     as its LS.
5  for (i = 1; i <= gen-size; i++)
6  {
7  Tour    child;
8   int index;
9   if(rand_01() < crossover-rate)
10{
11index = linear selection from population;
12father    population[index];
13index = linear selection from population;
14mother    population[index];
15crossover(father, mother, child);
16Improve child by lk;
17}
18else
19{
20child    linear selection from population;
21mutate child by double-bridge;
22Improve child by lk;
23}
24Sort population according to cost in ascendant order;
25if (i % period == 0)
26update candidate set according to edges density in population;
(27)if(best-so-far cost > population0  cost)
(28)best-so-far cost    population0;
(29)}
(30)Report best-so-far;

Conflict of Interests

The authors declare that there is no conflict of interests regarding the publication of this paper.