2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-08-01 18:27:41 +00:00
|
|
|
module Tables
|
|
|
|
class DiscomfortCalculator
|
|
|
|
private attr_reader :table
|
|
|
|
def initialize(table)
|
|
|
|
@table = table
|
|
|
|
end
|
|
|
|
|
|
|
|
def calculate
|
|
|
|
cohesion_penalty
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def cohesion_penalty
|
|
|
|
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 count_a * count_b if distance.nil?
|
|
|
|
next 0 if distance.zero?
|
|
|
|
|
|
|
|
count_a * count_b * Rational(distance, distance + 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|