org.apache.commons.math3.genetics

## Class TournamentSelection

- java.lang.Object
- - org.apache.commons.math3.genetics.TournamentSelection

- All Implemented Interfaces:
    SelectionPolicy

      public class TournamentSelection
      extends java.lang.Object
      implements SelectionPolicy

  Tournament selection scheme. Each of the two selected chromosomes is selected based on n-ary tournament -- this is done by drawing `arity` random chromosomes without replacement from the population, and then selecting the fittest chromosome among them.
  Since:
    2.0
  Version:
    $Id: TournamentSelection.java 1416643 2012-12-03 19:37:14Z tn $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private int` | `arity` number of chromosomes included in the tournament selections

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TournamentSelection(int arity)` Creates a new TournamentSelection instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getArity()` Gets the arity (number of chromosomes drawn to the tournament).
    `ChromosomePair` | `select(Population population)` Select two chromosomes from the population.
    `void` | `setArity(int arity)` Sets the arity (number of chromosomes drawn to the tournament).
    `private Chromosome` | `tournament(ListPopulation population)` Helper for `select(Population)`.

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

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

- - ### Field Detail

    - #### arity

          private int arity

      number of chromosomes included in the tournament selections

  - ### Constructor Detail

    - #### TournamentSelection

          public TournamentSelection(int arity)

      Creates a new TournamentSelection instance.
      Parameters:
        `arity` - how many chromosomes will be drawn to the tournament

  - ### Method Detail

    - #### select

          public ChromosomePair select(Population population)
                                throws MathIllegalArgumentException

      Select two chromosomes from the population. Each of the two selected chromosomes is selected based on n-ary tournament -- this is done by drawing `arity` random chromosomes without replacement from the population, and then selecting the fittest chromosome among them.
      Specified by:
        `select` in interface `SelectionPolicy`
      Parameters:
        `population` - the population from which the chromosomes are chosen.
      Returns:
        the selected chromosomes.
      Throws:
        `MathIllegalArgumentException` - if the tournament arity is bigger than the population size

    - #### tournament

          private Chromosome tournament(ListPopulation population)
                                 throws MathIllegalArgumentException

      Helper for `select(Population)`. Draw `arity` random chromosomes without replacement from the population, and then select the fittest chromosome among them.
      Parameters:
        `population` - the population from which the chromosomes are choosen.
      Returns:
        the selected chromosome.
      Throws:
        `MathIllegalArgumentException` - if the tournament arity is bigger than the population size

    - #### getArity

          public int getArity()

      Gets the arity (number of chromosomes drawn to the tournament).
      Returns:
        arity of the tournament

    - #### setArity

          public void setArity(int arity)

      Sets the arity (number of chromosomes drawn to the tournament).
      Parameters:
        `arity` - arity of the tournament

Copyright (c) 2003-2013 Apache Software Foundation