Tutorial 8
Tutorial 8
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
{| }
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):
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
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.
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
{| }
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]).
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
{| }
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)
3 to 5
{| }
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
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
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.
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
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 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:
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 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 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
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
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
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.
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 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 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 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 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)
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
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
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
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.
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.
{| }
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)
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
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)
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 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)
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
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 :