Initial version of VNS algorithm #8

Merged
bustikiller merged 20 commits from vns into main 2024-08-01 18:27:42 +00:00
Showing only changes of commit d194b91244 - Show all commits

View File

@ -66,6 +66,31 @@ module Tables
expect(calculator.send(:cohesion_penalty)).to eq(1 + Rational(1, 2) + Rational(2, 3))
end
end
context 'when the table contains four guests' do
let(:table) do
[
create(:guest, affinity_group_list: ['family']),
create(:guest, affinity_group_list: ['friends']),
create(:guest, affinity_group_list: ['work']),
create(:guest, affinity_group_list: ['school'])
]
end
before do
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with('family', 'friends').and_return(nil)
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with('friends', 'work').and_return(1)
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with('family', 'work').and_return(2)
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with('family', 'school').and_return(3)
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with('friends', 'school').and_return(4)
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with('work', 'school').and_return(5)
end
it 'returns the sum of the penalties for each pair of guests' do
expect(calculator.send(:cohesion_penalty))
.to eq(1 + Rational(1, 2) + Rational(2, 3) + Rational(3, 4) + Rational(4, 5) + Rational(5, 6))
end
end
end
end
end