diff --git a/app/services/tables/discomfort_calculator.rb b/app/services/tables/discomfort_calculator.rb index e1b413d..69214bb 100644 --- a/app/services/tables/discomfort_calculator.rb +++ b/app/services/tables/discomfort_calculator.rb @@ -12,13 +12,13 @@ module Tables private def cohesion_penalty - table.map { |guest| guest.affinity_group_list.first }.combination(2).sum do |a, b| + table.map { |guest| guest.affinity_group_list.first }.tally.to_a.combination(2).sum do |(a, count_a), (b, count_b)| distance = AffinityGroupsHierarchy.instance.distance(a, b) - next 1 if distance.nil? + next count_a * count_b if distance.nil? next 0 if distance.zero? - Rational(distance, distance + 1) + count_a * count_b * Rational(distance, distance + 1) end end end