From df563723ac16563a2f63d07b586fa1d4c10cbb44 Mon Sep 17 00:00:00 2001 From: halilsen Date: Mon, 12 Oct 2020 11:47:36 +0200 Subject: [PATCH 1/6] FIx: median function sort side effect --- lib/helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helper.rb b/lib/helper.rb index e3f9c673d..4178e0b21 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -141,9 +141,9 @@ def mean def median(already_sorted = false) return nil if empty? - sort! unless already_sorted + ret = already_sorted ? self : sort m_pos = size / 2 # no to_f! - size.odd? ? self[m_pos] : self[m_pos - 1..m_pos].mean + size.odd? ? ret[m_pos] : ret[m_pos - 1..m_pos].mean end # The mode is the single most popular item in the array. From 714ab0742d0991e8dcfdaf6d54b249af7c993dcf Mon Sep 17 00:00:00 2001 From: halilsen Date: Wed, 28 Oct 2020 18:14:37 +0100 Subject: [PATCH 2/6] Fix: invalid initial route in test_initial_routes --- test/wrappers/ortools_test.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/wrappers/ortools_test.rb b/test/wrappers/ortools_test.rb index 54ae48b45..986b2f9a9 100644 --- a/test/wrappers/ortools_test.rb +++ b/test/wrappers/ortools_test.rb @@ -4383,10 +4383,16 @@ def test_initial_routes point_id: 'point_3' } }], - routes: [{ - vehicle_id: 'vehicle_0', - mission_ids: ['service_1', 'service_3', 'service_2'] - }], + routes: [ + { + vehicle_id: 'vehicle_0', + mission_ids: ['service_2', 'service_3'] + }, + { + vehicle_id: 'vehicle_1', + mission_ids: ['service_1'] + } + ], configuration: { resolution: { duration: 10 From 413db6095c46526e2184cf89678f8efbe791f6fe Mon Sep 17 00:00:00 2001 From: halilsen Date: Sun, 1 Nov 2020 15:43:41 +0100 Subject: [PATCH 3/6] Test: fix vrp config usage --- test/real_cases_dichotomious_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/real_cases_dichotomious_test.rb b/test/real_cases_dichotomious_test.rb index b227e9e61..067efdfbc 100644 --- a/test/real_cases_dichotomious_test.rb +++ b/test/real_cases_dichotomious_test.rb @@ -28,8 +28,8 @@ def test_dichotomious_first_instance assert result # TODO: remove the logs after dicho overhead problem is fixed - log "duration_min = #{vrp[:configuration][:resolution][:minimum_duration] / 1000.to_f}", level: :debug - log "duration_max = #{vrp[:configuration][:resolution][:duration] / 1000.to_f}", level: :debug + log "duration_min = #{vrp.resolution_minimum_duration / 1000.to_f}", level: :debug + log "duration_max = #{vrp.resolution_duration / 1000.to_f}", level: :debug log "duration_optimization = #{result[:elapsed] / 1000.to_f}", level: :debug log "duration_elapsed = #{t2 - t1}", level: :debug @@ -37,8 +37,8 @@ def test_dichotomious_first_instance assert result[:unassigned].size < 50, "Too many unassigned services #{result[:unassigned].size}" # Check time - duration_min = vrp[:configuration][:resolution][:minimum_duration] / 1000.to_f - duration_max = vrp[:configuration][:resolution][:duration] / 1000.to_f + duration_min = vrp.resolution_minimum_duration / 1000.to_f + duration_max = vrp.resolution_duration / 1000.to_f duration_optimization = result[:elapsed] / 1000.to_f duration_elapsed = t2 - t1 @@ -61,8 +61,8 @@ def test_dichotomious_second_instance assert result # TODO: remove the logs after dicho overhead problem is fixed - log "duration_min = #{vrp[:configuration][:resolution][:minimum_duration] / 1000.to_f}", level: :debug - log "duration_max = #{vrp[:configuration][:resolution][:duration] / 1000.to_f}", level: :debug + log "duration_min = #{vrp.resolution_minimum_duration / 1000.to_f}", level: :debug + log "duration_max = #{vrp.resolution_duration / 1000.to_f}", level: :debug log "duration_optimization = #{result[:elapsed] / 1000.to_f}", level: :debug log "duration_elapsed = #{t2 - t1}", level: :debug @@ -73,8 +73,8 @@ def test_dichotomious_second_instance assert result[:routes].size < 48, "Too many routes: #{result[:routes].size}" # Check time - duration_min = vrp[:configuration][:resolution][:minimum_duration] / 1000.to_f - duration_max = vrp[:configuration][:resolution][:duration] / 1000.to_f + duration_min = vrp.resolution_minimum_duration / 1000.to_f + duration_max = vrp.resolution_duration / 1000.to_f duration_optimization = result[:elapsed] / 1000.to_f duration_elapsed = t2 - t1 From 203b1528ea63c610ec425366d95c3251588a08d7 Mon Sep 17 00:00:00 2001 From: halilsen Date: Tue, 24 Nov 2020 11:08:54 +0100 Subject: [PATCH 4/6] Fix: protobuf needs binarymode --- wrappers/ortools.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/ortools.rb b/wrappers/ortools.rb index 4e8126753..cebd95c09 100644 --- a/wrappers/ortools.rb +++ b/wrappers/ortools.rb @@ -684,11 +684,11 @@ def run_ortools(problem, vrp, services, points, matrix_indices, thread_proc = ni return [0, 0, @previous_result = parse_output(vrp, services, points, matrix_indices, 0, 0, nil)] end - input = Tempfile.new('optimize-or-tools-input', @tmp_dir) + input = Tempfile.new('optimize-or-tools-input', @tmp_dir, binmode: true) input.write(OrtoolsVrp::Problem.encode(problem)) input.close - output = Tempfile.new('optimize-or-tools-output', @tmp_dir) + output = Tempfile.new('optimize-or-tools-output', @tmp_dir, binmode: true) correspondant = { 'path_cheapest_arc' => 0, 'global_cheapest_arc' => 1, 'local_cheapest_insertion' => 2, 'savings' => 3, 'parallel_cheapest_insertion' => 4, 'first_unbound' => 5, 'christofides' => 6 } From 6929b719352013f50ea8d30fba4180df31b6088a Mon Sep 17 00:00:00 2001 From: halilsen Date: Tue, 24 Nov 2020 15:42:46 +0100 Subject: [PATCH 5/6] Fix: rewind output incase error in last iteration --- wrappers/ortools.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/wrappers/ortools.rb b/wrappers/ortools.rb index cebd95c09..9ded2913d 100644 --- a/wrappers/ortools.rb +++ b/wrappers/ortools.rb @@ -480,6 +480,7 @@ def parse_output(vrp, _services, points, _matrix_indices, _cost, _iterations, ou return empty_result('ortools', vrp) end + output.rewind content = OrtoolsResult::Result.decode(output.read) output.rewind From a37766c4665fbbeda8f9ad6be81c142891f3699e Mon Sep 17 00:00:00 2001 From: halilsen Date: Tue, 24 Nov 2020 16:19:02 +0100 Subject: [PATCH 6/6] Fix: parse last solution only once --- wrappers/ortools.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/ortools.rb b/wrappers/ortools.rb index 9ded2913d..bc10def8b 100644 --- a/wrappers/ortools.rb +++ b/wrappers/ortools.rb @@ -750,7 +750,7 @@ def run_ortools(problem, vrp, services, points, matrix_indices, thread_proc = ni next unless r && t # if there is no iteration and time then there is nothing to do begin - @previous_result = if vrp.restitution_intermediate_solutions && s + @previous_result = if vrp.restitution_intermediate_solutions && s && !/Final Iteration :/.match(line) parse_output(vrp, services, points, matrix_indices, cost, iterations, output) end block&.call(self, iterations, nil, nil, cost, time, @previous_result) # if @previous_result=nil, it will not override the existing solution