4. TSP
4
Problem definition
The traveling salesman problem consists of a salesman and a set
of cities. The salesman has to visit each one of the cities
starting from a certain one (e.g. the hometown) and
returning to the same city. The challenge of the problem is
that the traveling salesman wants to minimize the total length
of the trip.
5. TSP
The traveling salesman problem can be described as follows:
TSP = {(G, f, t): G = (V, E)
a complete graph,
f is a function V×V Z, t Z,→ ∈
G is a graph that contains a traveling salesman tour with cost
that does not exceed t}.
5
7. TSP
The problem lies in finding a minimal path passing from all
vertices once. For example the path Path1 {A, B, C, D, E,
A} and the path Path2 {A, B, C, E, D, A} pass all the
vertices but Path1 has a total length of 24 and Path2 has a
total length of 31.
7
8. TSP
Solution is given by enumerating each possible tour and
searching for the tour with smallest cost. Each possible tour
is a permutation of 123 . . . n, where n is the number of
cities, so therefore the number of tours is n! When n gets
large, it becomes impossible to find the cost of every tour in
polynomial time. Such a method, which will end up giving
the optimal solution, is obviously not very feasible because of
the time consumption required to calculate all the tours
8
9. Firefly algorithm
Basic concept
Fireflies are small winged beetles capable of producing a light
flashes in order to attract mates. They are believed to have a
capacitor-like mechanism, that slowly charges until certain
threshold is reached, at which they release the energy in
form of light, after which the cycle repeats.
Firefly Algorithm (FA) is novel nature inspired meta-heuristic
algorithm based on rhythmic flashing behavior of Fireflies.
9
10. Firefly algorithm
3 flashing characteristics of fireflies to develop firefly-
inspired algorithms.
1. one firefly will be attracted to other fireflies regardless of
their gender
2. The attractiveness is proportional to the brightness and they
both decrease as their distance increases.
3. The brightness of a firefly is determined by the landscape of
the objective function.
10
11. Firefly algorithm
Objective function f(x), x = (x1... xd)T
Generate initial population of fireflies xi (i = 1, 2... n)
Light intensity Ii at xi is determined by f (xi)
Define light absorption coefficient γ
while (t < MaxGeneration)
for i = 1 : n all n fireflies
for j = 1 : n all n fireflies (inner loop)
if (Ii < Ij),
Move firefly i towards j;
end if
Vary attractiveness with distance r via exp[− r]γ
Evaluate new solutions and update light intensity
end for j
end for i
Rank the fireflies and find the current global best g*
end while11
12. Firefly algorithm
First each firefly generates an initial solution randomly;
parameters like Light Intensity I, Initial Attractiveness 0,β
and light absorption coefficient are defined. Then for eachγ
firefly, find the brightest firefly. If there is brighter firefly
then less bright firefly will move towards the brighter one.
When firefly moves its light intensity decreases and its
attractiveness will change. Then best firefly will be chosen
based on an objective function for the next iteration. This
condition will continue until the max iteration is reached.
12
13. Adapting Firefly algorithm for TSP
FA can be used to solve a permutation problem, such as
Travelling Salesman Problem. For that we need to
implement functions Initial_Solution() and Distance(xi, xj )
in a way how it is represented in TSP. We also need to
redefine the step movements of the fireflies
13
14. Adapting Firefly algorithm for TSP
Initial Solution
fireflies are scattered over the search space in a uniform
distribution.
we need to produce m random permutations of (1, 2… n) as
the initial fireflies.
Use a greedy method or nearest neighborhood search for
solution initialization would improve the performance of the
algorithm.
By putting one relatively good solution among the random
solutions, would cause the random solutions immediately to
advance towards the better solution. This would probably
contribute to find the local optima faster, but not for better
exploration of the search space.14
15. Adapting Firefly algorithm for TSP
Distance Function
(a)Hamming’s distance
(b)the number of the required swaps of the first solution in
order to get the second one.
Let’s examine this example.
Consider permutations π1,π2 ∈ n�
�1 = [1 2 3 4 5 6]
�2 = [1 2 4 3 6 5]
15
16. Adapting Firefly algorithm for TSP
The Hamming’s distance between two permutations is the
number of non corresponding elements in the sequence.
Therefore, HammingDistance(π1, π2) is 4 (only the first
two positions have the same elements).
The Swap distance is the number of minimal required swaps
of one permutation in order to obtain the other one.
SwapDistance(π1, π2) is thereby, 2 (in the π2 we swap
elements: 4 with 3 and then 5 with 6).
16
17. Adapting Firefly algorithm for TSP
Movement
The movement of a firefly i attracted to another brighter (more
attractive) firefly j is determined by:
�� ������← (2,���)
Where, dij is distance between firefly i and j.
The length of movement of a firefly will be randomly selected
from 2 to dij.
17
18. Adapting Firefly algorithm for TSP
When a firefly moves, existing solutions in the firefly is
changed.
Since the representation of firefly is a permutation
representation, then we use Inversion Mutation to represent
the movement.
With inversion mutation, the path that has been formed can
be maintained so the good path formed previously is not
damaged.
18
19. Implementation and Results
The Firefly Algorithm with some modification in few
parameters in order to adapt it to solve travelling Salesman
problem is implemented by using MATLAB 2010.
Intel CORE i5 machine with 3 GB RAM is used to run the
algorithm. TSP datasets are standard TSP instances
downloaded from TSPLIB
This algorithm runs itself till the termination criteria are
satisfied. We can use more than one termination criteria in
the model such as predefined number of iterations,
stagnations in the result, time-limit etc. Here, stagnation in
the result is used as the termination criteria.
19
26. Implementation and Results
26
Table 1 also shows performance Comparison with
three of the most popular meta-heuristic algorithms the
Ant Colony Optimization (ACO), the Genetic Algorithm
(GA), and Simulated Annealing (SA).
27. Conclusion
Here, basic Firefly Algorithm (FA) is implemented with
some modifications in parameters to adapt it for Travelling
Salesman Problem (TSP) which consists of constructing a
suitable conversion of the continuous functions as are
attractiveness, distance and movement, into new discrete
functions. The experimental results obtained on standard
TSP instances. It shows that Firefly Algorithm (FA) provides
better results than ACO, GA and SA in most of the
instances.
These results can be further improved by using various local
search methods like Tabu Search, nearest neighborhood for
initial solution.
27