Class: PetriDish::Metadata
- Inherits:
-
Object
- Object
- PetriDish::Metadata
- Defined in:
- lib/petri_dish/metadata.rb
Instance Attribute Summary collapse
-
#generation_count ⇒ Object
readonly
Returns the value of attribute generation_count.
-
#highest_fitness ⇒ Object
readonly
Returns the value of attribute highest_fitness.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_fitness_increase ⇒ Object
readonly
Returns the value of attribute last_fitness_increase.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #increment_generation ⇒ Object
-
#initialize ⇒ Metadata
constructor
A new instance of Metadata.
- #set_highest_fitness(fitness) ⇒ Object
- #start ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Metadata
Returns a new instance of Metadata.
5 6 7 8 9 10 11 |
# File 'lib/petri_dish/metadata.rb', line 5 def initialize @id = SecureRandom.uuid @generation_count = 0 @highest_fitness = 0 @last_fitness_increase = 0 @start_time = nil end |
Instance Attribute Details
#generation_count ⇒ Object (readonly)
Returns the value of attribute generation_count.
3 4 5 |
# File 'lib/petri_dish/metadata.rb', line 3 def generation_count @generation_count end |
#highest_fitness ⇒ Object (readonly)
Returns the value of attribute highest_fitness.
3 4 5 |
# File 'lib/petri_dish/metadata.rb', line 3 def highest_fitness @highest_fitness end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/petri_dish/metadata.rb', line 3 def id @id end |
#last_fitness_increase ⇒ Object (readonly)
Returns the value of attribute last_fitness_increase.
3 4 5 |
# File 'lib/petri_dish/metadata.rb', line 3 def last_fitness_increase @last_fitness_increase end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/petri_dish/metadata.rb', line 3 def start_time @start_time end |
Instance Method Details
#increment_generation ⇒ Object
17 18 19 |
# File 'lib/petri_dish/metadata.rb', line 17 def increment_generation @generation_count += 1 end |
#set_highest_fitness(fitness) ⇒ Object
21 22 23 24 |
# File 'lib/petri_dish/metadata.rb', line 21 def set_highest_fitness(fitness) @highest_fitness = fitness @last_fitness_increase = generation_count end |
#start ⇒ Object
13 14 15 |
# File 'lib/petri_dish/metadata.rb', line 13 def start @start_time = Time.now end |
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/petri_dish/metadata.rb', line 26 def to_h { id: id, generation_count: generation_count, highest_fitness: highest_fitness, elapsed_time: (Time.now - start_time).round(2), last_fitness_increase: last_fitness_increase } end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/petri_dish/metadata.rb', line 36 def to_json to_h.to_json end |