Skip to content

Commit d72dc78

Browse files
committed
Improve type stability of algorithms
1 parent 683c047 commit d72dc78

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/algorithms.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +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)}()
12+
bounds = Dict{Int,BR}()
1313
# bounds = Vector{typeof(instance.destination_backward_resource)}(undef, nv(graph))
1414
bounds[destination_vertex] = instance.destination_backward_resource
1515

@@ -30,7 +30,7 @@ $TYPEDSIGNATURES
3030
Perform generalized A star algorithm on instnace using bounds
3131
(see [Generalized `A^\\star`](@ref)).
3232
"""
33-
function generalized_a_star(instance::CSPInstance, bounds; kwargs...)
33+
function generalized_a_star(instance::CSPInstance{T,G,FR}, bounds; kwargs...) where {T,G,FR}
3434
(; graph, origin_vertex, destination_vertex, is_useful) = instance
3535
nb_vertices = nv(graph)
3636

@@ -42,8 +42,8 @@ function generalized_a_star(instance::CSPInstance, bounds; kwargs...)
4242
instance.cost_function(forward_resources[empty_path], bounds[origin_vertex]),
4343
)
4444

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

src/utils/utils.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ 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)
13+
# to_delete = Int[]
14+
# for (i, r) in enumerate(Mw)
15+
# if rq <= r
16+
# push!(to_delete, i)
17+
# end
18+
# end
19+
# deleteat!(Mw, to_delete)
1820
return nothing
1921
end
2022

0 commit comments

Comments
 (0)