Skip to content

Commit 28dd315

Browse files
committed
Fix lint
1 parent b8ae816 commit 28dd315

File tree

9 files changed

+76
-58
lines changed

9 files changed

+76
-58
lines changed

api/v01/vrp.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Vrp < APIBase
217217
params {
218218
use(:input)
219219
optional(:format, type: Symbol, values: [:json, :geojson], default: :json,
220-
desc: 'Output format: json (full graph) or geojson')
220+
desc: 'Output format: json (full graph) or geojson')
221221
}
222222
post do
223223
d_params = declared(params, include_missing: false)
@@ -230,11 +230,12 @@ class Vrp < APIBase
230230
error!("Model Validation Error: #{vrp.errors}", 400)
231231
end
232232

233-
graph = begin
234-
VrpGraph::GraphBuilder.new(vrp).build
235-
rescue LoadError => e
236-
error!({ message: "Graph build failed: #{e.message}" }, 501)
237-
end
233+
graph =
234+
begin
235+
VrpGraph::GraphBuilder.new(vrp).build
236+
rescue LoadError => e
237+
error!({ message: "Graph build failed: #{e.message}" }, 501)
238+
end
238239

239240
if graph
240241
vrp.graph = graph

core/strategies/orchestration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require './lib/interpreters/re_partition.rb'
1+
require './lib/interpreters/re_partition'
22

33
module Core
44
module Strategies

lib/vrp_graph/batch_assigner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def build_proximity_matrix
109109
end
110110

111111
def route_stop_service_ids(route)
112-
route.stops.filter_map { |s| s.service_id }.compact.each_with_object({}) { |sid, h| h[sid] = true }
112+
route.stops.filter_map(&:service_id).compact.each_with_object({}) { |sid, h| h[sid] = true }
113113
end
114114

115115
def assign_with_ortools

lib/vrp_graph/delaunay_adapter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def compute_edges(points)
3737
return [] if points.size < 2
3838

3939
unless File.executable?(BINARY_PATH)
40-
raise LoadError, "vrp_delaunay binary not found. Run: rake ext:vrp_delaunay (expected: #{BINARY_PATH})"
40+
raise LoadError.new(
41+
"vrp_delaunay binary not found. Run: rake ext:vrp_delaunay (expected: #{BINARY_PATH})"
42+
)
4143
end
4244

4345
input = points.map { |lon, lat| [lon.to_f, lat.to_f] }.to_json

lib/vrp_graph/knn_neighborhood.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ module KnnNeighborhood
3333
# @param k [Integer] max neighbors per repaired point
3434
# @return [Hash] point_id => [neighbor_point_id, ...] sorted by travel time
3535
def compute_knn_points(repaired_point_ids, other_point_ids, knn_matrix, point_incompat, k: 10)
36-
incompat_set = point_incompat.is_a?(Hash) ? point_incompat : point_incompat.to_h { |a, b| [[a.to_s, b.to_s].sort, true] }
36+
incompat_set =
37+
if point_incompat.is_a?(Hash)
38+
point_incompat
39+
else
40+
point_incompat.to_h { |a, b| [[a.to_s, b.to_s].sort, true] }
41+
end
3742
result = {}
3843

3944
repaired_point_ids.each_with_index do |pid, i|

models/graph.rb

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def tours_connectivity(ids)
9292
def tours_connectivity_from_solution(solution)
9393
result = {}
9494
solution.routes.each_with_index do |route, idx|
95-
service_ids = route.stops.filter_map{ |s| s.service_id }.compact
95+
service_ids = route.stops.filter_map(&:service_id).compact
9696
result[idx] = tours_connectivity(service_ids)
9797
end
9898
result
@@ -160,20 +160,21 @@ def to_geojson
160160

161161
# Full adjacency list: Delaunay edges + KNN-repair edges, cached.
162162
def adjacency
163-
@adjacency_cache ||= begin
164-
adj = Hash.new { |h, k| h[k] = [] }
165-
(edges || []).each do |e|
166-
adj[e[0]] << e[1]
167-
adj[e[1]] << e[0]
168-
end
169-
(knn_neighbors || {}).each do |sid, neighbors|
170-
neighbors.each do |nb|
171-
adj[sid] << nb unless adj[sid].include?(nb)
172-
adj[nb] << sid unless adj[nb].include?(sid)
163+
@adjacency ||=
164+
begin
165+
adj = Hash.new { |h, k| h[k] = [] }
166+
(edges || []).each do |e|
167+
adj[e[0]] << e[1]
168+
adj[e[1]] << e[0]
169+
end
170+
(knn_neighbors || {}).each do |sid, neighbors|
171+
neighbors.each do |nb|
172+
adj[sid] << nb unless adj[sid].include?(nb)
173+
adj[nb] << sid unless adj[nb].include?(sid)
174+
end
173175
end
176+
adj
174177
end
175-
adj
176-
end
177178
end
178179

179180
def build_service_ids_by_point
@@ -229,45 +230,48 @@ def neighbors_for_point(point_id)
229230
end
230231

