2024-08-01 18:27:41 +00:00
|
|
|
module Tables
|
|
|
|
class Swap
|
|
|
|
private attr_reader :initial_solution
|
|
|
|
def initialize(initial_solution)
|
|
|
|
@initial_solution = initial_solution
|
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
@initial_solution.tables.combination(2) do |table_a, table_b|
|
|
|
|
table_a.product(table_b).each do |(person_a, person_b)|
|
2024-08-02 18:42:24 +02:00
|
|
|
new_solution = @initial_solution.dup
|
2024-08-01 21:14:28 +02:00
|
|
|
|
2024-08-02 18:42:24 +02:00
|
|
|
new_table_a = table_a.dup
|
|
|
|
new_table_b = table_b.dup
|
2024-08-01 18:27:41 +00:00
|
|
|
|
2024-08-02 18:42:24 +02:00
|
|
|
new_solution.replace(new_table_a)
|
|
|
|
new_solution.replace(new_table_b)
|
2024-08-01 18:27:41 +00:00
|
|
|
|
2024-08-02 18:42:24 +02:00
|
|
|
new_table_a.delete(person_a)
|
|
|
|
new_table_b.delete(person_b)
|
2024-08-01 18:27:41 +00:00
|
|
|
|
2024-08-02 18:42:24 +02:00
|
|
|
new_table_a << person_b
|
|
|
|
new_table_b << person_a
|
2024-08-01 21:14:28 +02:00
|
|
|
|
2024-08-02 18:42:24 +02:00
|
|
|
new_solution.freeze
|
|
|
|
|
|
|
|
yield(new_solution)
|
2024-08-01 18:27:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|