0% found this document useful (0 votes)
16 views34 pages

Revision

The document discusses various optimization algorithms including Particle Swarm Optimization (PSO), Ant Colony Optimization (ACO), and Genetic Algorithms (GA). It provides examples and calculations for maximizing functions, updating pheromones, and solving knapsack problems. Additionally, it covers game playing strategies and maze solving using A* algorithm.

Uploaded by

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

Revision

The document discusses various optimization algorithms including Particle Swarm Optimization (PSO), Ant Colony Optimization (ACO), and Genetic Algorithms (GA). It provides examples and calculations for maximizing functions, updating pheromones, and solving knapsack problems. Additionally, it covers game playing strategies and maze solving using A* algorithm.

Uploaded by

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

ARTIFICIAL

INTELLIGENCE
DR. MANAL TANTAWI
ASSOCIATE PROFESSOR
IN
SCIENTIFIC COMPUTING DEPARTMENT
FACULTY OF COMPUTER & INFORMATION
SCIENCES
AIN SHAMS UNIVERSITY
PART 7

➢Revision
PARTICLE SWARM OPTIMIZATION (PSO)
Consider maximizing the following function:
F(x, y) = ( 2x + y – 2 )(x + 2y +1)
we have three particles (Bees) searching for the optimum values for variables x and y and the status
after first iteration is as in the following table:

Bees Velocity Current x Current y Current Best x Best y Best fitness


fitness
1 0 4 3 99 4 3 99
2 0 -2 1 -5 -2 1 -5
3 0 3 -1 6 3 -1 6
Calculate the new positions for all bees and show the updated matrix, given inertia= 0.1, cognitive
constant =0.3, Social constant =0.4 and assume the cognitive random number generated for all bees is
0.4 and the social random number is 0.5 for all bees.
SOLUTION
Velocity of bee 1
Inertia + cognitive component + Social component
0.1 * 0 + (0.3*0.4) dis ([ 4, 3] , [4, 3] ) + (0.4 * 0.5) dis ([4, 3] , [4, 3])
0+0+ 0
0+0+0=0

Velocity of bee 2
Inertia + cognitive component + Social component
0.1 * 0 + (0.3*0.4) dis ([ -2, 1] , [-2, 1] ) + (0.4 * 0.5) dis ([4, 3] , [-2, 1])
0 + 0 + 0.4 * 0.5 * 6.3245
0 + 0 + 1.265= 1.265

Velocity of bee 3
Inertia + cognitive component + Social component
0.1 * 0 + (0.3*0.4) dis ([ 3, -1] , [3, -1] ) + (0.4 * 0.5) dis ([4, 3] , [3, -1])
0 + 0 + 0.4 * 0.5 * 4.123
0 + 0 + 0.824 = 0.824
SOLUTION
F(x, y) = ( 2x + y – 2 )(x + 2y +1)

Bees Velocity Current x Current y Current Best x Best y Best fitness


fitness
1 0 4 3 99 4 3 99
2 0 -2 1 -5 -2 1 -5
3 0 3 -1 6 3 -1 6

Bees Velocity Current x Current y Current Best x Best y Best fitness


fitness
1 0 4 3 99 4 3 99
2 1.265 -0.735 2.265 -5.77 -2 1 -5
3 0.824 3.824 -0.176 24.47 3.824 -0.176 24.47
ANT COLONY OPTIMIZATION (ACO)

The following fully connected graph represents four sites


Dis = 11
along with the distances between them and the P=9
pheromones produced by some ants. Hence, help the ant A
Dis = 14
C
on site A to find its next visit, given alpha =2 and beta = 3. P = 11
Dis = 9
(hint: don’t use roulette wheel, just choose the site with P=7 Dis = 10
highest probability) P=4
Dis = 8
P=4 D
B
Dis = 12
P=3
ANT COLONY OPTIMIZATION (ACO)

Dis = 11
P=9
A
Dis = 14
C
P = 11
Dis = 9
P=7

D
B

The next visit will be site B


ANT COLONY OPTIMIZATION (ACO)
Calculate the pheromone update which includes both evaporation and depositing given the following
scenario that considers two ants and evaporation factor = 0.5.
SOLUTION EVAPORATION STEP

Evaporation factor = 0.5


SOLUTION
DEPOSITING
STEP
GENETIC ALGORITHMS

CONSIDER A KNAPSACK PROBLEM WITH THE FOLLOWING SPECIFICATIONS


