implementation of heuristics for solving …€¦ · implementation of heuristics for solving...

17
International Journal of Advance Research, IJOAR .org ISSN 2320-9194 139 IJOAR© 2013 http://www.ijoar.org International Journal of Advance Research, IJOAR .org Volume 1, Issue 3, March 2013, Online: ISSN 2320-9194 IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST NEIGHBOUR AND NEAREST INSERTION APPROACHES Oloruntoyin Sefiu Taiwo, Ojo Josiah, Amao Taiwo, Salawudeen Dkhrullahi & Oloruntoyin Kehinde Sade 1Department of Computer Science & Engineering 2Department of Pure & Applied Physics 3Department of Chemical Engineering Ladoke Akintola University of Technology, Nigeria E-mail: [email protected], [email protected], [email protected] ABSTRACT: The travelling salesman problem (TSP) is a combinatorial optimization problem in which the goal is to find the shortest path between different cities that the salesman takes. In other words, the problem deals with finding a route covering all cities so that total distance and execution time is minimized. This work adopts the nearest neighbour and nearest insertion algorithm to solve the well- known travelling salesman problem. The algorithms were implemented using c# programming language of the dot Net framework .A sample of six cities were taken and nearest neighbour’s execution time for the six cities are: 59, 60, 63, 97, 58, 77, (in ms) respectively and for nearest insertion are: 137, 68, 48, 55, 45, 57, (in ms) respectively. The total distance covered by nearest neighbour are : 7584, 8946, 8835, 8196, 7946, 7156, (in km) respectively and the distance covered by nearest insertion are : 8246, 8509, 8574, 7227, 7946, 7156, (in km) respectively. Conclusively, nearest insertion which utilises lesser execution time and shorter distance covered is found to be more efficient and better than nearest neighbour approach. KEYWORDS: Heuristics, Travelling Salesman Problem (TSP), Nearest Neighbour, Insertion, Genetic Algorithm.

Upload: lydiep

Post on 02-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 139

IJOAR© 2013 http://www.ijoar.org

International Journal of Advance Research, IJOAR .org Volume 1, Issue 3, March 2013, Online: ISSN 2320-9194

IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST NEIGHBOUR AND NEAREST INSERTION APPROACHES

Oloruntoyin Sefiu Taiwo, Ojo Josiah, Amao Taiwo, Salawudeen Dkhrullahi & Oloruntoyin Kehinde Sade 1Department of Computer Science & Engineering 2Department of Pure & Applied Physics 3Department of Chemical Engineering Ladoke Akintola University of Technology, Nigeria E-mail: [email protected], [email protected], [email protected] ABSTRACT:

The travelling salesman problem (TSP) is a combinatorial optimization problem in which the goal is to find the shortest path between different cities that the salesman takes. In other words, the problem deals with finding a route covering all cities so that total distance and execution time is minimized. This work adopts the nearest neighbour and nearest insertion algorithm to solve the well- known travelling salesman problem. The algorithms were implemented using c# programming language of the dot Net framework .A sample of six cities were taken and nearest neighbour’s execution time for the six cities are: 59, 60, 63, 97, 58, 77, (in ms) respectively and for nearest insertion are: 137, 68, 48, 55, 45, 57, (in ms) respectively. The total distance covered by nearest neighbour are : 7584, 8946, 8835, 8196, 7946, 7156, (in km) respectively and the distance covered by nearest insertion are : 8246, 8509, 8574, 7227, 7946, 7156, (in km) respectively. Conclusively, nearest insertion which utilises lesser execution time and shorter distance covered is found to be more efficient and better than nearest neighbour approach. KEYWORDS:

Heuristics, Travelling Salesman Problem (TSP), Nearest Neighbour, Insertion, Genetic Algorithm.

Page 2: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 140

IJOAR© 2013 http://www.ijoar.org

I. INTRODUCTION

The travelling salesman problem (TSP) is a NP (non-deterministic polynomial) hard problem in combinatorial optimization studied in operations research and theoretical computer science. Given a list of cities and their pair wise distances, the task is to find the shortest possible route that visits each city exactly once and returns to the original city. It is a special case of the travelling purchaser problem. The problem was first formulated as a mathematical problem in 1930 and is one of the most intensively studied problems in optimization. It is used as a benchmark for many optimization methods. Even though the problem is computationally difficult, a large number of heuristics and exact method are known, so that some instances with tens of thousands cities can be resolved. (Bellman, 1960).

The TSP has several applications even in its purest formulation, such as planning, logistics and the manufacture of microchips. Slightly modified, it appears as a sub problem in many areas such as DNA sequencing. In these applications, the concept city represents, for example, customers, soldering points, or DNA fragments, and the concept distance represents travelling times or cost or a similarity measure between DNA fragments. In many applications, additional constraints such as limited resources or time windows make the problem considerably harder. In the theory of computational complexity, the decision version of the TSP (where given a length L, the task is to decide whether any tour is shorter than L) belongs to the class of NP-complete problems. Thus, it is likely that the worst-case running time for any algorithm for the TSP increases exponentially with the number of cities. (Johnson and McGeoch, 1997)

