22 SimpleLazyGraph{T}
33A type representing a graph that computes its vertices and edges as needed.
44"""
5- mutable struct SimpleLazyGraph{T<: Integer } <: AbstractSimpleLazyGraph{T}
5+ mutable struct SimpleLazyGraph{T<: Integer ,I<: Function ,O<: Function } < :
6+ AbstractSimpleLazyGraph{T}
67 simple_graph:: SimpleGraph{T}
78
89 # boolean vectors to keep track of created neighbors
910 created_inneighbors:: Vector{Bool}
1011 created_outneighbors:: Vector{Bool}
1112
1213 # function to compute the in/outneighbors of a vertex
13- inneighbors_lazy:: Function
14- outneighbors_lazy:: Function
14+ inneighbors_lazy:: I
15+ outneighbors_lazy:: O
1516
16- function SimpleLazyGraph {T} (
17+ function SimpleLazyGraph (
1718 simple_graph:: SimpleGraph{T} ,
1819 created_inneighbors:: Vector{Bool} ,
1920 created_outneighbors:: Vector{Bool} ,
20- inneighbors_lazy:: Function ,
21- outneighbors_lazy:: Function ,
22- ) where {T}
21+ inneighbors_lazy:: I ,
22+ outneighbors_lazy:: O ,
23+ ) where {T,I,O }
2324 num_vertices = nv (simple_graph)
2425 if length (created_inneighbors) != num_vertices
2526 error (" Created inneighbors is not the same length as the number of vertices!" )
2627 end
2728 if length (created_outneighbors) != num_vertices
2829 error (" Created outneighbors is not the same length as the number of vertices!" )
2930 end
30- return new {T} (
31+ return new {T,I,O } (
3132 simple_graph,
3233 created_inneighbors,
3334 created_outneighbors,
@@ -37,15 +38,15 @@ mutable struct SimpleLazyGraph{T<:Integer} <: AbstractSimpleLazyGraph{T}
3738 end
3839end
3940
40- function SimpleLazyGraph {T} (
41+ function SimpleLazyGraph (
4142 simple_graph:: SimpleGraph{T} ,
42- inneighbors_lazy:: Function ,
43- outneighbors_lazy:: Function ,
44- ) where {T}
43+ inneighbors_lazy:: I ,
44+ outneighbors_lazy:: O ,
45+ ) where {T,I,O }
4546 num_vertices = nv (simple_graph)
4647 created_inneighbors = fill (false , num_vertices)
4748 created_outneighbors = fill (false , num_vertices)
48- return SimpleLazyGraph {T} (
49+ return SimpleLazyGraph (
4950 simple_graph,
5051 created_inneighbors,
5152 created_outneighbors,
@@ -54,21 +55,21 @@ function SimpleLazyGraph{T}(
5455 )
5556end
5657
57- function SimpleLazyGraph {T} (
58+ function SimpleLazyGraph (
5859 simple_graph:: SimpleGraph{T} ,
59- neighbors_lazy:: Function , # function to compute the neighbors of a vertex
60- ) where {T}
61- return SimpleLazyGraph {T} (simple_graph, neighbors_lazy, neighbors_lazy)
60+ neighbors_lazy:: N , # function to compute the neighbors of a vertex
61+ ) where {T,N }
62+ return SimpleLazyGraph (simple_graph, neighbors_lazy, neighbors_lazy)
6263end
6364
64- function SimpleLazyGraph (inneighbors_lazy:: Function , outneighbors_lazy:: Function )
65+ function SimpleLazyGraph (inneighbors_lazy:: I , outneighbors_lazy:: O ) where {I,O}
6566 simple_graph = SimpleGraph {Int} ()
66- return SimpleLazyGraph {Int} (simple_graph, inneighbors_lazy, outneighbors_lazy)
67+ return SimpleLazyGraph (simple_graph, inneighbors_lazy, outneighbors_lazy)
6768end
6869
6970function SimpleLazyGraph (
70- neighbors_lazy:: Function , # function to compute the neighbors of a vertex
71- )
71+ neighbors_lazy:: N , # function to compute the neighbors of a vertex
72+ ) where {N}
7273 return SimpleLazyGraph (neighbors_lazy, neighbors_lazy)
7374end
7475
@@ -137,15 +138,17 @@ function has_edge(g::AbstractSimpleLazyGraph, e::SimpleGraphEdge)
137138 return has_edge (g. simple_graph, e)
138139end
139140
140- function a_star_impl! (g:: AbstractSimpleGraph , # the graph
141+ function a_star_impl! (
142+ g:: AbstractSimpleGraph , # the graph
141143 goal, # the end vertex
142144 open_set, # an initialized heap containing the active vertices
143145 closed_set, # an (initialized) color-map to indicate status of vertices
144146 g_score, # a vector holding g scores for each node
145147 came_from, # a vector holding the parent of each node in the A* exploration
146148 distmx,
147149 heuristic,
148- edgetype_to_return:: Type{E} ) where {E<: AbstractEdge }
150+ edgetype_to_return:: Type{E} ,
151+ ) where {E<: AbstractEdge }
149152 total_path = Vector {edgetype_to_return} ()
150153
151154 @inbounds while ! isempty (open_set)
0 commit comments