#54 FixedBinaryGene Size / Mutation


Mutation does not work on large FixedBinaryGese, because the size method does not return the actual length of the gene. I have a gene of 512 bits which was created as such:

FixedBinaryGene gene = new FixedBinaryGene(gaConfig, 512);

In the constructor M-length gets set to 512, however the int[] m_value gets created with size 16 (the appropriate size to tightly hold the bits). The getLength() method will correctly return 512 as the length of the gene, since it returns the m_length value. However, the size() method returns 16 since it returns m_value.length. Size should return the number of atomic elements which should be 512 and not 16. The fact that 16 int primitives are used to store the bits should be an internal construct not visible to the outside world.

Ultimately this causes mutation to fail. In the MutationOperator class the mutateGene(..) method has the following code:

for (int k = 0; k < a_gene.size(); k++) {
// Retrieve value between 0 and 1 (not included) from generator.
// Then map this value to range -1 and 1 (-1 included, 1 not).
// -------------------------------------------------------------
double percentage = -1 + a_generator.nextDouble() * 2;
// Mutate atomic element by calculated percentage.
// -----------------------------------------------
a_gene.applyMutation(k, percentage);

Since the size method for the FixedBinaryGene only returns 16, only the first 16 bits of the 512 bits ever get mutated. I believe the size() method should also return m_length;


  • Klaus

    • assigned_to: nobody --> klausikm
    • status: open --> open-fixed
  • Klaus

    You are right, it seems as it would be correct to do what you suggest: Let size() return m_length() instead of the number of the primitives used to store the bits.

    I just did the correction plus adaptation of test cases and will check in the changes to CVS.

  • Great! Thanks.