Vous êtes sur la page 1sur 13

University Mohammed First

Multidisciplinary Faculty of Nador

Master in Data Science and Intelligent Systems

Project memory for the


‘Optimization algorithm’ module

Ant colony algorithm to the


traveling salesman problem

Supervisor:
Prof.AL ALLALI Naoufal

Produced by:
BABZINE Bahija && CHABOUT Hajar

Academic year: 2022−2023


Abstract

The report deals with the Traveling Salesman Problem (TSP) and the use of the Ant Colony
Optimization (ACO) algorithm to solve it. The report begins by explaining the TSP problem
using an example. In the second chapter, it is explained what a real ant and an artificial ant are,
as well as how ACO uses pheromone trails to guide artificial ants in exploring the search space.
The third chapter covers the ACO algorithm and its variants, as well as the mathematical
relationships involved in the evaporation of pheromone trails and the selection of cities to visit.
The fourth chapter deals with code parallelization using fork join. Finally, in the last chapter,
the results obtained are presented, as well as a comparison between ACO and PSO, where it is
noticed that ACO is more effective than PSO in solving the TSP problem.

Resume
Le rapport traite du problème du TSP (Traveling Salesman Problem) et de l'utilisation de
l'algorithme ACO (Ant Colony Optimization) pour le résoudre. Le rapport commence par
expliquer le problème du TSP en donnant un exemple. Dans le deuxième chapitre, il est
expliqué ce qu'est une fourmi réelle et une fourmi artificielle, ainsi que la manière dont ACO
utilise les pistes de phéromones pour guider les fourmis artificielles dans l'exploration de
l'espace de recherche. Le troisième chapitre couvre l'algorithme ACO et ses variantes, ainsi que
les relations mathématiques impliquées dans l'évaporation des pistes de phéromones et la
sélection des villes à visiter. Le quatrième chapitre traite de la parallélisation du code par fork
join. Enfin, dans le dernier chapitre, les résultats obtenus sont présentés, ainsi qu'une
comparaison entre ACO et PSO, où il est remarqué que ACO est plus efficace que PSO pour
résoudre le problème du TSP.
Contents
Goal of this mini project .......................................................................................................................... 5
Organization of the report ...................................................................................................................... 5
I. Definition ......................................................................................................................................... 6
II. Example ........................................................................................................................................... 6
III. Conclusion ................................................................................................................................... 6
I. Real VS artificial ant colony ............................................................................................................. 7
II. Ant pheromones .............................................................................................................................. 7
1. pheromones ................................................................................................................................ 7
2. Pheromone trails ......................................................................................................................... 7
3. Evaporation of pheromones........................................................................................................ 7
III. Functioning .................................................................................................................................. 8
1. Finding the shortest path ............................................................................................................ 8
2. Conclusion ................................................................................................................................... 8
I. Ant Colony Optimization Algorithms (ACO) .................................................................................... 8
1. ACO variants ................................................................................................................................ 9
2. Operation of the Ant system algorithm: ..................................................................................... 9
II. Data provided: ................................................................................................................................. 9
III. Initialisation: ................................................................................................................................ 9
IV. Construction of the paths:........................................................................................................... 9
V. Pheromone Update: ...................................................................................................................... 10
VI. Algorithm: .................................................................................................................................. 10
VII. Conclusion ................................................................................................................................. 10
I. parallel and tsp problem ............................................................................................................... 10
1. Parallelization functioning in our code...................................................................................... 10
II. Conclusion ..................................................................................................................................... 11
I. Tools .............................................................................................................................................. 11
II. experimental results...................................................................................................................... 11
Table of Figures
Figure 1: Example of TSP ......................................................................................................................... 6
Figure 2: The shortest path ..................................................................................................................... 8
Figure 3: ACO Algorithm ........................................................................................................................ 10
Figure 4: Java Logo ................................................................................................................................ 11
Figure 5: Eclipse Logo ............................................................................................................................ 11
Figure 6: Comparison between ACO and PSO ....................................................................................... 12

