Skip to content

Commit

Permalink
Merge pull request #87 from senhalil/dev
Browse files Browse the repository at this point in the history
Fix parse_output protobuf error + other small fixes
  • Loading branch information
fab-girard authored Nov 26, 2020
2 parents 38fc2de + a37766c commit e1425b9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions test/real_cases_dichotomious_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ 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

# Check activities
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

Expand All @@ -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

Expand All @@ -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

Expand Down
14 changes: 10 additions & 4 deletions test/wrappers/ortools_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions wrappers/ortools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -684,11 +685,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 }

Expand Down Expand Up @@ -749,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
Expand Down

0 comments on commit e1425b9

Please sign in to comment.