Class: Annealing::Metal
- Inherits:
-
Object
- Object
- Annealing::Metal
- Defined in:
- lib/annealing/metal.rb
Overview
It manages the total energy of a given collection
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#temperature ⇒ Object
readonly
Returns the value of attribute temperature.
Instance Method Summary collapse
-
#cool!(new_temperature) ⇒ Object
This method is not idempotent! It relies on random probability to select the next state.
- #energy ⇒ Object
-
#initialize(current_state, current_temperature, configuration = nil) ⇒ Metal
constructor
A new instance of Metal.
Constructor Details
#initialize(current_state, current_temperature, configuration = nil) ⇒ Metal
Returns a new instance of Metal.
8 9 10 11 12 |
# File 'lib/annealing/metal.rb', line 8 def initialize(current_state, current_temperature, configuration = nil) @configuration = configuration || Annealing.configuration.merge({}) @state = current_state @temperature = current_temperature end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/annealing/metal.rb', line 6 def configuration @configuration end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/annealing/metal.rb', line 6 def state @state end |
#temperature ⇒ Object (readonly)
Returns the value of attribute temperature.
6 7 8 |
# File 'lib/annealing/metal.rb', line 6 def temperature @temperature end |
Instance Method Details
#cool!(new_temperature) ⇒ Object
This method is not idempotent! It relies on random probability to select the next state
20 21 22 23 24 25 26 27 28 |
# File 'lib/annealing/metal.rb', line 20 def cool!(new_temperature) = cool(new_temperature) if prefer?() else @temperature = new_temperature self end end |
#energy ⇒ Object
14 15 16 |
# File 'lib/annealing/metal.rb', line 14 def energy @energy ||= configuration.energy_calculator.call(state) end |