Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def self.has_many(name, options = {})
super

define_method(name) do
self[name] || []
self[name] ||= []
end

define_method("#{name}=") do |vals|
Expand Down
8 changes: 8 additions & 0 deletions models/concerns/expand_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def adapt_relations_between_shipments
}
end

def add_relation_references
self.relations.each{ |relation|
relation.linked_services.each{ |service|
service.relations << relation
}
}
end

def add_sticky_vehicle_if_routes_and_partitions
return if self.preprocessing_partitions.empty?

Expand Down
1 change: 1 addition & 0 deletions models/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Relation < Base
field :type, default: :same_route
field :lapse, default: nil
field :linked_ids, default: []
has_many :linked_services, class_name: 'Models::Service'
field :linked_vehicle_ids, default: []
field :periodicity, default: 1

Expand Down
1 change: 1 addition & 0 deletions models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ class Service < Base
has_many :activities, class_name: 'Models::Activity'
has_many :sticky_vehicles, class_name: 'Models::Vehicle'
has_many :quantities, class_name: 'Models::Quantity'
has_many :relations, class_name: 'Models::Relation'
end
end
10 changes: 10 additions & 0 deletions models/vrp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def self.check_consistency(hash)
end

def self.expand_data(vrp)
vrp.add_relation_references
vrp.add_sticky_vehicle_if_routes_and_partitions
vrp.adapt_relations_between_shipments
vrp.expand_unavailable_days
Expand Down Expand Up @@ -325,6 +326,7 @@ def self.filter(hash)

self.remove_unecessary_units(hash)
self.generate_schedule_indices_from_date(hash)
self.generate_linked_service_ids_for_relations(hash)
end

def self.remove_unecessary_units(hash)
Expand Down Expand Up @@ -477,6 +479,14 @@ def self.generate_schedule_indices_from_date(hash)
hash
end

def self.generate_linked_service_ids_for_relations(hash)
hash[:relations]&.each{ |relation|
next unless relation[:linked_ids]&.any?

relation[:linked_service_ids] = relation[:linked_ids].select{ |id| hash[:services]&.any?{ |s| s[:id] == id } }
}
end

def configuration=(configuration)
self.config = configuration
self.preprocessing = configuration[:preprocessing] if configuration[:preprocessing]
Expand Down