Class: SolutionSpaceCheckStrategy
- Inherits:
-
CheckStrategy
- Object
- CheckStrategy
- SolutionSpaceCheckStrategy
- Defined in:
- lib/gimuby/genetic/solution/check_strategy/solution_space_check_strategy.rb
Overview
Permutation goes represented as permutation from [0, … l] indexes
Instance Method Summary collapse
- #check(solution_representation) ⇒ Object
-
#initialize ⇒ SolutionSpaceCheckStrategy
constructor
A new instance of SolutionSpaceCheckStrategy.
- #set_max(max, index = nil) ⇒ Object
- #set_min(min, index = nil) ⇒ Object
Constructor Details
#initialize ⇒ SolutionSpaceCheckStrategy
Returns a new instance of SolutionSpaceCheckStrategy.
6 7 8 9 10 11 |
# File 'lib/gimuby/genetic/solution/check_strategy/solution_space_check_strategy.rb', line 6 def initialize @default_min = nil @default_max = nil @mins = {} @maxs = {} end |
Instance Method Details
#check(solution_representation) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gimuby/genetic/solution/check_strategy/solution_space_check_strategy.rb', line 13 def check(solution_representation) solution_representation.each_index do |index| value = solution_representation[index] if value.class == Array value = check(value) else min = get_min(index) unless min.nil? if value < min value = min end end max = get_max(index) unless max.nil? if value > max value = max end end end solution_representation[index] = value end solution_representation end |
#set_max(max, index = nil) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/gimuby/genetic/solution/check_strategy/solution_space_check_strategy.rb', line 49 def set_max(max, index = nil) if index.nil? @default_max = max else @maxs[index] = max end end |
#set_min(min, index = nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/gimuby/genetic/solution/check_strategy/solution_space_check_strategy.rb', line 41 def set_min(min, index = nil) if index.nil? @default_min = min else @mins[index] = min end end |