0% found this document useful (0 votes)
55 views3 pages

8-Queen Problem Solved by GA

The document outlines a genetic algorithm (GA) approach to solving the 8-Queen problem and maximizing a function. It details the steps of initialization, selection, crossover, mutation, and survival, including specific examples of chromosomes and their fitness calculations. The process is iterative, aiming to evolve solutions until a valid configuration with no attacking pairs is found for the 8-Queen problem and optimal values for the function are achieved.

Uploaded by

grabby173041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Topics covered

  • Search Space,
  • Algorithm Implementation,
  • Algorithm Design,
  • Algorithm Analysis,
  • Research Applications,
  • Algorithm Complexity,
  • 8-Queen Problem,
  • Binary Encoding,
  • Genetic Algorithms,
  • Evolutionary Strategies
0% found this document useful (0 votes)
55 views3 pages

8-Queen Problem Solved by GA

The document outlines a genetic algorithm (GA) approach to solving the 8-Queen problem and maximizing a function. It details the steps of initialization, selection, crossover, mutation, and survival, including specific examples of chromosomes and their fitness calculations. The process is iterative, aiming to evolve solutions until a valid configuration with no attacking pairs is found for the 8-Queen problem and optimal values for the function are achieved.

Uploaded by

grabby173041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Topics covered

  • Search Space,
  • Algorithm Implementation,
  • Algorithm Design,
  • Algorithm Analysis,
  • Research Applications,
  • Algorithm Complexity,
  • 8-Queen Problem,
  • Binary Encoding,
  • Genetic Algorithms,
  • Evolutionary Strategies

1.

Initialization of Population
2. Selection
3. Crossover/Recombination
4. Mutation
5. Survival/Accept

1. Solving 8-Queen Using GA


Place 8 queens on an 8×8 chessboard so that no two queens attack each other.

A) Initial Population (Chromosomes)

Each chromosome is an array where the index is the column (1–8) and the value is the row (1–8).

Chromosome (state) Representation Attacking Pairs Non-Attacking (max 28)


Chromosome 1 1 6 2 5 7 4 8 3 4 24
Chromosome 2 2 4 7 3 6 8 5 1 5 23
Chromosome 3 5 3 1 6 8 4 2 7 8 20
Chromosome 4 6 1 3 2 8 7 5 4 17 11
Step 1: Fitness Calculation

Total fitness sum = 24 + 23 + 20 + 11 = 78

Fitness Probabilities:

 Chromosome 1: 24/78 = 31%


 Chromosome 2: 23/78 ≈ 29%
 Chromosome 3: 20/78 ≈ 26%
 Chromosome 4: 11/78 ≈ 14%

Step 2: Selection

Randomly select 2 parents, say:

 Parent 1 = 1 6 2 5 7 4 8 3
 Parent 2 = 2 4 7 3 6 8 5 1
Step 3: Crossover

Suppose crossover happens at position 4.

 Offspring = First 4 genes from Parent 1 + last 4 from Parent 2


 Child = 1 6 2 5 | 6 8 5 1

Step 4: Mutation

Mutation might occur in 1 gene. Suppose column 6 (value = 8) mutates to row = 7.

 Mutated Child = 1 6 2 5 6 7 5 1

Step 5: Repeat

This new child is evaluated, added to the next generation, and the process repeats.

Final Goal:

Eventually, a chromosome like 1 5 8 6 3 7 2 4 appears, with:

 0 Attacking Pairs
 Fitness = 28

Valid 8-Queen solution found!

2
x
2. Maximize f ( x )= −3 x , when x in [0 to 31]
2

Binary Encoding – 5 digits


1. Initialization of Population
2. Selection
3. Crossover/Recombination
4. Mutation
5. Survival/Accept

Update Population

1. Selection (Let us take 6 chromosomes in initial population)

String Initial x 2 Probability Bin


x
No Population f ( x )= −3 x
2
1 [1,0,0,1,0] 18 108 0.211 0.001-0.211
2 [1,0,0,1,1] 19 123.5 0.242 0.212-0.453
3 [1,0,1,1,1] 23 195.5 0.383 0.454-0.836
4 [0,1,1,1,0] 14 56 0.110 0.837-0.946
5 [0,0,1,0,1] 5 0 [if negative] 0 ---
6 [0,1,0,1,1] 11 27.5 0.054 0.947-1.00
Total 510.5 1.00

Let us select 4 parents and perform 2. crossover and 3. mutation

Random Selected Chosen Offspring after Offspring after


Number Bin No. Parent Crossover at random point Mutation (1% chance)
0.54 3 [1,0,1,1,1] [1,0,1,1,0] [1,1,1,1,0]
0.88 4 [0,1,1,1,0] [0,1,1,1,1] [0,1,1,1,1]
0.45 2 [1,0,0,1,1] [1,0,0,1,0] [1,0,0,1,0]
0.20 1 [1,0,0,1,0] [1,0,0,1,1] [1,0,0,1,1]
4. Accept/Survival

