You are on page 1of 83

ST.

XAVIER’S COLLEGE
(Affiliated to Tribhuvan University)
Maitighar, Kathmandu

Final Year Project Report


on
“ANT COLONY OPTIMIZATION FOR SOLVING
TRAVELLING SALESMAN PROBLEM” - [CSC - 404]

Under the supervision of


“Er. Rajan Karmacharya”

Submitted by
Sanjay Paudel (TU Exam Roll No-510/066)
Suman Karki (TU Exam Roll No-518/066)
Suraj Shrestha (TU Exam Roll No-519/066)

Submitted to
ST. XAVIER’S COLLEGE
Department of Computer Science
Maitighar, Kathmandu, Nepal
October 7, 2013
Ant Colony Optimization for solving
Travelling Salesman Problem
[CSC-404]

A final year project submitted in partial fulfillment of the requirement


for the degree of Bachelor of Science in Computer Science and
Information Technology.

Submitted by:
Sanjay Paudel (TU Exam Roll No-510/066)
Suman Karki (TU Exam Roll No-518/066)
Suraj Shrestha (TU Exam Roll No-519/066)

Submitted to:
ST. XAVIER’S College
Department of Computer Science
Maitighar, Kathmandu
Nepal

October 7, 2013
CERTIFICATE OF APPROVAL
The undersigned certify that they have read and recommended to the Department of
Computer Science for acceptance, a project report entitled “Ant Colony Optimization
for solving Travelling Salesman Problem” submitted by Sanjay Paudel, Suman
Karki and Suraj Shrestha in partial fulfillment for the degree of Bachelor of Science
in Computer Science & Information Technology.

…………………………..

Er. Rajan Karmacharya


Supervisor
Department Of Computer Science
St. Xavier’s College, Maitighar, Kathmandu, Nepal

……………………………..

External Examiner
Department Of Computer Science
Tribhuvan University

……………………………..

Vishnu Kumar Rana


Head of Department
Department Of Computer Science
St. Xavier’s College, Maitighar, Kathmandu, Nepal

i
ACKNOWLEDGEMENT

The success and final outcome of this project required a lot of guidance and assistance
from many people and we are very fortunate to have got this all along the completion
of this project. We are very glad to express our deepest sense of gratitude and sincere
thanks to our highly respected and esteemed supervisor Er. Rajan Karmacharya for
his valuable supervision, guidance, encouragement and support for completing this
work. His useful suggestions for this whole work and co-operative behavior are
sincerely acknowledged.

We would like to express our sincere thanks to our Head of Department Mr. Vishnu
Kumar Rana, for giving us an opportunity to undertake this project being a subject
teacher as well as for guiding us to achieve our ultimate goal on behalf of Head of
Department. His inspiration and helpful guidance has made this project successful.

We are also grateful to our teachers Mr. Jeetendra Manandhar, Miss Shova
Shrestha, Mr. Bal Krishna Subedi, Mr. Sanjay Kumar Yadav for their constant
support and guidance. As well lab’s technicians Mr. Om Shrestha and Mr. Sunim
Shrestha for assisting us and providing required lab and other necessity throughout our
project duration. We would also like to thank Mr. Chiranjivi Sitaula to assist us and
supporting us in need.

At the end we would like to express our sincere thanks to all our friends and others who
helped us directly or indirectly during this project work.

Sanjay Paudel (TU Exam Roll No-510/066)


Suman Karki (TU Exam Roll No-518/066)
Suraj Shrestha (TU Exam Roll No-519/066)

ii
ABSTRACT
The travelling salesman problem is one of the most important combinatorial problems
and a NP-hard problem whose challenge is to complete Hamilton circle selecting the
shortest path without leaving any cities behind.

Nature is the solution to every problem and creatures are the actor. In ant colony, real
ants are able to create successively shorter feasible tours to their food, by using
information accumulated in the form of a pheromone trail deposited on their path. The
intelligence of the colony arises from indirect communication between individual ants
through pheromones in getting food with shorter path. ACO is a heuristic algorithm
which has been proven a successful technique and applied to a number of combinatorial
optimization problems where real ants are represented by the artificial ant. These
artificial ants are placed at random points, which spread pheromone on their travelling
route and with use of information of pheromone on their path, they find the shortest
path.

Among different algorithms of ACO, Ant System and Ant Colony System are the most
used algorithm in solving TSP, which uses probability calculation and global
pheromone update. Here in our project also we researched on the ACO, and adopt it to
solve the TSP problem. The simulation results show how this ACO algorithm is able
to solve TSP with varying city numbers.

We have selected the C# as programming language and Visual Studio as our platform
and for designing the application of our project. For user friendly, we have designed
the graphical user interface that can take input either map image or the manual input of
the nodes. User can enter the required parameter value as desired and save the generated
output either on local directory. Our project’s application can be used to determine the
optimal path for the other development project like road construction, water
distribution, network routing, etc.

iii
Table of Contents

Contents Page Number


ACKNOWLEDGEMENT ............................................................................................ ii
ABSTRACT ................................................................................................................. iii
A. List of Figures ...................................................................................................... vii
B. List of Tables ...................................................................................................... viii
C. List of Symbols ..................................................................................................... ix
D. List of Abbreviation............................................................................................... x
Chapter 1: Project Overview ......................................................................................... 1
1.1 Introduction ............................................................................................................. 1
1.1.1 Ant’s foraging behavior .......................................................................... 2
1.1.2 Problem Statement .................................................................................. 3
1.1.3 Travelling salesman problem .................................................................. 4
1.1.4 Ant Colony Optimization........................................................................ 6
1.1.5 Why ACO?.............................................................................................. 8
1.1.6 Why to use ACO for TSP?...................................................................... 8
1.2 Scope .............................................................................................................. 9
1.3 Objectives ....................................................................................................... 9
1.4 Project features ............................................................................................. 10
1.5 Feasibility ..................................................................................................... 10
1.5.1 Technology and system feasibility........................................................ 10
1.5.1.1 Why Visual Studio platform and Visual C#? .................................... 11
1.5.2 Legal feasibility .................................................................................... 11
1.5.3 Operational feasibility........................................................................... 11
1.5.4 Schedule feasibility ............................................................................... 12
1.6 System requirements .................................................................................... 12
Chapter 2: Literature Review ...................................................................................... 13
2.1 Double bridge experiments .......................................................................... 16

iv
2.2 Problems in Artificial Intelligence related to Travelling Salesman Problem18
2.3 Algorithms of ACO ...................................................................................... 19
2.3.1 Ant System ............................................................................................ 19
2.3.2 Ant Colony System ............................................................................... 20
2.4 Comparison of computational time of ACO with other algorithms ............. 22
Chapter 3: System Development ................................................................................ 23
3.1 Method ......................................................................................................... 23
3.1.1 Digital Representation of ant ................................................................ 24
3.1.2 General technique ................................................................................. 25
3.1.3 Tour Construction ................................................................................. 25
3.1.3.1 Role of α and β .................................................................................. 26
3.1.4 Pheromone updating and evaporation ................................................... 26
3.1.5 Constants ............................................................................................... 27
3.2 Design........................................................................................................... 28
3.2.1 Data Structures ...................................................................................... 28
3.2.1.1 Problem and Data Representation ..................................................... 28
3.2.1.2 Ant representation ............................................................................. 29
3.2.2 The Algorithm ....................................................................................... 31
3.2.2.1 Data Initialization .............................................................................. 34
3.2.2.2 Construct Solution and Update Statistics .......................................... 35
3.2.2.3 Probability Calculation ...................................................................... 38
3.2.2.4 Tour Length Calculation ................................................................... 41
3.2.2.5 Pheromone update ............................................................................. 41
3.2.2.6 Program Termination ........................................................................ 43
3.3 Development ................................................................................................ 44
3.3.1 Program Structure ................................................................................. 44
3.3.2 Interface of program ............................................................................. 46
3.4 Testing .......................................................................................................... 48
3.4.1 Unit testing ............................................................................................ 48

v
3.4.2 Integration testing ................................................................................. 49
3.4.3 System testing ....................................................................................... 49
3.5 Validation ..................................................................................................... 50
Chapter 4: Epilogue .................................................................................................... 51
4.1 Result............................................................................................................ 51
4.2 Result Analysis ............................................................................................. 53
4.3 Critical Analysis ........................................................................................... 55
4.4 Limitation ..................................................................................................... 59
4.5 Future enhancement ..................................................................................... 59
4.6 Conclusion.................................................................................................... 59
References ................................................................................................................... 60
Bibliography ............................................................................................................... 62
Appendices .................................................................................................................. 64
A. Time Schedule ................................................................................................. 64
B. Gantt Chart ....................................................................................................... 65
C. Source Code ..................................................................................................... 66

vi
A. List of Figures

Figure Name Page Number

Figure 1-1: Ant's foraging behavior 2


Figure 2-1: Experimental Setup for double bridge experiment 16
Figure 3-1: Flow chart of system design 33
Figure 3-2: Program Flow Diagram 45
Figure 3-3: Snapshot for startup form 46
Figure 3-4: Snapshot after point selection 47
Figure 3-5: Snapshot showing the optimal path 48
Figure 3-6: Validating Program 50
Figure 4-1: City selection 51
Figure 4-2: Result obtained showing optimal path 52
Figure 4-3: Graph showing computational time and number of cities 54
Figure 4-4: Graph showing straight connection in between cities 58

vii
B. List of Tables

Table Table Name Page Number

Table 1: Comparison of ACO with other algorithms 22


Table 2: Value of Constants 27
Table 3: Result showing computational time 53

viii
C. List of Symbols

n Number of cities

m Number of ants

α Relative influence of the pheromone trail

β Heuristic information

τ Pheromone value

ρ Cut-rate factor of deposited pheromone

η Heuristic visibility

ix
D. List of Abbreviation

ACO Ant Colony Optimization

ACS Ant Colony System

AI Artificial Intelligence

AS Ant System

CLR Common Language Runtime

CO Combinational Optimization

CPU Central Processing Unit

EN Elastic Net

FI Farthest Insertion

GPU Graphical Processing Unit

JSP Job-shop Scheduling Problem

OS Operating System

QAP Quadratic Assignment Problem

SA Simulated Annealing

SO Self-Organization

SOM Self-Organizing Map

TSP Travelling Salesman Problem

VRP Vehicle Routing Problem

x
Chapter 1: Project Overview

1.1 Introduction

Ants exhibit complex social behaviors that have long since attracted the attention of
human beings. Ant is a kind of animal which is puny and almost has no eyesight, but it
can achieve very complex action when ants are communal, which can not only transport
the food number of times larger than the ant in volume and weight to the ant hold, but
also can find the shortest path between food and ant hole.

The individual agents are not able to solve the problem by themselves, but a solution
emerges from the cooperative behavior of all associated individuals. Ants may not be
very clever individual, but ant colonies can be. Individual insects living in colonies,
such as ants, bees or wasps do their own specific task and yet the colony is very
organized, it does not require any kind of supervision. This is called self-organization
(SO).The mechanism that allows the SO in insect colonies is the stigmergy (mechanism
of indirect coordination between agents), which consists of the indirect communication
between pairs of individuals through the change of some environment property; in the
ant colonies case, this property is the pheromone concentration. [1]

The ants release chemicals known as pheromone on the ground while walking from
their nest to food and then go back to the nest. Ants can communicate with one another
through pheromones in their immediate environment. The ants move according to the
amount of pheromones, the richer the pheromone trail on a path is, the more likely it
would be followed by other ants. So a shorter path has a higher amount of pheromone
in probability, ants will tend to choose a shorter path. Through this mechanism, ants
will eventually find the shortest path.

