You are on page 1of 58

CSC583 – Artificial

Intelligence Algorithms
Topic 5 – Swarm Intelligence
Faculty of Computer & Mathematical Sciences
Universiti Teknologi MARA
A. Introduction: Swarms
A. Introduction: Objectives
• To understand the key principles of swarm intelligence;
• To understand the laying/following mechanisms;
• To understand Particle Swarm Optimization (PSO) and Ant
Colony Optimization (ACO).
A. Introduction: Swarm Intelligence
A. Introduction: Swarm Intelligence
A. Introduction: What is Swarm Intelligence?
• An individual ant is not very bright, almost blind
• But ants in a colony, operating in a team do remarkable
things
• At the basis of increased intelligence is shared information
discovered individually and communicated to the swarm
• These seamless coordination of all individual activities does
not to seem to require any leader / supervisor
A. Introduction: What is Swarm Intelligence?
• Swarm Intelligence (SI) is an artificial intelligence technique
based around the study of collective behavior in
decentralized, self-organized systems.
• A typical swarm intelligence system consists of a population
of simple agents which can communicate (either directly or
indirectly) locally with each other by acting on their local
environment.
A. Introduction: What is Swarm Intelligence?
(cont)
• Though the agents in a swarm follow very simple rules, the
interactions between such agents can lead to the emergence
of very complicated global behavior, far beyond the
capability of individual agents
• SI was introduced by Gerardo Beni and Jing Wang in 1989
• Main objectives of SI: minimize power consumption and
minimize path
A. Introduction: What is Swarm Intelligence?
(cont)
• Swarm Intelligence examples in nature:
• Ant colonies
• Bee beehives
• Fish schooling
• Bird flocking
• Bacterial growth
• Microbial intelligence
• There are biological advantages of swarm intelligence. E.g: birds flying
in formation use up to a fifth less energy than those flying solo
A. Introduction: What is Swarm Intelligence?
(cont)
B. Swarm Intelligence – From Natural to
Artificial Systems
• Swarm Intelligence are modeled for the purposes of:
• Understanding microscopic (local) to macroscopic
(global) transformations
• Getting ideas for artificial systems with similar
properties
B. Swarm Intelligence – From Natural to
Artificial Systems (cont)
• There are two main development areas of Swarm
Intelligence:
• Particle Swarm Optimization (PSO)
• Ant Colony Optimization (ACO)
Particle Swarm Optimization
C. Particle Swarm Optimization: Introduction
• PSO is inspired mostly by the social behavior of bird flocking and fish
schooling
• Key question: How does a large number of birds produce a seamless,
graceful flocking dance, while often, but suddenly changing direction,
scattering and regrouping?
D. Particle Swarm Optimization: Behaviors
• In 1986, Craig Reynolds described this process in 3 simple behaviors:

Separation Alignment Cohesion


avoid crowding move towards the move toward the
local flockmates average heading of average position of
local flockmates local flockmates
E. Particle Swarm Optimization: Concept
• Population based stochastic optimization technique
• Uses a number of agents (particles) that constitute a swarm moving
around in the search space looking for the best solution
• It mimics the behavior of birds, where each particle is a bird, and the
group of particles is a swarm
• Each particle in search space adjusts its “flying” according to its own
flying experience as well as the flying experience of other particles
E. Particle Swarm Optimization: Concept
(cont)
• Each particle in the swarm is flying in the search space to find the
optimum
• Because each particle is moving, all of the particles have their own
velocity
• During initialization, all particles are randomly assigned a position and
velocity
• Each particle also remembers the position of:
• where it had its best solution so far, personal best (pbest)
• the best value of any particle, global best (gbest)
E. Particle Swarm Optimization: Concept
(cont)
• Particles in swarm can cooperate, they exchange information about
what have been discovered in places they have visited
• How it works is very simple:
• Each particle has its own neighbourhood
• A particle knows the fitnesses of those in its neighbourhood
• Particle uses the position of the particle with best fitness in its
neighbourhood to adjust its own velocity
E. Particle Swarm Optimization: Concept
(cont)
14

12

10

