Class: Wallace::Selector
- Inherits:
-
Object
- Object
- Wallace::Selector
- Defined in:
- lib/core/selector.rb
Overview
Selectors are used to select individuals from a set of candidates (usually, but not exclusively the sub-population) as participants in the breeding process.
Different selector classes are used to implement different types of selection rules.
A “prepare” method is provided to allow the list of candidates to be pre-processed, saving time for selection methods such as roulette selection.
Direct Known Subclasses
Wallace::Selectors::RandomSelector, Wallace::Selectors::RouletteSelector, Wallace::Selectors::TournamentSelector
Class Attribute Summary collapse
-
.name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#prepare(candidates, opts = {}) ⇒ Object
Prepares a list of candidates for use with this selector.
-
#produce(rng, candidates) ⇒ Object
Selects a single individual from the list of prepared candidates according to the rules of this selection method.
Class Attribute Details
.name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/core/selector.rb', line 11 def name @name end |
Instance Method Details
#prepare(candidates, opts = {}) ⇒ Object
Prepares a list of candidates for use with this selector. Pre-processing can be performed on this list to improve performance. The list of candidates is not stored by the selector, instead it is stored by an associated input node.
Parameters:
-
candidates, the list of candidates to select from.
-
opts, a hash of keyword options for this method. -> random, random number generator to use in pre-processing of candidates.
Returns: A prepared list of candidates for use with this selector.
26 27 28 |
# File 'lib/core/selector.rb', line 26 def prepare(candidates, opts = {}) candidates end |
#produce(rng, candidates) ⇒ Object
Selects a single individual from the list of prepared candidates according to the rules of this selection method.
Parameters:
-
rng, the RNG to use to inform the choice of candidate.
-
candidates, the candidate individuals for selection.
Returns: A selected individual from the list of candidates.
39 40 41 |
# File 'lib/core/selector.rb', line 39 def produce(rng, candidates) raise NotImplementedError, 'No produce function was implemented by this selector.' end |