Skip to content

Commit 6b7808f

Browse files
authored
Merge pull request #30 from BatyLeo/improve-type-stability
Improve type stability of algorithms
2 parents 683c047 + 6ed7c88 commit 6b7808f

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
lines changed

CITATION.bib

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ @misc{ConstrainedShortestPaths.jl
22
author = {Léo Baty and contributors},
33
title = {ConstrainedShortestPaths.jl},
44
url = {https://github.com/BatyLeo/ConstrainedShortestPaths.jl},
5-
version = {v0.6.2},
5+
version = {v0.6.3},
66
year = {2024},
77
month = {12}
88
}

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ConstrainedShortestPaths"
22
uuid = "b3798467-87dc-4d99-943d-35a1bd39e395"
33
authors = ["Léo Baty and contributors"]
4-
version = "0.6.2"
4+
version = "0.6.3"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/algorithms.jl

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ $TYPEDSIGNATURES
33
44
Compute backward bounds of instance (see [Computing bounds](@ref)).
55
"""
6-
function compute_bounds(instance::CSPInstance; kwargs...)
6+
function compute_bounds(instance::CSPInstance{T,G,FR,BR}; kwargs...) where {T,G,FR,BR}
77
(; graph, destination_vertex, topological_ordering, is_useful) = instance
88

99
vertices_order = topological_ordering
1010
@assert vertices_order[1] == destination_vertex
1111

12-
bounds = Dict{Int,typeof(instance.destination_backward_resource)}()
13-
# bounds = Vector{typeof(instance.destination_backward_resource)}(undef, nv(graph))
12+
bounds = Dict{Int,BR}()
1413
bounds[destination_vertex] = instance.destination_backward_resource
1514

1615
for vertex in vertices_order[2:end]
@@ -30,7 +29,7 @@ $TYPEDSIGNATURES
3029
Perform generalized A star algorithm on instnace using bounds
3130
(see [Generalized `A^\\star`](@ref)).
3231
"""
33-
function generalized_a_star(instance::CSPInstance, bounds; kwargs...)
32+
function generalized_a_star(instance::CSPInstance{T,G,FR}, bounds; kwargs...) where {T,G,FR}
3433
(; graph, origin_vertex, destination_vertex, is_useful) = instance
3534
nb_vertices = nv(graph)
3635

@@ -42,8 +41,8 @@ function generalized_a_star(instance::CSPInstance, bounds; kwargs...)
4241
instance.cost_function(forward_resources[empty_path], bounds[origin_vertex]),
4342
)
4443

45-
forward_type = typeof(forward_resources[empty_path])
46-
M = [forward_type[] for _ in 1:nb_vertices]
44+
# forward_type = typeof(forward_resources[empty_path])
45+
M = [FR[] for _ in 1:nb_vertices]
4746
push!(M[origin_vertex], forward_resources[empty_path])
4847
c_star = Inf
4948
p_star = [origin_vertex]

src/utils/utils.jl

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ function is_dominated(rq::F, Mw::Vector{F}) where {F}
77
return false
88
end
99

10+
# Remove all elements in Mw that are dominated by rq
1011
function remove_dominated!(Mw::AbstractVector{R}, rq::R) where {R}
11-
to_delete = Int[]
12-
for (i, r) in enumerate(Mw)
13-
if rq <= r
14-
push!(to_delete, i)
15-
end
16-
end
17-
deleteat!(Mw, to_delete)
12+
filter!(r -> !(rq <= r), Mw)
1813
return nothing
1914
end
2015

test/code.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ end
77

88
@testset "Correctness (JET.jl)" begin
99
using JET
10-
if VERSION >= v"1.8"
11-
JET.test_package(ConstrainedShortestPaths; toplevel_logger=nothing, mode=:typo)
12-
end
10+
JET.test_package(ConstrainedShortestPaths; target_modules=[ConstrainedShortestPaths])
1311
end
1412

1513
@testset "Formatting (JuliaFormatter.jl)" begin

0 commit comments

Comments
 (0)