class FunctionBasedSolution

Public Class Methods

new(x_values = nil) click to toggle source
Calls superclass method Solution::new
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 11
def initialize(x_values = nil)
  super(x_values)

  @check_strategy = SolutionSpaceCheckStrategy.new
  @check_strategy.set_min(get_x_value_min)
  @check_strategy.set_max(get_x_value_max)

  @new_generation_strategy = CombinedNewGenerationStrategy.new
  @new_generation_strategy.add_strategy(ParentRangeNewGenerationStrategy.new)
  @new_generation_strategy.add_strategy(CrossOverNewGenerationStrategy.new)
  @new_generation_strategy.add_strategy(AverageNewGenerationStrategy.new)

  @mutation_strategy = SolutionSpaceMutationStrategy.new
  @mutation_strategy.set_min(get_x_value_min)
  @mutation_strategy.set_max(get_x_value_max)
end

Public Instance Methods

evaluate() click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 28
def evaluate
  raise NotImplementedError
end
get_solution_representation() click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 32
def get_solution_representation
  @x_values.clone
end
set_solution_representation(x_values) click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 36
def set_solution_representation(x_values)
  @x_values = x_values.clone
end

Protected Instance Methods

get_dimension_number() click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 60
def get_dimension_number
  raise NotImplementedError
end
get_x_value_max() click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 56
def get_x_value_max
  raise NotImplementedError
end
get_x_value_min() click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 52
def get_x_value_min
  raise NotImplementedError
end
init_representation() click to toggle source
# File lib/gimuby/genetic/solution/function_based_solution.rb, line 42
def init_representation
  @x_values = []
  dimension = get_dimension_number
  dimension.times do |_|
    range = get_x_value_max - get_x_value_min
    x_value = (rand() * range) + get_x_value_min
    @x_values.push(x_value)
  end
end