public < S > List < S > select ( List < EvaluatedCandidate < S > > population , boolean naturalFitnessScores , int selectionSize , Random rng ) { List < S > selection = new ArrayList < S > ( selectionSize ) ; double ratio = selectionRatio . nextValue ( ) ; assert ratio < 1 && ratio > 0 : "Selection ratio out-of-range: " + ratio ; int eligibleCount = ( int ) Math . round ( ratio * population . size ( ) ) ; eligibleCount = eligibleCount > selectionSize ? selectionSize : eligibleCount ; do { int count = Math . min ( eligibleCount , selectionSize - selection . size ( ) ) ; for ( int i = 0 ; i < count ; i ++ ) { selection . add ( population . get ( i ) . getCandidate ( ) ) ; } } while ( selection . size ( ) < selectionSize ) ; return selection ; }
Selects the fittest candidates . If the selectionRatio results in fewer selected candidates than required then these candidates are selected multiple times to make up the shortfall .