diff --git a/CHANGELOG.md b/CHANGELOG.md index d3962bf65..d2271d24d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Exclusive position for activities that needs to be both first and last position [#438](https://github.com/Mapotempo/optimizer-api/pull/438) +- The intermediate solutions are now cleaned similarly to the final solution [#435](https://github.com/Mapotempo/optimizer-api/pull/435) ### Changed diff --git a/test/api/v01/with_solver_test.rb b/test/api/v01/with_solver_test.rb index a91b70fa5..7270ea55a 100644 --- a/test/api/v01/with_solver_test.rb +++ b/test/api/v01/with_solver_test.rb @@ -74,4 +74,33 @@ def test_returned_graph end delete_completed_job @job_id, api_key: 'ortools' if @job_id end + + def test_filter_intermediate_solution + # Verify that intermediate solution are correctly filtered + asynchronously start_worker: true do + vrp = VRP.lat_lon + vrp[:configuration][:resolution][:duration] = 2000 + vrp[:units] = [{ id: 'unit_1' }] + vrp[:services].each{ |s| + s[:quantities] = [{ unit_id: 'unit_1', value: 1 }] + } + vrp[:services] << { + id: 'vidage_1', + activity: { + point_id: 'point_0' + }, + quantities: [{ + unit_id: 'unit_1', + empty: true + }] + } + vrp[:vehicles].first[:capacities] = [{ unit_id: 'unit_1', limit: 10 }] + vrp[:services] << vrp[:services].last.dup.tap{ |s| s[:id] = 'vidage_2' } + vrp[:configuration][:restitution][:intermediate_solutions] = true + @job_id = submit_vrp api_key: 'ortools', vrp: vrp + result = wait_avancement_match(@job_id, /run optimization, iterations/, api_key: 'ortools') + assert_equal "Duplicate empty service.", result['solutions'].first['unassigned'].first['reason'] + end + delete_job(@job_id, api_key: 'ortools') if @job_id + end end diff --git a/util/job_manager.rb b/util/job_manager.rb index e5ae11c45..8120c8517 100644 --- a/util/job_manager.rb +++ b/util/job_manager.rb @@ -105,7 +105,10 @@ def perform geometry: ask_restitution_geojson } p[:graph] << { iteration: avancement, cost: cost, time: time } - p[:result] = [solution.vrp_result].flatten if solution + if solution + Cleanse.cleanse(services_vrps.first[:vrp], solution) + p[:result] = [solution.vrp_result].flatten + end begin Result.set(self.uuid, p) rescue Redis::BaseError => e