31 lines
		
	
	
		
			752 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			752 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # Copyright (C) 2024-2025 LibreWeddingPlanner contributors
 | |
| 
 | |
| # frozen_string_literal: true
 | |
| 
 | |
| 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_optimization(Tables::Swap)
 | |
|       engine.add_optimization(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
 |