Some checks failed
Run unit tests / rubocop (pull_request) Failing after 34s
Run unit tests / copyright_notice (pull_request) Successful in 56s
Run unit tests / check-licenses (pull_request) Successful in 1m12s
Run unit tests / unit_tests (pull_request) Failing after 1m27s
Run unit tests / build-static-assets (pull_request) Has been skipped
51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
# 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
|