N Queens Solution with Genetic Algorithm - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

N Queens Solution with Genetic Algorithm

Description:

A queen can move horizontally, vertically, or diagonally. The problem can be solved with genetic algorithm for a n queens problem. ( n is between 8 and 30) ... – PowerPoint PPT presentation

Number of Views:1310
Avg rating:5.0/5.0
Slides: 18
Provided by: cisJu
Category:

less

Transcript and Presenter's Notes

Title: N Queens Solution with Genetic Algorithm


1
N- Queens Solution with Genetic Algorithm
  • By
  • Mohammad A. Ismael

2
N-Queens problem Definition
  • Place N queens on an NN board so that no queen
    is attacking another queen.
  • A queen can move horizontally, vertically, or
    diagonally.
  • The problem can be solved with genetic algorithm
    for a n queens problem. (n is between 8 and 30)

Here N8
3
8-Queens problem
  • Simple solutions may lead to very high search
    costs
  • 64 fields, 8 queens gt 648 possible sequences
  • Genetic algorithm solution trim the search space.

4
Problem formulation
  • Initial State n queens placed randomly on the
    board, one per column.
  • Successor function moving one queen to a new
    location.
  • Cost The number of queens that hit each others.

5
Genetic consists of
  • Genes
  • Chromosomes
  • Populations

6
In n-queens
  • A gene is a number between 0 to n-1.
  • Is a position of any queen in the board
  • A chromosome is an array of these genes. It
    could be the solution.
  • Population is a generated set of chromosomes.

7
Chromosomes and genes
A chromosome (array of genes. It could be an
answer)
  • 3,6,8,5,1,4,0,7,9,2
  • 7,6,9,5,1,4,0,3,8,2
  • 9,6,1,5,8,4,0,7,3,2
  • 6,3,8,5,2,4,0,7,9,1
  • 3,6,8,5,1,4,0,7,9,2
  • .
  • .
  • .

Gene
Population
Here N10
8
Create a random initial population
  • An initial population is created from a random
    selection of chromosomes.
  • The number of generations needed depends on the
    random initial population.

9
Finding the cost
  • To find the assigned cost for each chromosome a
    cost function is defined.
  • The result of the cost function is called cost
    value.
  • This value is used for chromosomes ranking
  • The best (minimum value) is placed on top and the
    worst (maximum) is placed in the bottom.

10
Producing next generation
  • Those chromosomes with a higher fitness (lesser
    cost) value are used to produce the next
    generation.
  • The offspring (or Child) is a product of the two
    parents, whose composition consists of a
    combination of genes from them (this process is
    known as "crossing over").
  • If the new generation (Child) contains a
    chromosome that produces an output that is close
    enough or equal to the desired answer then the
    problem has been solved.
  • If this is not the case, then the new generation
    will go through the same process as their parents
    did. This will continue until a solution is
    reached.

11
Steps to solving the problem with GA
  • Clear the board.
  • Generate the initial population.
  • This generation is a purely random generation.
  • Fill the chess board with a chromosome.
  • For example,
  • Let Chromosome Matrix 3,6,8,5,1,4,0,
  • 7,9,2,
  • Here Chess Board Length 10 (n10).

12
Steps to solving the problem with GA
  • Determines the cost value for each chromosome
    matrix.
  • For example,
  • For chromosome 2,6,9,3,5,
  • 0,4,1,7,8 , the cost value will be 2
  • Because of there are two queens
  • that hit each other

13
Steps to solving the problem with GA
  • Sort the new generation according to their cost
    value.
  • The best (minimum) is placed on top and the
    worst (maximum) is placed in the bottom.
  • Generate the cross over matrix. This matrix
    contains 0s and 1s.

14
Steps to solving the problem with GA
  • Generate children from parents using cross over
    matrix.
  • Genes are drawn from P0 and P1.
  • A gene is drawn from one parent and it is
    appended to the offspring (child) chromosome.
  • The corresponding gene is deleted in the other
    parent
  • This step is repeated until both parent
    chromosomes are empty and the offspring contains
    all genes involved.

15
Steps to solving the problem with GA
  • Apply mutation to the current generation.
  • First of all, a random chromosome is selected
    but the first (best) one in the list.
  • Then, two random genes of this chromosome are
    selected and replaced with each other.
  • Increasing the number of mutations increases the
    algorithms freedom to search outside the current
    region of chromosome space.

16
Example of such software
17
  • Questions?
Write a Comment
User Comments (0)
About PowerShow.com