class Fast::ExperimentCombinations
Suggest possible combinations of occurrences to replace.
Check for {#generate_combinations} to understand the strategy of each round.
Attributes
combinations[R]
Public Class Methods
new(round:, occurrences_count:, ok_experiments:, fail_experiments:)
click to toggle source
# File lib/fast/experiment.rb, line 148 def initialize(round:, occurrences_count:, ok_experiments:, fail_experiments:) @round = round @ok_experiments = ok_experiments @fail_experiments = fail_experiments @occurrences_count = occurrences_count end
Public Instance Methods
all_ok_replacements_combined()
click to toggle source
After identifying all individual replacements that work, try combining all of them.
# File lib/fast/experiment.rb, line 178 def all_ok_replacements_combined [@ok_experiments.uniq.sort] end
generate_combinations()
click to toggle source
Generate different combinations depending on the current round.
-
Round 1: Use {#individual_replacements}
-
Round 2: Tries {#all_ok_replacements_combined}
-
Round 3+: Follow {#ok_replacements_pair_combinations}
# File lib/fast/experiment.rb, line 159 def generate_combinations case @round when 1 individual_replacements when 2 all_ok_replacements_combined else ok_replacements_pair_combinations end end
individual_replacements()
click to toggle source
Replace a single occurrence at each iteration and identify which individual replacements work.
# File lib/fast/experiment.rb, line 172 def individual_replacements (1..@occurrences_count).to_a end
ok_replacements_pair_combinations()
click to toggle source
Divide and conquer combining all successful individual replacements.
# File lib/fast/experiment.rb, line 183 def ok_replacements_pair_combinations @ok_experiments .combination(2) .map { |e| e.flatten.uniq.sort } .uniq - @fail_experiments - @ok_experiments end