Class: Wallace::BreedingGraph::InputNode
- Defined in:
- lib/core/breeding_graph/input_node.rb
Overview
Used to represent input nodes (i.e. sub-population selection nodes) in the breeding graph.
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#clean! ⇒ Object
Clears the contents of the buffer and candidates list for this input node.
-
#clone ⇒ Object
Creates a clone of this node and its inputs.
-
#initialize(selector) ⇒ InputNode
constructor
Constructs a new input node.
-
#prepare!(candidates, opts = {}) ⇒ Object
Prepares this input node for the next breeding cycle by supplying the contents of the sub-population and performing any necessary post-processing.
-
#take!(rng) ⇒ Object
Selects a single individual from the list of candidates using the selection method associated with this node.
Constructor Details
#initialize(selector) ⇒ InputNode
Constructs a new input node.
Parameters:
-
selector, the selection method used by this input node.
9 10 11 12 |
# File 'lib/core/breeding_graph/input_node.rb', line 9 def initialize(selector) super(selector, []) @candidates = [] end |
Instance Method Details
#clean! ⇒ Object
Clears the contents of the buffer and candidates list for this input node.
50 51 52 53 |
# File 'lib/core/breeding_graph/input_node.rb', line 50 def clean! super @candidates.clear end |
#clone ⇒ Object
Creates a clone of this node and its inputs.
45 46 47 |
# File 'lib/core/breeding_graph/input_node.rb', line 45 def clone Wallace::BreedingGraph::InputNode.new(@function) end |
#prepare!(candidates, opts = {}) ⇒ Object
Prepares this input node for the next breeding cycle by supplying the contents of the sub-population and performing any necessary post-processing.
To prevent redundant post-processing when using multiple threads, we can supply a prepared candidate list from the same input node from an other breeding graph.
Parameters:
-
candidates, a list of (possibly post-processed) candidates for selection.
-
opts, a hash of keyword options for this method. -> random, the RNG to use when preparing the candidate list. -> processed, a flag indicating if this candidate list has already been post-processed.
Returns: The prepared candidate list (so that it can be exploited by identical nodes in other graphs).
39 40 41 42 |
# File 'lib/core/breeding_graph/input_node.rb', line 39 def prepare!(candidates, opts = {}) @candidates = opts[:processed] ? candidates.clone : @function.prepare(candidates, opts) return @candidates end |
#take!(rng) ⇒ Object
Selects a single individual from the list of candidates using the selection method associated with this node.
Parameters:
-
rng, the RNG to use when selecting an individual from the list of candidates.
21 22 23 |
# File 'lib/core/breeding_graph/input_node.rb', line 21 def take!(rng) @function.produce(rng, @candidates).clone end |