Skip to content

Commit

Permalink
Reference relations and services
Browse files Browse the repository at this point in the history
  • Loading branch information
senhalil committed Mar 1, 2021
1 parent 6b6809d commit ef57b46
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
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

0 comments on commit ef57b46

Please sign in to comment.