List of abbreviation:
ACO : Ant Colony Optimisation.
TSP : Travel Salesman Problem.
AS : Ant System.
ACS: Ant Colony System
MMAS: Max Min Ant System.
EAS: Elitist Ant System.
PSO: Particle Swarm Optimization.
Introduction general
The Traveling Salesman Problem (TSP) is a classic optimization problem that involves finding
the shortest path that visits a set of cities exactly once and returns to the starting city. TSP is an
NP-hard problem and has numerous applications in logistics, transportation, and circuit board
drilling. To solve TSP, a range of optimization algorithms have been developed, including
heuristics, metaheuristics, and exact algorithms. Examples of such algorithms are simulated
annealing, genetic algorithms, ant colony optimization
Ant Colony Optimization (ACO) is a metaheuristic algorithm inspired by the foraging behavior
of ants that has been successfully applied to solve TSP. ACO is based on the concept of
pheromone trails, where ants deposit pheromones as they travel, and other ants follow these
trails to find the shortest path. ACO has been found to be an effective algorithm for solving
TSP and has been applied to real-world problems.[1][2][3]

Goal of this mini project


The main objective of this mini project is to solve the traveling salesman problem (TSP) by the
ant colony optimization algorithm to find the shortest path.

Organization of the report


This article will include four chapters, besides a general introduction and conclusion :
❖ Chapter 1 covers the Traveling Salesman Problem (TSP)
❖ Chapter 2 couvers the principe of Ant Colony and how it works
❖ Chapitre 3 couvers the Algorithmes of Ant Colony Optimisation
❖ Chapitre 4 covers the parallelization of our code
❖ Chapter 5 covers the comparaison of experimental results between ACO and PSO
1- Traveling Salesman Problem (TSP)
I. Definition
The Traveling Salesman Problem (TSP) is an optimization problem that consists of find the
shortest path connecting a set of given cities, passing exactly once per city to return to the
starting city.[4]

II. Example

Figure 1: Example of TSP

Solving the traveling salesman problem amounts to finding in this graph, a cycle passing
through all the vertices once (such a cycle is said to be Hamiltonian”) and which is of minimal
length.

III. Conclusion
So despite the simplicity of the problem but it is a complex optimization problem because we
do not find the exact solution quickly, The TSP is an NP-hard problem, meaning that it becomes
computationally infeasible to find the optimal solution as the number of cities increases.
Therefore, various optimization algorithms have been developed to find good approximate
solutions to the TSP.

2- Optimization with Ant Colony


This paragraph compares real and artificial ant colony behavior in finding the shortest path, and
explores how pheromone trails and evaporation affect this behavior.
I. Real VS artificial ant colony
Real and artificial ants share similarities and differences in terms of physical characteristics,
behaviors and functions.
❖ Similarities :
• Both real and artificial ants are capable of moving and communicating with
other members of their colony.
• They both use chemical signals to communicate with other ants and mark their
paths.
• Real and artificial ants both have hierarchical social structures, with individuals
specialized in specific tasks.
❖ Differences:
• Real ants are biological organisms, while artificial ants are robots designed by
humans.
• Real ants have sensory abilities and complex behaviors that allow them to adapt
to their natural environment, while artificial ants rely on electronic sensors and
computer programs to interact with their artificial environment.
• Real ants have much more limited information processing capabilities than the
computers used to control artificial ants.
• Artificial ants can be programmed to perform specific tasks, while real ants are
guided by instinctive behaviors and social interactions.

II. Ant pheromones


1. pheromones
Pheromones in ant colonies are chemical signals used by ants to communicate and coordinate
collective behavior. They mark trails to food, signal nest locations, recruit other ants, and
distinguish between colony members and intruders. Pheromones facilitate efficient information
exchange and complex task execution in ant social behavior.

2. Pheromone trails
Pheromone trails are scent markings used by ants to communicate and navigate between their
nest and food sources. They allow other ants to locate and follow the trail. The strength and
duration of the trail are determined by the amount of pheromones deposited and the frequency
of use. Pheromone trails are crucial for efficient ant foraging behavior and colony success.

