Class: Ai4r::GeneticAlgorithm::ChromosomeBase
- Inherits:
-
Object
- Object
- Ai4r::GeneticAlgorithm::ChromosomeBase
- Defined in:
- lib/ai4r/genetic_algorithm/chromosome_base.rb
Overview
Base interface for chromosomes used by GeneticSearch. Implementations must define class methods ‘seed`, `mutate`, `reproduce` and the instance method `fitness`.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#normalized_fitness ⇒ Object
Returns the value of attribute normalized_fitness.
Class Method Summary collapse
- .mutate(_chromosome, _mutation_rate = 0.3) ⇒ Object
- .reproduce(_a, _b, _crossover_rate = 0.4) ⇒ Object
- .seed ⇒ Object
Instance Method Summary collapse
- #fitness ⇒ Object
- #initialize(data = nil) ⇒ Object constructor
Constructor Details
#initialize(data = nil) ⇒ Object
13 14 15 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 13 def initialize(data = nil) @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 9 def data @data end |
#normalized_fitness ⇒ Object
Returns the value of attribute normalized_fitness.
9 10 11 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 9 def normalized_fitness @normalized_fitness end |
Class Method Details
.mutate(_chromosome, _mutation_rate = 0.3) ⇒ Object
38 39 40 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 38 def self.mutate(_chromosome, _mutation_rate = 0.3) raise NotImplementedError, 'Implement .mutate in subclass' end |
.reproduce(_a, _b, _crossover_rate = 0.4) ⇒ Object
31 32 33 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 31 def self.reproduce(_a, _b, _crossover_rate = 0.4) raise NotImplementedError, 'Implement .reproduce in subclass' end |
.seed ⇒ Object
23 24 25 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 23 def self.seed raise NotImplementedError, 'Implement .seed in subclass' end |
Instance Method Details
#fitness ⇒ Object
18 19 20 |
# File 'lib/ai4r/genetic_algorithm/chromosome_base.rb', line 18 def fitness raise NotImplementedError, 'Subclasses must implement #fitness' end |