Skip to content

Commit

Permalink
fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
senhalil committed Jul 30, 2021
1 parent 6c957ee commit 8c8a2ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def self.has_many(name, options = {})
# Array and other objects that are not based on Models::Base class cannot have id methods
if options[:class_name]&.start_with? 'Models::'
define_method(ids_function_name) do
self[ids_function_name]
self[ids_function_name] ||= self[name]&.map(&:id) || []
end

define_method("#{ids_function_name}=") do |vals|
Expand Down Expand Up @@ -110,7 +110,7 @@ def self.belongs_to(name, options = {})
# Array and other objects that are not based on Models::Base class cannot have id methods
if options[:class_name]&.start_with? 'Models::'
define_method(id_function_name) do
self[id_function_name]
self[id_function_name] ||= self[name]&.id
end

define_method("#{id_function_name}=") do |val_id|
Expand Down
12 changes: 4 additions & 8 deletions wrappers/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,6 @@ def simplify_vehicle_pause(vrp, result = nil, options = { mode: :simplify })
vehicle.timewindow.end -= rest.duration if vehicle.timewindow&.end
}

vehicle[:simplified_rest_ids] = vehicle[:rest_ids].dup
vehicle[:rest_ids] = []
vehicle[:simplified_rests] = vehicle.rests.dup
vehicle.rests = []
}
Expand All @@ -988,11 +986,9 @@ def simplify_vehicle_pause(vrp, result = nil, options = { mode: :simplify })
when :rewind
# take the modifications back in case the vehicle is moved to another sub-problem
vrp.vehicles&.each{ |vehicle|
next unless vehicle[:simplified_rest_ids]&.any?
next unless vehicle[:simplified_rests]&.any?

vehicle[:rest_ids].concat vehicle[:simplified_rest_ids]
vehicle[:simplified_rest_ids] = nil
vehicle.rests.concat vehicle[:simplified_rests]
vehicle.rests += vehicle[:simplified_rests]
vehicle[:simplified_rests] = nil

vehicle.rests.each{ |rest|
Expand All @@ -1002,14 +998,14 @@ def simplify_vehicle_pause(vrp, result = nil, options = { mode: :simplify })
}

if vrp[:simplified_rests]
vrp.rests.concat vrp[:simplified_rests]
vrp.rests += vrp[:simplified_rests]
vrp[:simplified_rests] = nil
end
when :patch_result
# correct the result with respect to simplifications
pause_and_depot = %w[depot rest].freeze
vrp.vehicles&.each{ |vehicle|
next unless vehicle[:simplified_rest_ids]&.any?
next unless vehicle[:simplified_rests]&.any?

route = result[:routes].find{ |r| r[:vehicle_id] == vehicle.id }
no_cost = route[:activities].none?{ |a| pause_and_depot.exclude?(a[:type]) }
Expand Down

0 comments on commit 8c8a2ec

Please sign in to comment.