GenomeType
- Type of genome used to represent a single element in the
genetic population, such as a Vector, for example@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
Constructor and Description |
---|
TournamentSelector(double percent,
int tournamentSize)
Creates a new instance of TournamentSelector.
|
TournamentSelector(double percent,
int tournamentSize,
java.util.Random random)
Creates a new instance of TournamentSelector.
|
Modifier and Type | Method and Description |
---|---|
double |
getPercent()
Gets the percent of the population to select.
|
java.util.Random |
getRandom()
Gets the random number generator being used.
|
int |
getTournamentSize()
Gets the size for tournaments.
|
java.util.Collection<EvaluatedGenome<GenomeType>> |
select(java.util.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(java.util.Random random)
Sets the random number generator to use.
|
void |
setTournamentSize(int tournamentSize)
Sets the size for tournaments.
|
reproduce
public TournamentSelector(double percent, int tournamentSize)
percent
- The percent of the population to select.tournamentSize
- The size of each tournament when selecting.public TournamentSelector(double percent, int tournamentSize, java.util.Random random)
percent
- The percent of the population to select.tournamentSize
- The size of each tournament when selecting.random
- The random number generator to use.public java.util.Collection<EvaluatedGenome<GenomeType>> select(java.util.Collection<EvaluatedGenome<GenomeType>> genomes)
select
in interface Selector<GenomeType>
genomes
- The population to select from.public double getPercent()
public int getTournamentSize()
public java.util.Random getRandom()
getRandom
in interface Randomized
public void setPercent(double percent)
percent
- The new percent.public void setTournamentSize(int tournamentSize)
tournamentSize
- The new size.public void setRandom(java.util.Random random)
setRandom
in interface Randomized
random
- The new random number generator.