Compare commits

...

2 Commits

Author SHA1 Message Date
ead48c2588 Merge pull request 'Avoid stack too deep erros due to excessive recursion' (#178) from stack-error-vns into main
Some checks failed
Check usage of free licenses / check-licenses (push) Successful in 25s
Run unit tests / unit_tests (push) Successful in 1m21s
Build Nginx-based docker image / build-static-assets (push) Has been cancelled
Reviewed-on: #178
2024-12-09 17:16:40 +00:00
dfb50ed2dc Avoid stack too deep erros due to excessive recursion
All checks were successful
Add copyright notice / copyright_notice (pull_request) Successful in 56s
Check usage of free licenses / check-licenses (pull_request) Successful in 1m32s
Run unit tests / unit_tests (pull_request) Successful in 1m52s
2024-12-09 18:14:21 +01:00

View File

@ -29,7 +29,7 @@ module VNS
@best_score = @target_function.call(@best_solution)
self.class.sequence(@perturbations).each do |perturbation|
optimize(perturbation.new(@best_solution))
optimize(perturbation)
end
@best_solution
@ -37,15 +37,22 @@ module VNS
private
def optimize(perturbation)
perturbation.each do |alternative_solution|
def optimize(perturbation_klass)
loop do
optimized = false
perturbation_klass.new(@best_solution).each do |alternative_solution|
score = @target_function.call(alternative_solution)
next if score >= @best_score
@best_solution = alternative_solution.deep_dup
@best_score = score
optimized = true
return optimize(perturbation.class.new(@best_solution))
break
end
return unless optimized
end
end
end