class MetaheuristicAlgorithms::SimulatedAnnealing

Public Class Methods

new(function_wrapper, number_of_variables: 1, objective: :maximization) click to toggle source
# File lib/metaheuristic_algorithms/simulated_annealing.rb, line 11
def initialize(function_wrapper, number_of_variables: 1, objective: :maximization)
  @function_wrapper = function_wrapper
  @number_of_variables = number_of_variables
  @objective_comparison_operator = case objective
                           when :maximization
                             :>
                           when :minimization
                             :<
                         end        
end

Public Instance Methods

Private Instance Methods

acceptance_probability(evaluation_delta, temperature, bolzmann_constant) click to toggle source
# File lib/metaheuristic_algorithms/simulated_annealing.rb, line 130
def acceptance_probability(evaluation_delta, temperature, bolzmann_constant)
  # BigMath.exp((-evaluation_delta / (bolzmann_constant * temperature)), 10)
  Math.exp(-evaluation_delta / (bolzmann_constant * temperature))
end
estimate_solution(previous_estimates, standard_diviation_for_estimation) click to toggle source
# File lib/metaheuristic_algorithms/simulated_annealing.rb, line 105
def estimate_solution(previous_estimates, standard_diviation_for_estimation)

  (0...@number_of_variables).map do |variable_index|

    # The value out-of-range in order to enter while loop
    # new_estimate = @function_wrapper.minimum_decision_variable_values[variable_index] - BigDecimal('1')
    new_estimate = @function_wrapper.minimum_decision_variable_values[variable_index].to_f - 1

    while new_estimate < @function_wrapper.minimum_decision_variable_values[variable_index].to_f || new_estimate > @function_wrapper.maximum_decision_variable_values[variable_index].to_f

      # MatLab example code uses newGuess = initialGuess + rand(1,2) * randn;
      # But in our case, the value range is different.
      # In order to support JRuby, decided not to use Distribution::Normal.rng:
      # new_estimate = BigDecimal(Distribution::Normal.rng(previous_estimates[variable_index], standard_diviation_for_estimation).call.to_s)
      # new_estimate = BigDecimal(gaussian(previous_estimates[variable_index], standard_diviation_for_estimation).to_s)
      new_estimate = gaussian(previous_estimates[variable_index], standard_diviation_for_estimation)

    end

    new_estimate

  end

end