0 2 4 6 8 10 12 14 16
insert: Cooperation Example
E. Particle Swarm Optimization: Concept
(cont)
• In each timestep (t), a particle has to move to a new position. It
modifies its position according to:
• its current position
• its current velocity
• the distance between its current position and pBest
• the distance between its current position and gBest
• Having worked out a new velocity, its position is simply its old
position plus the new velocity.
• Goal of the movement: get swarm moving to a promising area that
signifies global optimum
E. Particle Swarm Optimization: Concept
(cont)
• Influences on particle flying:
F. Particle Swarm Optimization: Algorithm
Particle velocity (equation a):
• v = v + c1 * rand * (pBest – p) + c2 * rand * (gBest – p)
Particle update rule (equation b):
• p=p+v
where:
• p: particle’s position • pBest: best position of the
• v: path velocity particle
• c1: weight in the direction of • gBest: best position of the
personal best swarm
• c2: weight in the direction of • rand: random variable
global best between 0 - 1
F. Particle Swarm Optimization: Algorithm –
Pseudocode
For each particle
Initialize particle
END
Do
For each particle
Calculate fitness value
If the fitness value is better than its personal best
set current value as the new pBest
End
Choose the particle with the best fitness value of all as gBest
For each particle
Calculate particle velocity according equation (a)
Update particle position according equation (b)
End
While maximum iterations or minimum error criteria is not attained
F. Particle Swarm Optimization: Algorithm –
Parameters
• Parameters are the coefficients in the formula which indicates how to
update the velocity of a given particle.
• Swarm size and neighbourhood size are parameters but less
important.
• You can perfectly use a swarm size of 20 and a neighbourhood of 3 for a large
range of problems with good results.
• Particles' velocities on each dimension are clamped to a maximum
velocity Vmax – this parameter is specified by user
• If the sum causes velocity to exceed Vmax, then the velocity value is Vmax
F. Particle Swarm Optimization: Algorithm –
Parameters (cont)
• Parameters to be considered:
• Number of particles (10 – 50 are usually sufficient)
• C1: importance of personal best
• C2: importance of neighbourhood best
• Usually C1+C2 = 4. No good reason other than empiricism
• Vmax – too low, too slow; too high, too unstable
G. Particle Swarm Optimization: Visualization
G. Particle Swarm Optimization: Visualization
Ant Colony Optimization
H. Ant Colony Optimization: Introduction
• Ant Colony Optimization (ACO) is inspired from how ants forage for
food
• Individual ants lay pheromone trails while travelling from the nest, to
the nest or possibly in both directions.
• The pheromone trail gradually evaporates over time.
• But pheromone trail strength accumulate with multiple ants using
path.
Food source
Nest
I. Ant Colony Optimization: Concept
• Ants lay down pheromone trails when it is moving
• An isolated ant moves at random, but when it finds a pheromone
trail, the ant has a high probability of following the trail
• An ant foraging for food deposits pheromone over its route, when it
finds a food source, it returns to the nest reinforcing its trail

Nest Food
I. Ant Colony Optimization: Concept (cont)
• When other ants discover this trail, it follows the path therefore
laying more pheromones on it
• This process works as a positive feedback loop – the higher the
pheromone intensity of the trail, higher chance other ants start travel
on it
J. Ant Colony Optimization: Pheromone Trails
E E E

T= T=
0 1
30 ants
30 ants

D D D
10 20
15 15
d=1.0 d=0.5 ants ants
ants ants

H C C H C
H

d=1.0 d=0.5
B 10 B 20
15 B 15
ants ants
ants ants

30
30
A A ants A ants
J. Ant Colony Optimization: Pheromone Trails
(cont)
K. Ant Colony Optimization: Stigmergy
• Stigmergy is indirect communication via interaction with the
environment
• The highly sophisticated way ants collectively perform complex tasks
is due to stigmergy
• They communicate using pheromones
• They lay trails of pheromones that can be followed by other ants
L. Ant Colony Optimization: Algorithm Basic
Ideas
• Ants are agents that move along between nodes in a graph
• They choose where to go based on pheromone strength (and maybe
other factors)
• An ants path represents a specific candidate solution
• When an ant has finished a solution, pheromone is laid on its path
according to quality of solution – (problem specific, example distance
in TSP)
L. Ant Colony Optimization: Algorithm Basic
Ideas (cont)
• Pheromones on edges path also decrease by certain percentage for
every cycle, this is evaporation property that is also observed in
nature
• This procedure is repeatedly applied until a termination criterion is
satisfied.
M. Ant Colony Optimization: TSP4 Example
Initially, random levels of pheromone are scattered on the edges

