Skip to content

Commit

Permalink
Add 'strict_skills' field to 'resolution' for strict skills management
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Graber committed Apr 25, 2023
1 parent 76861c5 commit 45cada1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/v01/entities/vrp_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module VrpConfiguration
optional(:stable_iterations, type: Integer, allow_blank: false, documentation: { hidden: true }, desc: 'DEPRECATED : Jsprit solver and related parameters are not supported anymore')
optional(:stable_coefficient, type: Float, allow_blank: false, documentation: { hidden: true }, desc: 'DEPRECATED : Jsprit solver and related parameters are not supported anymore')
optional(:initial_time_out, type: Integer, allow_blank: false, documentation: { hidden: true }, desc: '[ DEPRECATED : use minimum_duration instead]')
optional(:strict_skills, type: Boolean, allow_blank: false, documentation: { hidden: true }, desc: 'All skills must be taken into during resolution')
optional(:minimum_duration, type: Integer, allow_blank: false, desc: 'Minimum solve duration before the solve could stop (x10 in order to find the first solution) (ORtools only)')
optional(:time_out_multiplier, type: Integer, desc: 'The solve could stop itself if the solve duration without finding a new solution is greater than the time currently elapsed multiplicate by this parameter (ORtools only)')
optional(:vehicle_limit, type: Integer, desc: 'Limit the maximum number of vehicles within a solution. Not available with periodic heuristic.')
Expand Down
6 changes: 3 additions & 3 deletions lib/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
module Filters
def self.filter(vrp)
merge_timewindows(vrp)

filter_skills(vrp)

unless vrp.configuration.resolution.strict_skills
filter_skills(vrp)
end
# calculate_unit_precision # TODO: treat only input vrp, not all models in memory from other vrps
nil
end
Expand Down
1 change: 1 addition & 0 deletions models/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Resolution < Base
field :variation_ratio, default: nil
field :batch_heuristic, default: false
field :repetition, default: nil
field :strict_skills, default: false

# random_seed parameter is set by the API during the POST process before dumping the VRP
# it is to make the runs repeatable/reproducible and simplifies comparing different environments
Expand Down
66 changes: 66 additions & 0 deletions test/wrappers/ortools_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5307,4 +5307,70 @@ def test_activities_order
unassigned_stops = solution.unassigned_stops
assert_equal 2, unassigned_stops.size
end

focus
def test_strict_skills
ortools = OptimizerWrapper.config[:services][:ortools]
problem = {
matrices: [{
id: 'matrix_0',
time: [
[0, 1, 1],
[1, 0, 1],
[1, 1, 0]
]
}],
points: [{
id: 'point_0',
matrix_index: 0
}, {
id: 'point_1',
matrix_index: 1
}, {
id: 'point_2',
matrix_index: 2
}],
vehicles: [{
id: 'vehicle_0',
start_point_id: 'point_0',
matrix_id: 'matrix_0'
}],
services: [{
id: 'service_1',
skills: ['frozen'],
activity: {
point_id: 'point_1'
}
}, {
id: 'service_2',
skills: ['frozen'],
activity: {
point_id: 'point_2'
}
}],
configuration: {
resolution: {
strict_skills: true,
duration: 20,
}
}
}

vrp_strict = TestHelper.create(problem)

Filters.filter(vrp_strict)

solution_strict = ortools.solve(vrp_strict, 'test')

assert_equal 1, solution_strict.routes.size
assert_equal problem[:services].size, solution_strict.unassigned_stops.size

problem_unstrict = Marshal.load(Marshal.dump(problem))
problem_unstrict[:configuration][:resolution][:strict_skills] = false
vrp_unstrict = TestHelper.create(problem_unstrict)
Filters.filter(vrp_unstrict)
solution_unstrict = ortools.solve(vrp_unstrict, 'test')
assert_equal 1, solution_unstrict.routes.size
assert_equal 0, solution_unstrict.unassigned_stops.size
end
end

0 comments on commit 45cada1

Please # to comment.