One of the most important and promising research held in recent years has been Heuristics from Nature. These heuristics

utilizing analogies with natural or social systems are using to derive non-deterministic heuristic methods and obtain very good results in NP-hard combinatorial optimization problems. A heuristic is a commonsense rule (or set of rules) intended to increase the probability of solving some problems. It is a general formulation that serves to guide investigation. Considering the travelling salesman problem, it is one of the most studied discrete optimization problems. TSP has many variations and a large number of applications. (Gutin, 2005).

Traveling salesman problem (TSP) means that a travelling salesman needs to promote products in n cities (including the city where he lives). After visiting each city (each city can be visited once), he returns to the departure city. Let’s suppose that there is one road to connect each two cities. What is the best route to follow in order to minimize the distance of the journey?

TSP has been proven to be a NP-hard problem, i.e. failure of finding a polynomial time algorithm to get a optimal solution. TSP is easy to interpret, yet hard to solve. This problem has aroused many scholars interests since it was put forward in 1932. However, until now, no effective solution has been found. Though TSP only represents a problem of the shortest ring road, in actual life, many physical problems are found to be the TSP.

Example 1: Postal route; Postal route problem is a TSP. Suppose that a mail car needs to collect mails in n places. Under such circumstances, you can show the route through a drawing containing n+1 crunodes. One crunodes means a post office which this mail car departs from and returns to. The remaining n crunodes mean the crunodes at which the mails need to be collected. The route that the mail car passes through is a travelling route. We hope to find a travelling route with the shortest length.

Example 2: Mechanical arm; When a mechanical arm is used to fasten the nuts for the ready-to-assembling parts on the assembly line, this mechanical arm will move from the initial position (position where the first nut needs to be fastened) to each nut in proper order and then return to the initial position. The route which the mechanical arm follows is a travelling route in the drawing which contains crunodes as nuts; the most economical travelling route will enable the mechanical arm to finish its work within the shortest time.

Example 3: Integrated circuit; In the course of manufacturing the integrated circuit, we often need to insert thousands of electrical elements. It will consume certain energy when moving from one electrical element to the other during manufacturing. How can we arrange the manufacturing order to minimize the energy consumption? This is obviously a solution for TSP. Except for the above examples, problems like route distribution of transportation network, choice of tourist route, laying of pipelines needed for city planning and engineering construction are interlinked with the problems of finding the shortest route. So, it is of significance to make a study on the problem of the shortest route. This renders us a use value as finding a solution for TSP plays an important role in the real life, since the TSP appeared; it has attracted many scholars to make a study on it. (Yuan-bin Mo, 2010).

II. RELATED WORK

The Travelling Salesman Problem (T.S.P) The Travelling Salesman Problem (TSP) is a classical optimization problem that has intrigued mathematicians and computer scientists over the years. This problem can be describes thus: Given a finite number of cities along with the cost of travel between each

Page 3: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 141

IJOAR© 2013 http://www.ijoar.org

of them, a salesman is given the objective of finding the cheapest way of visiting all the cities before returning to the original point of departure. Therefore, a travelling salesman is required to visit N cities before returning home.

Barachet, 1957 described an enumeration scheme for computing near-optimal tours and made observation on the structure of optimal tours for geometric problems. This project also detailed a tour for a 37– city instance which was solved by hand to demonstrate the practicality of the method for small instances.

The travelling salesman problem (TSP) is one which has commanded much attention of mathematicians and computer scientists specifically because it is so easy to describe and so difficult to solve. The travelling salesman problem (TSP) is a deceptively simple combinatorial problem. It can be stated very simply:

A salesman spends his time visiting N cities (or nodes) cyclically. In one tour he visits each city just once, and finishes up where he started. In what order should he visit them to minimize the distance traveled? “Given a collection of cities, the travelling salesman must determine the shortest route that will enable him to visit each city precisely once and then return back to his starting point.”

The travelling salesman problem can be re-phrased in term of a graph. Let a graph G=(X, A) whose vertices corresponds to the towns in the salesman’s district and whose arc correspond to the roads joining two towns. Also let the length d(x, y) ≥0 of the arc (x, y) equals the distance of the corresponding joining along arc (x, y) . A cycles that includes each vertex in G at least once is called a salesman cycle. Salesman problem can be formulated on either undirected or directed graph

BASIC HEURISTICS FOR THE TSP

A straightforward way of constructing a TSP tour is by starting from an arbitrary node, traversing a minimum-cost arc to an unvisited node until all nodes have been visited, and returning to the initial node to complete the tour. This greedy algorithm is known as the nearest neighbor heuristic and has an asymptotic complexity of O(n2), where n is the number of nodes. Intuitively it will work well most of the time, but will sometimes have to add an arc with very high cost because all nodes connected to the current one by an arc with low cost have already been visited.

