You are on page 1of 19

“REVIEW PAPER”

Report Submitted in partial fulfilment for the


degree of

M.Tech (1st SEM)

In

Electronics and Communication Engineering

By

INDU BALA 20204009

NIKHIL SHARMA 20204014

NIMISHA DWIVEDI 20204015

SUMMIT JOSHI 20204022

VIVEK SHARMA 20204026


Academic year: 2020-2021

Submitted to – Dr. DEEPTI KAKKAR

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING
Acknowledgment
I would like to thank my guide Dr. Deepti Kakkar for her guidance directly
related to this work, as well as for the knowledge I received while attending her
concurrently-running lectures in the semester on Advanced Communication
Systems, some of whose topics coincided with the present work.
Abstract
In this report, the An improved ant colony optimization based methodology with portable sink
for Wireless Sensor Networks (WSN) depicted, alongside the purposes for its presentation.

Conventional wireless sensor networks (WSNs) with one static sink hub experience the ill
effects of the notable problem area issue, that of sensor hubs close to the static sink bear more
traffic load than distant hubs. Hence, the general organization lifetime is decreased because of
the reality a few hubs exhaust their energy saves a lot quicker contrasted with the rest. As of
late, embracing sink portability has been considered as a decent system to beat the problem
area issue. Versatile sink(s) actually move inside the organize and speak with chosen hubs, for
example, cluster heads (CHs), to perform direct information assortment through short-range
interchanges that requires no steering. Finding an ideal portability direction for the versatile
sink is basic to accomplish energy

effectiveness. Taking clues from nature, the subterranean ant colony optimization (ACO)
algorithm has been viewed as a decent answer for finding an ideal crossing way. While the
conventional ACO algorithm will manage ants to make a little move to the following hub
utilizing current data, after some time they will stray from the objective. Similarly, a portable
sink may speak with chosen hub for a moderately significant time-frame making the customary
ACO algorithm defers not appropriate for high constant WSNs applications. In this paper, we
propose an improved ACO algorithm approach for WSNs that utilization versatile sinks by
considering CH distances. In this exploration, the organization is separated into a few clusters
and each group has one CH. While the distance between CHs is considered under the
conventional ACO algorithm, the portable sink hub finds an ideal portability direction to speak
with CHs under our improved ACO algorithm. Reenactment results show that the proposed
algorithm can altogether improve wireless sensor network execution contrasted with other
steering algorithms.
Introduction
The Internet of things (IoT) is an exceptionally incorporated and complete use of the new age
of data innovation. It has incredible importance for the new time of mechanical, green, savvy
networks under a reasonable economy and an advanced society. Wireless sensor networks
(WSNs) can be seen as an important innovation class under IoT, which has made a strong
establishment to empower the quick advancement of IoT.

WSNs are typically made out of an enormous number of static or portable sensors, which
structure a self-coordinated organization in a multi-jump way. Every sensor, often minuscule,
can shared, sense, gather, cycle and move their gathered crude or deciphered information from
the sensor field and ultimately send the data to the proprietor's organization. WSN filter be
applied to the fields, for example, the military, catastrophe help, climate checking including
woods fire and contamination, medical services observing and tele-medical care frameworks,
and so on [1].

The exploration and making of energy-productive steering algorithms is perhaps the main
issues for WSNs in light of the fact that sensor hubs will in general have restricted battery
power which is often not viable to supplant. In WSNs with static sinks, the sensor hubs
communicate data to the sink hub ordinarily in a multi-bounce way. A few hubs near the sink
are bound to exhaust their energy a lot quicker than different hubs far away from the sink as
more information are directed through these hubs contrasted with other distant hubs. Multi-
bounce courses and centralization of information traffic toward the sink are the most serious
issues to address. This issue is known as the problem area issue (or energy opening issue), and
the relating sensor hubs are likewise alluded to as hot hubs.

Embracing sink versatility has been misused lately to delay the lifetime of wireless sensor
networks. In spite of wireless sensor networks with a static sink, the portable sink-based
methodologies can reduce problem area issues and equilibrium the energy utilization among
sensor hubs. The portable sink hubs can wander around the detecting field to gather information
through generally short correspondences distance. Significant energy investment funds have
been accounted for broadening network lifetime. Finding an ideal direction for the versatile
sink to visit some meet hubs is a significant issue, and the writing has shown that the ant colony
optimization (ACO) algorithm has been a helpful answer for compute the portable sink
direction.

