diff --git a/app/services/tables/swap.rb b/app/services/tables/swap.rb index d77e2a4..f7d3d26 100644 --- a/app/services/tables/swap.rb +++ b/app/services/tables/swap.rb @@ -7,7 +7,7 @@ module Tables def each @initial_solution.tables.combination(2) do |table_a, table_b| - table_a.product(table_b).each do |(person_a, person_b)| + table_a.swap_candidates.product(table_b.swap_candidates).each do |(person_a, person_b)| new_solution = @initial_solution.dup new_table_a = table_a.dup diff --git a/app/services/tables/table.rb b/app/services/tables/table.rb index 54fd8cc..da08b75 100644 --- a/app/services/tables/table.rb +++ b/app/services/tables/table.rb @@ -5,20 +5,17 @@ module Tables def initialize(*args) super - reset @id = SecureRandom.uuid end - def reset - original_discomfort = @discomfort - @discomfort = nil - original_discomfort - end - def discomfort @discomfort ||= DiscomfortCalculator.new(self).calculate end + def swap_candidates + @swap_candidates ||= uniq { |person| person.affinity_group_list.first } + end + def dup super.tap do |new_table| new_table.discomfort = nil