Class: PetriDish::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/petri_dish/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetadata

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_countObject (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_fitnessObject (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

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/petri_dish/metadata.rb', line 3

def id
  @id
end

#last_fitness_increaseObject (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_timeObject (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_generationObject



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

#startObject



13
14
15
# File 'lib/petri_dish/metadata.rb', line 13

def start
  @start_time = Time.now
end

#to_hObject



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_jsonObject



36
37
38
# File 'lib/petri_dish/metadata.rb', line 36

def to_json
  to_h.to_json
end