Offspring x Fitness, f(x)


[1,1,1,1,0] 30 360
[0,1,1,1,1] 15 67.5
[1,0,0,1,0] 18 108
[1,0,0,1,1] 19 123.5

[Select survivors and add to population]

Updated Population:

String Initial
No Population
1 [1,0,0,1,0]
2 [1,0,0,1,1]
3 [1,0,1,1,1]
4 [0,1,1,1,0]
5 [0,0,1,0,1]
6 [0,1,0,1,1]
7 [1,1,1,1,0]

Check termination [Condition]

New Cycle:

Common questions

Powered by AI

The critical factors influencing the selection probability of a chromosome in genetic algorithms are primarily its fitness relative to the total fitness of the population. The selection probability is computed as the fitness of a particular chromosome divided by the total sum of fitness across all chromosomes. For example, Chromosome 1 in the 8-Queen problem has the highest fitness value, resulting in the highest probability of being selected at 31% . This establishes a preferential bias towards higher-fitness candidates, directing the algorithm toward more promising areas of the solution space.

Mutation introduces small random changes in the offspring to maintain genetic diversity within the population and prevent premature convergence on suboptimal solutions. The mutation can alter one or more genes in an offspring, thus potentially introducing traits that could lead to better solutions. For example, in the solutions provided, a mutation in the 8-Queen problem changes a gene in the child from 8 to 7 in one position, adding variety to the potential solutions . This randomness helps ensure that the genetic algorithm does not become stuck in a local optimum.

Using a crossover strategy with random point crossover in genetic algorithms introduces variability and explores diverse potential solutions by combining sections of two parents at different points. This strategy is expected to create offspring that possess characteristics from both parents, potentially leading to a more optimal solution. In the examples, this method is applied where a random crossover point blends genes from two parents, such as combining the first four genes of one parent with the last four of another . This method diversifies the gene pool, enhancing the algorithm's capability to explore different solution paths.

Survival and acceptance in a genetic algorithm involve evaluating offspring based on their fitness and determining which will be retained in the population for the next generation. In the examples provided, this decision is made by selecting those chromosomes that have higher fitness values post-crossover and mutation. The offspring with higher fitness values, such as the one reaching a fitness of 360 in the binary encoded problem, are preferable due to their potential to produce better subsequent generations. The process ensures only the most promising solutions survive into the next cycle .

The fitness calculation directly influences the selection process by determining the probability of each chromosome being selected as a parent. In the 8-Queen problem, the fitness of each chromosome is proportional to the number of non-attacking pairs of queens it contains, with higher fitness values indicating a better solution. Chromosomes with higher fitness have a greater chance of being selected, as illustrated by Chromosome 1 having a 31% probability compared to Chromosome 4's 14% probability . This ensures that superior solutions are more likely to be propagated to subsequent generations.

Crossover plays a critical role in the optimization process by combining genetic information from two parent chromosomes to explore new areas of the solution space. In the examples provided, crossover occurs at a specified point, thereby mixing genes from two parents to create offspring with potential new solution traits. For instance, in the 8-Queen example, offspring from parents 1 and 2 results in a new set of genes that could lead to a more optimal solution . This process introduces variation while maintaining characteristics of the original best solutions.

The final goal of the genetic algorithm for the 8-Queen problem is to find a chromosome that represents a board configuration where no queens attack each other. This is assessed by computing the number of non-attacking pairs among the queens; the target is to achieve 28 non-attacking pairs, which is the maximum possible for 8 queens. A chromosome such as 1 5 8 6 3 7 2 4 with zero attacking pairs meets this criterion .

The probability range for selection in the binary encoded example is determined by calculating the relative fitness proportion of each chromosome within the total fitness sum of the population. Each chromosome is assigned a specific probability range based on its fitness score, creating a cumulative selection framework. For instance, Chromosome 3 with the highest fitness has a probability range of 0.454-0.836 . During selection, a random number is generated to select a chromosome falling into its probability range, ensuring that those with higher fitness have a greater chance of being chosen as parents for the next generation.

Using a fixed mutation probability, such as a 1% chance, in genetic algorithms strikes a balance between exploration and exploitation. It ensures that solutions do not become overly homogeneous and stagnate by adding enough variability to search the solution space thoroughly. However, too high a mutation rate might disrupt the convergence to optimal solutions, while too low might lead to premature convergence. In the examples, this probability rate allows for occasional alterations, such as changing a single gene value, providing diversity without significantly deviating from potentially optimal solutions .

Binary encoding impacts the representation in genetic algorithms by allowing complex solutions to be expressed in simple binary strings, facilitating easier manipulation through crossover and mutation. In the solution process, binary encoding aids in simulating how solutions evolve over iterations. For instance, a 5-digit binary string in the optimization function defines potential values of 'x', with each digit representing a power of 2, thus allowing the search to cover a broad range efficiently. This encoding directly affects how solutions are assessed and selected based on fitness .

You might also like