3. Evaporation of pheromones
Pheromones evaporate naturally due to heat and ventilation, gradually reducing the strength of
ant trails. Lifetime depends on temperature, humidity, and type. Ants add new odor marks or
use tactile signals to compensate.
III. Functioning
1. Finding the shortest path
Real and virtual ants share a common goal: the search for more short path linking a starting
point (the nest) to destination sites (the food).

Figure 2: The shortest path

• The first ant finds the food source (F) via any path (a), then returns to the nest (N)
leaving behind a trail of pheromones (b).
• Ants travel indifferently on any of the four possible paths, but the reinforcement of the
pheromone trail makes the shortest path more attractive.
• Ants follow the shortest path, and the longer portions of other paths lose their
pheromone trail.

2. Conclusion
It is interesting to note that a single ant is able to build a solution of finding a way from the nest
to the food, this is only the behavior of the whole colony that creates the shortest path.

3- Ant Colony Optimization Algorithms


(ACO)
Ant Colony Optimization (ACO) algorithms are inspired by the behavior of ants and have been
successfully applied to various optimization problems. They use a probabilistic approach and
pheromone trails to guide the search for an optimal solution.

I. Ant Colony Optimization Algorithms (ACO)


Ant Colony Optimization Algorithms (ACO) are a family of optimization algorithms inspired
by the behavior of ant colonies. These algorithms mimic the collective decision-making
behavior of ants to find the optimal solution to a problem. ACO algorithms use a probabilistic
approach and employ pheromone trails to guide the search for a solution. They have been
successfully applied to various optimization problems, such as the traveling salesman problem,
the vehicle routing problem, and the job-shop scheduling problem…

1. ACO variants
• Ant system (AS): The first ant colony algorithm The goal is to find the shortest distance
between their nest and a food source.
• Ant Colony System (ACS): Algorithm variant ant System that uses a path selection
method based on a quality value called "visibility" to solve optimization problems.
• Max-Min Ant System (MMA): Variant of the Ant System algorithm that uses upper
and lower bounds on pheromone rates to avoid premature convergence of the algorithm
and to improve the quality of the final solution.
• Elitist Ant System (EAS) : Variant of the Ant System algorithm that gives an advantage
to ants that have found the best solutions by allowing them to deposit more pheromones
on their path.

2. Operation of the Ant system algorithm:

II. Data provided:


➢ A finite set X of nodes representing cities
➢ A finite set U = {(i, j) |i, j ∈ X} of arcs connecting the nodes in X
➢ A set of constants dij representing the length of each arc (i, j) ∈ U, i.e., the distance
between city i and city j (with i, j ∈ X).

III. Initialisation:
➢ bi(t) be the number of ants in city i at time t
➢ m = p Σi∈X bi be the total number of ants, which is invariant over time
➢ τij(t) be the amount of pheromone on the edge (i,j) at time t
➢ n = |X| be the number of cities
➢ ηij = 1/dij be the visibility of city j when located in city i, which is invariant over time.
Let's now specify the behavior of the entire colony. At any time t, each ant chooses a destination city
based on a defined choice. All ants move to a city of their choice at time t+1. An iteration of the Ant
System algorithm is defined as the set of movements of the entire colony between time t and time t+1.
Thus, after n iterations, the entire colony will have completed a Hamiltonian circuit on the graph. In this
way, all ants will start and finish their tour at the same time.

IV. Construction of the paths:


A ant k placed on city i at time t will choose its destination city j based on the visibility ηij of
that city and the amount of pheromones τij(t) deposited on the edge connecting these two cities.
This choice will be made randomly, with a probability of choosing city j given by:
V. Pheromone Update:
At the end of each cycle (when each ant has visited all n nodes in the graph), the pheromone
variables are updated according to the formula:
τij(t+1) = (1 - ρ) τij(t) + ∑ Δτijk(t)
where ρ is the evaporation coefficient, and Δτijk(t) is the amount of pheromone deposited by ant k on
arc (i, j) during the cycle. The evaporation coefficient ρ controls the rate at which the pheromone trail
evaporates, and ensures that the algorithm does not converge too quickly to a suboptimal solution. The
pheromone update rule ensures that good paths are reinforced over time, as the amount of pheromone
on a given path increases with the number of ants that travel on it.

