lib/vns.rb in vns-0.2.0.pre.rc.1 vs lib/vns.rb in vns-0.2.0.pre.rc.2
- old
+ new
@@ -69,11 +69,11 @@
puts 'Updated best solution'
best_solution = temporary_solution
end
progress = (counter + 1) * 1.0 / PERTURBATION_COUNT
- @inspection.call(progress, target_function(best_solution), best_solution) if @inspection
+ @inspection&.call(progress, target_function(best_solution), public_format(best_solution))
end
best_solution
end
@@ -117,18 +117,18 @@
end
def perturbate(solution)
2.times do
extracted = []
- solution.each do |_, people|
- extracted << people.delete_at(rand(people.length))
- end
+ solution.each do |_, people|
+ extracted << people.delete_at(rand(people.length))
+ end
- extracted.shuffle.each_with_index do |person, i|
- solution.values[i] << person
+ extracted.shuffle.each_with_index do |person, i|
+ solution.values[i] << person
+ end
end
- end
end
def combinations_of_two(solution)
solution.values
.combination(2)
@@ -159,7 +159,11 @@
end
def find_session(solution, person)
sessions.detect { |s| solution[s].include?(person) }
end
+
+ def public_format(solution)
+ solution.map { |k, v| [k.name, v.map(&:name)] }.to_h
+ end
end
-end
\ No newline at end of file
+end