Class: Fast::ExperimentCombinations

Inherits:
Object
  • Object
show all
Defined in:
lib/fast/experiment.rb

Overview

Suggest possible combinations of occurrences to replace.

Check for #generate_combinations to understand the strategy of each round.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(round:, occurrences_count:, ok_experiments:, fail_experiments:) ⇒ ExperimentCombinations

Returns a new instance of ExperimentCombinations.



153
154
155
156
157
158
# File 'lib/fast/experiment.rb', line 153

def initialize(round:, occurrences_count:, ok_experiments:, fail_experiments:)
  @round = round
  @ok_experiments = ok_experiments
  @fail_experiments = fail_experiments
  @occurrences_count = occurrences_count
end

Instance Attribute Details

#combinationsObject (readonly)

Returns the value of attribute combinations.



151
152
153
# File 'lib/fast/experiment.rb', line 151

def combinations
  @combinations
end

Instance Method Details

#all_ok_replacements_combinedObject

After identifying all individual replacements that work, try combining all of them.



183
184
185
# File 'lib/fast/experiment.rb', line 183

def all_ok_replacements_combined
  [@ok_experiments.uniq.sort]
end

#generate_combinationsObject

Generate different combinations depending on the current round.



164
165
166
167
168
169
170
171
172
173
# File 'lib/fast/experiment.rb', line 164

def generate_combinations
  case @round
  when 1
    individual_replacements
  when 2
    all_ok_replacements_combined
  else
    ok_replacements_pair_combinations
  end
end

#individual_replacementsObject

Replace a single occurrence at each iteration and identify which individual replacements work.



177
178
179
# File 'lib/fast/experiment.rb', line 177

def individual_replacements
  (1..@occurrences_count).to_a
end

#ok_replacements_pair_combinationsObject

Divide and conquer combining all successful individual replacements.



188
189
190
191
192
193
# File 'lib/fast/experiment.rb', line 188

def ok_replacements_pair_combinations
  @ok_experiments
    .combination(2)
    .map { |e| e.flatten.uniq.sort }
    .uniq - @fail_experiments - @ok_experiments
end