@@ -15,32 +15,32 @@ struct Solution
1515 path_value:: BitMatrix # list of vehicles paths
1616end
1717
18- function get_nb_vehicles (path_value:: BitMatrix )
19- return sum (any (path_value; dims= 2 ))
20- end
21-
22- function get_nb_vehicles (solution:: Solution )
23- return get_nb_vehicles (solution. path_value)
24- end
25-
26- """
27- $TYPEDSIGNATURES
28-
29- Compute routes of solution.
30- """
31- function get_routes (solution:: Solution )
32- res = Vector{Int}[]
33- for vehicle in 1 : get_nb_vehicles (solution)
34- resv = Int[]
35- for (index, value) in enumerate (solution. path_value[vehicle, :])
36- if value
37- push! (resv, index + 1 )
38- end
39- end
40- push! (res, resv)
41- end
42- return res
43- end
18+ # function get_nb_vehicles(path_value::BitMatrix)
19+ # return sum(any(path_value; dims=2))
20+ # end
21+
22+ # function get_nb_vehicles(solution::Solution)
23+ # return get_nb_vehicles(solution.path_value)
24+ # end
25+
26+ # """
27+ # $TYPEDSIGNATURES
28+
29+ # Compute routes of solution.
30+ # """
31+ # function get_routes(solution::Solution)
32+ # res = Vector{Int}[]
33+ # for vehicle in 1:get_nb_vehicles(solution)
34+ # resv = Int[]
35+ # for (index, value) in enumerate(solution.path_value[vehicle, :])
36+ # if value
37+ # push!(resv, index + 1)
38+ # end
39+ # end
40+ # push!(res, resv)
41+ # end
42+ # return res
43+ # end
4444
4545"""
4646$TYPEDSIGNATURES
@@ -152,32 +152,32 @@ function path_solution_from_JuMP_array(x::AbstractArray, graph::AbstractGraph)
152152 return sol
153153end
154154
155- function basic_path_solution (graph:: AbstractGraph )
156- nb_tasks = nv (graph) - 2
157- sol = falses (nb_tasks, nb_tasks)
158- for i_task in 1 : nb_tasks
159- sol[i_task, i_task] = true
160- end
161- return sol
162- end
163-
164- """
165- $TYPEDSIGNATURES
166-
167- Create a solution with one vehicle per task.
168- """
169- function basic_solution (instance:: Instance )
170- graph = instance. graph
171- value = falses (ne (graph))
172-
173- for (a, edge) in enumerate (edges (graph))
174- if edge. src == 1 || edge. dst == nv (graph)
175- value[a] = true
176- end
177- end
178-
179- return Solution (value, basic_path_solution (graph))
180- end
155+ # function basic_path_solution(graph::AbstractGraph)
156+ # nb_tasks = nv(graph) - 2
157+ # sol = falses(nb_tasks, nb_tasks)
158+ # for i_task in 1:nb_tasks
159+ # sol[i_task, i_task] = true
160+ # end
161+ # return sol
162+ # end
163+
164+ # """
165+ # $TYPEDSIGNATURES
166+
167+ # Create a solution with one vehicle per task.
168+ # """
169+ # function basic_solution(instance::Instance)
170+ # graph = instance.graph
171+ # value = falses(ne(graph))
172+
173+ # for (a, edge) in enumerate(edges(graph))
174+ # if edge.src == 1 || edge.dst == nv(graph)
175+ # value[a] = true
176+ # end
177+ # end
178+
179+ # return Solution(value, basic_path_solution(graph))
180+ # end
181181
182182"""
183183$TYPEDSIGNATURES
@@ -290,7 +290,7 @@ function to_array(path_value::BitMatrix, instance::Instance)
290290 current_task = 1
291291 while true
292292 index_shift = find_first_one (@view path_value[i, current_task: end ])
293- if isnothing ( index_shift)
293+ if index_shift === - 1
294294 mat[current_task, nb_nodes] = true
295295 break
296296 end
@@ -323,7 +323,7 @@ $TYPEDSIGNATURES
323323
324324Check if `solution` is an admissible solution of `instance`.
325325"""
326- function is_feasible (solution:: Solution , instance:: Instance )
326+ function is_feasible (solution:: Solution , instance:: Instance ; verbose = true )
327327 graph = instance. graph
328328 nb_nodes = nv (graph)
329329 nb_tasks = nb_nodes - 2
@@ -339,14 +339,13 @@ function is_feasible(solution::Solution, instance::Instance)
339339 current_task = 1
340340 while true
341341 index_shift = find_first_one (@view solution. path_value[i, current_task: end ])
342- if isnothing ( index_shift)
342+ if index_shift == - 1
343343 mat[current_task, nb_nodes] = true
344344 break
345345 end
346346 next_task = current_task + index_shift
347347 if ! has_edge (graph, current_task, next_task)
348- @warn " Flow not respected" current_task next_task
349- @warn " " outneighbors (graph, current_task)
348+ verbose && @warn " Flow not respected" current_task next_task
350349 return false
351350 end
352351 mat[current_task, next_task] = true
@@ -355,21 +354,15 @@ function is_feasible(solution::Solution, instance::Instance)
355354 end
356355
357356 if ! all (sum (solution. path_value; dims= 1 ) .== 1 )
358- @warn " One task done by more than one vehicle (or less than once)"
357+ verbose && @warn " One task done by more than one vehicle (or less than once)"
359358 return false
360359 end
361360
362361 for i in job_indices
363362 s1 = sum (mat[j, i] for j in inneighbors (graph, i))
364363 s2 = sum (mat[i, j] for j in outneighbors (graph, i))
365364 if s1 != s2 || s1 != 1
366- @warn " Flow is broken" i s1 s2
367- @warn " " inneighbors (graph, i)
368- @warn " " [mat[j, i] for j in inneighbors (graph, i)]
369- @warn " " outneighbors (graph, i)
370- @warn " " [mat[i, j] for j in outneighbors (graph, i)]
371- @warn " " mat
372- @warn " " solution. path_value
365+ verbose && @warn " Flow is broken" i s1 s2
373366 return false
374367 end
375368 end
380373function compute_path_list (solution:: Solution )
381374 (; path_value) = solution
382375 paths = Vector{Int64}[]
383- for v in 1 : size (path_value, 1 )
376+ for v in axes (path_value, 1 )
384377 path = [1 ]
385378 for (i, elem) in enumerate (path_value[v, :])
386379 if elem == 1
0 commit comments