Instead of adding a minimum-cost arc among those adjacent to the current node, we could add an arc that has minimum cost overall, while ensuring that the resulting set of arcs will form a tour. This corresponds to ordering the arcs by increasing cost and adding them to the tour in that order, skipping arcs that would lead to a node with degree more than two or a cycle of length less than n. This so-called savings heuristic has complexity O (n2logn), which is the complexity of sorting a set with n2 elements.

Another intuitive approach is to start with a sub tour, i.e., a tour on a subset of the set of nodes, and extending it with additional nodes. Heuristics following this general approach are known as insertion heuristics. A particular heuristics of this type has to specify a way of choosing (i) the initial sub tour, (ii) the node to be inserted, and (iii) the way the new node is inserted into the sub tour.

Obvious choices for the initial sub tour are cycles of length two or three. The cheapest insertion heuristic then chooses a node, and a place to insert the node into the sub tour, in order to minimize the overall length of the resulting sub tour. The farthest insertion heuristic, on the other hand, inserts a node whose minimum distance to any node in the current sub tour is maximal.

The idea behind the latter strategy is to fix the overall layout of the tour as soon as possible. Of course, optimization does not need to end once we have constructed a tour. Rather, we could try to make a small modification to the tour in order to reduce its cost, and repeat this procedure as long as we can find such an improving modification.

An algorithm that follows this general procedure is known as local search algorithm, because it makes local modifications to a solution to obtain a new solution with a better objective value. A tour created using the nearest neighbor heuristic, for example, will usually contain a few arcs with very high cost, so we would be interested in local modifications that eliminate these arcs from the tour.

The Various Method for Solving the TSP

The following are the various methods used for solving the travelling salesman problem developed by mathematicians and scientists.

1. Shortest path algorithm 2. Genetic Algorithm 3. Simulated Annealing Algorithm 4. Christofide‘s heuristics 5. Ant Algorithm

Shortest path Algorithms

Page 4: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 142

IJOAR© 2013 http://www.ijoar.org

The shortest- paths problem involves a weighted, possibly directed graph described by the set of edges and vertices { E, V } Given a source vertex, s, the goal is to find the shortest existing path between s and any of the other vertices in the graph. Each path, therefore, will have the minimum possible sum of its component edges’ (u, v) weights (w [u, v]). The method described here is Dijkstra’s algorithm. The basic reasoning behind the Dijkstra’s algorithm is as follows: 1. The algorithm gradually creates a tree from the vertices and some of the edges in the graph; the root of this tree is the source

of the search, vertex s, as specified at the outset of the algorithm. Thus for each vertex u, we maintain a parent pointer p (u) and a distance field d (u) (the distance, of course, is measured from the source.)

2. The algorithm maintains a queue in which it keeps the vertices it has not yet examined. However, this is a priority queue, not a simple first – in – first – out queue. This priority queue is sorted using the field of the vertices.

3. Dijkstra’s algorithm maintains a solution set S, which contains all the vertices, examined so far whose minimal distance to the source has been determined. As the algorithm progresses and examines more and more vertices, this set grows.

4. At the outset, we set all parent pointers to NIL and all distance fields to infinity, except that of the source which we set to zero. Likewise, we set the solution set to empty.

5. Each vertex in the priority queue is extracted in sequence (remember, the priority queue is ordered based on the d (u) field of the vertices).

III. GENETIC ALGORITHM

