From 093970b2afda2c3ca8496fe59ac0b1aa18b65c36 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Fri, 2 Aug 2024 18:49:18 +0200 Subject: [PATCH] Reduce the swap candidates per table to one per group --- app/services/tables/swap.rb | 2 +- app/services/tables/table.rb | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) 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