ACO is a heuristic multitude insight strategy propelled by the rummaging conduct of genuine
ant settlements. It has been end up being an effective procedure and has been applied to various
combinatorial optimization issues. The ACO algorithm builds up the most brief way between
food sources and homes. At the point when an ant moves, it delivers a path pheromone which
different ants can distinguish. As more ants pass by the way, more pheromones will be saved.
Since ants move contingent upon the measure of pheromones, the more extravagant the
pheromone trail on a way is, the almost certain it would be trailed by different ants. Through
this instrument, ants can at long last locate an ideal way from their home to food source.
Nonetheless, conventional ACO has a few disadvantages, for example, slow combination rate
and can fall into nearby ideal arrangement instead of a worldwide arrangement. Such
disadvantages adversely impact the time postponement and arrangement union of the networks.
In this paper, we propose an improved ACO-based approach and exhibit the advantage of our
algorithm when applied to portable sink-based WSNs. In our work, the distance heuristic factor
is considered to upgrade the worldwide inquiry capacity, to try not to be caught in a nearby
ideal arrangement and to improve the intermingling rate. The sensor field is separated into a
few clusters, and each cluster has just one cluster head (CH). At that point, versatile sink finds
an ideal sink portability direction by the improved ACO algorithm to speak with all CHs and
gather information from them through short-range interchanges.
The fundamental commitment in this paper incorporates the accompanying three perspectives.

•First, it consolidates clustering algorithm, ACO algorithm and portable sink to additionally
improve the general exhibition of sensor organization.

•Secondly, the improved ACO algorithm can upgrade the worldwide hunt capacity by
considering the distance between the cluster heads and distance to versatile sink. It is
advantageous to mitigate the organization time postpone issue.

•Finally, moving methodology of versatile sink can to a great extent save the energy utilization
of cluster heads. The remainder of the paper is coordinated as follows. Area 2 presents related
work. In Organization. 3, we first present relevant organization and energy models. At that
point, we present our proposed plot in detail. The presentation assessment is given in Sect. 4,
and Sect. 5 closes the paper with utilizations of ACO algorithm.
.
Proposed energy-efficient routing algorithm

1. Network model:-
Assume that a network consists of N sensor nodes and can be represented as a graph G (V, E)
where:
1. V = Vs U Vf, where Vs represents the sensor nodes and Vf represents the feasible sites,
2. E ⊆ V × V represents the set of wireless links.
We initially deploy the mobile sink node at the edge of the sensor field and make the following
assumptions:
1. All sensor nodes are homogeneous and static,
2. Hubs can change their transmission power as indicated by the overall distance to the
beneficiary,
3. Links are symmetric,
4. The mobile sink has enough transmit power and does not have any resource constraints.

2. Energy model:-
In our considered energy consumption model, we let ETx (k, d) and ERx (k) denote the total
energy required in a sensor node to transmit a k-bit length message to an adjoining sensor hub
at distance d away, separately. The Tx and Rx severally indicate the hubs to send and get
message. The energy burned-through to communicate a message can be apportioned into two
sections. The first part is the energy consumed Transmit then message, Eelec×k, where Eelec
denotes the energy consumed for driving the transmitter circuitry, the elec denotes the
transmitter circuitry. The second part is the energy consumed in the amplifier component, εamp
×k ×dn where εamp denotes the energy required for the transmitter amplifier. Based on the
distance between the transmitter and receiver, a free space (d2 power loss) or multi-path fading
(d4 power loss) channel models can be used.
The getting cycle acted in a sensor hub just incorporates the initial segment of the energy
utilization. Summing up the above depictions, the absolute energy utilization for message
communicating and accepting is:
ETx(k, d) = Eelec × k + εamp × k × dn (1)
ERx(k) = Eelec × k (2)

3. Clustering formation and cluster head selection:-