Genetic algorithms are algorithms developed from the concept of genetics. In genetics, it is understood that very living being’s structure was developed from a ‘data bank’ of information (its gene, or genetic code) that controls the being’s form and type. For example, a human being’s gene contains his genetic information, which includes his skin colour, his eye hue, his teeth structure and even his brain capacity. The gene is so minute, it takes a very powerful microscope to view it, and its ‘coding’ is too complex; it took quite a while- and a whole brood of scientists years to decode it (Barachet L.L, (1957),.

From this concept of complex coding, the idea that algorithms that could handle complex problems could be developed along the lines of the genome. This is how Genetic Algorithms were born. And because genetic algorithms are a very essential and effective alternative to direct problem- solving (because they give answer faster), they have become the logical option to solving complex problems. Genetic algorithms are not well understood, and are used to solve problems that are not well understood either. They perform very well, especially in commercial aspects or areas.

There are several types of Genetic algorithms, created to handle complex problems in several fields like Mathematics, Aeronautics, and even Agriculture, but most of the algorithms have been created for solving real life complex situation problems, one of which is called the “Shortest path” problem.

The shortest path problem has many varieties, examples of which are the Routing problem, the sorting problem, the Bin-packing problem, e.tc; but the main point of each one of them is to find the shortest distance between several locations. One of them is the Travelling Salesman Problem- the focus of this project.

In genetic algorithm, each solution is evaluated to give some measure of its “fitness”. Then new population is formed by selecting the more fit individuals. Some members of new population are undergoing transformation by means of “genetic operators” to form new solution; higher order transformation (crossover type), which create new individuals by combining parts from several individuals; selection purges poor solutions form population. The resulting process tends to find globally optimal solutions to the problem much in the same way as natural populations of organisms adapt to their surrounding environments. They have been applied to various optimization problems with continuously changeable parameters (Barachet L.L, (1957).

What the genetic algorithm does is to imitate one of Nature’s highly successful techniques, which is evolution by natural selection. This method of Nature chooses the best candidate to survive in an environment, but usually happens over a million years, but when a genetic algorithm is utilized in a computer it takes minutes, or even seconds to apply. Genetic algorithms employ the following parts; A fitness function, which, in Nature, is a way of deciding if a candidate will survive long enough to produce the next generation. A computer genetic algorithm uses a fitness function to decide if a genome will survive into the next generation, and/or be involved in producing them.

One or several Mutation mechanisms, which helps in creating modified candidates in the next generation, irrespective of fitness, and usually not involving other candidates. Examples in Nature include chemical influence, or radiation. It usually creates weaker candidates from the parent candidates both in computers, and in nature, but this effect is mostly waived aside by programmers. Involved usually is some kind of Filtering mechanism which somehow selects filter candidates with a higher probability to survive to the next generation (Barachet L.L, (1957). In nature, the factors to consider in the competition for survival include the fight for territory, for food, for mates, and other scarce resources. In genetic algorithms, this aspect is a part of fitness function, but it does not mean that the less fit do not survive. Suffice it to say that the fittest are more likely to survive than the less fit, considering luck, and opportunity, among other things. The algorithm consists of the following fundamental steps

Page 5: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 143

IJOAR© 2013 http://www.ijoar.org

a) Initialization: Chromosomes are randomly created. At this point it is very important that the population is diverse otherwise the algorithm may not produce good solutions.

b) Evaluation: Each chromosome is rated how well the chromosome solves the problem at hand. A fitness value is assigned to each chromosome.

c) Selection: Fittest chromosomes are selected for propagation into the future generation based on how fit they are. d) Recombination: Individual chromosomes and pairs of chromosomes are recombined and modified and then put back in the

population.

IV. CHRISTOFIDES HEURISTICS

Most heuristics can only guarantee a feasible soluiton or a fair near optimal solution. Christofides extended one of these heuristic approaches which is known as Christofides heuristic. Complexity of this approach is O(n3). The steps are given below:

I. Build a minimal spanning tree from the set of all cities. II. Create a minimum-weight matching (MWM) on the set of nodes having an odd degree. Add the MST together with the

MWM. III. Create an Euler cycle from the combined graph, and traverse it taking shortcuts to avoid visited nodes.

Tests have shown that Christofides’s algorithm tends to place itself around 10% above the Held-Karp lower bound (Johnson & McGeoch, 2002). The Held-Karp lower bound is the common way of testing the performance of any new TSP heuristic. Held-Karp (HK) bound is actually a solution to the linear programming relaxation of the integer formulation of TSP (Johnson et.al, 1996). A HK lower bound averages about 0.8% below the optimal tour length (Johnson et al., 1996).This lower bound is the common way of testing the performance of any new TSP heuristic.

V. DESIGN OF GLOBAL NAVIGATION SATELLITE SYSTEM SURVEYING NETWORKS

A very recent and an interesting application of the mTSP, as investigated by (Saleh and Chelouah, 2004) arises in the design of global navigation satellite system (GNSS) surveying networks. A GNSS is a space-based satellite system which provides coverage for all locations worldwide and is quite crucial in real-life applications such as early warning and management for disasters, environment and agriculture monitoring, etc. The goal of surveying is to determine the geographical positions of unknown points on and above the earth using satellite equipment. These points, on which receivers are placed, are co-ordinate by a series of observation sessions. When there are multiple receivers or multiple working periods, the problem of finding the best order of sessions for the receivers can be formulated as an mTSP

VI. ADVANTAGES OF HEURISTICS METHODS

Some advantages of using heuristics are as follows: 1. These methods are simple to understand and easier to implement so this helps to save the formulation time as well as save

computer running time(speed). 2. Heuristics help in training people to be creative and come up with heuristics for other problems. 3. These methods save the programming and storage requirement on the computers as well as produce multiple solutions in less

time. (Turban, 1990)

VII. DESIGN METHODOLOGY

Several heuristics have been developed to solve this travelling salesman problem that is the problem of finding the Hamiltonian cycle (tour with minimal path). The two of this heuristics are examined in this chapter, implemented using the C# programming language of the dot- net framework,

A salesman wants to travel to N cities (he should pass by each city). How can we order the cities so that the salesman’s journey will be the shortest? The objective function to minimize here is the execution time and total distance covered by each city.

To start solving this problem; we need: 1. Configuration setting: This is the permutation of the cities from 1 to N, given in all orders. Selecting an optimal one between

these permutations is our aim. 2. Rearrangement strategy: The strategy that we will follow here is replacing sections of the path, and replacing them with

random ones to retest if this modified one is optimal or not.

Page 6: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 144

IJOAR© 2013 http://www.ijoar.org

