2024-11-03 08:31:58 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-11-03 09:05:51 +01:00
|
|
|
class TableSimulatorJob < ApplicationJob
|
|
|
|
queue_as :default
|
|
|
|
|
2024-12-16 18:52:34 +01:00
|
|
|
MIN_PER_TABLE = 8
|
|
|
|
MAX_PER_TABLE = 10
|
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
def perform(wedding_id)
|
|
|
|
ActsAsTenant.with_tenant(Wedding.find(wedding_id)) do
|
|
|
|
engine = VNS::Engine.new
|
2024-11-03 09:05:51 +01:00
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
engine.add_perturbation(Tables::Swap)
|
|
|
|
engine.add_perturbation(Tables::Shift)
|
2024-11-03 09:05:51 +01:00
|
|
|
|
2024-12-16 18:52:34 +01:00
|
|
|
initial_solution = Tables::Distribution.new(min_per_table: MIN_PER_TABLE, max_per_table: MAX_PER_TABLE)
|
2024-12-01 10:41:05 +01:00
|
|
|
initial_solution.random_distribution(Guest.potential.shuffle)
|
2024-11-03 09:05:51 +01:00
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
engine.initial_solution = initial_solution
|
2024-11-03 09:05:51 +01:00
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
engine.target_function(&:discomfort)
|
2024-11-03 09:05:51 +01:00
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
best_solution = engine.run
|
2024-11-03 09:05:51 +01:00
|
|
|
|
2024-12-01 10:41:05 +01:00
|
|
|
best_solution.save!
|
|
|
|
end
|
2024-11-03 09:05:51 +01:00
|
|
|
end
|
|
|
|
end
|