0% found this document useful (0 votes)
19 views26 pages

Tutorial 8

The document describes how the traveling salesman problem can be solved using the ant colony optimization algorithm. It involves delivery men minimizing costs to visit 5 cities, with changing traffic conditions between cities. The algorithm models this using ant behavior to probabilistically determine the best path while depositing and following pheromone trails, with the goal of finding the shortest route.

Uploaded by

2021899796
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views26 pages

Tutorial 8

The document describes how the traveling salesman problem can be solved using the ant colony optimization algorithm. It involves delivery men minimizing costs to visit 5 cities, with changing traffic conditions between cities. The algorithm models this using ant behavior to probabilistically determine the best path while depositing and following pheromone trails, with the goal of finding the shortest route.

Uploaded by

2021899796
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Tutorial – Travel Salesman Problem using Ant Colony Algorithm

Imagine that there are three (3) number of delivery men of that send postage
items into five (5) different cities. These delivery men want to minimize the
cost of their journey going to the cities and visit each city only once.
Because each day maybe different roads are having different peak busy hour.
For example, sometimes City1 to City2 during Monday is not a peak day. But
during Tuesday it is really crowded with cars.
Hence, the delivery men need to communicate with each other’s to get the
best possible path road in such way that it is minimize the journey cost and visit
once for each city. Therefore, this behaviour can be represented like the three
(3) number of ants in the colony behaviour that trying to find food in five (5)
different food sources.
Info Table:
Info Description
d Indicate the distance matrix between each city/food source.
to Indicate the Initial Pheromone level matrix between each city/food source.
t1 Indicate the Update Pheromone level matrix between each city/food source.
h Indicate the Visibility of Pheromone level between each city/food source after the ants move.
Formula Table:
Formula Description

