Compare commits

..

No commits in common. "5dce77c29ddf37a5a1e7f9e237aec37106688b46" and "1953ba9d7f0063492172c8eda05180a906fdcc94" have entirely different histories.

2 changed files with 5 additions and 36 deletions

View File

@ -14,18 +14,17 @@ module Tables
attr_accessor :tables, :min_per_table, :max_per_table, :hierarchy attr_accessor :tables, :min_per_table, :max_per_table, :hierarchy
def initialize(min_per_table:, max_per_table:, hierarchy: AffinityGroupsHierarchy.new) def initialize(min_per_table:, max_per_table:)
@min_per_table = min_per_table @min_per_table = min_per_table
@max_per_table = max_per_table @max_per_table = max_per_table
@hierarchy = hierarchy @hierarchy = AffinityGroupsHierarchy.new
@tables = [] @tables = []
end end
def random_distribution(people, random: Random.new) def random_distribution(people)
min_tables = (people.count * 1.0 / @max_per_table).ceil min_tables = (people.count * 1.0 / @max_per_table).ceil
max_tables = (people.count * 1.0 / @min_per_table).ceil max_tables = (people.count * 1.0 / @min_per_table).ceil
table_size = random.rand(min_tables..max_tables) @tables = people.in_groups(rand(min_tables..max_tables), false)
@tables = people.in_groups(table_size, false)
.map { |group| Table.new(group) } .map { |group| Table.new(group) }
.each { |table| table.min_per_table = @min_per_table } .each { |table| table.min_per_table = @min_per_table }
.each { |table| table.max_per_table = @max_per_table } .each { |table| table.max_per_table = @max_per_table }
@ -42,8 +41,7 @@ module Tables
end end
def deep_dup def deep_dup
self.class.new(min_per_table: @min_per_table, max_per_table: @max_per_table, self.class.new(min_per_table: @min_per_table, max_per_table: @max_per_table).tap do |new_distribution|
hierarchy: @hierarchy).tap do |new_distribution|
new_distribution.tables = @tables.map(&:dup) new_distribution.tables = @tables.map(&:dup)
end end
end end

View File

@ -1,29 +0,0 @@
# frozen_string_literal: true
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"
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:)
engine.initial_solution = initial_solution
engine.target_function(&:discomfort)
solution = Rails.benchmark('VNS Benchmarking') { engine.run }
Rails.logger.info "Best solution found with discomfort: #{solution.discomfort}"
end
end
end