3. The objective function (which is the aim of the minimization): This is the execution time and total distance covered by each city.

VIII. NEAREST NEIGHBOUR

The Nearest Neighbour heuristic is a simple approach for solving the Travelling Salesman Problem. To solve TSP with a

Nearest Neighbor heuristic we look at all the arcs coming out of the city (node) that have not been visited and choose the next closest city, then return to the starting city when all the other cities are visited.

The nearest neighbour algorithm is easy to implement and executes quickly, but it can sometimes miss shorter routes which are easily noticed with human insight due to its greedy nature. It may not find a feasible tour at all, even when one exists. To solve TSP using Nearest Neighbor Heuristic we can use the following steps: Step 1: Pick any starting node. Step 2: Look at all the arcs coming out of the starting node that have not been visited and choose the next closest node. Step 3: Repeat the process until all the nodes have been visited at least once. Step 4: Check and see if all nodes are visited. If so return to the starting point which gives us a tour. Step 5: Draw and write down the tour, and calculate the distance of the tour.

Suppose and as seen in Figure.1. Calculate TSP using Nearest Neighbor heuristic.

Fig 1: Network of a 4 city TSP

Step 1: Suppose we start at city A. Step 2: there are three arcs coming out of city A, first one is arc A B with distance of 3, second one is arc A C with

distance of 4 , and the third one is arc A D with distance of 7. The next closest city is the one which has the minimum total distance, which is arc A B with a distance of 3; therefore, the next closest city is B.

Step 3: Now from B, we have three arcs coming out of it. We cannot go back to A because we have already visited that city. So we have two options we can either go to city C or city D. The arc coming out of B which has the minimum distance is the next closest city; therefore B D is the next closest city with the minimum distance of 1. Now from D we cannot visit cities A and B since we have already visited those cities. Our only option is to visit city D C with distance of 10. Even though D C is the arc with the largest distance, it is our only option to choose that arc; therefore D C is the next closest city with the distance of 10.

Step 4: since we have visited all the cities, now we can finally return from city C to city A which has the distance of 4. Step 5: Tour: A B D C A

Distance of the tour: 3+1+10+4 = 18

Page 7: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 145

IJOAR© 2013 http://www.ijoar.org

Figure 2: Tour of a 4 city TSP using Nearest Neighbor H

Figure

3: Network of a 5 city TSP

Example 2: Suppose and as seen in Figure 3. Calculate TSP using Nearest Neighbor heuristic. Step 1: Suppose we start with city A. Step 2: there are four arcs coming out of city A, first one is arc A B with distance of 7, second one is arc A C with

distance of 36, and the third one is arc A D with distance of 11, and the fourth one is arc A E with distance of 9. The next closest city is B with the distance of 7.

Step 3: from city B, we have four arcs coming out. We cannot go back to A since we have already visited that city. We can either go to city C, city D, or city E. We pick city C since the next closest city from city B is C with the distance of 13.Now from C we cannot go back to city A and city B, since we have already visited those cities. Therefore, the closest city from city C is D with the distance of 8, and from D the next closest city is E with the distance of 10.

Step 4: since we have visited all the cities, now we can finally return from city E to city A which has the distance of 9. Step 5: Tour: A B C D E A Distance of tour: 7+13+8+10+9=47

Figure 4: Tour of a 4 city TSP using Nearest Neighbor Heuristic

Page 8: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 146

IJOAR© 2013 http://www.ijoar.org

YES

NO

NO

YES

Fig 5: Flow chart for Nearest Neighbour

IX. Mathematical Description for the TSP

According to the definition of the TSP, its mathematical description is as follows:

Start

Stop

Has first city been reach?

Are there any unvisited cities

left?

Select a random city.

Find the nearest unvisited city and go there.

Start

Page 9: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 147

IJOAR© 2013 http://www.ijoar.org

𝑚𝑖𝑛�𝑑𝑖𝑗 𝑥𝑖𝑗

s.t

�𝑥𝑖𝑗 = 1, i = 1,2, … . n𝑛

𝑗=1

�𝑥𝑖𝑗 = 1, j = 1,2, … . n𝑛

𝑖=1

� xij ≤/S/−1 2 ≤/S/≤ n − 2, S𝑖,𝑗∈𝑆

⊂ {1,2, … , n}

xij ∈ (0,1), 𝑖, 𝑗 = 1,2, … . .𝑛 𝑖 ≠ 𝑗 Where dij means the distance between the city i and city j; decision variable xij= 1 means the route the salesman passes through (including the route from city i and city j); xij means the route which isn’t chosen by the salesman. Objective function (2.1.1) means the minimum total distance; (2.1.2) means that a salesman only can departure from the city i for one time; (2.1.3) means that a salesman only can enter the city j for one time; (2.1.2) and (2.1.3) only give an assurance that the salesman visits each city once, but it doesn’t rule out the possibility of any loop; (2.1.4) requires that no loop in any city subset should be formed by the salesman; S means the number of elements included in the set S.

X. HEURISTIC ALGORITHMS

