BinaryChromosome (Apache Commons Math 3.6.1 API)

org.apache.commons.math3.genetics

## Class BinaryChromosome

- java.lang.Object
- - org.apache.commons.math3.genetics.Chromosome
  - - org.apache.commons.math3.genetics.AbstractListChromosome<Integer>
    - - org.apache.commons.math3.genetics.BinaryChromosome

- All Implemented Interfaces:
    Comparable<Chromosome>, Fitness

      public abstract class BinaryChromosome
      extends AbstractListChromosome<Integer>

  Chromosome represented by a vector of 0s and 1s.
  Since:
    2.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BinaryChromosome(Integer[] representation)` Constructor.
    `BinaryChromosome(List<Integer> representation)` Constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `checkValidity(List<Integer> chromosomeRepresentation)` Asserts that `representation` can represent a valid chromosome.
    `protected boolean` | `isSame(Chromosome another)` Returns `true` iff `another` has the same representation and therefore the same fitness.
    `static List<Integer>` | `randomBinaryRepresentation(int length)` Returns a representation of a random binary array of length `length`.

    - ### Methods inherited from class org.apache.commons.math3.genetics.AbstractListChromosome

      `getLength, getRepresentation, newFixedLengthChromosome, toString`

    - ### Methods inherited from class org.apache.commons.math3.genetics.Chromosome

      `compareTo, findSameChromosome, getFitness, searchForFitnessUpdate`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.commons.math3.genetics.Fitness

      `fitness`

- - ### Constructor Detail

    - #### BinaryChromosome

          public BinaryChromosome(List<Integer> representation)
                           throws InvalidRepresentationException

      Constructor.
      Parameters:
        `representation` - list of {0,1} values representing the chromosome
      Throws:
        `InvalidRepresentationException` - iff the `representation` can not represent a valid chromosome

    - #### BinaryChromosome

          public BinaryChromosome(Integer[] representation)
                           throws InvalidRepresentationException

      Constructor.
      Parameters:
        `representation` - array of {0,1} values representing the chromosome
      Throws:
        `InvalidRepresentationException` - iff the `representation` can not represent a valid chromosome

  - ### Method Detail

    - #### checkValidity

          protected void checkValidity(List<Integer> chromosomeRepresentation)
                                throws InvalidRepresentationException

      Asserts that `representation` can represent a valid chromosome.
      Specified by:
        `checkValidity` in class `AbstractListChromosome<Integer>`
      Parameters:
        `chromosomeRepresentation` - representation of the chromosome
      Throws:
        `InvalidRepresentationException` - iff the `representation` can not represent a valid chromosome

    - #### randomBinaryRepresentation

          public static List<Integer> randomBinaryRepresentation(int length)

      Returns a representation of a random binary array of length `length`.
      Parameters:
        `length` - length of the array
      Returns:
        a random binary array of length `length`

    - #### isSame

          protected boolean isSame(Chromosome another)

      Returns `true` iff `another` has the same representation and therefore the same fitness. By default, it returns false -- override it in your implementation if you need it.
      Overrides:
        `isSame` in class `Chromosome`
      Parameters:
        `another` - chromosome to compare
      Returns:
        true if `another` is equivalent to this chromosome

Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.