THE TOTAL WEIGHT CAN’T EXCEED 9 KG
WE HAVE FOR ITEMS: A = 4 KG, B = 1 KG, C= 2 KG AND D= 3
FOR YOUR SOLUTION:
LET THE POPULATION SIZE = 4
SELECT BEST 2 PARENTS AND RANDOMLY CHOOSE THEIR PARTNERS FROM THE POPULATION
CONSIDER SINGLE POINT CROSSOVER (ASSUME THE RANDOM INTEGER IS 2)
FOR MUTATION CHOOSE ONE RANDOM GENE ( CONSIDER RANDOM INTEGERS 2, 1, 2 AND 1)
FOR NEXT GENERATION CHOOSE BEST 4 CHROMOSOMES FROM OLD GENERATIONS AND OFFSPRINGS
STOPPING CRITERIA: REACHING FITNESS 9
GENETIC ALGORITHMS
Population randomly initialized

A =4 B=1 C=2 D=3 Fitness


C1 0 0 1 1
C2 1 1 0 1
C3 0 1 0 0
C4 1 0 1 0
GENETIC ALGORITHMS
Calculate Fitness

A =4 B=1 C=2 D=3 Fitness


C1 0 0 1 1 5
C2 1 1 0 1 8
C3 0 1 0 0 1
C4 1 0 1 0 6

Best parents
C2 1 1 0 1 8

C4 1 0 1 0 6
GENETIC ALGORITHMS
First parent

C2 1 1 0 1 8

Assume random chosen partner is

C1 0 0 1 1 5

single point crossover (assume the random integer is 2) Mutation random integers 2, 1
for these offsprings respectively
Offspring 1 1 1 1 Offspring
1 1
1 0 1 1 9

Offspring 0 0 0 1 Offspring
2 2
1 0 0 1 7
GENETIC ALGORITHMS
First parent

C4 1 0 1 0 6

Assume random chosen partner is

C2 1 1 0 1 8

single point crossover (assume the random integer is 2) Mutation random integers 2, 1
for these offsprings respectively
Offspring 1 0 0 1 Offspring
1 3
1 1 0 1 8

Offspring 1 1 1 0 Offspring
2 4
0 1 1 0 3
GENETIC ALGORITHMS
Choose next generation

A =4 B=1 C=2 D=3 Fitness


C1 0 0 1 1 5
Offspring 1 0 1 1 9
C2 1 1 0 1 8 1
C3 0 1 0 0 1 Offspring 1 1 0 1 8
3
C4 1 0 1 0 6
C2 1 1 0 1 8
Offspring 1 0 1 1 9
1 Offspring 1 0 0 1 7
2
Offspring 1 0 0 1 7
2
Offspring 1 1 0 1 8
3 Stopping criteria is reached
Offspring 0 1 1 0 3 by the best chromosome of fitness 9 so no
4 more iteration is needed
GENETIC ALGORITHMS
Regarding the following population of four chromosomes calculate the fitness of each chromosome
which represents the total weight in a bag with maximum capacity 12 kg

Item A = 4 kg Item B = 1 kg Item C = 2 Kg Item D = 3 kg


C1 2 4 0 0
C2 1 3 1 1
C3 2 4 2 1
C4 0 4 0 2

Does there any invalid chromosome ?


GENETIC ALGORITHMS
Regarding the following population of five chromosomes calculate the fitness of each chromosome
which represents the total weight in a bag with maximum capacity 14 kg

Item A = 4 kg Item B = 1 kg Item C = 2 Kg Item D = 3 kg Solution


C1 2 4 0 0 Fitness: 2x4 + 4x1 = 12
C2 1 2 1 1 Fitness: 1x4+ 2x1+1x2+1x3 =11
C3 2 4 2 1 Fitness: 2x4+ 4x1+2x2+1x3 =19
C4 0 3 0 2 Fitness: 0x4+ 3x1+0x2+2x3=9
C5 1 5 1 0 Fitness: 1x4+ 5x1+1x2+0x3=11

Does there any invalid chromosome ? Yes, chromosome C3


GENETIC ALGORITHMS
Regarding the following chromosomes, select two parents using a roulette wheel and consider 0.54 and 0.2
as the random numbers needed for selecting the first and second parent, respectively.

Item A = 4 kg Item B = 1 kg Item C = 2 Kg Item D = 3 kg Fitness


C1 2 4 0 0 12
C2 1 2 1 1 11
C4 0 3 0 2 9
C5 1 5 1 0 11
SOLUTION
Item A = 4 kg Item B = 1 kg Item C = 2 Kg Item D = 3 kg Fitness
C1 2 4 0 0 12
C2 1 2 1 1 11
C4 0 3 0 2 9
C5 1 5 1 0 11

