wedding-planner/app/services/tables/discomfort_calculator.rb
Manuel Bustillo 8c4e6a0109
All checks were successful
Run unit tests / unit_tests (push) Successful in 3m36s
Initial version of VNS algorithm (#8)
Reviewed-on: #8
Co-authored-by: Manuel Bustillo <bustikiller@bustikiller.com>
Co-committed-by: Manuel Bustillo <bustikiller@bustikiller.com>
2024-08-01 18:27:41 +00:00

26 lines
579 B
Ruby

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