Skip to content

Commit

Permalink
Linked_ids and linked_service_ids are currently most of the time dupl…
Browse files Browse the repository at this point in the history
…icate values
  • Loading branch information
Braktar committed Mar 9, 2022
1 parent 5a86dd9 commit 95a011f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/interpreters/split_clustering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def self.build_partial_service_vrp(service_vrp, partial_service_ids, available_v
sub_vrp.points.uniq!
sub_vrp = add_corresponding_entity_skills(entity, sub_vrp)

sub_vrp_hash = JSON.parse(sub_vrp.to_json, symbolize_names: true)
sub_vrp_hash = sub_vrp.as_json

vehicle_ids = sub_vrp_hash[:vehicles]&.map{ |v| v[:id] } || []
sub_vrp_hash[:services]&.each{ |service|
Expand Down
10 changes: 6 additions & 4 deletions models/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ class Relation < Base

def self.create(hash)
# TODO: remove it after the linked_ids is replaced with linked_service_ids in the api definition
exclusive = [:linked_service_ids, :linked_ids, :linked_services].freeze
raise "#{exclusive} fields are mutually exclusive" if hash.keys.count{ |k| exclusive.include? k } > 1
if hash.key?(:linked_service_ids) && hash.key?(:linked_ids) && hash[:linked_service_ids] != hash[:linked_ids]
raise 'linked_service_ids and linked_ids should have the same content if both used'
end

# Raise condition required due to the use of lib/helper deep_copy
raise 'linked_services should not belong to vrp hash' if hash.key?(:linked_services)

# TODO: remove it after the linked_ids is replaced with linked_service_ids in the api definition
if hash.key?(:linked_ids)
hash[:linked_service_ids] = hash[:linked_ids]
elsif hash.key?(:linked_service_ids)
hash[:linked_ids] = hash[:linked_service_ids]
elsif hash.key?(:linked_services)
hash[:linked_ids] = hash[:linked_services].map(&:id)
end

super(hash)
Expand Down
11 changes: 4 additions & 7 deletions wrappers/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -981,13 +981,10 @@ def simplify_complex_multi_pickup_or_delivery_shipments(vrp, solution = nil, opt
quantity.value = -shipment_quantity + extra_per_quantity[q_index]
}

new_shipment_relation = Helper.deep_copy(
relation,
override: {
linked_ids: nil, # this line can be removed when linked_ids is replaced with linked_service_ids
linked_services: relation.linked_services.map{ |s| s.id == service.id ? new_service : s }
}
)
relation_hash = relation.as_json
relation_hash.delete(:linked_ids)
relation_hash[:linked_service_ids] = relation.linked_services.map{ |s| s.id == service.id ? new_service.id : s.id }
new_shipment_relation = Models::Relation.create(relation_hash)

new_service.relations << new_shipment_relation

Expand Down

0 comments on commit 95a011f

Please sign in to comment.