A B

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B
An ant is placed at a random node

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B
The ant decides where to go from that node,
based on probabilities
calculated from:
- pheromone strengths,
- next-hop distances.

Suppose this one chooses BC

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B
The ant is now at C, and has a `tour
memory’ = {B, C} – so he cannot
visit B or C again.

Again, he decides next hop (from


those allowed) based on
pheromone strength and distance;
suppose he chooses CD

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B

The ant is now at D, and has a `tour


memory’ = {B, C, D}
There is only one place he can go now:

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B

So, he has nearly finished his tour,


having gone over the links:
BC, CD, and DA.

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
AB is added to complete the round A B
trip.

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
• Examples of three ants solutions on first run

Ant Path Distance


Ant 1 BCDAB 100
Ant 2 ACBDA 95
Ant 3 CDABC 110

• After all ants have finished creating their solutions, pheromones are updated
based on quality of solution
• At the same time, pheromones everywhere are also decreased to model decay
M. Ant Colony Optimization: TSP4 Example
(cont)
A B

Now, pheromone on the tour


is increased, in line with the
fitness of that tour.

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B

Now, pheromone on the tour


is increased, in line with the
fitness of that tour.

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B

Next, pheromone everywhere


is decreased a little, to model
decay of trail strength over
time

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B

Next, pheromone everywhere


is decreased a little, to model
decay of trail strength over
time

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
M. Ant Colony Optimization: TSP4 Example
(cont)
A B
We start again, with another
ant in a random position.

Where will he go?

D
Pheromone C

AB: 10, AC: 10, AD, 30, BC, 40, BD, 15, CD 20
Ant
The ACO algorithm for the TSP
[a simplified version with all essential details]

We have a TSP, with n cities.


1. We place some ants at each city. Each ant then does this:
• It makes a complete tour of the cities, coming back to its starting city, using a transition
rule to decide which links to follow. By this rule, it chooses each next-city at random, but
biased partly by the pheromone levels existing at each path, and biased partly by
heuristic information.
2. When all ants have completed their tours.
Global Pheromone Updating occurs.
• The current pheromone levels on all links are reduced (I.e. pheromone levels decay over
time).
• Pheromone is lain (belatedly) by each ant as follows: it places pheromone on all links of
its tour, with strength depending on how good the tour was.
Then we go back to 1 and repeat the whole process many times, until we reach a termination
criterion.
Ant Systems Algorithm for TSP
Initialize

Place each ant in a randomly chosen city

For Each Ant

Choose NextCity(For Each Ant)

yes more cities


to visit

No

Return to the initial cities

Update pheromone level using the tour cost for each ant

No
Stopping
criteria

yes

Print Best tour


M. Ant Colony Optimization: TSP Pseudocode
N. Ant Colony Optimization: Basic Framework

initialize best-so-far solution

set of valid solutions


loop over ants

update best-so-far solution


store valid solution
O. Other Algorithms
• Cuckoo Search: inspired by cuckoo birds laying eggs
• Intelligent Water Drops: inspired by water drops in rivers
• River Formation Dynamics: inspired by river formations
• Firefly Algorithm: inspired by flashing behaviors of fireflies
O. Other Algorithms: Waze Routing?
It is a complex algorithm that takes into account:
• Live traffic
• Major traffic events
• Historic average speed
• Number of crossroads
• Time of the day
• Type and priority of the street
P. Review Questions
• Watch this quick demo on PSO:
https://www.youtube.com/watch?v=h7ppck9BcEw
• Define PSO and ACO
• List the pseudocode for PSO and ACO
References
• https://www.sciencedirect.com/topics/computer-
science/swarm-intelligence
• http://www.swarmintelligence.org/tutorials.php

You might also like