# Copyright (C) 2024-2025 LibreWeddingPlanner contributors # frozen_string_literal: true 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| new_solution = Distribution.new( min_per_table: @initial_solution.min_per_table, max_per_table: @initial_solution.max_per_table, hierarchy: @initial_solution.hierarchy ) new_solution.tables = @initial_solution.tables.dup new_solution.tables.delete(table_a) new_solution.tables.delete(table_b) modified_table_a = table_a.dup.tap(&:reset) modified_table_b = table_b.dup.tap(&:reset) new_solution.tables << modified_table_a new_solution.tables << modified_table_b # original_discomfort_a = table_a.reset # original_discomfort_b = table_b.reset modified_table_a.delete(person) modified_table_b << person yield(new_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