VI. Algorithm:

Figure 3: ACO Algorithm

VII. Conclusion
Ant Colony Optimization Algorithms (ACO) mimic the collective decision-making behavior
of ants to find optimal solutions to problems. ACO variants, such as Ant System, Ant Colony
System, Max-Min Ant System, and Elitist Ant System, have been successful in solving various
optimization problems.

4- parallelization
Parallelism is a computer technique that allows tasks to be executed in parallel, i.e.
simultaneously, in order to reduce the overall execution time of a program.

I. parallel and tsp problem


1. Parallelization functioning in our code
Parallelism is used to speed up the processing of the ants algorithm for the traveling salesman
problem.
More precisely, parallelism is used to execute in parallel the search for the next city to be visited
by each ant. This is done using Java's ForkJoinPool class, which allows creating a pool of
threads to execute tasks in parallel. In the code, the ParallelFor class is created to execute the
for loop which finds the next city to visit for each ant.
Each instance of the ParallelFor class is created with a start index, an end index, the current
city, and a random number calculated based on the pheromone. The for loop is then executed
in parallel for each instance of the ParallelFor class, with each thread executing part of the loop.
At the end of each instance of ParallelFor execution, the results are combined to get the next
city for each ant.

II. Conclusion
By using this parallelism technique, the ants' algorithm can be executed faster, which makes it
possible to find a solution for the traveling salesman problem more quickly.

5- tools and experimental results


In this part, we will introduce the tools that enabled us to carry out this work, present our
experimental results, and interpret them.

I. Tools
Java is a high-level, object-oriented programming language with bytecode
compilation and platform independence, designed to be simple, secure, and
portable.
Figure 4: Java Logo

Eclipse is an integrated development environment (IDE) for software developers.

Figure 5: Eclipse Logo

II. experimental results


Number of cities ACO PSO
4 6 185
6 10 400
10 11 418
14 12 528
17 16 663
700
Comparison between ACO and PSO
600

500

Time in ms
400

300 ACO

200 PSO

100

0
0 5 Number
10 of cities 15 20

Figure 6: Comparison between ACO and PSO

▪ We notice in the two algorithms (ACO, PSO) that more the number of cities is increased,
the execution time increases.
▪ We also notice the more we increase the search space, the more the execution time in
PSO becomes larger and larger than the time execution in ACO. That is, the more
complex the problem becomes, the better the performance of the algorithms is ACO.
▪ Which is obvious since ACO is supposed to improve the performance of algorithms by
reducing their execution time.

6- Conclusion
In conclusion, this report has presented the TSP problem and the ACO algorithm as a solution.
By explaining in detail the functioning of artificial ants and pheromone trails, we have shown
how ACO can be used to efficiently explore the search space and find an optimal solution for
TSP. The variants of the ACO algorithm have also been presented, as well as how the code can
be parallelized to improve performance. Finally, by comparing ACO to PSO, we have shown
that ACO is more effective for solving the TSP problem. In summary, the ACO algorithm is a
powerful and effective method for solving TSP, and understanding it can be useful for solving
other combinatorial optimization problems.
References

[1]: awler, E. L., Lenstra, J. K., Rinnooy Kan, A. H. G., & Shmoys, D. B. (1985). The Traveling
Salesman Problem: A Guided Tour of Combinatorial Optimization. John Wiley & Sons.
[2]: Blum, C., & Roli, A. (2003). Metaheuristics in combinatorial optimization: Overview and
conceptual comparison. ACM Computing Surveys, 35(3), 268-308.
[3]: Dorigo, M., & Stützle, T. (2004). Ant Colony Optimization. MIT Press.
[4] : Papadimitriou, C. H., & Steiglitz, K. (1998). Combinatorial Optimization: Algorithms and
Complexity. Dover Publications.

Vous aimerez peut-être aussi