Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Braktar committed Oct 29, 2021
1 parent 8fa6cc6 commit 7091d8b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion models/concerns/vrp_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def vrp_result(options = nil)
include_root_in_json
end

hash = serializable_hash(options).vrp_result
hash = serializable_hash(options).vrp_result(options)
if root
root = model_name.element if root == true
{ root => hash }
Expand Down
8 changes: 5 additions & 3 deletions models/solution/parsers/step_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
module Parsers
class ServiceParser
def self.parse(service, options)
activity = options[:index] && service.activities[options[:index]] || service.activity
activity_hash = Models::Activity.field_names.map{ |key|
activity = options[:index] && service.activities[options[:index]] || service.activity
next if key == :point_id

[key, activity.send(key)]
}.to_h
}.compact.to_h

dup_activity = Models::Activity.new(activity_hash)
dup_activity[:simplified_setup_duration] = service.activity[:simplified_setup_duration]
dup_activity[:simplified_setup_duration] = activity[:simplified_setup_duration] if activity[:simplified_setup_duration]

{
id: service.original_id,
Expand Down
4 changes: 2 additions & 2 deletions models/solution/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def count_services
steps.count(&:service_id)
end

def insert_step(vrp, step_object, index)
def insert_step(vrp, step_object, index, idle_time = 0)
steps.insert(index, step_object)
shift_route_times(step_object.activity.duration, index)
shift_route_times(idle_time + step_object.activity.duration, index)
end

def shift_route_times(shift_amount, shift_start_index = 0)
Expand Down
4 changes: 2 additions & 2 deletions models/solution/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def update_costs
self.cost -= (previous_total - cost_info.total).round
end

def insert_step(vrp, route, step_object, index)
route.insert_step(vrp, step_object, index)
def insert_step(vrp, route, step_object, index, idle_time = 0)
route.insert_step(vrp, step_object, index, idle_time)
Parsers::SolutionParser.parse(self, vrp)
end
end
Expand Down
3 changes: 1 addition & 2 deletions test/wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3038,8 +3038,7 @@ def test_empty_result_when_no_vehicle

assert_equal 0, corresponding_in_route.activity.timewindows.first.start
assert_equal 10, corresponding_in_route.activity.timewindows.first.end
# Services which can be served have their timewindows interpreted and the day index is removed
assert_nil corresponding_in_route.activity.timewindows.first.day_index
assert_equal 0, corresponding_in_route.activity.timewindows.first.day_index

corresponding_unassigned = solutions[0].unassigned.find{ |un| un.id == vrp[:services][1][:id] }
assert_equal 30, corresponding_unassigned.activity.timewindows.first.start
Expand Down
18 changes: 8 additions & 10 deletions wrappers/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1254,13 +1254,13 @@ def simplify_vehicle_pause(vrp, result = nil, options = { mode: :simplify })
end
else
# there is a clear position to insert
activity_after_rest = route.steps[insert_rest_at]
step_after_rest = route.steps[insert_rest_at]

rest_start = activity_after_rest.info.begin_time
rest_start = step_after_rest.info.begin_time
# if this the first service of this location then we need to consider the setup_duration
rest_start -= activity_after_rest.activity.setup_duration.to_i if activity_after_rest.info.travel_time > 0
rest_start -= step_after_rest.activity.setup_duration.to_i if step_after_rest.info.travel_time > 0
if rest.timewindows&.last&.end && rest_start > rest.timewindows.last.end
rest_start -= activity_after_rest.info.travel_time
rest_start -= step_after_rest.info.travel_time
rest_start = [rest_start, rest.timewindows&.first&.start.to_i].max # don't induce idle_time if within travel_time
end

Expand All @@ -1283,18 +1283,16 @@ def simplify_vehicle_pause(vrp, result = nil, options = { mode: :simplify })
end
times = { begin_time: rest_start, end_time: rest_start + rest.duration, departure_time: rest_start + rest.duration }
rest_step = Models::Solution::Step.new(rest, info: Models::Solution::Step::Info.new(times))
result.insert_step(vrp, route, rest_step, insert_rest_at)

result.insert_step(vrp, route, rest_step, insert_rest_at, idle_time_created_by_inserted_pause)
# shift_route_times(route, idle_time_created_by_inserted_pause + rest.duration, insert_rest_at + 1)

next if no_cost

cost_increase = vehicle.cost_time_multiplier.to_f * rest.duration +
vehicle.cost_waiting_time_multiplier.to_f * idle_time_created_by_inserted_pause

route[:cost_info]&.time += cost_increase
result[:cost_info]&.time += cost_increase
result[:cost] += cost_increase # totals are not calculated yet
route.cost_info&.time += cost_increase
result.cost_info&.time += cost_increase
result.cost += cost_increase # totals are not calculated yet
}
}
else
Expand Down

0 comments on commit 7091d8b

Please sign in to comment.