class MHL::HyperMutationPlusRechenbergController

Constants

DEFAULT_HM_GENERATIONS

Public Class Methods

new(params={}) click to toggle source
# File lib/mhl/hm_plus_rechenberg_controller.rb, line 7
def initialize(params={})
  @opts = { keep_for: DEFAULT_HM_GENERATIONS }.merge!(params)
  @rc = RechenbergController.new
  @gen = @gens_from_last_reset = 1
end

Public Instance Methods

call(solver, best) click to toggle source
# File lib/mhl/hm_plus_rechenberg_controller.rb, line 13
def call(solver, best)
  if @pending_reset
    # set mutation_probability to HM value
    solver.mutation_probability = @pending_reset

    # reinitialize controller
    @rc = RechenbergController.new

    # reinitialize counter of generations from last reset
    @gens_from_last_reset = 0

    # undefine pending_reset
    # NOTE: not sure if we should we go as far as calling
    # remove_instance_variable(:@pending_reset) here
    @pending_reset = nil
  end

  # do nothing for the first @opts[:keep_for] generations
  if @gens_from_last_reset > @opts[:keep_for]
    @rc.call(solver, best)
  end

  # update counters
  @gen += 1
  @gens_from_last_reset += 1
end
reset_mutation_probability(value) click to toggle source
# File lib/mhl/hm_plus_rechenberg_controller.rb, line 40
def reset_mutation_probability(value)
  @pending_reset = value
end