GA written in Java

后端 未结 7 803
天命终不由人
天命终不由人 2020-12-24 00:52

I am attempting to write a Genetic Algorithm based on techniques I had picked up from the book \"AI Techniques for Game Programmers\" that uses a binary encoding and fitness

相关标签:
7条回答
  • 2020-12-24 01:25

    I have implemented this algorithm by creating a "cumulative fitness array" and binary search, thus reducing the need to iterate through each element in the array during the selection:

    1. For population size N create cumulative fitness array: arr[N].
    2. Set arr[0] := computeFitness(individual[0]).
    3. Then, for each subsequent element: X, arr[X] = arr[X-1] + computeFitness(individual[X]).
    4. Generate a random number between 0 and arr[N] (i.e. the total fitness).
    5. Use a binary search (e.g. Collections.binarySearch) to locate the appropriate index in the cumulative fitness array, and use this index to select the individual.

    Note that you only need to create the fitness array at the start of the reproduction phase, and can then re-use it multiple times to perform selections in O(log N) time.

    As an aside, note that tournament selection is far easier to implement!

    0 讨论(0)
提交回复
热议问题