Improve benchmark
Some checks failed
Run unit tests / rubocop (pull_request) Failing after 1m54s
Run unit tests / check-licenses (pull_request) Successful in 1m57s
Run unit tests / copyright_notice (pull_request) Successful in 2m40s
Run unit tests / unit_tests (pull_request) Failing after 4m9s
Run unit tests / build-static-assets (pull_request) Has been skipped
Some checks failed
Run unit tests / rubocop (pull_request) Failing after 1m54s
Run unit tests / check-licenses (pull_request) Successful in 1m57s
Run unit tests / copyright_notice (pull_request) Successful in 2m40s
Run unit tests / unit_tests (pull_request) Failing after 4m9s
Run unit tests / build-static-assets (pull_request) Has been skipped
This commit is contained in:
parent
25bd53600e
commit
c050f2027f
@ -4,26 +4,47 @@ namespace :vns do
|
||||
desc 'Benchmarks the efficiency of the VNS implementation'
|
||||
task benchmark: :environment do
|
||||
ActsAsTenant.with_tenant(Wedding.first) do
|
||||
Rails.logger.info "There are #{Guest.potential.count} potential guests"
|
||||
|
||||
iterations = 10
|
||||
|
||||
guests = Guest.potential
|
||||
|
||||
Rails.logger.info "There are #{guests.count} potential guests"
|
||||
|
||||
time_acc = 0
|
||||
solution_acc = 0
|
||||
|
||||
hierarchy = AffinityGroupsHierarchy.new
|
||||
|
||||
iterations.times do |i|
|
||||
engine = VNS::Engine.new
|
||||
|
||||
engine.add_perturbation(Tables::Swap)
|
||||
engine.add_perturbation(Tables::Shift)
|
||||
|
||||
hierarchy = AffinityGroupsHierarchy.new
|
||||
initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10, hierarchy:)
|
||||
|
||||
random = Random.new(561_163)
|
||||
initial_solution.random_distribution(Guest.potential.shuffle(random:), random:)
|
||||
random = Random.new(i)
|
||||
initial_solution.random_distribution(guests.shuffle(random:), random:)
|
||||
|
||||
engine.initial_solution = initial_solution
|
||||
|
||||
engine.target_function(&:discomfort)
|
||||
|
||||
solution = Rails.benchmark('VNS Benchmarking') { engine.run }
|
||||
start_time = Time.now
|
||||
|
||||
Rails.logger.info "Best solution found with discomfort: #{solution.discomfort}"
|
||||
solution = engine.run
|
||||
|
||||
elapsed = Time.now - start_time
|
||||
|
||||
time_acc += elapsed
|
||||
solution_acc += solution.discomfort
|
||||
|
||||
Rails.logger.info "[#{elapsed}] Best solution found with discomfort: #{solution.discomfort}"
|
||||
end
|
||||
|
||||
Rails.logger.info "Average time: #{time_acc / iterations} seconds"
|
||||
Rails.logger.info "Average discomfort: #{solution_acc / iterations}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user