Skip to content

Commit

Permalink
More Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Braktar committed Nov 5, 2021
1 parent 5ed2027 commit d88ab59
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions lib/heuristics/dichotomious_approach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def self.insert_unassigned_by_skills(service_vrp, services, skills, solution, jo
remove_bad_skills(sub_service_vrp, solution_loop)

Helper.replace_routes_in_result(solution, solution_loop)
solution.parse(vrp)
sub_solutions << solution_loop
end
new_routes = build_initial_routes(sub_solutions)
Expand Down
6 changes: 3 additions & 3 deletions lib/heuristics/periodic_heuristic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ def compute_visits_number
end

def prepare_output_and_collect_routes(vrp)
routes = []
vrp_routes = []
solution_routes = []

compute_visits_number
Expand All @@ -1205,7 +1205,7 @@ def prepare_output_and_collect_routes(vrp)
}
computed_steps, _start_time, _end_time = get_activities(day, route_data, vrp_vehicle)

routes << {
vrp_routes << {
vehicle_id: vrp_vehicle.id,
mission_ids: computed_steps.collect{ |stop| stop[:service_id] }.compact
}
Expand All @@ -1223,7 +1223,7 @@ def prepare_output_and_collect_routes(vrp)
elapsed: (Time.now - @starting_time) * 1000) # ms
solution.parse(vrp)
vrp.preprocessing_heuristic_result = solution
routes
vrp_routes
end

def select_point(insertion_costs, empty_route)
Expand Down
14 changes: 9 additions & 5 deletions models/solution/parsers/route_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ def self.compute_route_total_dimensions(matrix)
total = dimensions.collect.with_object({}) { |dimension, hash| hash[dimension] = 0 }
@route.steps.each{ |step_object|
matrix_index = step_object.activity.point&.matrix_index
if previous_index && matrix_index
dimensions.each{ |dimension|
dimensions.each{ |dimension|
if previous_index && matrix_index
unless step_object.info.send("travel_#{dimension}".to_sym)
step_object.info.send("travel_#{dimension}=", matrix.send(dimension)[previous_index][matrix_index])
end
total[dimension] += step_object.info.send("travel_#{dimension}".to_sym).round
step_object.info.current_distance = total[dimension].round if dimension == :distance
}
end
else
step_object.info.send("travel_#{dimension}=", 0)
end
}

previous_index = matrix_index if step_object.type != :rest
}
Expand All @@ -88,7 +90,9 @@ def self.compute_missing_dimensions(matrix)
dimensions.each{ |dimension|
next unless matrix&.send(dimension)&.any?

next if @route.steps.any?{ |step| step.info.send("travel_#{dimension}") > 0 }
next if @route.steps.any?{ |step|
step.info.send("travel_#{dimension}") && step.info.send("travel_#{dimension}") > 0
}

previous_departure = dimension == :time ? @route.steps.first.info.begin_time : 0
previous_index = nil
Expand Down
8 changes: 4 additions & 4 deletions models/solution/route_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ module Models
class Solution < Base
class Route < Base
class Info < Base
field :total_time, default: 0
field :total_travel_time, default: 0
field :total_waiting_time, default: 0
field :total_time
field :total_travel_time
field :total_waiting_time

field :total_distance, default: 0
field :total_distance

field :total_travel_value

Expand Down
6 changes: 3 additions & 3 deletions models/solution/step_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Info < Base
field :day_week_num
field :day_week

field :travel_distance, default: 0
field :travel_time, default: 0
field :travel_value, default: 0
field :travel_distance
field :travel_time
field :travel_value

field :waiting_time, default: 0
field :begin_time, default: 0
Expand Down
2 changes: 0 additions & 2 deletions optimizer_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,6 @@ def self.build_independent_vrps(vrp, skill_sets, skill_vehicle_ids, skill_servic
return independent_vrps if unused_vehicle_indices.empty?

sub_service_vrp = Interpreters::SplitClustering.build_partial_service_vrp({ vrp: vrp }, [], unused_vehicle_indices)
sub_service_vrp[:vrp].matrices = []
sub_service_vrp[:vrp].vehicles.each{ |v| v.matrix_id = nil }
independent_vrps.push(sub_service_vrp[:vrp])

independent_vrps
Expand Down
6 changes: 3 additions & 3 deletions test/lib/heuristics/periodic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ def test_first_last_possible_day_validation_done_in_data_initialization

vrp[:configuration][:schedule] = { range_date: { start: Date.new(2021, 1, 19), end: Date.new(2021, 1, 24)} }

result = OptimizerWrapper.wrapper_vrp('ortools', { services: { vrp: [:ortools] }}, TestHelper.create(vrp), nil)
assert_equal 4, result[:unassigned].size
assert(result[:unassigned].all?{ |u| u[:reason] == 'First and last possible days do not allow this service planification' })
solutions = OptimizerWrapper.wrapper_vrp('ortools', { services: { vrp: [:ortools] }}, TestHelper.create(vrp), nil)
assert_equal 4, solutions[0].unassigned.size
assert(solutions[0].unassigned.all?{ |u| u.reason == 'First and last possible days do not allow this service planification' })
end
end
end
2 changes: 1 addition & 1 deletion test/wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2970,7 +2970,7 @@ def test_split_independent_skills_with_trip_relation

def test_split_independent_vrps_with_useless_vehicle
vrp = TestHelper.create(VRP.independent_skills)
vrp.vehicles << Models::Vehicle.create(id: 'useless_vehicle')
vrp.vehicles << Models::Vehicle.create(id: 'useless_vehicle', matrix_id: 'matrix_0')
solutions = OptimizerWrapper.wrapper_vrp('ortools', { services: { vrp: [:ortools] }}, vrp, nil)
assert_equal vrp.vehicles.size, solutions[0].routes.size,
'All vehicles should appear in result, even though they can serve no service'
Expand Down
4 changes: 2 additions & 2 deletions wrappers/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ def add_unassigned_internal(unfeasible, vrp, service, reason)
step_id = vrp.schedule? ? "#{service.id}_#{index + 1}_#{service.visits_number}" : service.id
unfeasible[service.id] << Models::Solution::Step.new(
service,
id: step_id,
service_id: service.id,
id: service.id,
service_id: step_id,
reason: reason
)
}
Expand Down

0 comments on commit d88ab59

Please sign in to comment.