1
1.1.1 Ant’s foraging behavior

When an ant is searching for the nearest food source and arrives at several possible
trails, it tends to choose the trail with the largest concentration of pheromones, with a
certain probability. After choosing the trail, it deposits another pheromone, increasing
the concentration of pheromones in this trail. The ants return to the nest using always
the same path, depositing another portion of pheromone in the way back. Imagine then,
that two ants at the same location choose two different trails at the same time.

The pheromone concentration on the shortest way will increase faster than the other:
the ant that chooses this way, will deposit more pheromone in a smaller period of time,
because it returns earlier. If a whole colony of thousands of ants follows this behavior,
soon the concentration of pheromone on the shortest path will be much higher than the
concentration in other paths. Then the probability of choosing any other way will be
very small and only very few ants among the colony will fail to follow the shortest
path.

Figure 0-1: Ant's foraging behavior

2
(A) Real ants follow a path between nest and food source. (B) An obstacle appears on
the path: Ants choose whether to turn left or right with equal probability. (C)
Pheromone is deposited more quickly on the shorter path. (D) All ants have chosen the
shorter path.

(Source: Marco Dorigo, Ant colonies for the traveling salesman problem,
TR/IRIDIA/1996-3Université Libre de Bruxelles Belgium pg: 3)

There is another phenomenon related with the pheromone concentration. Since it is a


chemical substance, it tends to evaporate, so the concentration of pheromones vanishes
along the time. In this way, the concentration of the less used paths will be much lower
than that of the most used ones, not only because the concentration increases on the
other paths, but also because its own concentration decreases [1].

By sensing pheromone trails foragers can follow the path to food discovered by other
ants. This collective trail-laying and trail-following behavior whereby an ant is
influenced by a chemical trail left by other ants is the inspiring source of ACO. [2]

1.1.2 Problem Statement


In the field of computer science all the problems are defined under the NP class
problem. The class NP is the set of problems that can be solved by a non-deterministic
Turing machine that can be solved in polynomial time. These problems have the
solution on non-polynomial time. The processing time for those problems takes infinite
time to execute in compare to those class p problems. P-Class problem is the subset of
NP-class problems. That means NP contains many problem not in P. The best example
for this is TSP problem.

In real world experience time is most crucial factor to get every development work
optimal. And with time the complexity in doing such work is also a great problem.
Development work like vehicle routing, networking, water distribution, etc. are lacking

3
the proper analysis before their implementation on due to which more resources with
time acquired. TSP problem represent such real world problem regarding its
importance in real life our project is based on solving the TSP problem.

1.1.3 Travelling salesman problem


Traveling salesman problem is one of the well-known and extensively studied problems
in discrete or combinational optimization and asks for the shortest round trip of minimal
total cost visiting each given city exactly once. TSP is an NP-hard problem and it is so
easy to describe but so difficult to solve. [3] The class NP contains all decision
problems that are decidable by a non-deterministic algorithm that runs in polynomial
time. A problem n is NP-hard if a polynomial-time algorithm for n would imply a
polynomial-time algorithm for every problem in NP. In other words: n is NP-hard- if n
can be solved in polynomial time. [4]

Intuitively, the TSP is the problem of a salesman who, starting from his hometown,
wants to find a shortest tour that takes him through a given set of customer cities and
then back home, visiting each customer city exactly once. More formally, the TSP can
be represented by a complete weighted graph G = (N, A) with N being the set of nodes
representing the cities, and A being the set of arcs. (Note that if the graph is not
complete, one can always add arcs to obtain a new, complete graph G with exactly the
same optimal solutions as G; this can be achieved by assigning to the additional arcs
weights that are large enough to guarantee that they will not be used in any optimal
solution.) Each arc (i, j) ε A is assigned a value (length) dij, which is the distance
between cities i and j, with i, j ε N. Then the goal of TSP is to find the shortest path that
could be used to visit every city and then return back to the starting city with minimum
cost. In the general case of the asymmetric TSP, the distance between a pair of nodes
i, j is dependent on the direction of traversing the arc, that is, there is at least one arc (i,
j) for which dij≠dji. For any two points i and j, with (xi, yi) and (xj, yj), their distance is
calculated by the given equation (1.1).

4
2 2
𝑑𝑖 𝑗 = √(𝑥𝑖 − 𝑥𝑗 ) + (𝑦𝑖 − 𝑦𝑗 ) …………. (1.1)

In the symmetric TSP, dij =dji holds for all the arcs in A. The goal in the TSP is to find
a minimum length Hamiltonian circuit of the graph, where a Hamiltonian circuit is a
closed path visiting each of the n = |N| nodes of G exactly once. Thus, an optimal
solution to the TSP is a permutation p of the node indices (1, 2 . . . n) such that the
length 𝑓(𝜋) is minimal, where 𝑓(𝜋)is given by

𝑓(𝜋) = ∑𝑛−1
𝑖=1 𝑑𝜋(𝑖)𝜋(𝑖+1) + 𝑑𝜋(𝑛)𝜋(1) …………. (1.2)

TSP consists of finding the shortest route in complete weighted graph G with n nodes
and n (n-1) edges; so that the start node and the end node are identical and all other
nodes in this tour are visited exactly once. The most popular practical application of
TSP are: regular distribution of goods or resources, finding of the shortest of costumer
servicing route, planning bus lines etc., but also in the areas that have nothing to do
with travel routes. [5]

The TSP problem belongs in the class of combinatorial optimization problems known
as NP-complete. Specifically, if one can find an efficient algorithm (i.e., an algorithm
that will be guaranteed to find the optimal solution in a polynomial number of steps)
for the traveling salesman problem, then efficient algorithms could be found for all
other problems in the NP-complete class [6].Unfortunately, the TSP is a very difficult
problem. A brute force approach to a TSP of n cities would have a computational
complexity of

(𝑛−1)!
…………. (1.3)
2

However, Ant Colony Optimization is taken as one of the high performance computing
methods for TSP. [7]

5
1.1.4 Ant Colony Optimization

Ant Colony Optimization (ACO) is the only algorithm that implements the foraging
behavior of the ants. ACO is a paradigm for designing meta-heuristic algorithms for
combinatorial optimization problems. This algorithm is a member of the ant colony
algorithms family, in swarm intelligence methods, and it constitutes some
metaheuristic optimizations. Metaheuristic algorithms are algorithms which, in order
to escape from local optima, drive some basic heuristic: either a constructive heuristic
starting from a null solution and adding elements to build a good complete one, or a
local search heuristic starting from a complete solution and iteratively modifying some
of its elements in order to achieve a better one. The metaheuristic part permits the low-
level heuristic to obtain solutions better than those it could have achieved alone, even
if iterated. Usually, the controlling mechanism is achieved either by constraining or by
randomizing the set of local neighbor solutions to consider in local search (as is the
case of simulated annealing or tabu search), or by combining elements taken by
different solutions (as is the case of evolution strategies and genetic or bionomic
algorithms). [8]

Initially proposed by Marco Dorigo in 1992 in his PhD thesis, the first algorithm was
aiming to search for an optimal path in a graph, based on the behavior of ants seeking
a path between their colony and a source of food. And, since then, many diverse
variants of the basic principle have been reported in the literature [2]. The essential trait
of ACO algorithms is the combination of a priori information about the structure of a
promising solution with a posteriori information about the structure of previously
obtained good solutions.

This algorithm is inspired by the fact that ants are able to find the shortest route between
their nest and a food source, even though they are almost blind. This is accomplished
by using pheromone chemical trails as a form of indirect communication. Ants deposit
pheromone trails whenever they travel. The path taken by individual ants from the nest

6
in search for a food source is essentially random ~Dorigo et al. 1996. However, when
many ants are searching for a food source simultaneously, the paths taken are affected
by the pheromone trails laid by other ants. When ants encounter pheromone trails, there
is a higher probability that trails with higher pheromone intensities will be chosen. As
more ants travel on paths with higher pheromone intensities, the pheromone on these
paths builds up further, making it more likely to be chosen by other ants .[9]

Thus, after starting with the random path that might be/might not be shortest path, they
end up with the optimal path to reach their colony from their food and vice – versa.

7
1.1.5 Why ACO?

ACO has a number of advantages, for which it has been used in different fields. Some
of them are given below:

 Inherent parallelism
 Positive feedback accounts for rapid discovery of good solution
 Efficient for travelling salesman problem and similar problems
 Can be used in dynamic applications where it can adapt to changes like new
distance, etc.

1.1.6 Why to use ACO for TSP?

There are numerous reasons for the choice of the TSP as the problem to explain the
working of ACO algorithms:

 TSP is an important NP-hard optimization problem that arises in several


applications;
 TSP is a problem to which ACO algorithms are easily applied;
 TSP is easily understandable, so that the algorithm behavior is not obscured by
too many technicalities;
 TSP is a standard test bed for new algorithmic ideas - a good performance on
the TSP is often taken as a proof of their usefulness.

Additionally, the history of ACO shows that very often the most efficient ACO
algorithms for the TSP were also found to be among the most efficient ones for a wide
variety of other problems.

8
1.2 Scope

The research on ACO doesn’t just limit on development of certain application in spite
it is very vast and require to make more efficient. After the development of the ACO
algorithm the concept of this algorithm can be implemented in the various aspects. As
similar to search algorithm, it can be used to trace the various database server. Beside
this there are more real world areas where ACO concept can be implemented like water
distribution in city, Data mining, network routing, travelling salesman problem,
comparison in searching algorithm, robot path planning, etc. Regarding the wide scope
and even helpful to day to day life this project will add some more milestone on the
development of the country.

This project has certain scope to solve TSP problem and implement that algorithm in
the development procedure like road construction for road development department
and optimal path finding for any circumstances like water distribution, electricity
wiring, etc. inside our country for the development.

1.3 Objectives

The main objectives of our project are listed below:

1. To develop computer programs that can solve TSP with the use of ACO
algorithm.
2. To compare ACO algorithm that addresses and solves TSP with other
algorithms that are capable of solving TSP.
3. To analysis the data and generate report for ACO and TSP.

9
1.4 Project features

Our project is based on ACO to solve the TSP problem using AS algorithm. Here using
the probability and pheromone update we have succeeded to generalize the TSP
problem. With detailed research we have implement the ACO in real application. Using
our project development project work like road mapping, drinking water distribution
planning can be implemented inside the country with optimal path of selection. Our
project helps for the projection of the optimal path through which with minimum
expenses and time also other development project can be done in accordance.

Studying the current system feasibility our application has been developed in .net
framework depended system like Microsoft windows XP, windows 7, using Visual
C# programming language. It can be executed in every Microsoft OS dependent
machine. Our project is the windows form based application. In spite of better user
interface, it also uses map coordinates as input which may be either points selected
through random drawing or selected from a browsed map which dynamically get into
program and gives result after the various calculation and manipulation rounds in the
form of map with highlighted selected optimal path.

1.5 Feasibility

With detailed research and analyzing the necessity of TSP solution in the country
development aspect we had proposed this project. .Our application is feasible in the
following factors:

1.5.1 Technology and system feasibility

Our application is built in Visual Studio 2012 platform using Visual C# programming
language and can run in every Microsoft OS products later from windows XP having
.net framework version greater than 3.5.It’s very reliable and can perform even in lower