Heuristic Algorithms ‘heuristic’ is a Greek word which means “Serving to discover or stimulate investigation” its original form was heuriskein which meant “to discover”. In heuristics, one endeavours to understand the process of solving problems, especially the mental operation of a human problem-solver, which is most useful in this process (K. N. Krishnaswamy et al, 2009).

There are several reasons for using heuristic method for solving problem. They are as follows (Edward A. Silver et al, 1984): 1. The mathematical problem is such that analytic (closed form) or iterative solution procedure is unknown. 2. Although an exact analytic or iterative solution procedure may exist, it may be computationally prohibitive to use or it may

be unrealistic in its data requirements. This is particularly true of enumerative methods, which in theory, are often applicable where analytic and iterative procedures cannot be found.

3. The heuristic method is simpler for the decision maker to understand, hence, it markedly increases the chance of implementation.

4. For a well-defined problem that can be solved optimally, a heuristics method can be used for learning purposes. 5. In implicit enumeration approaches, a good starting solution can give a bound that drastically reduces the computational

effort; heuristics can be used to give such “good” starting point. 6. Heuristics may be used as part of an iterative procedure that guarantees the finding of an optimal solution. Two distinct

possibilities exist: i. To easily obtain an initial feasible solution.

ii. To make a decision at an intermediate step of an exact solution procedure.

XI. GRAPHICAL USER INTERFACES

The following are the results derived from the implementation and performance evaluation of the traveling sales man problem using two selected heuristics (nearest neighbor and nearest insertion). This Section shows how the travelling sales man problem was solved using two advanced programming languages. The Visual studio .NET Integrated development environment (IDE) was used to create the interface. Visual studio .NET is Microsoft’s integrated development environment (IDE) for creating, documenting, running and debugging programs written in a variety of .NET programming languages. Visual studio.NET also offers editing tools for manipulating several types of files.

Page 10: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 148

IJOAR© 2013 http://www.ijoar.org

Visual Studio.NET is a powerful and sophisticated tool for creating business-critical and mission-critical applications. The interface contains series of menus and tools used to create from which link available into several programming language are used to write simple programs.

XII. INPUT GRAPHICAL USER INTERFACE

