Class: Evolvable::SearchSpace
- Inherits:
-
Object
- Object
- Evolvable::SearchSpace
- Defined in:
- lib/evolvable/search_space.rb
Overview
The search space encapsulates the range of possible genes for a particular evolvable. You can think of it as the boundaries of genetic variation. It is configured via the .search_space method that you define on your evolvable class. It's used by populations to initialize new evolvables.
Evolvable provides flexibility in how you define your search space.
The below example implementations for .search_space
produce the
exact same search space for the
Hello World
demo program. The different styles arguably vary in suitability for
different contexts, perhaps depending on how programs are loaded and
the number of different gene types.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#evolvable_class ⇒ Object
Returns the value of attribute evolvable_class.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config: {}, evolvable_class: nil) ⇒ SearchSpace
constructor
A new instance of SearchSpace.
- #merge_search_space(val) ⇒ Object
- #merge_search_space!(val) ⇒ Object
- #new_genome ⇒ Object
Constructor Details
#initialize(config: {}, evolvable_class: nil) ⇒ SearchSpace
Returns a new instance of SearchSpace.
53 54 55 56 |
# File 'lib/evolvable/search_space.rb', line 53 def initialize(config: {}, evolvable_class: nil) @evolvable_class = evolvable_class @config = normalize_config(config) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
58 59 60 |
# File 'lib/evolvable/search_space.rb', line 58 def config @config end |
#evolvable_class ⇒ Object
Returns the value of attribute evolvable_class.
58 59 60 |
# File 'lib/evolvable/search_space.rb', line 58 def evolvable_class @evolvable_class end |
Class Method Details
.build(config, evolvable_class = nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/evolvable/search_space.rb', line 43 def build(config, evolvable_class = nil) if config.is_a?(SearchSpace) config.evolvable_class = evolvable_class if evolvable_class config else new(config: config, evolvable_class: evolvable_class) end end |
Instance Method Details
#merge_search_space(val) ⇒ Object
64 65 66 67 |
# File 'lib/evolvable/search_space.rb', line 64 def merge_search_space(val) val = val.config if val.is_a?(self.class) @config.merge normalize_config(val) end |
#merge_search_space!(val) ⇒ Object
69 70 71 72 |
# File 'lib/evolvable/search_space.rb', line 69 def merge_search_space!(val) val = val.config if val.is_a?(self.class) @config.merge! normalize_config(val) end |