Class: MetaheuristicAlgorithms::FireflyAlgorithm::Firefly

Inherits:
Object
  • Object
show all
Defined in:
lib/metaheuristic_algorithms/firefly_algorithm.rb

Overview

Note: May be able to use Struct for this purpose, moving update_light_intensity method to FireflyAlgorithm class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function_wrapper, location_coordinates, light_intensity) ⇒ Firefly

Returns a new instance of Firefly.



16
17
18
19
20
# File 'lib/metaheuristic_algorithms/firefly_algorithm.rb', line 16

def initialize(function_wrapper, location_coordinates, light_intensity)
  @function_wrapper = function_wrapper
  @location_coordinates = location_coordinates
  @light_intensity = light_intensity
end

Instance Attribute Details

#light_intensityObject

Returns the value of attribute light_intensity.



14
15
16
# File 'lib/metaheuristic_algorithms/firefly_algorithm.rb', line 14

def light_intensity
  @light_intensity
end

#location_coordinatesObject

Returns the value of attribute location_coordinates.



13
14
15
# File 'lib/metaheuristic_algorithms/firefly_algorithm.rb', line 13

def location_coordinates
  @location_coordinates
end

Instance Method Details

#deep_cloneObject



26
27
28
29
30
# File 'lib/metaheuristic_algorithms/firefly_algorithm.rb', line 26

def deep_clone
  clone_object = self.clone
  clone_object.location_coordinates = self.location_coordinates.clone
  clone_object
end

#update_light_intensityObject



22
23
24
# File 'lib/metaheuristic_algorithms/firefly_algorithm.rb', line 22

def update_light_intensity
  @light_intensity = @function_wrapper.objective_function_value(@location_coordinates).to_f
end