Refactor implementation to make it more efficient
This commit is contained in:
parent
41589af738
commit
3971fab196
@ -12,13 +12,13 @@ module Tables
|
|||||||
private
|
private
|
||||||
|
|
||||||
def cohesion_penalty
|
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)
|
distance = AffinityGroupsHierarchy.instance.distance(a, b)
|
||||||
|
|
||||||
next 1 if distance.nil?
|
next count_a * count_b if distance.nil?
|
||||||
next 0 if distance.zero?
|
next 0 if distance.zero?
|
||||||
|
|
||||||
Rational(distance, distance + 1)
|
count_a * count_b * Rational(distance, distance + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user