The input interface was designed using basic programming languages (C#). This interface provides option for the heuristic, on each tab the heuristic is chosen and the starting node is selected. Then the start tour button is pushed to activate the tour through all the cities and that displays the results (which include the execution time, total distance covered and number of nodes it went through). However, the same arrangement was prepared for the programming language interfaces.

Fig 6: The C# input interface

XIII. OUTPUT GRAPHICAL USER

Page 11: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 149

IJOAR© 2013 http://www.ijoar.org

Fig 7: C# output interface for nearest neigbour

Fig 8: Visual Output Interface for Nearest Insertion

Page 12: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 150

IJOAR© 2013 http://www.ijoar.org

Table 1: Showing the varying Execution time and Total Distance for a

TSP using Nearest Neighbour Approach

SERIAL NO START NODE FINISH NODE NO OF NODES EXECUTION TIME (ms)

TOTAL DISTANCE

(km) 1 ABAKALIKI ABAKALIKI 37 81 6307 2 ABEOKUTA ABEOKUTA 37 78 7441 3 ABUJA ABUJA 37 59 7584 4 ADO-EKITI ADO-EKITI 37 75 7231 5 AKURE AKURE 37 57 8200 6 ASABA ASABA 37 84 7966 7 AKWA AKWA 37 63 8509 8 BAUCHI BAUCHI 37 85 7841 9 BENIN-CITY BENIN-CITY 37 60 8946 10 BIRNIN-KEBBI BIRNIN-KEBBI 37 75 8396 11 CALABAR CALABAR 37 63 8835 12 DAMATURU DAMATURU 37 65 7749 13 DUTSE DUTSE 37 67 8262 14 ENUGU ENUGU 37 58 8509 15 GOMBE GOMBE 37 76 7841 16 GUSAU GUSAU 37 57 8398 17 IBADAN IBADAN 37 97 8196 18 IKEJA IKEJA 37 59 7441 19 ILORIN ILORIN 37 62 7227 20 JALINGO JALINGO 37 69 7129 21 JOS JOS 37 83 7836 22 KADUNA KADUNA 37 56 7079 23 KANO KANO 37 67 7799 24 KATSINA KATSINA 37 75 7444 25 LAFIA LAFIA 37 60 7035 26 LOKOJA LOKOJA 37 70 8002 27 MADUGURI MADUGURI 37 55 6769 28 MARKURDI MARKURDI 37 62 7754 29 MINNA MINNA 37 75 6791 30 OSOGBO OSOGBO 37 58 7946 31 OWERRI OWERRI 37 63 6726 32 P-HARCOURT P-HARCOURT 37 78 7308 33 SOKOTO SOKOTO 37 65 7761 34 UMUAHIA UMUAHIA 37 80 8775 35 UYO UYO 37 69 8840 36 YENEGOA YENEGOA 37 66 7323 37 YOLA YOLA 37 77 7156

Page 13: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 151

IJOAR© 2013 http://www.ijoar.org

Table 2: Showing the varying Execution time and Total Distance for a

TSP using Nearest Insertion Approach

SERIAL NO START NODE FINISH NODE

NO OF NODES EXECUTION TIME (ms)

TOTAL DISTANCE

(km) 1 ABAKALIKI ABAKALIKI 37 109 8509 2 ABEOKUTA ABEOKUTA 37 83 7441 3 ABUJA ABUJA 37 137 8246 4 ADO-EKITI ADO-EKITI 37 83 7231 5 AKURE AKURE 37 90 8200 6 ASABA ASABA 37 76 7966 7 AKWA AKWA 37 66 8509 8 BAUCHI BAUCHI 37 68 7841 9 BENIN-CITY BENIN-CITY 37 100 8509 10 BIRNIN-KEBBI BIRNIN-KEBBI 37 79 8396 11 CALABAR CALABAR 37 48 8574 12 DAMATURU DAMATURU 37 74 7749 13 DUTSE DUTSE 37 79 8262 14 ENUGU ENUGU 37 97 8509 15 GOMBE GOMBE 37 86 7841 16 GUSAU GUSAU 37 79 8398 17 IBADAN IBADAN 37 55 7227 18 IKEJA IKEJA 37 81 7441 19 ILORIN ILORIN 37 71 7227 20 JALINGO JALINGO 37 64 7129 21 JOS JOS 37 92 7836 22 KADUNA KADUNA 37 85 8458 23 KANO KANO 37 67 7812 24 KATSINA KATSINA 37 85 7884 25 LAFIA LAFIA 37 62 8246 26 LOKOJA LOKOJA 37 53 7957 27 MADUGURI MADUGURI 37 86 7749 28 MARKURDI MARKURDI 37 72 8458 29 MINNA MINNA 37 89 8458 30 OSOGBO OSOGBO 37 45 7946 31 OWERRI OWERRI 37 86 7966 32 P-HARCOURT P-HARCOURT 37 112 7445 33 SOKOTO SOKOTO 37 58 8396 34 UMUAHIA UMUAHIA 37 71 8031 35 UYO UYO 37 68 8031 36 YENEGOA YENEGOA 37 99 7214 37 YOLA YOLA 37 57 7156

Table 3: Execution time for both Nearest Neighbour and Nearest Insertion for a TSP of six visited cities.

Page 14: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 152

IJOAR© 2013 http://www.ijoar.org

VISITED CITY EXECUTION TIME

(ms)

FOR NEAREST

NEIGHBOUR

EXECUTION TIME

(ms)

FOR NEAREST

INSERTION

ABUJA 59 137

BENIN 60 68

CALABAR 63 48

IBADAN 97 55

OSOGBO 58 45

YOLA 77 57

The table 3 above explains the execution time for the nearest neighbour method and nearest insertion method respectively for the six visited cities. For the first and second cities visited which are Abuja and Benin respectively, the execution time for the nearest neighbour was shorter compared to the execution time for the nearest insertion. Approaching the third, fourth, fifth and sixth cities visited which are Calabar, Ibadan, osogbo and yola respectively, reverse was the case as compared to the first two cities visited since the execution time for the nearest insertion method was shorter than the execution time for the nearest neighbour.

From the above table, we arrived at a ratio of 4:2; therefore the nearest insertion method will be the most preferred method for solving the travelling salesman problem since it has the shortest execution time.

Figure 9: Representing the Execution time (in ms) by the two algorithms

Table 2: Total Distance for both Nearest Neighbour and Nearest Insertion for a TSP of six visited cities.

020406080

100120140160

TIME FOR NN

TIME FOR NI

Page 15: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 153

IJOAR© 2013 http://www.ijoar.org

VISITED CITY TOTAL DISTANCE

(km) FOR NEAREST

NEIGHBOUR

TOTAL DISTANCE

(km) FOR NEAREST

INSERTION

ABUJA 7584 8246

BENIN 8946 8509

CALABAR 8835 8574

IBADAN 8196 7227

OSOGBO 7946 7946

YOLA 7156 7156

The table 4 above explains the total distance covered by the nearest neighbour method and the nearest insertion method respectively for the six visited cities. For the first city visited which is Abuja, the total distance covered by nearest neighbour is shorter compared to the total distance covered by nearest insertion. Approaching the second, third and fourth cities visited which are Benin, Calabar and Ibadan respectively, the total distance covered by nearest insertion was smaller compared to that of nearest neighbour. For the fifth and sixth cities visited which is Osogbo and Yola respectively, the total distance covered by the nearest neighbour and nearest insertion were the same.

From the above table, we arrived at a ratio of 3:1; therefore the nearest insertion method will be the most preferred method for solving the travelling salesman problem since it has the shortest total distance covered.

Figure 10: Representing the Total distance covered (in km) by the two algorithms

XIV. CONCLUSION

The travelling salesman problem can be solved within the little percent of the optimal solution by employing the two heuristics discussed in this Research work. The TSP is believed to be a combinatorial problem meaning that solutions becomes

0

2000

4000

6000

8000

10000

DISTANCE FOR NN

DISTANCE FOR NI

Page 16: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 154

IJOAR© 2013 http://www.ijoar.org

extremely large for N, so that an exhaustive search is impractical due to its exorbitant execution time, but with help of the implementation in this paper, instances can be solved within few seconds of time.

Under the nearest neighbor algorithm, each node serves as the apparent initial node for the next closet node, meaning that nodes are dependent on one another. The final result or solution can be foreseen as the salesman proceeds from one city to another and finally to the last city back to the initial city. The execution time for 37 cities instance is very small, and indeed expressed in milliseconds, which indicates that instances with very large number of cities can be solved within some minutes at most, and with limited memory requirement.

Despite all these, the nearest neighbour algorithm still has shortcoming, and the shortcoming is that it quickly yields a short tour, but usually not the optimal one. In nearest insertion algorithm, the nodes are independent of one another, and the total distance covered at last depends on the final path generated. Its execution time is slightly lesser than that of the nearest neighbour.

Both algorithms keep the solution reachable within a very short computational time. It is therefore concluded that the use of these heuristics to solve the TSP and problem related to the TSP, provides us with acceptable results that are not too far from the optimal and yet are affordable computationally.

REFERENCES

[1] Angel R.D, Caudle W.L., Noonan R. and Whiston A. (1972). ‘Computer assisted school bus Scheduling’, Management Science, Vol. 18, pg. 279-88.

[2] Barachet L.L, (1957), ‘Graphics Solution of the Travelling Salesman Problem’, The Symmetric travelling Salesman problem , Mathematical.

[3] Bellman R., (1960). ‘Combinatorial processes and dynamic programming in Combinatorial Analysis’, proceeding of symposia in Applied Mathematics 10,

American Mathematics Society, pg 217-249.

[4] Dorigo, Gambardella (1996). ‘Ant colonies for the Travelling Salesman Problem’, university Libre De Bruxelles, Belgium.

[5] Gilbert K.C, Hofstra R.B., (1992). ‘A new multiperiod multiple salesman travelling problem with Heuristics and application to a scheduling problem’,

Decision Sciences, Vol. 23, pg 250-9.

[6] Gutin G., (2005). ‘Travelling Salesman and related Problems’, Royal Holloway University of London.

[7] Johnson D.S. and Mc Geoch L.A., (1997). ‘The travelling salesman problem’, A case study in local Optimization and local search in combinatorial

optimization, pg 215 310.

[8] Johnson D.S. and Mc Geoch L.A., (2002). ‘Experimental Analysis of Heuristics for the STSP’, The Travelling Salesman Problem and its variations, Gutin,

Punnen (eds), Kluwer Academics Publishers, pg 369-443.

[10] Johnson et. al., (1996). ‘Asymptotic Experimental Analysis for the Held-Karp Travelling Salesman Bound Proceedings of the Annual ACM-SIAM

Symposium on Discretz Algorithms’, pg 341-350.

[11] Kirkpatrick et.al., (1983). ‘Optimization by Simulated Annealing Science’, Vol. 220, pg 671- 680.

[12] Lenstra, Rinnooy Kan, (1975). ‘Some Simple Application of the Travelling Salesman Problem’, Operational research Quarterly, Vol. 26, pg 717-33.

[13] Saleh H.A. and Chelouah R.,(2004). ‘The design of the global navigation satellite system surveying networks Using genetic algorithms’, Engineering

Application Intelligence, Vol. 17, pg 111-22.

[14] Svestka J.A. and Huckfeldt V.E., (1973). ‘Computational Experience with an m-salesman travelling Salesman algorithm’, Management Science, Vol.19, No.

7, pg 790-9.

Page 17: IMPLEMENTATION OF HEURISTICS FOR SOLVING …€¦ · IMPLEMENTATION OF HEURISTICS FOR SOLVING TRAVELLING SALESMAN PROBLEM USING NEAREST ... Oloruntoyin Sefiu Taiwo, ... Amao Taiwo,

International Journal of Advance Research, IJOAR .org ISSN 2320-9194 155

IJOAR© 2013 http://www.ijoar.org

[15] Turban E. (1990). ‘ Decision Support and Expert System’, Macmillan Series in Information System.

[16] Van Laarhoven P. and Aarts E.H.L., (1987). ‘Simulated Annealing: Theory and Applications, Kluwer Academics’.

[17] Yuan-bin Mo, (2010). ‘The Advantage of intelligent Algorithms for TSP’, Travelling Salesman Problem Theory and Applications, Prof. Donald Davendra

(Ed.), ISBN: 978-953-307-426-9, In Tech.

[18] Zhang T., Gruver W.A and Smith M.H., (1999). ‘Team Scheduling by genetic search’, Proceedings of the Second international conference on intelligent

processing and manufacturing of materials, Vol. 2, pg 839-44.