Refactor class to reduce complexity of #run method
Some checks failed
Run unit tests / rubocop (pull_request) Failing after 2m17s
Run unit tests / check-licenses (pull_request) Successful in 3m51s
Run unit tests / copyright_notice (pull_request) Successful in 4m4s
Run unit tests / unit_tests (pull_request) Successful in 10m37s
Run unit tests / build-static-assets (pull_request) Failing after 56s
Some checks failed
Run unit tests / rubocop (pull_request) Failing after 2m17s
Run unit tests / check-licenses (pull_request) Successful in 3m51s
Run unit tests / copyright_notice (pull_request) Successful in 4m4s
Run unit tests / unit_tests (pull_request) Successful in 10m37s
Run unit tests / build-static-assets (pull_request) Failing after 56s
This commit is contained in:
parent
78ab27a697
commit
7d8ecfd0e3
@ -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