Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views5 pages

Genetic Algorithms

Uploaded by

manjulavijiraj06
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)
7 views5 pages

Genetic Algorithms

Uploaded by

manjulavijiraj06
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/ 5

Genetic algorithms

●​ A genetic algorithm is a search technique inspired by the process of natural evolution


(like how animals evolve over generations).
●​ It’s used to find the best solution to a problem by "evolving" a set of possible
solutions over time.
●​ Instead of trying every possible solution (which can take forever), GAs use ideas like
selection, crossover, and mutation to gradually improve solutions.

Key Components of a Genetic Algorithm

1. Starting Population (P)


- You start with a group of random possible solutions to your problem. This group is called
the population, and each solution is called an individual

- How is it represented?
Each individual is a string of characters (like 001101), where the string is called a
chromosome, and each character (0 or 1) is called a gene. These genes represent the
solution in a coded form.
- Example: If you’re trying to find the best 6-bit string where more 1s are better, your
population might look like:
- Individual 1: 000111
- Individual 2: 101010
- Individual 3: 111000
- Size: The population size (e.g., 50 or 100 individuals) is chosen based on the problem. Too
small, and you might miss good solutions; too big, and it takes too long to compute.

2. Fitness Function (f)

- A fitness function measures how good each individual is at solving the problem. It gives a
score to each solution.
- How does it work?
The higher the score, the better the solution. The book mentions oulette wheel selection,
where the probability of picking an individual as a parent is based on its fitness:

This means individuals with higher fitness have a higher chance of being selected.

- Example: If the goal is to maximize the number of 1s in a 6-bit string:


- Individual 1: 000111 → Fitness = 3 (three 1s)
- Individual 2: 101010 → Fitness = 3 (three 1s)
- Individual 3: 111000 → Fitness = 3 (three 1s)
- Total fitness = 3 + 3 + 3 = 9

- Why is it important?
The fitness function guides the algorithm to focus on better solutions.

3. Crossover Technique

- Crossover is how you create new solutions (children) by combining parts of two good
solutions (parents). It mimics how parents pass traits to their kids in nature.

- Types of Crossover:
- Single Crossover: Pick one point in the string and swap the parts after that point.
- Example: Parents are 000|111 and 111|000 (crossover point at position 3).
- Child 1: 000000
- Child 2: 111111
- Multiple Crossover: Pick multiple points and swap sections.
- Example: Parents are 00|01|11 and 11|10|00 (crossover points at positions 2 and 4).
- Child 1: 001000
- Child 2: 110111
- Probability: You decide how often crossover happens (e.g., 80% of the time). If crossover
doesn’t happen, the parents are copied as-is to the next generation.
- Why use it?
Crossover helps combine good traits from two solutions to create potentially better ones.

4. Mutation

Mutation introduces small random changes to the children to add variety and avoid getting
stuck with bad solutions.

- How does it work?


For each gene in a child, there’s a small chance (e.g., 1%) to change it. For binary strings
(0s and 1s), this means flipping a 0 to 1 or a 1 to 0.
- Example:
- Child: 000000
- Mutate at position 2 (flip 0 to 1): 010000

- Why use it?


Mutation ensures the algorithm explores new solutions and doesn’t get trapped in a "local
optimum" (a solution that’s good but not the best).

5. Algorithm to Apply Crossover and Mutation

- This is the process that ties everything together. It iteratively applies selection, crossover,
and mutation to improve the population.
This algorithm shows how a genetic algorithm (GA) improves a group of solutions (called a
population) to find the best one for a problem. It’s like breeding better plants or animals over
generations, but for solving problems like finding the best number or pattern.

Simple Explanation of the Algorithm

Input and Output

- Input: A starting group of solutions, called the population \( P \). For example, P could be a
list of binary strings like {000111, 101010, 111000}.

- Output: An improved group of solutions, called P after running the algorithm.

Steps in Simple Terms:

The algorithm keeps repeating a process to make better solutions. Here’s what it does:

1. Start with the Population


- You have a group P (e.g., {000111, 101010, 111000}).
- Create an empty group P to store new solutions.

2. Make a New Population:


- Keep repeating until P has the same number of solutions as P:
- Pick Two Parents: Choose two solutions from P based on how good they are (using
their fitness score). For example, if 000111 and 111000 are the best, pick them.
- Mix Them (Crossover): Combine the two parents to make two new solutions (children).
For example:
- Parents: 000111 and 111000
- Mix at position 3: New children are 000000 and 111111.
- Add Small Changes (Mutation): Randomly change a tiny part of the children. For
example:
- 000000 might become 010000 (flip a 0 to 1).
- 111111 might become 110111.
- Add to New Group: Put the children into P.

3. Replace the Old Group:


- Once Pis full (same size as P , replace P \) with P

4. Keep Going:
- Repeat the whole process (from step 2) until you find a good solution or reach a set
number of rounds.

Why Do This
- The goal is to keep improving the population. Each round, you’re making new solutions that
are (hopefully) better than the old ones.
- Over time, you’ll get closer to the best solution for your problem.

Example: Maximizing 1s in a 6-Bit String


Let’s say your problem is to find a 6-bit string with the most 1s (best solution is 111111).

Step 1: Start with a Population


- P ={000111, 101010, 111000} (3 solutions).
- Each has a fitness score (number of 1s):
- 000111 → 3 ones
- 101010 → 3 ones
- 111000 → 3 ones
- Set P' = ∅ (empty).

Step 2: Make a New Population


- Pick Parents: Choose 000111 and 111000 (based on fitness).
- Crossover: Mix at position 3:
- 000|111 and 111|000 → Children: 000000 and 111111.
- Mutation: Randomly change a bit:
- 000000 → 010000 (flip position 2).
- 111111 → 110111 (flip position 3).
- Add to P: Now P' ={010000, 110111}
- Since P had 3 solutions, pick one more pair (e.g., 101010 and 111000), repeat crossover
and mutation, and add the children to P'

Step 3: Replace
- Once P' has 3 solutions, set P = P'

Step 4: Repeat
- Keep going until you get 111111 (fitness = 6) or stop after a set number of rounds.

Why It’s Useful


This process helps solve tough problems where you can’t easily calculate the answer, like
optimizing a schedule or finding patterns in data. It’s like letting solutions "evolve" to get
better over time.

-Advantages of Genetic Algorithms

- Parallel Search: GAs explore many solutions at once, unlike traditional methods that try
one solution at a time.
- Works on Tough Problems: Great for problems where the solution space is huge or
complex, like scheduling, robotics, or data mining (e.g., finding patterns in data).
- Flexible: Can work with different types of data (not just binary strings, but also numbers,
trees, etc.).

🤔Challenges
1. Hard to Explain: GAs can be tricky to understand for beginners or non-technical people.
2. Problem Representation: Deciding how to encode the problem as a chromosome (e.g.,
binary string) is not always easy.
3. Fitness Function: Designing a good fitness function is critical but can be difficult for
complex problems.
4. Crossover and Mutation Rates: Choosing the right probabilities for crossover and
mutation takes trial and error.

Real-World Applications

- Data Mining: GAs can find patterns, classify data, or generate association rules (e.g., "if
someone buys bread, they also buy butter").
- Scheduling: Optimize schedules for schools, factories, or airlines.
- Robotics: Design robot movements or paths.
- Biology: Model genetic processes or protein folding.

You might also like