How to frame a genetic algorithm for this problem?

In summary, the conversation discusses the use of a genetic algorithm to find the module that causes the maximum number of method calls with the minimum number of methods. The algorithm involves initial population, fitness function, selection, crossover, and mutation steps. The user is seeking guidance on how to apply crossover and mutation, as well as how to discard the population and keep only the best solutions.
  • #1
zak100
462
11
Hi,
I have a random array which represents method calls. For instance: [3, 4, 7, 40, 39, ...] meaning that method 0 is called 3 times, method 1 is called 4 times, method 2 is called 7 times, method 3 is called 40 times, method 4 is called 39 times and so on upto n. Now consider a module as a collection of random methods from 1-5 and there are 20 such modules. Find out a module whose execution causes exercising maximum number of method calls with minimum number of method.

I have applied the genetic algorithm without considering the binary values and I have obtained the module which can have maximum method calls with minimum number of methods. The steps of my algorithm are:

Initial population Fitness function Selection

However, I have not applied the other two steps i.e. crossover and mutation. Some body please guide me how to apply these two steps in my algorithm. Also I am not using binary values. How to incorporate binary values in the data? Some body please guide me.

Zulfi.
 
Technology news on Phys.org
  • #2
Mutation means that you select a random array from a collection of random arrays (think each random array a string of letters) and then you alter one or more of its elements like you increase the count or zero one count and bump another like selectively changing the letters of the string

from xxxxxxxxxx to xxYxxxZxxxxAxx the capital letters represent the mutations

For crossover, you select two random arrays from your collection of random array solutions and mate them together by swapping selected elements between them. You can use a random number generator to select indices of elements to swap.

array 1: aaabbbcccddd
array 2: AAABBBCCCDDD

new array aAAbbbCCcDdD

The mutated and crossover arrays along with the original solutions become a part of your solution pool to try out for the next cycle. Their scores determine whether they remain or are tossed out.
 
  • #3
Hi,
Thanks for your information. But Mutation would increase the population. I have to find the largest generation. What is the method of discarding the population. I can use fittest function but then I won't be able to incorporate mutation and cross over concepts. I want to use the concepts of Mutation and cross over but to discard the population so that I would be left with only largest genes or near largest valued genes.

Please guide me.

Zulfi.
 
  • #4
You use the score you got, order your solutions from highest to lowest and cutoff the population at some number like say the top 20 solutions go to the next iteration aka generation.

The Best of the Best go forward.
 

1. What is a genetic algorithm?

A genetic algorithm is a computational method inspired by natural selection and genetics. It is used to find solutions to complex problems by mimicking the process of natural selection and genetic evolution.

2. How does a genetic algorithm work?

A genetic algorithm works by starting with a random population of possible solutions to a problem. The algorithm then evaluates each solution and selects the most fit individuals to reproduce and create new offspring. This process is repeated for multiple generations until a suitable solution is found.

3. What are the main components of a genetic algorithm?

The main components of a genetic algorithm include a population of potential solutions, a fitness function to evaluate each solution, selection methods to choose the most fit individuals for reproduction, and genetic operators such as crossover and mutation to create new offspring.

4. How do I determine the parameters for my genetic algorithm?

The parameters for a genetic algorithm, such as population size, crossover rate, and mutation rate, can be determined through experimentation and fine-tuning. It is important to test different parameter values and analyze the results to find the most effective combination for a specific problem.

5. Can I use a genetic algorithm for any problem?

A genetic algorithm can be applied to a wide range of problems, but it is not suitable for every problem. It is most effective for problems that have a large search space and a well-defined fitness function. It may also not be the best approach for problems with a small number of variables or constraints.

Similar threads

  • Programming and Computer Science
Replies
1
Views
959
  • Programming and Computer Science
Replies
13
Views
3K
  • General Math
Replies
5
Views
845
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
29
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
Back
Top