10
processor like pentium4 but its execution get a little slow with that because of less
number of core processor. Talking about the input data, user can just browse their map
or other pictures and select required points as cities. Our product is more feasible and
can run efficiently with current available any system.

1.5.1.1 Why Visual Studio platform and Visual C#?


The main advantage of C# is that it runs on the CLR, making it easy to integrate with
components written in other languages (specifically, CLR-compatible languages) and
many of Microsoft's proprietary technologies. Also note that much of .NET has been
standardized, which means that it could run on other platforms.

Writing in C# also gives one access to all the .NET Framework class libraries, which
are quite extensive. While these libraries might support specific features better than in
Java (WPF is arguably better suited for rich multimedia GUIs than java.Swing), on the
whole Java SDK's feature set if very similar to the .NET Framework and one can't say
one is better than the other in general.

1.5.2 Legal feasibility

This application will not violate any rules and regulation. Whatever the formulas and
measures were researched and used are noted with references of their paper published
and author names. Also this project will not violate copyright act because with full
description of references we have documented each and every minor parts thinking
sensitively. And in regards of codes, they are coded by our team members and the
copyright solely goes to our team member only.

1.5.3 Operational feasibility

As we have already mentioned about the technical feasibility, there is no errors and
bugs are found during our runtime procedure as well this application solves even TSP

11
problem with more than 100 nodes with assigned value of ants but that may take long
enough time for calculation and manipulation.

This project and application has wide space of scope so whatever are described above
this product can adequately solve every development works if applied with intelligence
conscience.

1.5.4 Schedule feasibility

We had given the period of this whole semester to fulfill the proposed project so now
we think we had successfully accomplished the project with proposed time schedule
though there were certain activity risk occurred in between they are represented in Time
Schedule and Gantt chart as final schedule of our project in appendix A and B.

1.6 System requirements

The minimum system requirements of the project are:

 Platform: .net framework version 3 or greater.


 Operating System: OS later from Microsoft XP, Microsoft products.
 Processors: Pentium 4 or any greater processor.
 Ram: 512 MB minimum
 Display: Graphical over 64mb

12
Chapter 2: Literature Review

In the history of the ACO, First of all, the first ACO system was introduced by Marco
Dorigo in his Ph.D. thesis (1992), and was called Ant System. AS is the result of a
research on computational intelligence approaches to combinatorial optimization that
Dorigo conducted at Politecnico di Milano in collaboration with Alberto Colorni and
Vittorio Maniezzo. AS was initially applied to the travelling salesman problem, and to
the quadratic assignment problem. Alberto Colorni and Vittorio Maniezzo contributed
at the beginning. Alberto and Vittorio collaborated closely with Marco Dorigo in the
definition of the first ACO algorithms while Marco was a doctoral student at
Politecnico di Milano, in Milan, Italy. Marco Dorigo (born 26 August 1961, in Milan,
Italy) is a research director for the Belgian Funds for Scientific Research (FNRS), a
professor in the computer science department of the University of Paderborn and a co-
director of IRIDIA, the artificial intelligence lab of the Université Libre de Bruxelles.
He is the proponent of the ant colony optimization metaheuristic , and one of the
founders of the swarm intelligence research field. Recently he got involved with
research in swarm robotics.

Jean-Louis Deneubourg and Luca Maria Gambardella, recognized experts in the study
of social insects, provided the inspiration for the ACO work. Luca, a computer scientist
with a strong feeling for practical applications, was the one who most helped in
transforming ACO from a fascinating toy into a competitive metaheuristic[2].Since
then ACO has been weapons to solve many major problems like Routing Problems,
Assignment Problems, Scheduling Problems, Subset Problems, Other NP-Hard
Problems, Machine Learning Problems, etc.

Blum & Dorigo (2003, 2004) experimentally and theoretically studied the behavior of
AS applied to unconstrained binary problems, that is, binary problems for which the
values of different decision variables are independent of each other. They were able to

13
prove that, in this setting, the expected quality of the solutions generated by AS
increases monotonically over time. Although their result cannot be transferred to the
application of AS to constrained problems, in Blum & Dorigo (2003) they give
empirical evidence that it holds for one of the most studied constrained problems: the
TSP. In 2003, Marco Dorigo received the European Commission's Marie Curie
Excellence Award for his research on Ant Colony Optimization and Ant Algorithms.

In recent years, many research works have been devoted to ant colony optimization
(ACO) techniques in different areas. It is a relatively novel meta-heuristic technique
and has been successfully used in many applications especially problems in
combinatorial optimization. ACO has been widely applied to solving various
combinatorial optimization problems such as Traveling Salesman Problem (TSP), Job-
shop Scheduling Problem (JSP), Vehicle Routing Problem (VRP), Quadratic
Assignment Problem (QAP), etc. [3]

Conferences happened till now on ACO:

 IEEE Swarm Intelligence Symposium 2013, Singapore, 16.-19. April 2013.


 ANTS 2012: Eighth International Conference on Ant Colony Optimization and
Swarm Intelligence, Brussels, Belgium, 12.-14. September 2012.
 ANTS 2010: Seventh International Conference on Ant Colony Optimization
and Swarm Intelligence, Brussels, Belgium, 08.-10. September 2010.
 ANTS 2008: Sixth International Conference on Ant Colony Optimization and
Swarm Intelligence, Brussels, Belgium, 22.-24. September 2008.
 IEEE Swarm Intelligence Symposium 2007, Hilton Hawaiian Village,
Honolulu, Hawaii, April 1-5, 2007.
 ANTS 2006: Fifth International Workshop on Ant Colony Optimization and
Swarm Intelligence, Brussels, Belgium, 4.-7. September 2006.
 IEEE Swarm Intelligence Symposium 2006, Indianapolis, Indiana, USA, 12.-
14. May 2006.

14
 ACO/Swarm Intelligence Track at GECCO 2005 Washington D.C., USA, June
25-29, 2005
 IEEE 2005: Swarm Intelligence Symposium, The Westin Pasadena, Pasadena,
California, USA, June 8-10, 2005.
 ANTS 2004: Fourth International Workshop on Ant Colony Optimization and
Swarm Intelligence, Brussels, Belgium, 5.-8. September 2004.
 ANTS 2002 - From Ant Colonies to Artificial Ants: Third International
Workshop on Ant Algorithms, Brussels, Belgium, 11.-14. September 2002.
 Special ACO session at MIC-2001 Porto, Portugal, July 16-20, 2001.
 ACO special track at GECCO-2001 San Francisco, USA, July 7-11, 2001.
 ANTS'2000 - From Ant Colonies to Artificial Ants: Second International
Workshop on Ant Algorithms, Brussels, Belgium, September 8-9, 2000.
 Ant Colony Methods Session at 1999 Congress on Evolutionary Computation,
 Washington DC, USA, July 6-9, 1999
 ANTS'98 - From Ant Colonies to Artificial Ants: First International Workshop
on Ant Colony Optimization, Brussels, Belgium, October 15-16, 1998.
 Ant Colony Optimization Session at INFORMS Tel Aviv 1998
 Tel Aviv, Israel, June 28 - July 1, 1998

(Source:aco-metaheuristic.org)

15
2.1 Double bridge experiments

The foraging behavior of many ant species, as, for example, I. humilis (Goss et al.,
1989), Linepithemahumile, and Lasiusniger (Bonabeau et al., 1997), is based on
indirect communication mediated by pheromones. While walking from food sources to
the nest and vice versa, ants deposit pheromones on the ground, forming in this waya
pheromone trail. Ants can smell the pheromone and they tend to choose,
probabilistically, paths marked by strong pheromone concentrations. The pheromone
trail-laying and -following behavior of some ant species has been investigated in
controlled experiments by several researchers. One particularly brilliant experiment
was designed and run by Deneubourg and colleagues (Deneubourg, Aron, Goss,
&Pasteels, 1990; Goss et al., 1989), who used a double bridge connecting a nest of ants
of the Argentine ant species I. humilis and a food source. They ran experiments varying
the ratio r =1, ll=ls between the length of the two branches of the double bridge, where
ll was the length of the longer branch and ls the length of the shorter one.

Figure 1-1: Experimental Setup for double bridge experiment

(a) Branches have equal length. (b) Branches have different length.

(source:Marco Dorigo and Thomas Stutzle, Ant Colony Optimization,pg:3)

16
In the first experiment the bridge had two branches of equal length (r=1, in figure
2.1(a)). At the start, ants were left free to move between the nest and the food source
and the percentage of ants that chose one or the other of the two branches were observed
over time. The outcome was that see figure 2.1(a), although in the initial phase random
choices occurred, eventually all the ants used the same branch. This result can be
explained as follows. When a trial starts there is no pheromone on the two branches.
Hence, the ants do not have a preference and they select with the same probability any
of the branches. Yet, because of random fluctuations, a few more ants will select one
branch over the other. Because ants deposit pheromone while walking, a larger number
of ants on a branch results in a larger amount of pheromone on that branch; this larger
amount of pheromone in turn stimulates more ants to choose that branch again, and so
on until finally the ants converge to one single path.

This autocatalytic or positive feedback process is, in fact, an example of a self-


organizing behavior of the ants: a macroscopic pattern (corresponding to the
convergence toward one branch) emerges out of processes and interactions taking place
at a ‘‘microscopic’’ level (Camazine, Deneubourg, Franks, Sneyd, Theraulaz, &
Bonabeau, 2001; Haken, 1983; Nicolis& Prigogine, 1977). In our case the convergence
of the ants’ paths to one branch represents the macroscopic collective behavior, which
can be explained by the microscopic activity of the ants, that is, by thelocal interactions
among the individuals of the colony. It is also an example of stigmergic
communication; ants coordinate their activities, exploiting indirect communication
mediated by modifications of the environment in which they move.

In the second experiment, the length ratio between the two branches was set to r = 2
(Goss et al., 1989), so that the long branch was twice as long as the short one(figure
2.1(b) shows the experimental setup). In this case, in most of the trials, after some time
all the ants chose to use only the short branch (in figure 2.1(b)). As in the first
experiment, ants leave the nest to explore the environment and arrive at a decision point
where they have to choose one of the two branches. Because the two branches initially

17
appear identical to the ants, they choose randomly. Therefore, it can be expected that,
on average, half of the ants choose the short branch and the other half the Long Branch,
although stochastic oscillations may occasionally favor one branch over the other.

However, this experimental setup presents a remarkable difference with respect to the
previous one: because one branch is shorter than the other (in figure 2.1(b)), the ants
choosing the short branch are the first to reach the food and to start their return to the
nest. But then, when they must make a decision between the short and the Long Branch,
the higher level of pheromone on the short branch will bias their decision in its favor.
Therefore, pheromone starts to accumulate faster on the short branch, which will
eventually be used by all the ants because of the autocatalytic process described
previously. When compared to the experiment with the two branches of equal length,
the influence of initial random fluctuations is much reduced, and stigmergy,
autocatalysis, and differential path length are the main mechanisms at work.
Interestingly, it can be observed that, even when the Long Branch is twice as long as
the short one, not all the ants use the short branch, but a small percentage may take the
longer one. This may be interpreted as a type of ‘‘path exploration’’ [2].

2.2 Problems in Artificial Intelligence related to Travelling


