Persist and expose via API the progress of the tables arrangement simulations #316
@ -13,6 +13,10 @@ module VNS
|
||||
end
|
||||
end
|
||||
|
||||
def initialize
|
||||
@perturbations = Set.new
|
||||
end
|
||||
|
||||
def target_function(&function)
|
||||
@target_function = function
|
||||
end
|
||||
@ -23,7 +27,6 @@ module VNS
|
||||
end
|
||||
|
||||
def add_perturbation(klass)
|
||||
@perturbations ||= Set.new
|
||||
@perturbations << klass
|
||||
end
|
||||
|
||||
@ -38,11 +41,7 @@ module VNS
|
||||
attr_writer :initial_solution
|
||||
|
||||
def run
|
||||
raise 'No target function defined' unless @target_function
|
||||
raise 'No optimizations defined' unless @optimizations
|
||||
raise 'No initial solution defined' unless @initial_solution
|
||||
|
||||
@perturbations ||= Set.new
|
||||
check_preconditions!
|
||||
|
||||
@current_solution = @initial_solution
|
||||
@best_score = @target_function.call(@current_solution)
|
||||
@ -77,6 +76,12 @@ module VNS
|
||||
|
||||
private
|
||||
|
||||
def check_preconditions!
|
||||
raise 'No target function defined' unless @target_function
|
||||
raise 'No optimizations defined' unless @optimizations
|
||||
raise 'No initial solution defined' unless @initial_solution
|
||||
end
|
||||
|
||||
def run_all_optimizations
|
||||
self.class.sequence(@optimizations).each do |optimization|
|
||||
optimize(optimization)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user