gov.sandia.cognition.learning.algorithm.genetic.selector
Class TournamentSelector<GenomeType>

java.lang.Object
  extended by gov.sandia.cognition.learning.algorithm.genetic.selector.AbstractSelector<GenomeType>
      extended by gov.sandia.cognition.learning.algorithm.genetic.selector.TournamentSelector<GenomeType>
Type Parameters:
GenomeType - Type of genome used to represent a single element in the genetic population, such as a Vector, for example
All Implemented Interfaces:
Reproducer<GenomeType>, Selector<GenomeType>, Randomized, Serializable

@CodeReviews(reviews={@CodeReview(reviewer="Kevin R. Dixon",date="2008-07-23",changesNeeded=false,comments={"Now implements Randomized.","Moved previous code review as CodeReview annotation","Looks fine."}),@CodeReview(reviewer="Justin Basilico",date="2006-10-04",changesNeeded=false,comments={"I optimized the code to make it faster and use less memory.","I also made the Random object a parameter of the class, not generated each time select is called."})})
public class TournamentSelector<GenomeType>
extends AbstractSelector<GenomeType>
implements Randomized

The TournamentSelector class implements a Selector that uses tournament selection to create a new population.

The tournament selector selects each member of the population by having a tournament of the given tournament size. The winner of that tournament (the genome with the lowest cost) is then entered into the selected population. This allows

Since:
1.0
Author:
Justin Basilico, Jonathan McClain
See Also:
Serialized Form

Constructor Summary
TournamentSelector(double percent, int tournamentSize)
          Creates a new instance of TournamentSelector.
TournamentSelector(double percent, int tournamentSize, Random random)
          Creates a new instance of TournamentSelector.
 
Method Summary
 double getPercent()
          Gets the percent of the population to select.
 Random getRandom()
          Gets the random number generator being used.
 int getTournamentSize()
          Gets the size for tournaments.
 Collection<EvaluatedGenome<GenomeType>> select(Collection<EvaluatedGenome<GenomeType>> genomes)
          Uses tournament selection to create a new population.
 void setPercent(double percent)
          Sets the percent of the population to select.
 void setRandom(Random random)
          Sets the random number generator to use.
 void setTournamentSize(int tournamentSize)
          Sets the size for tournaments.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.genetic.selector.AbstractSelector
reproduce
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TournamentSelector

public TournamentSelector(double percent,
                          int tournamentSize)
Creates a new instance of TournamentSelector.

Parameters:
percent - The percent of the population to select.
tournamentSize - The size of each tournament when selecting.

TournamentSelector

public TournamentSelector(double percent,
                          int tournamentSize,
                          Random random)
Creates a new instance of TournamentSelector.

Parameters:
percent - The percent of the population to select.
tournamentSize - The size of each tournament when selecting.
random - The random number generator to use.
Method Detail

select

public Collection<EvaluatedGenome<GenomeType>> select(Collection<EvaluatedGenome<GenomeType>> genomes)
Uses tournament selection to create a new population.

Specified by:
select in interface Selector<GenomeType>
Parameters:
genomes - The population to select from.
Returns:
The selected population.

getPercent

public double getPercent()
Gets the percent of the population to select.

Returns:
The percent.

getTournamentSize

public int getTournamentSize()
Gets the size for tournaments.

Returns:
The size.

getRandom

public Random getRandom()
Gets the random number generator being used.

Specified by:
getRandom in interface Randomized
Returns:
The random number generator being used.

setPercent

public void setPercent(double percent)
Sets the percent of the population to select.

Parameters:
percent - The new percent.

setTournamentSize

public void setTournamentSize(int tournamentSize)
Sets the size for tournaments.

Parameters:
tournamentSize - The new size.

setRandom

public void setRandom(Random random)
Sets the random number generator to use.

Specified by:
setRandom in interface Randomized
Parameters:
random - The new random number generator.