Compare commits

..

No commits in common. "ead48c2588c83d06b7b6f908a267c689c1519d73" and "ff0e0b69314d38cacf3ddb8941d009ebe3b79efa" have entirely different histories.

View File

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