Manuel Bustillo
8c12884212
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 1m38s
Add copyright notice / copyright_notice (pull_request) Successful in 3m16s
Run unit tests / unit_tests (pull_request) Successful in 5m31s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 41m31s
33 lines
785 B
Ruby
33 lines
785 B
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|
|
|
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
|