diff --git a/models/base.rb b/models/base.rb index d58438033..ba27e887c 100644 --- a/models/base.rb +++ b/models/base.rb @@ -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| @@ -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| diff --git a/wrappers/wrapper.rb b/wrappers/wrapper.rb index c889eb898..ece8581a8 100644 --- a/wrappers/wrapper.rb +++ b/wrappers/wrapper.rb @@ -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 = [] } @@ -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| @@ -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]) }