Salesman Problem
TSP could be used in the ordering of genes on a chromosome (Gunnels et al. 1994),
problems in cryptanalysis, such as the discovery of a key of a simple substitution cipher
(Spillmann et al. 1993), or breaking of transportation ciphers in cryptographic system
(Matthews 1993). In addition work carried out on systems identification, specifically
those related with the induction of stochastic models, could benefit on the information
about the genetic operators.Likewise, on the topic of Bayesian networks, a problem of
evidence propagation according to Lauritzen and Spiegelhalter’s algorithm (1988), can
used in searching of the optimal order of elimination of vertexes that cause
triangularization of moral graph associated to the Bayesian network. Optimality is
defined according to the weight of the triangulated graph (Larranaga et al. 1990).

18
Another classic problem in statistics, called Cluster Analysis, which consists of
obtaining the optimal classification of a set of individuals characterized by any number
of variables. [10]

2.3 Algorithms of ACO

2.3.1 Ant System

Ant System is the first ACO algorithm proposed in the literature. Initially, each ant is
randomly put on a city. During the construction of a feasible solution, ants select the
following city to be visited through a probabilistic decision rule. When an ant k states
in city i and constructs the partial solution, the probability moving to the next city j
neighboring on city i is given by following equation.

𝛼 𝛽
[𝜏𝑖𝑗 (𝑡)] [𝜂𝑖𝑗 ]
𝑘
𝑝𝑖𝑗 (𝑡) = { 𝛼
∑𝑢𝜖𝑗 [𝜏𝑖𝑗 (𝑡)] [𝜂𝑖𝑗 ]
𝛽
𝑖𝑓 𝑗𝜖𝑗𝑘 (𝑖) …………. (2.1)
𝑘
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

where 𝜏𝑖 𝑗 is the intensity of trails between edge (i, j) and 𝜂𝑖𝑗 is the heuristic visibility
of edge (i, j), and 𝜂𝑖𝑗 =1/𝑑𝑖𝑗 . 𝑗𝑘 (i) is a set of cities which remain to be visited when the
ant is at city i. α and β are two adjustable positive parameters that control the relative
weights of the pheromone trail and of the heuristic visibility. After each ant completes
its tour, the pheromone amount on each path will be adjusted with equation (2.2).

𝑘
𝜏𝑖 𝑗 (𝑡 + 1) ← (1 − 𝜌) ∙ 𝜏𝑖 𝑗(𝑡) + ∑𝑚
𝑘=1 ∆𝜏𝑖 𝑗 (𝑡) …………. (2.2)

𝑄
∆𝜏𝑖𝑘𝑗 ={ 𝐿𝑘 if ant 𝑘 used edge (𝑖, 𝑗)in its tour…………. (2.3)
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

19
(1- ρ) is the pheromone decay parameter (0<ρ<1) where it represents the trail
evaporation when the ant chooses a city and decide to move and𝐿𝑘 is the length of the
tour performed by ant k and m is the number of ants.[3]

2.3.2 Ant Colony System

The ACS is mainly different from the AS in these aspects:

 The decision rules of the ants are different;


 The global updating rules are different;
 Local updating rules which adjust the amount of the pheromone on various
paths are newly added.

Step 1: Initiation. The amount of the pheromone on each side is initiated into a tiny
constant value; allocate m ants randomly to n cities.

Step 2: In ACS, the so-called pseudorandom proportional rule is used: the probability
for an ant to move from city i to city j depends on a random variable q uniformly
distributed over [0, 1], and a predefined parameter q0.

𝛼 𝛽
arg 𝑚𝑎𝑥𝑢𝜖𝑎𝑙𝑙𝑜𝑤𝑒𝑑𝑘(𝑖) {[𝜏𝑖𝑗 (𝑡)] [𝜂𝑖𝑗 ] } 𝑖𝑓 𝑞 < 𝑞0
𝑗={ …………. (2.4)
𝑗 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

J is a random variable determined in accordance with equation (2.4). This strategy


obviously increases the variety of any searching, thus avoiding any premature falling
into the local optimal solution and getting bogged down.

Step 3: The local pheromone update is performed by all the ants after each construction
step. Each ant applies it only to the chosen city,

20
𝜏𝑖 𝑗 (t + 1) = (1 − ρ )𝜏𝑖 𝑗 (t ) + ρ .τ 0 …………. (2.5)

where 0< ρ<= 1 is a decay parameter, τ0=1/n.𝐿𝑛𝑛 is the initial values of the pheromone
trails, where n is the number of cities in the TSP and 𝐿𝑛𝑛 is the cost produced by the
nearest neighbor heuristic. Equation (2.5) is mainly to avoid very strong pheromone
paths to be chosen by other ants and to increase the explorative probability for other
paths. Once the edge between city i and city j has been visited by all ants, the local
updating rule makes pheromone level diminish on the edge. So, the effect of the local
updating rule is to make an already edge less desirable for a following ant.

Step 4: Computing of the optimal path. After m ants have travelled through all the
cities, compute the length of the optimal.

Step 5: Global updating of pheromone. After all the ants have travelled through all the
cities, update only the amount of the pheromone on the optimal path with equation
(2.6):

𝜏𝑖 𝑗 (t + 1) = (1 − ρ )𝜏𝑖 𝑗 (t ) + ρ .Δ𝜏𝑖 𝑗 (t ) …………. (2.6)

1
∆𝜏𝑖𝑗 (𝑡) = { 𝐿𝑔𝑏 , if (𝑖, 𝑗)ϵ global best tour, …………. (2.7)
0 , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

where ρ is constant and Lgb is the length of global best tour.

Step 6: If the designated search number is not attained, then repeat the above steps. [3]

21
2.4 Comparison of computational time of ACO with other
algorithms

According to the experiment performed by M. Dorigo, L.M. Gambardella, 1997, on


five different city sets with 50 cities, the obtained result shows that ACO is better than
other type of algorithms for solving TSP like SA(Simulated Annealing), EN(elastic
net), SOM(Self-Organizing Map) and FI(Farthest Insertion). The result of average tour
length obtained from their experiment is shown below, where the best one is
highlighted:
Problem Name ACS SA EN SOM FI
City set 1 5.86 5.88 5.98 6.06 6.03
City set 2 6.05 6.01 6.03 6.25 6.28
City set 3 5.57 5.65 5.70 5.83 5.85
City set 4 5.70 5.81 5.86 5.87 5.96
City set 5 6.17 6.33 6.49 6.70 6.71
Table 1: Comparison of ACO with other algorithms
(Source: Marco Dorigo, Luca Maria Gambardella, Ant Colonies for travelling salesman
problem, 1997)

These results were averaged over 15 trials starting from different initial cities.

22
Chapter 3: System Development

3.1 Method

While implementing ACO, we used ACS (Ant Colony System) to solve the TSP
problem. ACS is the modified algorithm from AS (Ant system). In between AS and
ACS the difference is in pheromone update procedure. Though both algorithms uses
the global pheromone update trail there is the difference in procedure. In AS at first,
the evaporation procedure is done on all the city then after the update is carried out on
all the state where as in ACS, pheromone evaporation and pheromone update are done
simultaneously. Consequently ACS seems to work faster and advance one. The ACS
is mainly different from the AS in these aspects: The decision rules of the ants are
different; the global updating rules are different; and local updating rules which adjust
the amount of the pheromone on various paths are newly added.

To initialize ACO, if a greedy construction procedure like a nearest-neighbor heuristic


is available, then the same graph used by the construction procedure can be used as a
construction graph, and then it is only necessary to (1) add pheromone trail variables
to the construction graph and (2) define the set of artificial ants to be used for
constructing solutions in such a way that they implement, according to a randomized
version of the construction procedure. It must be noted, however, that in order to have
an efficient implementation, often additional data structures are required, like arrays,
to represent the TSP instance and the pheromone trails, and representing artificial ants.

23
3.1.1 Digital Representation of ant

In computer science, artificial ant is the barrier of the real ant. In this work an artificial
ant is an agent which moves from city to city on a TSP graph. It chooses the city to
move to using a probabilistic function both of trail accumulated on edges and of a
heuristic value, which was chosen here to be a function of the edges length. Artificial
ants probabilistically prefer cities that are connected by edges with a lot of pheromone
trail and which are close-by. Initially, numbers of artificial ants are placed on randomly
selected cities. At each time step they move to new cities and modify the pheromone
trail on the edges used –this is termed local trail updating. When all the ants have
completed a tour the ant that made the shortest tour modifies the edges belonging to its
tour termed global trail updating by adding an amount of pheromone trail that is
inversely proportional to the tour length.

There are three ideas from natural ant behavior that we have transferred to our artificial
ant colony:

(i) the preference for paths with a high pheromone level,


(ii) The higher rate of growth of the amount of pheromone on shorter paths, and
(iii) The trail mediated communication among ants.

Artificial ants were also given a few capabilities which do not have a natural
counterpart, but which have been observed to be well suited to the TSP application:
artificial ants can determine how far away cities are, and they are endowed with a
working memory used to memorize cities already visited (the working memory is
emptied at the beginning of each new tour, and is updated after each time step by adding
the new visited city). [11]

24
3.1.2 General technique

Tours are constructed by applying the following simple constructive procedure toeach
ant:

 Choose, according to some criterion, a start city at which the ant is positioned;
 Use pheromone and heuristic values to probabilistically construct a tour by
iteratively adding cities that the ant has not visited yet, until all cities have been
visited;
 Go back to the initial city.

After all ants have completed their tour, they may deposit pheromone on the tours they
have followed.

3.1.3 Tour Construction

Initially, each ant is put on some randomly chosen city. At each construction step, ant
k applies a probabilistic action choice rule. In particular, the probability with which ant
k, currently at city i, chooses to go to city j at the tth iteration of the algorithm is:

𝛼 𝛽
[𝜏𝑖𝑗 ] [𝜂𝑖𝑗 ]
𝑘
𝑝𝑖𝑗 ={ 𝛼
∑𝑢𝜖𝑗 [𝜏𝑖𝑗 ] [𝜂𝑖𝑗 ]
𝛽
𝑖𝑓 𝑗𝜖𝑗𝑘 (𝑖) …………. (3.1)
𝑘
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

Where 𝜏𝑖𝑗 is the pheromone, j is the current city and 𝑗𝑘 is the set of unvisited city and
𝜂𝑖𝑗 =1/𝑑𝑖𝑗 is an a priori available heuristic value, 𝛼 and 𝛽are two parameters which
determine the relative influence of the pheromone trail and the heuristic information,
and 𝑁𝑖𝑘 is the feasible neighborhood of ant k, that is, the set of cities which ant k has
not yet visited.

25
3.1.3.1 Role of α and β

If 𝛼 = 0, the closest cities are more likely to be selected: this corresponds to a classical
stochastic greedy algorithm with multiple starting points since ants are initially
randomly distributed on the cities. If 𝛽 = 0, only pheromone amplification is at work:
this method will lead to the rapid emergence of a stagnation situation with the
corresponding generation of tours which, in general, are strongly suboptimal.

According to experiment performed by Marco Dorigo, Thomas Stutzle, for a good


performance value of α should be 1 and β should be between 2 to 5.[2]

3.1.4 Pheromone updating and evaporation

The pheromone trail is changed both locally and globally. Global updating is intended
to reward edges belonging to shorter tours. Once artificial ants have completed their
tours, the best ant deposits pheromone on visited edges; that is, on those edges that
belong to its tour (the other edges remain unchanged). The amount of pheromone ∆𝜏(i,
j) deposited on each visited edge (i, j) by the best ant is inversely proportional to the
length of the tour: the shorter the tour the greater the amount of pheromone deposited
on edges. This manner of depositing pheromone is intended to emulate the property of
differential pheromone trail accumulation, which in the case of real ants was due to the
interplay between the length of the path and continuity of time. The global trail
updating formula is

𝜏(𝑖, 𝑗) ← (1 − 𝜌). 𝜏(𝑖, 𝑗) + 𝜌. ∆𝜏(𝑖, 𝑗) …………. (3.2)

Where ∆𝜏(i, j) is the shortest tour.

Global trail updating is similar to are enforcement learning scheme in which better
solutions get a higher reinforcement.

26
Local updating is intended to avoid a very strong edge being chosen by all the ants:
every time an edge is chosen by an ant its amount of pheromone is changed by applying
the local trail updating formula:

𝜏(𝑖, 𝑗) ← (1 − 𝜌). 𝜏(𝑖, 𝑗) + 𝜌. 𝜏0 …………. (3.3)

where 𝜏0 is a parameter and 𝜌 is cut-rate factor of deposited pheromone.

Local trail updating is also motivated by trail evaporation in real ants. In fact, the above
equation (3.2) and (3.3) dictate that an ant can either, with probability q0, exploit the
experience accumulated by the ant colony in the form of pheromone trail (pheromone
trail will tend to grow on those edges which belong to short tours, making them more
desirable) or, with probability (1-𝑞0 ), apply a biased exploration (exploration is biased
towards short and high trail edges) of new paths by choosing the city to move to
randomly, with a probability distribution that is a function of both the accumulated
pheromone trail, the heuristic function and the working memory.[12] With the update
process simultaneously the pheromone intensity will evaporate with increase in time in
both types of pheromone update process.

3.1.5 Constants

Four constants are used in ACO which are given below with their respective values:

Name of Constant Value Description

Α 1 The relative influence of the pheromone trail

Β 2 to 5 The heuristic information

Ρ 0.1 Cut-rate factor of deposited pheromone

Table 2: Value of Constants

27
For effective implementation these values should be used, but small changes can be
done for α, β and ρ.

3.2 Design

3.2.1 Data Structures

In order to carry out effective implementation, different data structures are required,
like arrays, which are used to represent the problem and data representation like TSP
instance and the pheromone trails, and representing artificial ants.

3.2.1.1 Problem and Data Representation

a) City Representation

As the points or cities are selected by the user, those selected points are identified by
their pixel value which are stored in x_cord[] and y_cord[] for x-coordinate and y-
coordinate respectively. For each selected city a unique string is given to it through
city[] array. There are two 2-dimensional arrays cityVisited[,], used for storing cities
visited by each ant in a round and cityUnvisited[,], for storing remaining cities to be
visited by each ant in a round.

b) Pheromone Trails Representation

For each connection between cities (i, j), a number τij corresponding to the pheromone
trail associated between city i and j has to be adjusted. This pheromone is stored in the
array pheromone[,]. For symmetric TSPs this requires storing n(n-1)/2 distinct
pheromone values, because we assume that τij = τji, for all i and j excluding i=j, for which
its value is set to 0.

28
3.2.1.2 Ant representation

Ant in ACO is represented by the artificial ant. Artificial ant holds the foraging
behavior of the real ant. Here also in this program, artificial ants are the agent that visits
around the graph. While visiting initially numbers of the ants are localized in different
city and are allowed to visit around the graph. It also deposits an amount of pheromone
Δτ on the arcs it has traversed. For this, an ant must be able to:

 Store the partial solution it has constructed so far, which is done with cityVisited[,]
array where each ant stores its visited city information.
 Determine the feasible neighborhood at each city, which is done through scanning
cityUnvisited[,] array from each current city, which is updated while the ant builds
the solutions.
 Compute and store the objective function value of the solutions an ant generates,
by storing the length of tour traversed by ant in the array tourLength[,].

In our design, ants are represented by ants[] array.

From this array of ant, a single ant travels round all the cities completing the Hamilton
circuit. Likewise, the entire ants travel and complete a Hamilton circuit in each round.
The travelling speed of every ant is uniform only the distance they are travelling
through these cities varies the time to complete one circuit. While travelling those ants
spread the pheromone as according to the pheromone update rule and simultaneously
through this pheromone the best and optimal circuit is determined.

The main data structures used for implementing ACO are:

public static String[] city //Initialize cities with string name.

public const int CityNumber //maximum number of cities

29
public const int AntNumber //number of ants

public static double[,] pheromone = new double[CityNumber,


CityNumber]; //pheromone matrix

public static int[] ants //ants reperesentation

public static String[,] cityVisited = new


String[AntNumber, CityNumber]; //matrix representing city already
visited by respective ants

public static String[,] cityUnvisited = new


String[AntNumber, CityNumber]; //matrix representing city that are
going to be visited by respective ants

public static double[,] probs = new double[AntNumber,


CityNumber]; //matrix of probability of any ant going to any cities

public static double[,] distance = new double[CityNumber,


CityNumber]; //distance matrix

public static double[] tourLength = new double[AntNumber];


//length of tour of each ant

public static double optimalTourLength //best tour length at


specific round

public static String[] optimalTourCity = new


String[CityNumber]; //best tour cities

public static double bestTourLength //overall best tour length

public static String[] bestTourCity = new


String[CityNumber]; //overall best tour cities

public static int[] x_cord = new int[200]; //X-


coordinate matrix

30
public static int[] y_cord = new int[200]; //Y-
coordinate matrix

public static TimeSpanelapsedTime; //variable to measure the


time for total execution

3.2.2 The Algorithm

During implementation of ACO, the major task that are to be done are data structure
and parameter initialization, solution construction, management of pheromone trails
and maintenance of execution of code like termination of program etc.

The algorithm of ACO for solving TSP is given below:

Step 1: initialize the program.

Step 2: defining those cities and their co-ordinates

Step 3: on accordance to number of ant assigned to the cities, ant from those initialize
visiting all around calculating the distance of those cities from one to another.

Step 4: after calculating the distance the best one will be choosen and pheromone is
updated in all edges of that route.

Step 5: if condition approval of visiting maximum round then draw the best path and
print their length and time taken otherwise go to step 6.

Step 6: check whether all ants had tour or not. If yes then goto step 7 else goto step 11.

Step 7: optimal trail path is find out.

Step 8: if this is best path then go to step 9 else goto step 5.

Step 9: optimal path is made as best one.

31
Step 10: pheromone update is carried out on the best path and goto step 5.

Step 11: the list of unvisited cities is initialized.

Step 12: if all cities are visited i.e. unvisited cities= NULL then goto step 5 else

Step 13: the probability of next unvisited city is calculated.

Step 14: city is removed from unvisited list and goto step 12.

32
The flowchart for the algorithm is given below:

Figure 3-1: Flow chart of system design

33
The high level view of ACO Algorithm for solving TSP is given below:

Procedure ACOforTSP
InitializeData
while(not terminate)do
ConstructSolutions and UpdateStatistics
UpdatePheromoneTrails
End-while
End-procedure
Each task from above algorithm are described below.

3.2.2.1 Data Initialization

In the data initialization, following task are performed:

 The instance, provided by the user has to be read and cities are initialized.
 the distance matrix between each points has to be computed; whose pseudo
code is given below:

distance_calc (int x1,int y1,int x2,int y2)


Calculate distance between two points (x1, y1) and

(x2, y2) using formula √(𝑥1 − 𝑥2)2 + (𝑦1 − 𝑦2)2


Return distance
End of the function

 the pheromone matrix have to be initialized for each city edges with a value of
0.01 for each city(i, j) for all i and j except i = j;
 the ants have to be initialized;
 the algorithm’s parameters like cityUnvisited[,] must be initialized;

34
 Some variables that keep track of statistical information, such as the used CPU
time, the number of iterations, or the best solution found so far, have to be
initialized.

The data initialization is proceeded with instantiation of a new object of class start
ACO, through the use of constructor. A possible organization of the tasks into several
data initialization procedures is indicated in given pseudo code.

function StartClassACO(FormMap object_form)


1 Calculate distance between each coordinates by calling
function distance_calc
2 Initialize the pheromone for each city edges
3 Initialize the cities unvisited
4 Call the mainproc function
End of the function

3.2.2.2 Construct Solution and Update Statistics


For each ant, a tour is accomplished in a round. Among all the tour created by ants, an
optimal tour is selected which is compared with best tour length of all previous rounds.
This optimal tour is assigned to best tour if it is better than previous best tour. For the
best tour, pheromone is updated by calling its function. The tour construction is
accomplished by the function mainproc, whose pseudo code is shown below.

function mainproc(FormMap object_form)


1 Start stopwatch
2 for k = 0 to rounddo
3 Update the progress bar in MapForm
4 Get a new_index as random number
5 Obtain initial city from new_index
6 for antindex = 0 to AntNumberdo

35
7 Initialize the unvisited cities
8 Initialize m as 0
9 Store initial city in cityVisited matrix as
cityVisited[antIndex, m] = initial
10 for j = 0 to countdo
11 Calculate index = Array.IndexOf(city,
initial)
12 Increase value of m by 1
13 Remove the current city from
cityUnvisited matrix as cityUnvisited[antIndex,
index] = "\0"
14 for i = 0 to countdo
15 Initialize probability as
probs[antIndex, i] = 0.0
16 End of for loop
17 Call CalcProbability function with
parameters initial and ants[antIndex] and store the
returned value in selectedCity
18 Store the selectedCity in cityVisited
matrix as cityVisited[antIndex, m] = selectedCity
19 Initalize the initial city as
selectedCity
20 End of for loop
21 Call CalcLength to calculate the tour length
of corresponding ant as CalcLength(ants[antIndex])
22 Get a new_index from random number
23 Obtain initial city from new_index
24 Initialize optimalTourLength = tourLength[0]
25 if bestTourInitialize = 1
26 Assign bestTourLength =
optimalTourLength

36
27 for i = 0 to countdo
28 Assign bestTourCity[i] = cityVisited[0,
i]
29 End of for loop
30 Assign bestTourInitialize = 0
31 End of for loop
32 Initialize sum as 0.0
33 for i = 0 to AntNumberdo
34 Calculate sum = sum +1 / tourLength[i]
35 if optimalTourLength > tourLength[i]
36 Assign optimalTourLength = tourLength[i]
37 Initialize flag as corresponding ant
index i
38 End if
39 End of for loop
40 if optimalTourLength <= bestTourLength
41 Assign bestTourLength = optimalTourLength;
42 for i = 0 to countdo
43 Assign bestTourCity[i] =
cityVisited[flag, i]
44 Call function UpdatePheromone(ants[flag],
sum);
45 End of for loop
46 End if
47 End of for loop
48 Stop stopwatch
49 Assign total time taken to elapsedTime
End of the function

37
The solution construction requires the following phases.

1. First, in line 1, the stopwatch is started in order to measure the time taken for
calculation.
2. For each round, progress bar is updated and a new random index is obtained.
3. The ants’ memory must be emptied. This is done in lines 6 and 7 of above
function by placing all cities into cityUnvisited[,], marking all cities to be
visited by each ant.
4. Remove the current city i.e. city with obtained index from cityUnvisited[,] and
place it into cityVisited[,] matrix which is accomplished in line 13.
5. Initialize the probability matrix as a value of 0.0 as in line 14 and 15.
6. Call calcProbability function by passing the index of current city, from which
city with higher probability is returned. Store this city in cityVisited[,] matrix
and make this an initial one, as in line 17 to 19.
7. After ant construct the path by completing tour, obtain tour length of
corresponding ant by calling function calcLength, as in line 21.
8. Assign optimalTourLength as tour length of first ant and compare it with all
other remaining ants’ tour and obtain the optimal tour length in the current
round. If this optimalTourLength is better than bestTourLength, assign
optimalTourLength to bestTourLength and update pheromone in the path
having bestTourLength, which is implemented in line 24 to 45.
9. At last stop stopwatch and assign its value to elapsedTime.

3.2.2.3 Probability Calculation


In each tour of an ant, the probability of selecting an unvisited city from a current city
is calculated. The city having higher probability is selected as a city to be visited next,
which is calculated using the given pseudo code.

38
Function CalcProbability (String initial, int ant)
1 Initialize sum = 0.0;
2 cityIndex = Array.IndexOf(city, initial);
3 antIndex = Array.IndexOf(ants, ant);
4 for i = 0 to countdo
5 if (city[i] == initial)
6 for j = 0 to countdo
7 if (city[j] == cityUnvisited[antIndex,
j] && city[j] != initial)
8 Calculate sum = sum +
(Math.Pow(pheromone[cityIndex, j], alpha) * Math.Pow((1.0
/ distance[cityIndex, j]), beta));
9 End of for loop
10 End of for loop
11 For i = 0 to countdo
12 if (city[i] == cityUnvisited[antIndex, i])
13 Calculate probability as probs[antIndex, i] =
(Math.Pow(pheromone[cityIndex, i], alpha) * Math.Pow((1.0
/ distance[cityIndex, i]), beta));
14 Else probs[antIndex, i] = 0.0;
15 End of for loop
16 Calculate temporary probability prob as prob =
p_r.NextDouble() * sum;
17 Initialize j_counter as 0
18 Iniitalize p as probability of ant as p = probs[antIndex,
j_counter];
19 While p < probdo
20 Increase j_counter by 1
21 Calculate p as p = p + probs[antIndex, j_counter]
22 End of while loop

39
23 Initialize randomDecision as j_counter, maxHeuristic as -
1 and maxHeuristicIdx as -1
24 For j = 0 to countdo
25 Initialize temp as probs[antIndex, j]
26 If maxHeuristic < temp and city[j] ==
cityUnvisited[antIndex, j]
27 Assign maxHeuristic as temp
28 Assign maxHeuristicIdx as j
29 End if
30 End of for loop
31 If p_r.NextDouble() < Q0
32 Assign selectedcity as cityUnvisited[antIndex,
maxHeuristicIdx];
33 Assign cityUnvisited[antIndex, maxHeuristicIdx] =
"\0";
34 End if
35 Else
36 Assign selectedcity as cityUnvisited[antIndex,
randomDecision];
37 Assign cityUnvisited[antIndex, randomDecision] =
"\0";
38 End if
39 Return Selectedcity
End of the function

40
3.2.2.4 Tour Length Calculation
For each ant after their complete tour traversal, length of their tour is calculated. This
is done by using a function calcLength, whose pseudo code is given below:

function CalcLength(int ant)


1 Initialize antIndex = Array.IndexOf(ants, ant);
2 Initialize tourLength[antIndex] = 0.0;
3 For a = 0 to countdo
4 Assign
index1=Array.IndexOf(city,cityVisited[antIndex,a]);
5 Assign index2 = Array.IndexOf(city,
cityVisited[antIndex, (a + 1) % count]);
6 Calculate tourLength[antIndex] =
tourLength[antIndex] + distance[index1,index2];
7 End of for loop
End of the function

3.2.2.5 Pheromone update


As the algorithm we choose to implement is ACS, global best ant is allowed to add the
pheromone after each iteration. The equation used to update the pheromone is given
below in equation (3.4).

𝜏(𝑖, 𝑗) ← (1 − 𝜌). 𝜏(𝑖, 𝑗) + 𝜌. ∆𝜏(𝑖, 𝑗) …………. (3.4)

Where 𝜏(𝑖, 𝑗) is the pheromone stating the from i city to j city

It is important to note that the trail update only applies to the arcs of the global-best
tour, not to all the arcs. The parameter 𝜌 again represents the pheromone evaporation.
Here only the global best solution receives feedback. Initially, also using the iteration
best solution was considered for the pheromone update. Although for smaller TSP
instances the difference in solution quality between using the global-best solution or

41
the iteration-best solution is minimal, for larger instances the use of the global-best tour
gives by far better results.

This is implemented by the function UpdatePheromone, which comprises two


pheromone update procedures: pheromone evaporation and pheromone deposit. The
first one, Evaporate, decreases the value of the pheromone trails on all the arcs (i, j) by
a constant factor ρ. The second one, pheromonedeposit, adds pheromone to the arcs
belonging to the tours constructed by the ants. Note that in both procedures are taken
to guarantee that the pheromone trail matrix is kept symmetric, because of the
symmetric TSP instances.

The pseudo codes for pheromone update is given below:

Function UpdatePheromone(int ant, double sum)


1 initialize antIndex = Array.IndexOf(ants, ant);
2 Calculate temp = 1 / bestTourLength;
3 for i = 0 to countdo
4 Calculate index1 =
Array.IndexOf(city,cityVisited[antIndex,i]);
5 Calculate index2 = Array.IndexOf(city,
cityVisited[antIndex, (i + 1) % count]);
6 Calculate pheromone[index1, index2] = (1-rho) *
pheromone[index1, index2] + Q * sum;
7 Assign pheromone[index2, index1] =
pheromone[index1, index2];
8 End of for loop
End of the function

42
3.2.2.6 Program Termination
The program stops when a maximum number of tour constructions or a maximum
number of algorithm iterations has been reached. After its termination, it shows final
graph showing the result of optimal path along with its length and time of execution.

43
3.3 Development
3.3.1 Program Structure
The program being developed consists of a class ‘ClassACO’ and three different
windows forms: FormMap, FormDisplay and FormViewMap. ClassACO defines
different functions like mainproc for creating solution and updating statistics,
calcProbability for calculating probability, calcLength for calculating length of tour of
each ant and UpdatePheromone for global updating pheromone for pheromone deposit
and evaporation.

FormMap is a startup from for city initialization, which intakes points as a reference of
the cities through user either by clicking on the map browsed by user or making random
points on the white picture box. FormViewMap displays the selected points along with
all the edges connecting those points. The parameters for the program like rounds to
perform, number of ants, value of alpha, beta and rho can also be provided through the
form. If those values are not changed, then default values are provided. After a round
of operations, the graph with final result showing optimal path is displayed in
FormDisplay form. This graph can be saved as a picture format in the directory of
computer.

44
The flow diagram of the program is displayed below:

Figure 3-2: Program Flow Diagram

45
3.3.2 Interface of program
The snapshots of our program is given below:

a. This is the startup form, where user can enter points in the white picture box
randomly or can browse a map of formats like JPEG, BMP etc. from a directory
and select desired cities from that map. Values of round, ants, alpha, beta and
rho can be entered.

Figure 3-3: Snapshot for startup form

46
b. This snapshot shows when user has selected a set of cities. User can also change
the value of rounds, ants, alpha, beta and rho.

Figure 3-4: Snapshot after point selection

47
c. After calculation, result id shown in the graph, displaying the optimal path with
dark red color, along with time taken and length.

Figure 3-5: Snapshot showing the optimal path

3.4 Testing
During the designing process, this project has so many bugs which were debugged one
by one analyzing the problem occurred on each steps. This project has gone through
following testing procedure.

3.4.1 Unit testing


Separately each and every functional module is tested and analyzed the result of that
module.

48
3.4.2 Integration testing
While integrating all separate modules as one, errors that were detected were analyzed
and debugged.

3.4.3 System testing


After all the system has been prepared this system has been tested to identify the
optimal path of the outcome where we tested the system with known distance valued
graph and finally got the outcome as expected.

49
3.5 Validation
In order to validate our ACO and to know the optimal path assurance, we provided a
graph of a pentagon and pass it to the program by selecting five nodes. As our program
displayed result showing the pentagon, so we can validate that our program is executing
correctly, which is shown below:

Figure 3-6: Validating Program


As our final result was a pentagon, so we are conform that our system is right.For the
other complex graph, the only way to know whether the path is optimal or not is by
taking the input from the map with distance by this way finally we can calculate the
optimal path doing manual calculation too. This project has been analyzed by this way
too so the result is assured as optimal one. That means this project can solve TSP
problem without any doubt.

50
Chapter 4: Epilogue
4.1 Result
After the program is started, user can either enter the points randomly at white picture
box or can browse a map and select cities, for which shortest path has to be found. As
given in figure below, user can browse a map and select cities and adjust values of
rounds, ants, alpha, beta and rho.

Figure 4-1: City selection

51
After clicking calculate button, the final output is displayed, which shows the optimal
path highlighted in red color along with path, length and time taken for total round
execution, which as shown in figure below.

Figure 4-2: Result obtained showing optimal path

The red line indicates the optimal TSP path completing the Hamilton circuit. The
information part has optimal path and length with time taken to complete the round in
second.

This is the result of this project which gives the optimal path with length calculation
and time taken to visit around the graph.

52
4.2 Result Analysis
The result of our program was executed and analyzed for a number of times with
varying inputs. We performed test for computational capability of our program by
giving different number of points and calculating and observing the time taken to run.
We provided 5 to 50 cities, with 1000 rounds, 10 ants and value of alpha was 1, beta
was 2 and rho was 0.5. For each set of cities, this calculation was done for ten times
and the time taken to solve the problem was averaged. The averaged computational
time for solving and finding shortest path for different cities is given below in table:

Number of cities Computational Time


5 0.18084432
10 0.45567678
15 0.84175982
20 1.3452476
25 1.9872501
30 2.6476588
35 3.49762444
40 4.46278875
45 5.4586210
50 6.63181736
Table 3: Result showing computational time

All experiments were performed in a computer having Windows 7 operating system,


processor of Intel core i5-2410M CPU of 2.30GHz, physical memory of 4GB and
graphical memory of 512MB. The experiments were performed for 10 times for each
city sets, whose computational time were then averaged.

53
This result is depicted in graph as below in figure 4-3. This graph shows that the
computational time of the algorithm increases with the increase in number of cities.

Time
7

5
Time (seconds)

0
0 10 20 30 40 50 60

Number of cities

Figure 4-3: Graph showing computational time and number of cities

54
4.3 Critical Analysis
We have seen that in real ant colonies the emergence of high-level patterns like shortest
paths is only possible through the interaction of a large number of individuals. It is
interesting that experimental results show that the same is true to a large extent for
ACO: the use of a colony of ants is important to exploit the differential path length
effect and to increase the robustness of the algorithm and reduce its dependence on
parameter settings. As we have seen, a colony size larger than one is necessary to solve
even simple problems like the double bridge.

In general, we noticed that as problems become more complex, the parameter settings
of ACO become increasingly important to obtain convergence to the optimal solution.
In particular, the experimental results presented above support the following
conclusions:

(1) The differential path length effect, although important, is not enough to allow the
effective solution of large optimization problems;

(2) Pheromone updates based on solution quality are important for fast convergence

(3) Large values for parameter a lead to a strong emphasis of initial, random
fluctuations and to bad algorithm behavior;

(4) The larger the number of ants, the better the convergence behavior of the algorithm,
although this comes at the cost of longer simulation times;

(5) Pheromone evaporation is important when trying to solve more complex problems.

These observations will be of importance in the following chapters, where design


decisions will be made both to define the ACO metaheuristic and to apply it to a
multitude of different discrete optimization problems.

Artificial ants iteratively sample tours through a loop that includes a tour construction
biased by the artificial pheromone trails and the heuristic information. The main

55
mechanism at work in ACO algorithms that triggers the discovery of good tours is the
positive feedback given through the pheromone update by the ants: the shorter the ant’s
tour, the higher the amount of pheromone the ant deposits on the arcs of its tour. This
in turn leads to the fact that these arcs have a higher probability of being selected in the
subsequent iterations of the algorithm. The emergence of arcs with high pheromone
values is further reinforced by the pheromone trail evaporation that avoids an unlimited
accumulation of pheromones and quickly decreases the pheromone level on arcs that
only very rarely, or never, receive additional pheromone.

The first theoretical aspect of ACO that we consider is the convergence problem: Does
the algorithm considered eventually find the optimal solution? This is an interesting
question, because ACO algorithms are stochastic search procedures in which the bias
due to the pheromone trails could prevent them from ever reaching the optimum. It is
important to note that, when considering a stochastic optimization algorithm, there are
at least two possible types of convergence: convergence in value and convergence in
solution. Informally, and making the hypothesis that in case of problems with more
than one optimal solution we are interested in convergence toward any of them, when
studying convergence in value we are interested in evaluating the probability that the
algorithm will generate an optimal solution at least once. On the contrary, when
studying convergence in solution we are interested in evaluating the probability that
the algorithm reaches a state which keeps generating the same optimal solution. Note,
however, that although in general convergence in solution is a stronger and more
desirable result to prove than convergence in value, in optimization we are interested
in finding the optimal solution once (after it has been found the problem is solved and
the algorithm can be stopped), so that convergence in value is all that we need.

ACO performs better against other global optimization techniques, retains memory of
entire colony instead of previous generation only, less affected by poor initial solutions
and can be used in dynamic applications and has been applied to a wide variety of
applications. It is also a good choice for constrained discrete problems. Theoretical

56
analysis is difficult; due to sequence of random decision, research is experimental
rather than theoretical, convergence is guaranteed, but time to convergence is uncertain.
In NP-hard problems, need high-quality solutions quickly focus on quality of solutions
and in dynamic network routing problems, need solutions for changing conditions.

We are more interested in finding an optimal solution at least once than in generating
it over and over again, let us have a closer look at the role played by τmin (minimum
pheromone value) and τmax (maximum pheromone value). We need to consider the
worst-case situation in which the bias in the solution construction introduced by the
pheromone trails is counterproductive and leads to suboptimal solutions; that is, we
have to assume that the pheromone trail level associated with the connection an ant
needs to pass for constructing an optimal solution is τmin, while on the other connections
it is much higher—in the worst case corresponding to τmax. In practice, however, as
shown by the results of many published experimental works (Dorigo & Di Caro,1999b;
Dorigo et al., 1999; Dorigo & Stu¨ tzle, 2002), normally this does not happen, and the
bias introduced by the pheromone trails does indeed help to speed up convergence to
an optimal solution.

As with other project, this project also has some drawbacks like stagnation and pre-
convergence problem. To reduce such drawbacks further research and optimization in
coding requires. In spite of those problems also, this application can give optimal tour
by which we can generalize our other real world problems. Beside those this project
lacks some modern technology like dynamic optimization modification on ACS
algorithm, parallel optimization algorithms. Such optimization’s abstract concept can
be implement in future to make this project works more optimizing the paths. In aspect
of hardware too CPU and GPU can be enhance together to make the calculation more
efficient. Regarding the development of this project till now, this project is more useful
in generalizing the problem in vehicle routing, road construction, network routing, etc.
that has limit number of cities and nodes. Its working mechanism for limited cities is
best part of this project. This project can gives optimal path for the limit number of

57
cities. Using the more number of ants, traveling the path also can help in generating the
more optimal path.

Moreover, this project only works for straight path in between two nodes like:

Figure 4-4: Graph showing straight connection in between cities

So the construction on the path also can be taken as its drawback regarding the real
world scenario. In real word it may be impossible to have straight path in between the
cities so our project also require to work on curve path. Beside those, analyzing the
above figure, the red path gives the optimal path. So while network routing this
representation can give the optimal path for routing purpose and for water distribution
purpose without leaving any cities, water can be flowed through optimal path as
represented in above graph. As similar to, while vehicle routing the optimal path can
save both time and cost.

58
4.4 Limitation
It still has some drawbacks such as stagnation behavior, and premature convergence
problem of the basic ACO algorithm on TSP. Those problems will be more obvious
when the considered problems size increases. The system is likely to fall into the local
optimal solution and becomes stagnation when it has large scale.

4.5 Future enhancement


Our future plan is to overlap CPU and GPU computation by running suitable operations
on both processors in order to maximize the use of the computational power of the
system on which it is running. And another goal for us to work toward in the future is
to add more implementations of ACO to give the user more flexibility.

4.6 Conclusion
The key to the application of ACO to a new problem is to identify an appropriate
representation for the problem that is to be represented as a graph searched by many
artificial ants, and an appropriate heuristic that defines the distance between any two
nodes of the graph. Then the probabilistic interaction among the artificial ants mediated
by the pheromone trail deposited on the graph edges will generate good, and often
optimal, problem solutions. The ACO is an optimization algorithm based on self-
organization effects of individual agents and it was particularly suited for Travelling
Salesman Problem, since one of the optimization constraints depends on how the
solution is constructed.

59
References

[1]Carlos A. Silva and Thomas A. Runkler,Ant Colony Optimization for dynamic


Traveling Salesman Problems,Siemens AG, Corporate Technology Information and
Communications, CT IC 481730 Munich - Germany

[2]Marco Dorigo, Thomas Stutzle,Ant Colony Optimization, ISBN 0-262-04219-3, The


MIT Press, Cambridge, Massachusetts, London, England, 2004, pp. i-ii.

[3]Zar Chi Su SuHlaing, May Aye Khine, An Ant Colony Optimization Algorithm for
Solving Traveling Salesman Problem,University of Computer Studies, Yangon

[4] Grace Murray Hopper and Shimon Peres, NP-Hard Problems, 2009, pp. 2

[5] Ivan Brezina Jr. ZuzanaČičková, Solving the Travelling Salesman Problem Using
the Ant Colony Optimization, University of Economics in Bratislava, 2011, pp. intro.

[6] Karla Hoffman, George Mason University, Manfred Padberg, http://iris.gmu.edu/,


New York University, May 20, 2013.

[7] Peter Ahrens, Dustin Tauxe, ExcellAnts, Los Alamos High School, April 4, 2012,
pp. 4

[8]Vittorio Maniezzo, Luca Maria Gambardella, Fabio de Luigi, Ant Colony


Optimization, Springer-Verlag, Berlin Heidelberg, 2004, pp.21

[9]Holger R. Maier, Angus R. Simpson, Aaron C. Zecchin, WaiKuanFoong,


KuangYeowPhang, HsinYeowSeah and Chan Lim Tan, Ant Colony Optimization for
Design of Water Distribution Systems, Univ. of Adelaide, Adelaide, S.A. 5005,
Australia, May/June 2003, pp. 200-201

60
[10] P. Larrañaga, C.M.H. Kuijpers, R.H. Murga, I. Inza, S. Dizdarevic, Genetic
Algorithms for the Travelling Salesman Problem: A Review of Representations and
Operators, Kluwer Academic Publishers, 1999-04-01

[11]Marco Dorigo,Ant colonies for the traveling salesman problem, TR/IRIDIA/1996-


3Université Libre de Bruxelles Belgium

[12] Marco Dorigo a,*, Luca Maria Gambardella, Ant colonies for the travelling
salesman problem, a IRIDIA, Uni6ersite´ Libre de Bruxelles, A6enue Franklin
Roose6elt 50, CP 194 :6, 1050 Bruxelles, Belgiumb IDSIA, Corso El6ezia 36, 6900
Lugano, Switzerland accepted 24 October 1996

61
Bibliography

[1] Marco Dorigo, Gianni Di CaroAnt Colony Optimization: A New Meta-Heuristic,


IRIDIAUniversit´e Libre de Bruxelles, 50 Avenue F. Roosevelt, B-1050 Brussels,
Belgium, 1999

[2] S. Lin and B. W. Kernighan, An Effective Heuristic Algorithm for the Traveling-
Salesman Problem,

[3] Peter Ahrens,Dustin Tauxe, ExcellAnts, Los Alamos High School, New Mexico,
April 4, 2012

[4] Peter Ahrens, Dustin Tauxe, Stephanie Djidjev, BrilliAnts, Los Alamos High
School, New Mexico, April 6, 2012

[5] Marco Dorigo,Ant Algorithms Solve Difficult Optimization Problems,


IRIDIAUniversit´e Libre de Bruxelles, 50 Avenue F. Roosevelt, B-1050 Brussels,
Belgium, mdorigo@ulb.ac.be, 2001

[6] Ozgur Baskan *, Soner Haldenbilen, Huseyin Ceylan, Halim Ceylan, A new
solution algorithm for improving performance of ant colony optimization,Department
of Civil Engineering, Engineering Faculty, Pamukkale University, Denizli 20017,
Turkey, 2009

[7] Wang Cuiru, Li Yang, The Application of the Ant Colony Pheromones in Intelligent
Learning, Department of Computer Science, Southwestern North China Electric Power
University, Baoding Hebei 071003, liyang20032006@126.com, 2009

[8] Nattapat Attiratanasunthron, Jittat Fakcharoenphol, A running time analysis of an


Ant Colony Optimization algorithmfor shortest paths in directed acyclic graphs,

62
Department of Computer Engineering, Kasetsart University, Bangkok 10900,
Thailand, 2007

[9] Marco Dorigo, Luca Maria Gambardella, Solving Symmetric and Asymmetric TSPs
by Ant Colonies, IRIDIAUniversit´e Libre de Bruxelles, 50 Avenue F. Roosevelt, B-
1050 Brussels, Belgium, 1996

[10] Marco Dorigo, Luca Maria Gambardella, Ant Algorithms for


DiscreteOptimization, Massachusetts Institute of Technology, 1999

[11] Marco Dorigoa, Christian Blum, Ant colony optimization theory: A survey,
Theoretical Computer Science, 2005

[12] Vittorio Maniezzo, Antonella Carbonaro, Ant Colony Optimization: An


Overview, Scienze dell’Informazione, University of Bologna, Italy

[13] Vittorio Maniezzo, Luca Maria Gambardella, Fabio de Luigi, Ant Colony
Optimization

[14] Marco Dorigo, Mauro Birattari and Thomas Stutzle, Ant Colony Optimization:
Artificial ants as a computational Intelligent Technique, IEEE Computational
Intelligence Magazine, November 2006

[15] Mark Zlochin, Mauro Birattari, Nicolas Meuleau, Marco Dorigo, Model-Based
Search for Combinatorial Optimization: A Critical Survey, Annals of Operations
Research, Kluwer Academic Publishers, 2004

63
Appendices
A. Time Schedule
TASK NUMBER

Planned Actual
Planned Date Actual Date
OBJECTIVE
LINK TO

Duration Duration
TASK

HOURS

HOURS
DAYS

DAYS
START DATE FINISH DATE START DATE FINISH DATE

Ant Colony Optimization for Traveling Salesman Problem 5/8/2013 9/14/2013 5/8/2013 10/4/2013 111 467 130 497
1 Preliminary Work 5/8/2013 5/29/2013 5/8/2013 5/28/2013 18 64 18 64
1.1 1 Planning for the project 5/8/2013 5/9/2013 5/8/2013 5/9/2013 2 6 2 6
1.2 1 Analysis on the topics 5/10/2013 5/13/2013 5/10/2013 5/13/2013 2 6 2 6
1.3 Discussion with the supervisor 5/12/2013 5/12/2013 5/12/2013 5/12/2013 1 1 1 1
1.4 2,3 Background reading from different research papers 5/13/2013 5/15/2013 5/13/2013 5/15/2013 3 11 3 11

1.5 1 Understanding the overview of the project and analyzing the contents 5/16/2013 5/19/2013 5/16/2013 5/19/2013 3 8 3 8
1.6 7 Preparation of project proposal 5/16/2013 5/26/2013 5/16/2013 5/26/2013 9 13 9 13
1.7 7 Preparing the Gantt Chart and Project Schedule 5/21/2013 5/26/2013 5/21/2013 5/26/2013 5 15 5 15
1.8 7 Collecting and producing initial list of references of the project 5/27/2013 5/27/2013 5/27/2013 5/27/2013 1 2 1 2
1.9 Approval from Supervisor 5/28/2013 5/28/2013 5/28/2013 5/28/2013 1 1 1 1
1.1 7 First Review 5/28/2013 5/28/2013 5/28/2013 5/28/2013 1 1 1 1
1.11 Milestone 5/29/2013 5/29/2013 5/29/2013 5/29/2013
2 Research Work 5/29/2013 6/23/2013 5/29/2013 6/23/2013 21 72 21 72
2.1 2 Research on ant behavior 5/29/2013 5/31/2013 5/29/2013 5/31/2013 3 5 3 5
2.2 2,4 Research on ant colony algorithm and its optimization 6/2/2013 6/5/2013 6/2/2013 6/5/2013 4 14 4 14
2.3 Meeting with the supervisor 6/5/2013 6/5/2013 6/5/2013 6/5/2013 1 1 1 1
2.4 2,4 Research on applications of ant colony optimization algorithm 6/6/2013 6/7/2013 6/6/2013 6/7/2013 2 8 2 8
2.5 3,5 Research on traveling salesman problem and NP hard problems 6/9/2013 6/11/2013 6/9/2013 6/11/2013 3 10 3 10
2.6 3,5 Research on ant colony optimization for traveling salesman problem 6/12/2013 6/20/2013 6/12/2013 6/20/2013 8 32 8 32
2.7 Meeting with the supervisor 6/21/2013 6/21/2013 6/21/2013 6/21/2013 1 1 1 1
2.8 Second Review 6/21/2013 6/21/2013 6/21/2013 6/21/2013 1 1 1 1
2.9 Milestone 6/23/2013 6/23/2013 6/23/2013 6/23/2013
3 Development Phase 6/23/2013 8/21/2013 6/23/2013 8/23/2013 52 190 54 204
3.1 6 Study of Visual Studio and C# 6/23/2013 6/28/2013 6/23/2013 6/28/2013 6 22 6 22
3.2 6 Application Design 6/30/2013 7/4/2013 6/30/2013 7/8/2013 5 20 8 24
3.3 Meeting with Supervisor 7/5/2013 7/5/2013 7/12/2013 7/12/2013 1 1 1 1
3.4 6 Application Development, Unit and Module Test 7/5/2013 8/8/2013 7/7/2013 8/8/2013 29 120 29 120
3.5 Meeting with the Supervisor 7/19/2013 7/19/2013 7/19/2013 7/19/2013 1 1 1 1
3.6 6 Application Testing, validating and verifying 8/9/2013 8/2/2013 8/9/2013 8/22/2013 10 25 12 35
3.7 Meeting with Supervisor 8/21/2013 8/21/2013 8/23/2013 8/23/2013 1 1 1 1
3.8 Milestone 8/21/2013 8/21/2013 8/23/2013 8/23/2013
4 Dissertation 6/10/2013 9/9/2013 6/10/2013 10/1/2013 79 126 100 147
4.1 7 Report Writing 6/10/2013 8/25/2013 6/10/2013 9/9/2013 66 90 79 110
4.2 7 Report evaluation and conclusion 8/26/2013 8/29/2013 9/24/2013 9/26/2013 4 15 3 15
4.3 7 Proof reading 8/30/2013 9/2/2013 9/25/2013 10/1/2013 3 8 6 15
4.4 7 Submission of draft copy Report 9/3/2013 9/3/2013 10/2/2013 10/2/2013 1 1 1 1
4.5 7 Corrections for final draft copy 9/4/2013 9/8/2013 10/3/2013 10/3/2013 4 12 1 6
4.6 Milestone 9/9/2013 9/9/2013 10/3/2013 10/3/2013
5 Final Phase 9/9/2013 9/14/2013 10/4/2013 10/4/2013 5 15 2 10
5.1 7 Final Documentation Printing and Binding 9/9/2013 9/13/2013 10/4/2013 10/6/2013 5 15 2 10
5.2 Milestone 9/15/2013 9/15/2013 10/6/2013 10/6/2013

64
B. Gantt Chart

65
C. Source Code
a. Variables used
city[], ants[], distance[][], CityNumber, AntNumber, Round,
cityVisited[][], cityUnvisited[][], probs[][]

tourLength[], optimalTourLength, optimalTourCity[], bestTourLength,


bestTourCity[],

x_cord[], y_cord[]. elapsedTime, stopWatch.

b. Constants Used:
alpha=1, beta=3, rho=0.5, Q=2.0

c. Code to calculate distance


public double distance_calc(int x1,int y1,int x2,int y2)
{
double dist;
double temporary=Math.Pow((x2 - x1), 2) +
Math.Pow((y2 - y1), 2);
dist = Math.Sqrt(temporary);
return (dist);
}
d. To initialize the distance in array
for (int i = 0, counter = count; i < count; i++, counter
{
for (int k = 0, j = i; k < counter; k++, j++)
{
if (i == j)
{
distance[i, j] = 0.0;
continue;
}
distance[i, j] =
(distance_calc(x_cord[i],y_cord[i],x_cord[j],y_cord[j]));
totaldiatance += distance[i,j];
distance[j, i] = distance[i, j];
}
}

66
e. To initialize the pheromones in array
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
if (i != j)
pheromone[i, j] = 0.01;
else if (i == j)
pheromone[i, j] = 0.00;
}
}
f. To initialize unvisited cities:
public void unvisit_initialization()
{
for (int ant = 0; ant < AntNumber; ant++)
{
for (int i = 0; i < count; i++)
{
cityUnvisited[ant,i] = city[i];
}
}
}
g. Program Function Code:
public void mainproc(FormMap object_form)
{
stopWatch.Reset();
elapsedTime=stopwatch.elapsed;
stopWatch.Start();
for (int k = 1; k <= Round; k++) //how many round
{
Random rand = new Random();
int new_index = rand.Next();
new_index = new_index % count;
String initial = city[new_index];

//How many ants


for (int antIndex = 0; antIndex < AntNumber; antIndex++)
//ant loop
{
unvisit_initialization(); //initialize the
unvisited cities.
int m = 0;
cityVisited[antIndex, m] = initial; //store initial
city as first visited city for ant.

67
for (int j = 0; j < count - 1; j++)
{
int index = Array.IndexOf(city, initial);
m++;
cityUnvisited[antIndex, index] = "\0";
for (int i = 0; i < count; i++)
{
probs[antIndex, i] = 0.0;
}
String selectedCity = CalcProbability(initial,
ants[antIndex]);
cityVisited[antIndex, m] = selectedCity;
initial = selectedCity;
}

CalcLength(ants[antIndex]);

new_index = run_d.Next(0, count);


initial = city[new_index];
}

optimalTourLength = tourLength[0]; //initialize optimal


tourlength of ant 0

if (bestTourInitialize == 1) //initialize best tour


length and best tour city for 1 time only.
{
bestTourLength = optimalTourLength;
for (int i = 0; i < count; i++)
{
bestTourCity[i] = cityVisited[0, i];
//initialize visited city of ant 0 as best tour city
}
bestTourInitialize = 0;

}
int flag = 0;
double sum = 0.0;
for (int i = 0; i < AntNumber; i++) //Calculate
optimal tour.
{
sum += 1 / tourLength[i];
if (optimalTourLength > tourLength[i])
{
optimalTourLength = tourLength[i];
flag = i;
}

68
}

if (optimalTourLength <= bestTourLength)


{
bestTourLength = optimalTourLength;
for (int i = 0; i < count; i++)
{
bestTourCity[i] = cityVisited[flag, i];
//initialize optimal city as best tour city
}

UpdatePheromone(ants[flag], sum);
}
}
stopWatch.Stop();
elapsedTime = stopWatch.Elapsed;
}

h. To calculate probability for Cities:


public String CalcProbability(String initial, int ant)
{
double sum = 0.0;
int cityIndex = Array.IndexOf(city, initial);
int antIndex = Array.IndexOf(ants, ant);
for (int i = 0; i < count; i++)
{
if (city[i] == initial)
{
for (int j = 0; j < count; j++)
{
if (city[j] == cityUnvisited[antIndex, j] &&
city[j] != initial)
{
sum += (Math.Pow(pheromone[cityIndex, j], alpha)
* Math.Pow((1.0 / distance[cityIndex, j]), beta));
}
}
}
}

for (int i = 0; i < count; i++)


{
if (city[i] == cityUnvisited[antIndex, i])

69
probs[antIndex, i] = (Math.Pow(pheromone[cityIndex,
i], alpha) * Math.Pow((1.0 / distance[cityIndex, i]), beta));

else
probs[antIndex, i] = 0.0;
}

Random p_r = new Random();


double prob = p_r.NextDouble() * sum;
int j_counter = 0;
double p = probs[antIndex, j_counter];

while (p < prob)


{
j_counter++;
p += probs[antIndex, j_counter];
}
int randomDecision = j_counter;
double maxHeuristic = -1;
int maxHeuristicIdx = -1;
for (int j = 0; j < count; j++)
{
double temp = probs[antIndex, j];
if (maxHeuristic < temp && city[j] ==
cityUnvisited[antIndex, j])
{
maxHeuristic = temp;
maxHeuristicIdx = j;
}
}
String selectedcity;
if (p_r.NextDouble() < Q0)
{
selectedcity = cityUnvisited[antIndex, maxHeuristicIdx];
cityUnvisited[antIndex, maxHeuristicIdx] = "\0";
}
else
{
selectedcity = cityUnvisited[antIndex, randomDecision];
cityUnvisited[antIndex, randomDecision] = "\0";
}
return (selectedcity);
}

70
i. To calculate distance travelled by each ant
public void CalcLength(int ant)
{
int antIndex = Array.IndexOf(ants, ant);
tourLength[antIndex] = 0.0;
int index1,index2;
for (int a = 0; a < count; a++)
{
index1=Array.IndexOf(city,cityVisited[antIndex,a]);
index2 = Array.IndexOf(city, cityVisited[antIndex, (a + 1) %
count]);
tourLength[antIndex] += distance[index1,index2];
}
}
j. To update pheromones
public void UpdatePheromone(int ant, double sum)
{
int antIndex = Array.IndexOf(ants, ant);
double temp = 1 / bestTourLength;
int index1, index2;
for (int i = 0; i < count; i++)
{
index1=Array.IndexOf(city,cityVisited[antIndex,i]);
index2 = Array.IndexOf(city, cityVisited[antIndex, (i + 1)
% count]);
pheromone[index1, index2] = (1-rho) * pheromone[index1,
index2] + Q * sum;
pheromone[index2, index1] = pheromone[index1, index2];
}
}

71

You might also like