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