Class: Annealing::Simulator
- Inherits:
-
Object
- Object
- Annealing::Simulator
- Defined in:
- lib/annealing/simulator.rb
Overview
It runs simulated annealing
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#initialize(config_hash = {}) ⇒ Simulator
constructor
A new instance of Simulator.
- #run(initial_state, config_hash = {}) ⇒ Object
Constructor Details
#initialize(config_hash = {}) ⇒ Simulator
Returns a new instance of Simulator.
8 9 10 |
# File 'lib/annealing/simulator.rb', line 8 def initialize(config_hash = {}) @configuration = Annealing.configuration.merge(config_hash) end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/annealing/simulator.rb', line 6 def configuration @configuration end |
Instance Method Details
#run(initial_state, config_hash = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/annealing/simulator.rb', line 12 def run(initial_state, config_hash = {}) with_runtime_config(config_hash) do |runtime_config| initial_temperature = runtime_config.temperature current = Metal.new(initial_state, initial_temperature, runtime_config) steps = 0 until termination_condition_met?(current, runtime_config) steps += 1 current = reduce_temperature(current, steps, runtime_config) end current end end |