wedding-planner/app/jobs/table_simulator_job.rb
Manuel Bustillo 3bfe889747
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 32s
Add copyright notice / copyright_notice (pull_request) Successful in 1m4s
Run unit tests / unit_tests (pull_request) Successful in 2m33s
Redo TablesArrangements#show to display arrangement ID and discomfort breakdown
2024-12-16 18:52:34 +01:00

29 lines
699 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
class TableSimulatorJob < ApplicationJob
queue_as :default
MIN_PER_TABLE = 8
MAX_PER_TABLE = 10
def perform(wedding_id)
ActsAsTenant.with_tenant(Wedding.find(wedding_id)) do
engine = VNS::Engine.new
engine.add_perturbation(Tables::Swap)
engine.add_perturbation(Tables::Shift)
initial_solution = Tables::Distribution.new(min_per_table: MIN_PER_TABLE, max_per_table: MAX_PER_TABLE)
initial_solution.random_distribution(Guest.potential.shuffle)
engine.initial_solution = initial_solution
engine.target_function(&:discomfort)
best_solution = engine.run
best_solution.save!
end
end
end