We partition the whole organization into a few equivalent clusters, with the goal that the cluster
development is accomplished first. Each cluster has just a single CH. Different hubs in a similar
cluster become part hubs and send their information to their CH.. The selection of the CHs
is decided by the residual energy and the distance to the centre location of cluster.
Initially, we first select the sensor node that is located in the centre of each cluster as
the CH candidate At that point, the CH competitor will rival different hubs in the equivalent
cluster. In each round, only the node that has the larger residual energy will become
the new CH competitor, or for the situation where more than one CH has a similar lingering
energy then the hub closest to the middle area of cluster is chosen as the new CH. All the hubs
in the cluster ought to be thought about just a single time. Thusly, the hub with the greatest
extra energy is picked as the CH. Likewise the CHs are conveyed in the focal point of the
cluster, so it inalienably stays away from a significant distance correspondence between the
part hubs and the CH.

4. Inter-cluster routing procedure:-


In the wake of choosing a CH for each cluster, the part hubs speak with the CH
straightforwardly or utilizing multi-bounce correspondence as per their distance to the CH.
Some member nodes may receive CH messages from more than one CH; these nodes are likely
slightly beyond the cluster boundary. These special nodes will share the information of the
secondary CH with their primary CH. In this way, CHs can calculate the distance with their
neighbour CHs.

5. Rotation of cluster head:-


The CH selection does not need to be carried out in each round in order to save energy. We
setup an energy threshold for a CH, such that if any of the CHs residual energy falls below the
energy threshold, the CH selection process will be carried out accordingly. This approach can
avoid a frequent CH election process so that the energy consumption of sensor nodes is
reduced.

6. Improved ant colony optimization:-


In the conventional ACO algorithm, every ant is haphazardly put on a city.. During the
construction of a feasible solution, ants select the next city to be visited through a probabilistic
decision rule. When ant k stays in city i and constructs the partial solution, at time t, the
probability of moving to the next city j neighbouring on city I is calculated as:

Pkij (t)= { Ʈijα(t)ηijβ(t) if j ∈ allowedk (3)


ΣƮikα(t) ηikβ(t)
k ∈ allowedk
0 otherwise

where τij (t) is the amount of pheromone trail on arc(i, j ) at time t, ηij = 1/di j is the heuristic
benefit of moving from city I to city j , permitted k is the visited city set of ant k, α and β are
two boundaries that control the general load of pheromone trail and heuristic value.
Nonetheless, the customary ant colony optimization algorithm has a few weaknesses, for
example, slow pace of assembly and is not difficult to fall into nearby ideal arrangement. So
we propose to improve the conventional ACO algorithm by further considering a distance
heuristic factor to build consequences for the following hub in order to upgrade the worldwide
inquiry capacity, try not to be caught in a neighborhood ideal arrangement and improve the
pace of union. We increment the impact of the objective hub to the following hub and improve
ηij by utilizing the base amount of distance between the current hub to the following hub and
the following node to the destination node, thus:
nij = 1 (4)
Min[dis(i,j) +dis(j,m)]

Where dis(i, j ) is the separation from hub I to next hub j, dis( j,m) is the distance
from node j to the target node m.

The measure of pheromone trail on a way vanishes over the long run.. After time m, the trail
intensity is updated according to:
τij (t + s) = ρτij (t) + τkij (5)
τij =n k =1τ ij (6)
where ρ is a coefficient which represents the evaporation of trail between time t and t+s, its
value between 0 and 1. τkij is the quantity per unit of length of trail substance (akin to pheromone
in real ants) laid on edge (i , j ) by ant k between time t and t +s, n is the total number of ant
This process will terminate until an optimal path is found after a given number of iterations.

7. Sink movement strategy:-

In this paper, we treat the versatile sink as a sales rep, the CHs as urban communities, and the
portable sink will visit CHs.. Therefore, this problem is a TSP, which we solve using the ACO
algorithm. The versatile sink will navigate the ideal way dictated by the ACO algorithm to visit
the places of CHs to gather information utilizing single bounce actually close interchanges.
The energy utilization of CHs are significantly diminished because of the transmission range
is short between versatile sink and the CH. We also take into account the shortcomings of the
traditional ACO algorithm, and we implement the proposed and distance heuristic factor to
increase the effects on the next node, to upgrade the worldwide inquiry capacity, evade trap in
nearby ideal arrangement and improve the pace of assembly. Therefore, the network latency is
thus decreased.
Performance evaluation
We evaluate the performance of our algorithm (termed IACO-MS) via simulations. Our
algorithm is contrasted and the algorithm proposed in [18] (named ACO–M). The reenactment
climate is set up with the boundaries recorded in Table 1. It has been assumed that all the senor
nodes and the sink nodes are uniformly deployed in a 200 × 200 m2 area.
Broad reenactments have been performed to decide appropriate qualities for α and β, as is
recorded in Table 2. From the table, when α, β and ρ have values of 5, 10 and 0.6, respectively,
the length of path is the shortest and iteration number is also small.
Parameter name Value
Network size [200, 200] m2
Number of nodes (N) [50, 200]
Transmission radius (R0) 50 m
Packet length (l) 2000 bits
Initial energy (E0) 0.5 J
Energy consumption on circuit (Eelec) 50 nJ/bit
Free-space channel parameter (εfs) 10 pJ/bit/m2
Multi-path channel parameter (εmp) 0.0013 pJ/bit/m4
Distance threshold (d0) sqrt (εfs/εmp) m

Table 2 Length of path by


using different values for α, β and ρ
α β ρ Path length Iteration
0.5 1 0.3 425.01 65
0.5 1 0.4 426.32 74
0.5 1 0.5 426.32 82
0.5 1 0.6 426.58 79
1 5 0.3 423.94 54
2 6 0.4 424.28 38
4 8 0.5 424.12 45
5 10 0.6 423.73 46

Fig. 1 Comparison of network lifetime


Lifetime is an important metric to evaluate network performance and is defined as the time
when the first node ceases operation due to energy depletion. The network lifetime for our
work contrasted with ACO–M is appeared in Fig. 1. ACO–M begins to have drained hubs after
2330 rounds and our work at around 2600 rounds. Plainly our algorithm has the better
presentation in delaying the network lifetime contrasted with ACO–M because of the portable
sink discussing straightforwardly with the CH over a short correspondence range. Hence, the
energy of the CHs can be decreased utilizing the portable sink hub.
In our proposed algorithm, the hub with the most extreme lingering energy will be chosen as
the CH. The CH pivot is possibly performed when the leftover energy of the CH is not exactly
a given energy limit. In Fig. 2, it tends to be seen that the pace of energy utilization is lower
than ACO–M and hence our proposed algorithm has great execution for WSNs. Broad
reproductions have been done to exhibit that our improved ACO algorithm has better execution
in a WSN utilizing various quantities of hubs, as can be found in Tables 3 and 4. Table 3 shows
when the principal hub stops to work because of energy exhaustion, over various quantities of
hubs. Our algorithm consistently has an improved exhibition contrasted with ACO–M
broadening the lifetime of the network.
Fig.2 Comparison of energy consumption

Table 3 Round when the first node dies

Algorithm Number of nodes


100 200 300
ACO–M 2400 2100 2000
IACO-MS 2600 2400 2200

Table 4 Round when the energy of nodes run out


Algorithm Number of nodes
100 200 300
ACO–M 2750 2600 2700
IACO-MS 2950 2750 3000

Table 4 shows the total energy consumption in the WSN with different numbers of nodes until
all the energy in all the nodes are exhausted. Our algorithm further offers improved utilization
of energy to drag out the entire network lifetime contrasted with ACO–M. We used the ACO
algorithm to find an optimal mobility trajectory for the mobile sink. The conventional ACO
algorithm drives ants to move to the following hub utilizing current data, however they go
amiss from the objective over the long run. Subsequently, we considered the distance between
CHs to improve distance heuristic factor to upgrade the worldwide inquiry capacity, try not to
be caught in nearby ideal arrangements and improve the rate of convergence. Thusly, we
additionally decrease the time postpone issue when the portable sink gathers information from
the CHs. In Fig. 3, it very well may be seen that when utilizing our algorithm the measure of
information gathered at some random purpose of time has been expanded contrasted with the
other one, so our algorithm has an improved presentation in the information assortment
for the WSNs.
Fig. 3 Comparison of packet delivery

Applications of Ant Colony Optimization

As of late, the interest of mainstream researchers in ACO has risen forcefully. In fact, several
successful applications of ACO to a wide range of different discrete optimization problems are
now available. The large majority of these applications are to NP-hard problems; that is, to
problems for which the best known algorithms that guarantee to identify an optimal
Solution have exponential time worst case complexity. The utilization of such algorithms is
often infeasible by and by, and ACO algorithms can be helpful for rapidly discovering great
arrangements. Other mainstream applications are to dynamic briefest way issues emerging in
telecom networks issues arising in telecommunication networks problems. The number of
successful applications to academic problems has motivated people to adopt ACO for the
solution of industrial problems, proving that this computational intelligence technique is also
useful in real-world applications.

Conclusions

In this paper, an energy-effective improved ant colony optimization-based methodology for


wireless sensor networks that have portable sinks is proposed. Cluster heads (CHs) are chosen
dependent on the leftover energy of every hub, except in this work the CH pivot is possibly
done when the remaining energy of the CH less than a given energy threshold. The versatile
sink gathers information by means of an ideal moving direction which is controlled by our
improved ACO algorithm and straightforwardly speaks with CHs through short-range
correspondences. The simulation results show that the proposed approach performs particularly
well compared to other standard algorithms in the literature thus extending the wireless sensor
network lifetime.
Different algorithmic strategies have been motivated by practices of ants. Ant colony
optimization is the best constantly known among them..

References
1. Akyildiz IF, Su W, Sankarasubramaniam Y, Cayirci E (2002) A survey on sensor networks.
IEEE
Commun Mag 40(8):102–114. doi:10.1109/MCOM.2002.1024422
2. Heinzelman W, Chandrakasan A, Balakrishnan H (2000) Energy-efficient communication
protocol
for wireless micro sensor networks. In: Proceedings of the 33rd IEEE Hawaii Conference on
System
Sciences, pp 1–10
3. Mottaghi S, Zahabi MR (2014) Optimizing LEACH clustering algorithm with mobile sink
and rendezvous
nodes. Int J Electron Commun 69(2):507–514. doi:10.1016/j.aeue.2014.10.021
4. Nazir B, Hasbullah H (2011) Mobile sink based routing protocol (MSRP) for prolonging
network
lifetime in clustered wireless sensor network. In: Proceedings of the 2010 International
Conference on
Computer Applications and Industrial Electronics. pp 624–629
5. Jafri MR, Javaid N, Javaid A, Ali Z (2013) Maximizing the lifetime of multi-chain PEGASIS
using
sink mobility. J World Appl Sci 21(9):1283–1289. doi:10.5829/idosi.wasj.2013.21.9.175
6. Lindsey S, RaghavendraCS (2002) PEGASIS: Power efficient gathering in sensor
information systems.
Proc IEEE Aerosp Conf 3:1125–1130
7. Chu WC, Ssu KF (2014) Sink discovery in location-free and mobile-sink wireless sensor
networks.
Comput Netw 67(5):123–140. doi:10.1016/j.comnet.2014.03.028
8. Sharma S, Puthal D, Jena SK et al (2016) Rendezvous based routing protocol for wireless
sensor
networks with mobile sink. J Supercomput 73(3):1168–1188
9. Wang J, Cao J, Ji S et al (2017) Energy-efficient cluster-based dynamic routes adjustment
approach
for wireless sensor networks with mobile sinks. J Supercomput 73(7):3277–3290
10. Chen M, Xu X, Zhang S, Feng G (2012) Energy efficient routing protocol in mobile-sink
wireless
sensor networks. Telkomnika Indonesian J Electr Eng 10(8):2056–2062.
doi:10.11591/telkomnika.
v10i8.1640
11. Shi L, Zhang B, Mouftah HT,Ma J (2012) DDRP: An efficient data-driven routing protocol
for wireless
sensor networks with mobile sinks. Int J Commun Syst 26(10):1341–1355.
doi:10.1002/dac.2315
12. Wang C-F, Shih J-D, Pan B-H, Wi T-Y (2014) A network lifetime enhancement method
for sink
relocation and its analysis in wireless sensor networks. IEEE Sens J 14(6):1932–1943.
doi:10.1109/
JSEN.2014.2306429
13. Xie S, Wang Y (2014) Construction of tree network with limited delivery latency in
homogeneous
wireless sensor networks. Wirel Pers Commun 78(1):231–246. doi:10.1007/s11277-014-1748-
5
14. Shen J, Tan H-W, Wang J, Wang J-W, Lee S-Y (2015) A novel routing protocol providing
good
transmission reliability in underwater sensor networks. J Intern Technol 16(1):171–178.
doi:10.6138/
JIT.2014.16.1.20131203e
15. Zhang Y, He S, Chen J (2016) Near optimal data gathering in rechargeable sensor networks
with a
mobile sink. IEEE Trans Mobile Comput 16(6):1718–1729
16. Deng R, He S, Chen J (2014) Near-optimal online algorithm for data collection by multiple
sinks in
wireless sensor networks. IEEE International Conference on Communications, pp 2803–2808
17. Zhang X, Bao H, Ye J, Yan K, Zhang H (2013) A data gathering scheme for WSN/WSAN
based on
partitioning algorithm and mobile sinks. In: Proceedings of the IEEE 10th International
Conference
on High Performance Computing and Communications & 2013 IEEE International Conference
on
Embedded and Ubiquitous Computing. pp 1968–1973
18. Liu X, Zhao H, Yang X, Li X (2013) SinkTrail: A proactive data reporting protocol for
wireless sensor
networks. IEEE Trans Comput 62(1):151–162. doi:10.1109/TC.2011.207
19. Andziulis A, Dzemydien˙e D, Steponaviˇcius R, Jakovlev S (2011) Comparison of two
heuristic
approaches for solving the production scheduling problem. Inf Technol Control 40(2):118–
122. doi:10.
5755/j01.itc.40.2.426
20. Neumann F, Witt C (2010) Ant colony optimization and the minimum spanning tree
problem. Theor
Comput Sci 411(25):2406–2413. doi:10.1016/j.tcs.2010.02.012
21. López-Ibáñez M, Blum C (2010) Beam-ACO for the travelling salesman problem with time
windows.
Comput Oper Res 37(9):1570–1583. doi:10.1016/j.cor.2009.11.015
22. Wang J, Cao J, Li B, Lee S, Sherratt RS (2015) Bio-inspired ant colony optimization based
clustering
algorithm with mobile sinks for applications in consumer home automation networks. IEEE
Trans
Consum Electron 61(4):438–444. doi:10.1109/TCE.2015.7389797
23. M. Dorigo and T. St¨utzle, Ant Colony Optimization, MIT Press, Cambridge, MA,
2004.
24. K. Socha, J. Knowles, and M. Sampels, “A MAX–MIN ant system for the university
timetabling problem,” in Proc. ANTS 2002, ser. LNCS, M. Dorigo et al., Eds., vol. 2463, p.
1,
Berlin, Germany: Springer Verlag, 2002
25 L.M. Gambardella and M. Dorigo, “Ant Colony System hybridized with a new local
search for the sequential ordering problem,” INFORMS Journal on Computing, vol. 12, no.
3.
MATLAB CODE
clear all close all clc
%% Problem preparation
% Create the graph
[ graph] = createGraph();
% Draw the graph figure subplot(1,3,1) drawGraph( graph);
%% ACO algorithm
%% Initial parameters of ACO maxIter = 500;
antNo = 50;
tau0 = 10 * 1 / (graph. n * mean (graph. edges (:))); % Initial phromone concentration tau =
tau0 * ones (graph. n, graph. n); % Phromone matirx
eta = 1. / graph. edges; % desirability of each edge rho = 0.5; % Evaporation rate
alpha = 1; % Phromone exponential parameters beta = 1; % Desirability exponetial paramter
%% Main loop of ACO bestFitness = inf; bestTour = [];
for t = 1 : maxIter
% Create Ants colony = [];
colony = createColony (graph, colony, antNo, tau, eta, alpha, beta);

% Calculate the fitness values of all ants for i = 1 : antNo


colony.ant(i).fitness = fitnessFunction(colony.ant(i).tour , graph ); end
% Find the best ant (queen) allAntsFitness = [ colony.ant(:).fitness ];
[ minVal , minIndex ] = min( allAntsFitness ); if minVal < bestFitness
bestFitness = colony.ant(minIndex).fitness; bestTour = colony.ant(minIndex).tour;
end
colony.queen.tour = bestTour; colony.queen.fitness = bestFitness;
% Evaporation
tau = ( 1 - rho ) .* tau;
% Display the results
outmsg = [ 'Iteration #' , num2str(t) , ' Shortest length = ' , num2str(colony.queen.fitness) ];
disp(outmsg)
subplot(1,3,1)
title(['Iteration #' , num2str(t) ])
% Visualize best tour and phromone concentration subplot(1,3,2)
cla
drawBestTour( colony, graph ); subplot(1,3,3)
cla
drawPhromone( tau , graph ); drawnow
end
function [ fitness ] = fitnessFunction ( tour , graph)

fitness = 0;
for i = 1 : length(tour) -1 currentNode = tour(i); nextNode = tour(i+1);
fitness = fitness + graph.edges( currentNode , nextNode ); end
end
function [ colony ] = createColony( graph, colony , antNo, tau, eta, alpha, beta) nodeNo =
graph.n;
for i = 1 : antNo
initial_node = randi( [1 , nodeNo] ); % select a random node colony.ant(i).tour(1) =
initial_node;
for j = 2 : nodeNo % to choose the rest of nodes currentNode = colony.ant(i).tour(end);
P_allNodes = tau( currentNode , : ) .^ alpha .* eta( currentNode , : ) .^ beta;
P_allNodes(colony.ant(i). tour) = 0; % assing 0 to all the nodes visited so far P =
P_allNodes. / sum(P_allNodes);
nextNode = rouletteWheel(P);
colony.ant(i). tour = [ colony.ant(i). tour, nextNode];
end
% complete the tour
colony.ant(i). tour = [ colony.ant(i). tour, colony.ant(i). tour (1)]; end
end
function [ graph] = createGraph ()
% To create the graph and calculate the distances between each node
% x = [ 0.09, 0.16, 0.84, 0.70];
% y = [0.17, 0.52, 0.92, 0.16];
%
% 14 nodes
x=
[16.47000,16.47000,20.09000,22.39000,25.23000,22,20.47000,17.20000,16.30000,14.0500
0,16.530
00,21.52000,19.41000,20.09000];
y=
[96.10000,94.44000,92.54000,93.37000,97.24000,96.05000,97.02000,96.29000,97.38000,9
8.12000,
97.38000,95.59000,97.13000,94.55000]
% % 50 nodes
% nodes =
[7,9,2,0,0,1,7,1,2,51,42,31,5,12,36,52,27,17,13,57,62,42,16,8,7,27,30,43,58,58,37,38,46,61,
62,63,32,
45,59,5,10,21,5,30,39,32,25,25,48,56;52,49,64,26,30,47,63,62,33,21,41,32,25,42,16,41,23,
33,13,58,
42,57,57,52,38,68,48,67,48,27,69,46,10,33,63,69,22,35,15,6,17,10,64,15,10,39,32,55,28,37
]
% x = nodes (1, :);
% y = nodes (2, :);
% % 100 nodes
% % nodes =
[1380,2848,3510,457,3888,984,2721,1286,2716,738,1251,2728,3815,3683,1247,123,1234,
252,611,
2576,928,53,1807,274,2574,178,2678,1795,3384,3520,1256,1424,3913,3085,2573,463,387
5,298,34
79,2542,3955,1323,3447,2936,1621,3373,1393,3874,938,3022,2482,3854,376,2519,2945,9
53,2628,
2097,890,2139,2421,2290,1115,2588,327,241,1917,2991,2573,19,3911,872,2863,929,839,
3893,217
8,3822,378,1178,2599,3416,2961,611,3113,2597,2586,161,1429,742,1625,1187,1787,22,3
640,3756,
776,1724,198,3950;939,96,1671,334,666,965,1482,525,1432,1325,1832,1698,169,1533,19
45,862,19
46,1240,673,1676,1700,857,1711,1420,946,24,1825,962,1498,1079,61,1728,192,1528,196
9,1670,59
8,1513,821,236,1743,280,1830,337,1830,1646,1368,1318,955,474,1183,923,825,135,1622,
268,1479
,981,1846,1806,1007,1810,1052,302,265,341,687,792,599,674,1673,1559,558,1766,620,10
2,1619,8
99,1048,100,901,143,1605,1384,885,1830,1286,906,134,1025,1651,706,1009,987,43,882,3
92,1642,
1810,1558]
% x = nodes (1, :);
% y = nodes (2, :); graph. n = length(x); for i = 1: graph. n
graph. node(i).x = x(i);
graph. node(i). y = y(i); end
graph. edges = zeros (graph. n, graph. n); for i = 1: graph. n
for j = 1: graph. n
x1 = graph. node(i).x;
x2 = graph. node(j).x;
y1 = graph. node(i). y; y2 = graph. node(j). y;
graph. edges (i, j) = sqrt ((x1 - x2) ^2 + (y1 - y2) ^2); end
end
function [] = drawBestTour (colony, graph)
queenTour = colony. queen. tour; hold on
for i = 1: length(queenTour) - 1 currentNode = queenTour(i); nextNode = queenTour(i+1);
x1 = graph.node(currentNode).x; y1 = graph. node(currentNode). y; x2 = graph.
node(nextNode).x;
y2 = graph. node(nextNode). y; X = [x1, x2];
Y = [y1, y2];
plot (X, Y, '-r'); end
for i = 1: graph. n
X = [graph. node(:).x];
Y = [graph. node (:). y];
plot (X, Y, 'ok', 'markerSize’, 10, 'MarkerEdgeColor’, 'r’, 'MarkerFaceColor', [1, 0.6, 0.6]);
end
title ('Best tour (the queen)') box('on');
end
function [ ] = drawGraph( graph )
% To visualize the nodes and edges of the graph
hold on
for i = 1: graph. n - 1 for j = i+1: graph. n x1 = graph. node(i).x;
y1 = graph. node(i). y; x2 = graph. node(j).x; y2 = graph. node(j). y; X = [x1, x2];
Y = [y1, y2];
plot (X, Y, '-k'); end
end
for i = 1: graph. n
X = [graph. node(:).x];
Y = [graph. node (:). y];
plot (X, Y, 'ok', 'MarkerSize', 10, 'MarkerEdgeColor' , 'r' , 'MarkerFaceColor' , [ 1, 0.6 , 0.6]);
end
title ('Al nodes and edges') box('on')
end
function [] = drawPhromone (tau, graph) maxTau = max (tau (:));
minTau = min (tau (:));
tau_normalized = (tau - minTau). / (maxTau - minTau); for i = 1: graph. n -1
for j = i+1: graph. n
x1 = graph. node(i).x; y1 = graph. node(i). y; x2 = graph. node(j).x; y2 = graph. node(j). y; X = [x1,
x2];
Y = [y1, y2];
tau (i, j);
plot (X, Y, 'color’, [0, 0, (1-tau_normalized (i, j)), tau_normalized (i, j)], 'lineWidth', 10.
*tau_normalized (i, j) + 1) end
end
for i = 1: graph. n hold on
X = [graph. node(:).x];
Y = [graph. node (:). y];
plot (X, Y, 'ok’, ‘MarkerSize', 10, 'MarkerEdgeColor', 'r', 'MarkerFaceColor', [1 .6 .6])
end
title ('All Phromones') box on
end
function [ nextNode] = rouletteWheel (P)
% Roulette wheel to choose one edge based on P values cumsumP = cumsum(P);
r = rand ();
nextNode = find (r <= cumsumP); nextNode = nextNode (1);
end
function [ tau] = updatePhromone (tau, colony)
% Update the phromone matrix. nodeNo = length (colony.ant (1). tour); antNo = length
(colony.ant (:));
for i = 1: antNo % for each ant
for j = 1: nodeNo-1 % for each node in the tour currentNode = colony.ant(i). tour(j); nextNode
= colony.ant(i). tour(j+1);
tau (currentNode, nextNode) = tau (currentNode, nextNode) + 1. / colony.ant(i). fitness;
tau (nextNode, currentNode) = tau (nextNode, currentNode) + 1. / colony.ant(i). fitness; end
end
end

You might also like