Reduce the swap candidates per table to one per group

This commit is contained in:
Manuel Bustillo 2024-08-02 18:49:18 +02:00
parent 5f50c1fe11
commit 093970b2af
2 changed files with 5 additions and 8 deletions

View File

@ -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

View File

@ -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