Total fitness: 12+11+9+11 = 43 Cumulative probability (slices): (Random number = 0.54)


C1=12/43 =0.279 C1= 0.279 First parent : C5
C2=11/43 = 0.2558 C2= 0.5348 (Random number = 0.2)
C5 = 11/43= 0.2558 C5= 0.7906 First parent : C1
C4 = 9/43 = 0.209 C4= 1
GENETIC ALGORITHMS

APPLY SINGLE POINT CROSSOVER ON THE FOLLOWING TWO PARENTS TO GENERATE TWO
OFFSPRINGS ( CONSIDER THE NEEDED RANDOM INTEGER = 1)

C1 2 4 0 0
C5 1 5 1 0

Solution
C1 2 5 1 0
C5 1 4 0 0
GENETIC ALGORITHMS

For genes ranged from 0 to 10, apply boundary mutation on a randomly selected
gene and show the resulted chromosome if the mutation random integer = 3

0 4 3 2 1 0 6 8 5 2

Solution

0 4 10 2 1 0 6 8 5 2
GENETIC ALGORITHMS

For the following binary encoded offspring, apply mutation with rate 0.4 and show the resulted chromosome.

Genes 0 1 1 0 1 0 1 0 1 0
Random Numbers 0.6 0.5 0.1 0.55 0.8 0.72 0.25 0.3 0.78 0.15

Solution
0 1 0 0 1 0 0 1 1 1
0.6 0.5 0.1 0.55 0.8 0.72 0.25 0.3 0.78 0.15
GAME PLAYING
Calculate the scores for the following game tree
max
Agent is x
Player is o
Agent winning score is +10 -10 0
min
Player winning score is -10
+10

max
-10 0 +10 0

0 +10 0
GAME PLAYING
Apply alpha-beta pruning on the following game tree
GAME PLAYING
Apply alpha-beta pruning on the following game tree

a=7
b=∞ 7
Solution
a =-∞ a=7
b=7 b=1
7 1
a= 8 a=7
b= 7 b=∞
a=7 7
b=∞ 8 1
SOLVING MAZE USING A*

FIND THE SHORTEST PATH TO THE GOAL USING A*

(1,1) G (1,2) (1,3)


(2,1) (2,2) (2,3)
(3,1) (3,2) (3,3)
(4,1) (4,2) (4,3) S
SOLVING MAZE USING A*
(1,1) G (1,2) (1,3) (4,3) 5+0
(2,1) (2,2) (2,3) (4,2) 4+1
(4,1) 3+2
(3,1) (3,2) (3,3) (3,1) 2+3
(4,1) (4,2) (4,3) S (2,1) 1+4

(2,2) 2+5
(3,2) 3+4
(3,2) 3+2
(3,3) 4+1

Open list Closed list


SOLVING MAZE USING A*
(1,1) G (1,2) (1,3) (4,3) 5+0
(2,1) (2,2) (2,3) (4,2) 4+1
(4,1) 3+2
(3,1) (3,2) (3,3) (3,1) 2+3
(4,1) (4,2) (4,3) S (1,1) 0+5 (2,1) 1+4
(2,2) 2+5 (3,3) 4+1
(2,2) 2+5 (2,3) 3+2
(3,2) 3+4 (1,3) 2+3
(3,2) 3+2 (1,2) 1+4

Open list Closed list


SOLVING MAZE USING A*
(1,1) G (1,2) (1,3) (4,3) 5+0
(4,2) 4+1
(2,1) (2,2) (2,3)
(4,1) 3+2
(3,1) (3,2) (3,3) (3,1) 2+3
(4,1) (4,2) (4,3) S (2,1) 1+4
(2,2) 2+5 (3,3) 4+1
(2,2) 2+5 (2,3) 3+2
(1,3) 2+3
(3,2) 3+4
(1,2) 1+4
(3,2) 3+2
(1,1) 0+5

Open list Closed list


INFORMAL SEARCH

FIND THE SHORTEST PATH TO THE GOAL USING A*


INFORMAL SEARCH
FIND THE SHORTEST PATH TO THE GOAL USING A*
S
B (11)
D (9)

(F 8)
(E 11)
(A 16)
(C 23)

Open list Closed list


INFORMAL SEARCH
FIND THE SHORTEST PATH TO THE GOAL USING A*
S
B (11)
D (9)
(F 8)

(E 11)
(A 16)
(C 23)

Open list Closed list


THANK YOU

You might also like