{
[1] Pheromone level 1
for a single ant k th
△ T i , j= Lk , k ant travels on the edge i , j
0
• L is length of path edge
• I,j are (node/city/corner) in graph
• K in specific ant
[2] Pheromone level m

for multiple ant T =∑ △ T ki , j wit h out vaporization


k
i,j
k=1
or
m
T ki , j =( 1− p ) T i , j ∑ △ T ki , j wit h vaporization
k=1
• p is evaporation rate
[3] The probability of
choosing the edges ( Initial P h eromone Level ) ×( P h eromone level ant on edge)
Pi , j =
∑ ( ( Initial P h eromone Level ) ×( P h eromone level ant on edge))
or
( Initial P h eromone Level ) ×(vis ibility of cities)
Pi , j =
∑ ( ( Initial P h eromone Level ) ×( visibility of cities))
or
Iteration 1:
Step 1: Ant 1

{| }
Determine
visibility
City 1 2 3 4 5
1 0 10 12 11 14
d= 2 10 0 13 15 8
3 12 13 0 9 14
4 11 15 9 0 16
5 14 8 14 16 0

{| }
City 1 2 3 4 5
1 1 1 1 1 1
t o= 2 1 1 1 1 1
3 1 1 1 1 1
4 1 1 1 1 1
5 1 1 1 1 1

Using both matrices, the visibility (h) or Pheromone Level for each path can
be calculated using formula [1].
For example, 1 city to all cities (2,3,4,5):

City Path Pheromone Level


1 to 2 1 1
T 1 ,2=1 x =0.1
10
1 to 3 1 1
T 1 ,3=1 x =0.083
12
1 to 4 1 1
T 1 ,4 =1 x =0. 0909
11
1 to 5 1 1
T 1 ,4 =1 x =0.0 714
14

Hence, . . .

{| }
City 1 2 3 4 5
1 0 0.1 0.083 3 0.0909 0.0714
h= 2 0.1 0 0.7692 0.6667 0.125
3 0.083 0.7692 0 0.1111 0.0714
4 0.0909 0.6667 0.1111 0 0.0625
5 0.0714 0.125 0 0.0714 0.0625 0

Step 2: Ant 1 Determine the probability of the ant 1 moving from one city to another
Determine city. In this case city 1 is designated as a departure city. Then from the
The last city visited ant 1/deliveryman are going back to city 1.
probability As city 1 is chosen as the beginning city 1 then city will be taboo to visit
again, so that the level of visibility of the city 1 is made =0. (sbb tak lalu
dah aka origin location)

{| }
City 1 2 3 4 5
1 0 0.1 0.0833 0.0909 0.0714
h= 2 0 0 0.7692 0.6667 0.125 0
3 0 0.7692 0 0.1111 0.0714
4 0 0.6667 0.1111 0 0.0625
5 0 0.125 0 0.0714 0.0625 0

As mentioned, this step is going to calculate the probability of the ant 1


choose the path from 1 city to all cities (2,3,4,5).
Hence, we can calculate the probability using formula [3]:

City Path Probability


1 to 2

Pi , j =
( 0.1 ) × ( 101 ) =0.3
( )
( 0.1 000 )
1
10 ( )
+ ( 0.083 0 )
1
12
+ ( 0.0909 )
1
11 ( ) ( )
+ ( 0.0714 )
1
14
1 to 3

Pi , j =
( 0. 0830 ) × ( 112 ) =0.2
( )
( 0.1 000 )
1
10 ( )
+ ( 0.083 0 )
1
12
+ ( 0.0909 )
1
11 ( ) ( )
+ ( 0.0714 )
1
14

1 to 4

Pi , j =
( 0. 0909 ) × ( 111 ) =0.2
( )
( 0.1 000 )
1
10 ( )
+ ( 0.083 0 )
1
12
+ ( 0.0909 )
1
11 ( ) ( )
+ ( 0.0714 )
1
14

1 to 5

Pi , j =
( 0.0714 ) × ( 114 ) =0.1
( )
( 0.1 000 )
1
10 ( )
+ ( 0.083 0 )
1
12
+ ( 0.0909 )
1
11 ( ) ( )
+ ( 0.0714 )
1
14

Hence, below shows the probability of the ant 1 going to choose the path
between city 1 to all cities (2,3,4,5) are:
City Path Probability
1 to 2 0.3299
1 to 3 0.2291
1 to 4 0.2727
1 to 5 0.1683

Therefore, the easier way to determine the WHICH the ant 1 going to
choose the path is using the Roulette wheel selection.

First calculate the cumulative probabilities of each city.

City Path Probability Cumulative Probability


1 to 2 0.3299 0 + 0.3299 = 0.3299
1 to 3 0.2291 0.3299 + 0.2291 = 0.5590
1 to 4 0.2727 0.5590 +0.2727 = 0.8317
1 to 5 0.1683 0.8317 + 0.1683 = 1.000

Step 3: Ant 1 Hence from the cumulative probability, the range for each path can be
Determine created:
choice of
cities City Path Cumulative Probability Range
(1st selection 1 to 2 0.3299 0.000 - 0.3299
1 to 3 0.5590 0.3300 - 0.5590
city)
1 to 4 0.8317 0.5591 - 0.8317 (has highest
space probability)
1 to 5 1.000 0.8318 - 1.000

Suppose that a random number is being generated, r = 0.6841.

Since the r lies on range of the city


Therefore, the ant is going to

route formed for ant 1 so far is .


Repeat Step Ant 1 Since city 4 has been selected then 4th column of the matrix, the
2 : Determine visibility set to 0 so that

{| }
probability City 1 2 3 4 5
1 0 0.1 0.0833 0 0.0714
h= 2 0 0 0.7692 0 0.125 0
3 0 0.7692 0 0 0.0714
4 0 0.6667 0.1111 0 0.0625
5 0 0.125 0 0.0714 0 0

{| }
City 1 2 3 4 5
1 0 10 12 11 14
d= 2 10 0 13 15 8
3 12 13 0 9 14
4 11 15 9 0 16
5 14 8 14 16 0

From here, the probability for each path city 4 to others city (except 1) is
being calculated. Before that, first it is better if the summation of the
probability is being calculated (denominator of formula [3.1]).

Probability of each path is calculated as shown below:


*Solve this because >1
City Path Probability
4 to 2

Pi , j =
(
( 0. 6667 )
15)
1
=0. 7334
( 0. 6667 ) ( )+ ( 0.1 111) ( )+ ( 0. 0 625 ) ( )
1 1 1
15 9 16

4 to 3

Pi , j =
( 0.1111 ) ×( 9)
1
=0. 2037
( 0. 6667 ) ( )+ ( 0.1 111) ( )+ ( 0. 0 625 ) ( )
1 1 1
15 9 16

4 to 5

Pi , j =
( 0. 0 625 ) ×( 16 )
1
=0. 064 4
( 0. 6667 ) ( )+ ( 0.1 111) ( )+ ( 0. 0 625 ) ( )
1 1 1
15 9 16

Hence, the cumulative probability:


City Path Probability Cumulative Probability
4 to 2
4 to 3
4 to 5

Repeat Step 3 Ant 1 Then, the range of each path:


(2nd selection City Path Cumulative Probability Cumulative Probability
city) 4 to 2
4 to 3
4 to 5

Suppose that a random number is being generated, r = 0.4024.

Since the r lies on range of the city


Therefore, the ant is going to.

route formed for ant 1 so far is


Repeat Step Ant 1 Since city 3 has been selected then 3th column of the matrix, the
2 : Determine visibility set to 0 so that
probability

{| }
City
1
h= 2 1 2 3 4 5 0 ¿ 0 ¿ ¿ 0 ¿ ¿ 0 ¿ 0 ¿ ¿ 0 ¿ ¿ 0 ¿ 0 ¿ ¿ 0 ¿ ¿ 0 ¿ 0 ¿ 0 ¿
3 0 ¿0 0 ¿0 ¿
4
5
From here it is better again if the summation of the probability is being
calculated (denominator of formula [3.1]) from city 3 to all of the cities
(except city 1,4)

Probability of each path is calculated as shown below:

City Path Probability


3 to 2

3 to 5

Hence, the cumulative probability:


City Path Probability Cumulative Probability
3 to 2
3 to 5
Repeat Step 3 Ant 1 Then, the range of each path:
( 3rd selection City Path Cumulative Probability Cumulative Probability
city) 3 to 2
3 to 5

Suppose that a random number is being generated, r = 0.8024.

Since the r lies on range of the city


Therefore, the ant is going to

route formed for ant 1 so far is


Repeat Step Ant 1 Since city 5 has been selected then 5th column of the matrix, the
2 : Determine visibility set to 0 so that
probability

{| }
City
1
h= 2 1 2 3 4 5 0 ¿ 0 ¿ 0 ¿ 0 ¿ 0 ¿ ¿ 0 ¿ 0 ¿ 0 ¿ 0 ¿ ¿ 0 ¿ 0 ¿ 0 ¿ 0 ¿ ¿ 0 ¿ 0 ¿ 0 ¿
3 0 ¿0 0 ¿ ¿
4
5

From here it is better again if the summation of the probability is being


calculated (denominator of formula [3.1]) from city 5 to all of the cities
(except city 1,4,3)

Probability of each path is calculated as shown below:


City Path Probability
5 to 2
Hence, the cumulative probability:
City Path Probability Cumulative Probability
5 to 2
Repeat Step 3 Ant 1 Then, the range of each path:
( 4th selection City Path Cumulative Probability Cumulative Probability
city) 5 to 2

Suppose that a random number is being generated, r = 0.7023.

Since the r lies on range of the city


Therefore, the ant is going to.

route formed for ant 1 so far is

Since the requirement for last city visited is City 1, so we are going back
to City 1 such as: Ant 1:
Step 1: Ant 2

{| }
Determine (Same
visibility distance,
City 1 2 3 4 5
d) 1 0 10 12 11 14
d= 2 10 0 13 15 8
3 12 13 0 9 14
4 11 15 9 0 16
5 14 8 14 16 0

{| }
City 1 2 3 4 5
1 1 1 1 1 1
t o= 2 1 1 1 1 1
3 1 1 1 1 1
4 1 1 1 1 1
5 1 1 1 1 1

Using both matrices, the visibility (h) or Pheromone Level for each path can
be calculated using formula [1].

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0.0909 0.0714
h= 2 0.1000 0 0.0769 0.0667 0.1250
3 0.0833 0.0769 0 0.1111 0.0714
4 0.0909 0.0667 0.1111 0 0.0625
5 0.0714 0.1250 0.0714 0.0625 0

Step 2 : Ant 2 Determine the probability of moving from one city to another. In this
Determine case city 1 is designated as a departure city. Then from the last city
probability visited we are going back to city 1. As city 1 is chosen as the beginning
city 1 then city will be taboo to visit again, so that the level of visibility
of the city 1 is made =0.

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0.0909 0.0714
h= 2 0 0 0.0769 0.0667 0.1250
3 0 0.0769 0 0.1111 0.0714
4 0 0.0667 0.1111 0 0.0625
5 0 0.1250 0.0714 0.0625 0

As mentioned, this step is going to calculate the probability of the ant 1


choose the path from 1 city to all cities (2,3,4,5).
Hence, we can calculate the probability using formula [3], for this let try
to use formula [3.2/3.3], similar way, calculate the denominator but
using the formula [3.2/3.3].

City Path Denominator


1 to 2 2
1 ×0.1 =0.01
1 to 3 2
1 ×0.0833 =0.0069
1 to 4 2
1 ×0.0909 =0.0083
1 to 5 2
1 ×0.0714 =0.0051

The total number of t ( 1 , s )2 n ( 1 , s )2=0.0303

City Probability
Path
1 to 2
0.01
=0.3299
0.0303

1 to 3
0.0069
=0.2291
0.0303

1 to 4
0.083
=0.2727
0.0303

1 to 5
0.0051
=0.1683
0.0303

Hence, below shows the probability of the ant 1 going to choose the
path between city 1 to all cities (2,3,4,5) are:
City Path Probability
1 to 2 0.3299
1 to 3 0.2291
1 to 4 0.2727
1 to 5 0.1683

Therefore, the easier way to determine the WHICH the ant 1 going to
choose the path is using the Roulette wheel selection.

First calculate the cumulative probabilities of each city.

City Path Probability Cumulative Probability


1 to 2 0.3299 0.3299
1 to 3 0.2291 0.5590
1 to 4 0.2727 0.8317
1 to 5 0.1683 1.0000

Step 3 : Ant 2 Hence from the cumulative probability, the range for each path can be
Determine created:
choice of cities
(1st selection City Path Cumulative Probability Range
city) 1 to 2 0.3299 0.0000−0.3299
1 to 3 0.5590 0.3300−0.5590
1 to 4 0.8317 0.5591−0.8317
1 to 5 1.0000 0.8318−1.0000

Suppose that a random number is being generated, r = 0.5841.

Since the r lies on range of the city 1 to 4.


Therefore, the ant is going to city from city 1.

0.5591 < 0.5841 (random) < 0.8317


route formed for ant 1 so far is 1-4.

Repeat Step Ant 2 Since city 4 has been selected then 4th column of the matrix, the
2 : Determine visibility set to 0 so that:
probability

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0 0.0714
h= 2 0 0 0.0769 0 0.1250
3 0 0.0769 0 0 0.0714
4 0 0.0667 0.1111 0 0.0625
5 0 0.1250 0.0714 0 0

From here we calculate again the value of τ 𝜏(4, 𝑠) 1𝜂(4, 𝑠) 2 from city 4
to all of the cities (except city 1) (denominator of formula [3.2/3.3].

City Path Denominator


4 to 2 2
1 ×0.0667 =0.0044
4 to 3 2
1 ×0.1111 =0.0123
4 to 4 2
1 ×0.0 =0.0
4 to 5 2
1 ×0.0714 =0.0039

The total number of t ( 1 , s )2 n ( 1 , s )2=0.0207

City Probability
Path
4 to 2
0.0044
=0.2147
0.0207

4 to 3
0.0123
=0.5965
0.0207

4 to 4
0.0
=0.0
0.0207

4 to 5
0.0039
=0.1887
0.0207
(City 4 has been visited, so do not select this city)
Hence, the cumulative probability:

City Path Probability Cumulative Probability


4 to 2 0.2147 0.2147
4 to 3 0.5965 0.8112
4 to 5 0.1887 1.0000
Repeat Step 3 Ant 2 Then, the range of each path:
( 2nd selection City Path Cumulative Probability Cumulative Probability
city) 4 to 2 0.2147 0.0000−0.2147
4 to 3 0.8112 0.2148−0.8112
4 to 5 1.0000 0.8113−1.0000

Suppose that a random number is being generated, r = 0.1134.

Since the r lies on range of the city 4 to 3.


Therefore, the ant is going to city from city 3.

0.0000 < 0.1134 (random) < 0.2147

route formed for ant 1 so far is 1-4-2.

Repeat Step Ant 2 Since city 2nd has been selected then 2nd column of the matrix, the
2 : Determine visibility set to 0 so that:
probability

{| }
City 1 2 3 4 5
1 0 0 0.0833 0 0.0714
h= 2 0 0 0.0769 0 0.1250
3 0 0 0 0 0.0714
4 0 0 0.1111 0 0.0625
5 0 0 0.0714 0 0

From here we calculate again the value of τ 𝜏 (2, 𝑠) 1𝜂 (2, 𝑠) 2 from city 2
to all of the cities (except city 1) (denominator of formula [3.2/3.3].

City Path Denominator


2 to 2 2
1 ×0.0 =0.0
2 to 3 2
1 ×0.0769 =0.0059
2 to 4 2
1 ×0.0 =0.0
2 to 5 2
1 ×0.1250 =0.0156

The total number of 𝜏(2, 𝑠)1𝜂(2, 𝑠)2 = 0.0215

City Probability
Path
2 to 2
0.0
=0.0
0.0215

2 to 3
0.0059
=0.2744
0.0215

2 to 4
0.0
=0.0
0.0215

2 to 5
0.0156
=0.7256
0.0215

(City 2,4 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


2 to 3 0.2744 0.2744
2 to 5 0.7256 1.0000

Repeat Step 3 Ant 2 Then, the range of each path:


( 3rd selection City Path Cumulative Probability Cumulative Probability
city) 2 to 3 0.2744 0.0000−0.2744
2 to 5 1.0000 0.2745−1.0000

Suppose that a random number is being generated, r = = 0.8024.

Since the r lies on range of the city 2 to 5.


Therefore, the ant is going to city from city 5.

0.2745 < 0.8024 (random) < 1.000

route formed for ant 1 so far is 1-4-2-5


Repeat Step Ant 2 Since city 5 has been selected then 5th column of the matrix, the
2 : Determine visibility set to 0 so that:
probability

{| }
City 1 2 3 4 5
1 0 0 0.0833 0 0.0714
h= 2 0 0 0.0769 0 0.1250
3 0 0 0 0 0.0714
4 0 0 0.1111 0 0.0625
5 0 0 0.0714 0 0

From here we calculate again the value of τ 𝜏(5, 𝑠) 1𝜂(5, 𝑠) 2 from city 5
to all of the cities (except city 1) (denominator of formula [3.2/3.3].
City Path Denominator
5 to 2 2
1 ×0.0 =0.0
5 to 3 2
1 ×0.0714 =0.0051
5 to 4 2
1 ×0.0 =0.0
5 to 5 2
1 ×0.0 =0.0

The total number of 𝜏(5, 𝑠)1𝜂(5, 𝑠)2 = 0.0051

City Probability
Path
5 to 2
0.0
=0.0
0.0051

5 to 3
0.0051
=1.000
0.0051

5 to 4
0.0
=0.0
0.0051

5 to 5
0.0
=0.0
0.0051

(City 2,4,5 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


5 to 3 1.0000 1.0000
Repeat Step 3 Ant 2 Then, the range of each path:
( 4th selection City Path Cumulative Probability Cumulative Probability
city) 5 to 3 1.0000 0.000−1.0000

Suppose that a random number is being generated, r = = 0.8023.

Since the r lies on range of the city 5 to 3.


Therefore, the ant is going to city from city 3.

0.0000 < 0.8023 (random) < 1.000

route formed for ant 1 so far is 1-4- 2-5-3.

Since the requirement for last city visited is City 1, so we are going back
to City 1 such as : Ant 1: 1-4- 2-5-3-1.

Step 1: Ant 3
Determine (same
visibility distance,d)
{| }
City 1 2 3 4 5
1 0 10 12 11 14
d= 2 10 0 13 15 8
3 12 13 0 9 14
4 11 15 9 0 16
5 14 8 14 16 0

{| }
City 1 2 3 4 5
1 1 1 1 1 1
t o= 2 1 1 1 1 1
3 1 1 1 1 1
4 1 1 1 1 1
5 1 1 1 1 1

Using both matrices, the visibility (h) or Pheromone Level for each path can
be calculated using formula [1].

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0.0909 0.0714
h= 2 0.1000 0 0.0769 0.0667 0.1250
3 0.0833 0.0769 0 0.1111 0.0714
4 0.0909 0.0667 0.1111 0 0.0625
5 0.0714 0.1250 0.0714 0.0625 0
Step 2 : Ant 3 Determine the probability of moving from one city to another. In this
Determine case city 1 is designated as a departure city. Then from the last city
probability visited we are going back to city 1. As city 1 is chosen as the beginning
city 1 then city will be taboo to visit again, so that the level of visibility
of the city 1 is made =0.

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0.0909 0.0714
h= 2 0 0 0.0769 0.0667 0.1250
3 0 0.0769 0 0.1111 0.0714
4 0 0.0667 0.1111 0 0.0625
5 0 0.1250 0.0714 0.0625 0

Calculated the probability of 𝜏(1, 𝑠)1𝜂(1, 𝑠)2 ,

City Path Denominator


1 to 2 2
1 ×0.1 =0.01
1 to 3 2
1 ×0.0833 =0.0069
1 to 4 2
1 ×0.0909 =0.0083
1 to 5 2
1 ×0.0714 =0.0051

The total number of t ( 1 , s )2 n ( 1 , s )2=0.0303

City Probability
Path
1 to 2
0.01
=0.3299
0.0303

1 to 3
0.0069
=0.2291
0.0303

1 to 4
0.083
=0.2727
0.0303

1 to 5
0.0051
=0.1683
0.0303

Therefore, the easier way to determine the WHICH the ant 1 going to
choose the path is using the Roulette wheel selection.

First calculate the cumulative probabilities of each city.

City Path Probability Cumulative Probability


1 to 2 0.3299 0.3299
1 to 3 0.2291 0.5590
1 to 4 0.2727 0.8317
1 to 5 0.1683 1.0000
Step 3 : Ant 3 Hence from the cumulative probability, the range for each path can be
Determine created:
choice of cities
(1st selection City Path Cumulative Probability Range
city) 1 to 2 0.3299 0.0000−0.3299
1 to 3 0.5590 0.3300−0.5590
1 to 4 0.8317 0.5591−0.8317
1 to 5 1.0000 0.8318−1.0000
Suppose that a random number is being generated, r = 0.5841.

Since the r lies on range of the city 1 to 4.


Therefore, the ant is going to city from city 4.

0.5591 < 0.5841 (random) < 0.8317


route formed for ant 1 so far is 1-4.

Repeat Step Ant 3 Since city 4 has been selected then 4th column of the matrix, the
2 : Determine visibility set to 0 so that:
probability

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0 0.0714
h= 2 0 0 0.0769 0 0.1250
3 0 0.0769 0 0 0.0714
4 0 0.0667 0.1111 0 0.0625
5 0 0.1250 0.0714 0 0

From here we calculate again the value of τ 𝜏(4, 𝑠) 1𝜂(4, 𝑠) 2 from city 4
to all of the cities (except city 1)

City Path Denominator


4 to 2 2
1 ×0.0667 =0.0044
4 to 3 2
1 ×0.1111 =0.0123
4 to 4 2
1 ×0.0 =0.0
4 to 5 2
1 ×0.0714 =0.0039

The total number of t ( 1 , s )2 n ( 1 , s )2=0.0207

City Probability
Path
4 to 2
0.0044
=0.2147
0.0207

4 to 3
0.0123
=0.5965
0.0207

4 to 4
0.0
=0.0
0.0207

4 to 5
0.0039
=0.1887
0.0207

(City 4 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


4 to 2 0.2147 0.2147
4 to 3 0.5965 0.8112
4 to 5 0.1887 1.0000
Repeat Step 3 Ant 3 Then, the range of each path:
(2nd selection City Path Cumulative Probability Cumulative Probability
city) 4 to 2 0.2147 0.0000−0.2147
4 to 3 0.8112 0.2148−0.8112
4 to 5 1.0000 0.8113−1.0000
Suppose that a random number is being generated, r = 0.9134.

Since the r lies on range of the city 4 to 5.


Therefore, the ant is going to city from city 5.

0.8113 < 0.9134 (random) < 1.0000

route formed for ant 1 so far is 1-4-5.


Repeat Step Ant 3 Since city 5 has been selected then 5th column of the matrix, the
2 : Determine visibility set to 0 so that:
probability

{| }
City 1 2 3 4 5
1 0 0.1000 0.0833 0 0
h= 2 0 0 0.0769 0 0
3 0 0.0769 0 0 0
4 0 0.0667 0.1111 0 0
5 0 0.1250 0.0714 0 0

From here we calculate again the value of τ 𝜏 (5, 𝑠) 1𝜂 (5, 𝑠) 2 from city 5
to all of the cities (except city 1)

City Path Denominator


5 to 2 2
1 ×0.1250 =0.0156
5 to 3 2
1 ×0.0714 =0.0051
5 to 4 2
1 ×0.0 =0.0
5 to 5 2
1 ×0.0 =0.0

The total number of 𝜏(5, 𝑠)1𝜂(5, 𝑠)2 = 0.0207

City Probability
Path
5 to 2
0.0156
=0.7536
0.0207

5 to 3
0.0051
=0.2464
0.0207

5 to 4
0.0
=0.0
0.0207

5 to 5
0.0
=0.0
0.0207

(City 2,4,5 has been visited, so do not select this city)


Hence, the cumulative probability:
City Path Probability Cumulative Probability
5 to 2 0.7536 0.7536
5 to 3 0.2464 1.0000
Repeat Step 3 Ant 3 Hence from the cumulative probability, the range for each path can be
(3rd selection created:
city)
City Path Cumulative Probability Range
5 to 2 0.3299 0.0000−0.7536
5 to 3 1.0000 0.7537−1.0000
Suppose that a random number is being generated, r = 0.6024.

Since the r lies on range of the city 5 to 2.


Therefore, the ant is going to city from city 4.

0.0000 < 0.6024 (random) < 0.7537

route formed for ant 1 so far is 1-4- 5-2


Repeat Step Ant 3 Since city 2 has been selected then 2nd column of the matrix, the
2 : Determine visibility set to 0 so that:
probability

{| }
City 1 2 3 4 5
1 0 0 0.0833 0 0
h= 2 0 0 0.0769 0 0
3 0 0 0 0 0
4 0 0 0.1111 0 0
5 0 0 0.0714 0 0

From here we calculate again the value of τ 𝜏(2, 𝑠) 1𝜂(2, 𝑠) 2 from city 2
to all of the cities (except city 1)

City Path Denominator


2 to 2 2
1 ×0.0 =0.0
2 to 3 1 ×0.0769=0.0059
2 to 4 2
1 ×0.0 =0.0
2 to 5 2
1 ×0.0 =0.0
1 2
The total number of 𝜏(2, 𝑠) 𝜂(2, 𝑠) = 0.0059
City Probability
Path
5 to 2
0.0
=0.0
0.0059

5 to 3
0.0059
=1.000
0.0059

5 to 4
0.0
=0.0
0.0059
5 to 5
0.0
=0.0
0.0059

(City 2,4,5 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


5 to 3 1.0000 1.0000
Repeat Step 3 Ant 3 Then, the range of each path:
(4th selection City Path Cumulative Probability Cumulative Probability
city) 5 to 3 1.0000 0.000−1.0000

Suppose that a random number is being generated, r = = 0.8023.

Since the r lies on range of the city 5 to 3.


Therefore, the ant is going to city from city 3.

0.0000 < 0.8023 (random) < 1.000

route formed for ant 1 so far is 1-4-2-5-3.

Since the requirement for last city visited is City 1, so we are going back
to City 1 such as : Ant 1: 1-4- 5-2-3-1.
Step 4 :
Update After all of the ants has gone through the city. Then, there will be
pheromone changes on the pheromone level.
level
Ant 1 : Ants 1: 1-4-3-5-2-1
additional pheromone 1/52 = 0.0192.
evaporation will occur at (1-0.5) x1 = 0.5

0.5000 0.5000 0.5000 0.5192 0.5000


0.5192 0.5000 0.5000 0.5000 0.5000
0.5000 0.5000 0.5000 0.5000 0.5192
0.5000 0.5000 0.5192 0.5000 0.5000
0.5000 0.5192 0.5000 0.5000 0.5000

Ant 2: Ant 2: 1-4- 2-5-3-1


additional pheromone 1/60 = 0.0167.
as well as reduced the evaporation rate (1-0.5) x1 = 0.5

0.5000 0.5000 0.5000 0.5359 0.5000


0.5192 0.5000 0.5000 0.5000 0.5167
0.5167 0.5000 0.5000 0.5000 0.5192
0.5000 0.5167 0.5192 0.5000 0.5000
0.5000 0.5192 0.5167 0.5000 0.5000

Ant 3: Ants 3: 1 - 4-5 - 2 - 3-1


additional pheromone 1/60 = 0.0167.
as well as reduced the evaporation rate (1-0.5) x1 = 0.5

0.5000 0.5000 0.5000 0.5526 0.5000


0.5192 0.5000 0.5167 0.5000 0.5167
0.5334 0.5000 0.5000 0.5000 0.5192
0.5000 0.5167 0.5192 0.5000 0.5167
0.5000 0.5359 0.5167 0.5000 0.5000
Iteration 2:

Step 1: Ant 1

{| }
Determine
visibility City 1 2 3 4 5
1 0 10 12 11 14
d= 2 10 0 13 15 8
3 12 13 0 9 14
4 11 15 9 0 16
5 14 8 14 16 0

{| }
City 1 2 3 4 5
1 0.5000 0.5000 0.5000 0.5526 0.5000
t 1= 2 0.5192 0.5000 0.5167 0.5000 0.5167
3 0.5334 0.5000 0.5000 0.5000 0.5192
4 0.5000 0.5167 0.5192 0.5000 0.5167
5 0.5000 0.5359 0.5167 0.5000 0.5000

Using both matrices, the visibility (h) or Pheromone Level for each path can
be calculated using formula [1].

{| }
City 1 2 3 4 5
1 0 0.0500 0.0417 0.0502 0.0357
h= 2 0.0500 0 0.0398 0.0333 0.0646
3 0.0417 0.0385 0 0.0556 0.0371
4 0.0455 0.0345 0.0577 0 0.0323
5 0.0357 0.0670 0.0369 0.0313 0
Step 2 : Ant 1 Determine the probability of moving from one city to another. In this
Determine case city 1 is designated as a departure city. Then from the last city
probability visited we are going back to city 1. As city 1 is chosen as the beginning
city 1 then city will be taboo to visit again, so that the level of visibility
of the city 1 is made =0.

{| }
City 1 2 3 4 5
1 0 0.0500 0.0417 0.0502 0.0357
h= 2 0 0 0.0398 0.0333 0.0646
3 0 0.0385 0 0.0556 0.0371
4 0 0.0345 0.0577 0 0.0323
5 0 0.0670 0.0369 0.0313 0

Calculate the 𝜏(1, 𝑠)1𝜂(1, 𝑠)2 :

City Path Denominator


1 to 2 2
0.5000 × 0.0500 =0.0013
1 to 3 2
0.5000 × 0.0417 =0.0009
1 to 4 2
0.5526 × 0.0502 =0.0014
1 to 5 2
0.5000 × 0.0357 =0.0006

The total number of t ( 1 , s )2 n ( 1 , s )2=0.0042

City Path Probability


1 to 2
0.0013
=0.3095
0.0042

1 to 3
0.0009
=0.2143
0.0042

1 to 4
0.0014
=0.3333
0.0042

1 to 5
0.0006
=0.1429
0.0042

Therefore, the easier way to determine the WHICH the ant 1 going to
choose the path is using the Roulette wheel selection.

First calculate the cumulative probabilities of each city

City Path Probability Cumulative Probability


1 to 2 0.3095 0.3095
1 to 3 0.2143 0.5238
1 to 4 0.3333 0.8571
1 to 5 0.1429 1.0000

Step 3 : Ant 1 Hence from the cumulative probability, the range for each path can be
Determine created:
choice of cities
(1st selection City Path Cumulative Probability Range
city) 1 to 2 0.3095 0.0000−0.3095
1 to 3 0.5238 0.3096−0.5238
1 to 4 0.8571 0.5239−0.8571
1 to 5 1.0000 0.8572−1.0000
Suppose that a random number is being generated, r = 0.6841.

Since the r lies on range of the city 1 to 4.


Therefore, the ant is going to city from city 4.
0.5239 < 0.6841 (random) < 0.8571
route formed for ant 1 so far is 1-4.
Repeat Step 2 : Ant 1 Since city 4 has been selected then 4th column of the matrix, the
Determine visibility set to 0 so that
probability

{| }
City 1 2 3 4 5
1 0 0.0500 0.0417 0 0.0357
h= 2 0 0 0.0398 0 0.0646
3 0 0.0385 0 0 0.0371
4 0 0.0345 0.0577 0 0.0323
5 0 0.0670 0.0369 0 0

From here we calculate again the value of τ 𝜏(4, 𝑠) 1𝜂(4, 𝑠) 2 from city 4
to all of the cities (except city 1)

City Path Denominator


4 to 2 2
0.5167 × 0.0345 =0.0006
4 to 3 2
0.5192 ×0.0577 =0.0017
4 to 4 2
0.5000 × 0.0 =0.000
4 to 5 2
0.5167 × 0.0323 =0.0005

The total number of t ( 1 , s )2 n ( 1 , s )2=0.0028

City Path Probability


4 to 2
0.0006
=0.2143
0.0028

4 to 3
0.0017
=0.6071
0.0028

4 to 4
0.0
=0.0
0.0028

4 to 5
0.0005
=0.1786
0.0028

(City 4 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


4 to 2 0.2143 0.2143
4 to 3 0.6071 0.8214
4 to 5 0.1786 1.0000
Repeat Step 3 Ant 1 Then, the range of each path:
(2nd selection City Path Cumulative Probability Cumulative Probability
city) 4 to 2 0.2143 0.0000−0.2143
4 to 3 0.8112 0.2144−0.8214
4 to 5 1.0000 0.8215−1.0000

Suppose that a random number is being generated, r = 0.4024.

Since the r lies on range of the city 4 to 3.


Therefore, the ant is going to city from city 3.

0.2144 < 0.4024 (random) < 0.8214

route formed for ant 1 so far is 1-4-3.

Repeat Step 2 : Ant 1 Since city 3 has been selected then 3th column of the matrix, the
Determine visibility set to 0 so that
probability

{| }
City 1 2 3 4 5
1 0 0.0500 0 0 0.0357
h= 2 0 0 0 0 0.0646
3 0 0.0385 0 0 0.0371
4 0 0.0345 0 0 0.0323
5 0 0.0670 0 0 0

From here we calculate again the value of τ 𝜏(3, 𝑠) 1𝜂(3, 𝑠) 2 from city 3
to all of the cities (except city 1)

City Path Denominator


3 to 2 2
0.5000 × 0.0385 =0.000741
3 to 3 2
0.5000 × 0.0 =0.0000
3 to 4 2
0.5000 × 0.0 =0.000
3 to 5 2
0.5192 ×0.0371 =0.000717

The total number of t ( 1 , s )2 n ( 1 , s )2=0.001458

City Path Probability


3 to 2
0.000741
=0.5082
0.001458

3 to 3
0.0
=0.0
0.001458

3 to 4
0.0
=0.0
0.001458

3 to 5
0.000717
=0.4918
0.001458

(City 4,3 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


3 to 2 0.5082 0.5082
3 to 5 0.4918 1.0000
Repeat Step 3 Ant 1 Then, the range of each path:
( 3rd selection City Path Cumulative Probability Cumulative Probability
city) 3 to 2 0.5082 0.0000−0.5082
3 to 5 1.0000 0. 5083−1.0000

Suppose that a random number is being generated, r = 0.8024.

Since the r lies on range of the city 3 to 5.


Therefore, the ant is going to city from city 5.

0.5083 < 0.8024 (random) < 1.0000

route formed for ant 1 so far is 1-4- 3-5.


Repeat Step 2 : Ant 1 Since city 5 has been selected then 5th column of the matrix, the
Determine visibility set to 0 so that
probability

{| }
City 1 2 3 4 5
1 0 0.0500 0 0 0
h= 2 0 0 0 0 0
3 0 0.0385 0 0 0
4 0 0.0345 0 0 0
5 0 0.0670 0 0 0

From here we calculate again the value of τ 𝜏(5, 𝑠) 1𝜂(5, 𝑠) 2 from city 5
to all of the cities (except city 1)

City Path Denominator


5 to 2 2
0.5359 × 0.00 =0.0
5 to 3 2
0.5167 × 0.0670 =0.0024
5 to 4 2
0.5000 × 0.0 =0.0
5 to 5 2
0.5000 × 0.0 =0.0
The total number of 𝜏(5, 𝑠)1𝜂(5, 𝑠)2 = 0.0024
City Path Probability
5 to 2
0.0
=0.0
0.0024

5 to 3
0.0024
=1.0000
0.0024

5 to 4
0.0
=0.0
0.0024

5 to 5
0.0
=0.0
0.0024

(City 2,4,5 has been visited, so do not select this city)


Hence, the cumulative probability:

City Path Probability Cumulative Probability


5 to 3 1.0000 1.0000
Repeat Step 3 Ant 1 Then, the range of each path:
( 4th selection City Path Cumulative Probability Cumulative Probability
city) 5 to 3 1.0000 0.000−1.0000

Suppose that a random number is being generated, r = = 0.7023.

Since the r lies on range of the city 5 to 3.


Therefore, the ant is going to city from city 3.

0.0000 < 0.7023 (random) < 1.000

route formed for ant 1 so far is 1-4-2-5-3.

Since the requirement for last city visited is City 1, so we are going back
to City 1 such as : Ant 1: 1-4- 5-2-3-1.

Output :

Iteration Ant Path Fitness value


Iteration 1 Ant 1 1-4-3-5-2-1 52
Ant 2 1-4-2-5-3-1 60
Ant 3 1-4-5-2-3-1 60
Iteration 2 Ant 1 1-4-3-5-2-1 52
.. .. ..
.. .. ..
Iteration .. .. .. ..

You might also like