231232
def knn_neighbors
232-
@knn_neighbors_cache ||= begin
233-
merged = {}
234-
@graphs.each_value do |g|
235-
(g.knn_neighbors || {}).each do |sid, neighbors|
236-
(merged[sid] ||= []).concat(neighbors)
233+
@knn_neighbors ||=
234+
begin
235+
merged = {}
236+
@graphs.each_value do |g|
237+
(g.knn_neighbors || {}).each do |sid, neighbors|
238+
(merged[sid] ||= []).concat(neighbors)
239+
end
237240
end
241+
merged.each_value(&:uniq!)
242+
merged
238243
end
239-
merged.each_value(&:uniq!)
240-
merged
241-
end
242244
end
243245

244246
def nodes
245-
@nodes_cache ||= begin
246-
merged = {}
247-
@graphs.each_value { |g| merged.merge!(g.nodes || {}) }
248-
merged
249-
end
247+
@nodes ||=
248+
begin
249+
merged = {}
250+
@graphs.each_value { |g| merged.merge!(g.nodes || {}) }
251+
merged
252+
end
250253
end
251254

252255
def edges
253-
@edges_cache ||= begin
254-
seen = {}
255-
result = []
256-
@graphs.each_value do |g|
257-
(g.edges || []).each do |e|
258-
pair = [e[0], e[1]].sort
259-
next if seen[pair]
260-
261-
seen[pair] = true
262-
result << e
256+
@edges ||=
257+
begin
258+
seen = {}
259+
result = []
260+
@graphs.each_value do |g|
261+
(g.edges || []).each do |e|
262+
pair = [e[0], e[1]].sort
263+
next if seen[pair]
264+
265+
seen[pair] = true
266+
result << e
267+
end
263268
end
269+
result
264270
end
265-
result
266-
end
267271
end
268272

269273
def edge_set
270-
@edge_set_cache ||= edges.each_with_object({}) { |e, h| h[[e[0], e[1]].sort] = true }
274+
@edge_set ||= edges.each_with_object({}) { |e, h| h[[e[0], e[1]].sort] = true }
271275
end
272276

273277
def connected?(id_a, id_b)
@@ -292,7 +296,7 @@ def tours_connectivity(ids)
292296
def tours_connectivity_from_solution(solution)
293297
result = {}
294298
solution.routes.each_with_index do |route, idx|
295-
service_ids = route.stops.filter_map{ |s| s.service_id }.compact
299+
service_ids = route.stops.filter_map(&:service_id).compact
296300
result[idx] = tours_connectivity(service_ids)
297301
end
298302
result

models/vrp.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def find_mission_by_id(mission_id)
117117
reload_depots.find{ |rd| rd.id == mission_id || rd.original_id == mission_id }
118118
end
119119

120-
# Builds Models::Route list from rows produced by Solution#vrp_routes (optionally filtered via Solution.vrp_routes_for_vehicles).
120+
# Builds Models::Route list from rows produced by Solution#vrp_routes
121+
# (optionally filtered via Solution.vrp_routes_for_vehicles).
121122
def routes_from_initial_specs(route_specs)
122123
route_specs.filter_map{ |spec|
123124
vehicle = vehicles.find{ |v| v.id == spec[:vehicle_id] }

test/lib/vrp_graph/delaunay_adapter_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
module VrpGraph
66
class DelaunayAdapterTest < Minitest::Test
77
def setup
8-
skip 'vrp_delaunay binary not built (rake ext:vrp_delaunay)' unless File.executable?(VrpGraph::DelaunayAdapter::BINARY_PATH)
8+
return if File.executable?(VrpGraph::DelaunayAdapter::BINARY_PATH)
9+
10+
skip 'vrp_delaunay binary not built (rake ext:vrp_delaunay)'
911
end
1012

1113
def test_compute_edges_returns_empty_for_insufficient_points
12-
assert_equal [], DelaunayAdapter.compute_edges([])
13-
assert_equal [], DelaunayAdapter.compute_edges([[1.0, 2.0]])
14+
assert_empty DelaunayAdapter.compute_edges([])
15+
assert_empty DelaunayAdapter.compute_edges([[1.0, 2.0]])
1416
end
1517

1618
def test_compute_edges_two_points

test/lib/vrp_graph/graph_builder_test.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
module VrpGraph
66
class GraphBuilderTest < Minitest::Test
77
def setup
8-
skip 'vrp_delaunay binary not built (rake ext:vrp_delaunay)' unless File.executable?(VrpGraph::DelaunayAdapter::BINARY_PATH)
8+
return if File.executable?(VrpGraph::DelaunayAdapter::BINARY_PATH)
9+
10+
skip 'vrp_delaunay binary not built (rake ext:vrp_delaunay)'
911
end
1012

1113
def test_build_creates_graph_with_service_level_nodes
@@ -99,9 +101,10 @@ def test_intra_point_edges_between_colocated_services
99101
assert_equal graph.nodes['svc_a'][:point_id], graph.nodes['svc_b'][:point_id],
100102
'Co-located services should share the same point_id'
101103

102-
intra_edge = graph.edges.any?{ |e|
103-
[e[0], e[1]].sort == ['svc_a', 'svc_b'].sort
104-
}
104+
intra_edge =
105+
graph.edges.any?{ |e|
106+
[e[0], e[1]].sort == ['svc_a', 'svc_b'].sort
107+
}
105108
assert intra_edge, 'Compatible co-located services should have an intra-point edge'
106109
end
107110
end

0 commit comments

Comments
 (0)