Manuel Bustillo 1fcca38576
All checks were successful
Check usage of free licenses / build-static-assets (pull_request) Successful in 51s
Run unit tests / unit_tests (pull_request) Successful in 2m11s
Add copyright notice / copyright_notice (pull_request) Successful in 56s
Implement shift perturbation
2024-11-10 17:53:52 +01:00

31 lines
732 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
module Tables
class Shift
private attr_reader :initial_solution
def initialize(initial_solution)
@initial_solution = initial_solution
end
def each
@initial_solution.tables.permutation(2) do |table_a, table_b|
table_a.dup.each do |person|
original_discomfort_a = table_a.reset
original_discomfort_b = table_b.reset
table_a.delete(person)
table_b << person
yield(@initial_solution)
ensure
table_b.delete(person)
table_a << person
table_a.discomfort = original_discomfort_a
table_b.discomfort = original_discomfort_b
end
end
end
end
end