@@ -13,6 +13,22 @@ function remove_dominated!(Mw::AbstractVector{R}, rq::R) where {R}
1313 return nothing
1414end
1515
16+ function dfs (graph:: G , v:: T ; out= true ) where {T,G<: AbstractGraph{T} }
17+ visited = falses (nv (graph))
18+ stack = [v]
19+ while ! isempty (stack)
20+ v = pop! (stack)
21+ if visited[v]
22+ continue
23+ end
24+ visited[v] = true
25+ for w in (out ? outneighbors (graph, v) : inneighbors (graph, v))
26+ push! (stack, w)
27+ end
28+ end
29+ return visited
30+ end
31+
1632# Topological order computing
1733function scan! (
1834 graph:: G , vertex:: T , order:: Vector{T} , opened:: BitVector
@@ -29,11 +45,19 @@ function scan!(
2945end
3046
3147function topological_order (graph:: G , s:: T , t:: T ) where {T,G<: AbstractGraph{T} }
48+ s_visited = dfs (graph, s; out= true )
49+ t_visited = dfs (graph, t; out= false )
50+ visited = s_visited .& t_visited
51+
3252 order = Int[]
3353 opened = falses (nv (graph))
3454 scan! (graph, s, order, opened)
3555
36- start = findfirst (x -> (x == t), order) # Can we do smarter than that ?
37- @assert ! isnothing (start)
38- return order[start: end ]
56+ res = [o for o in order if visited[o]]
57+ @assert res[1 ] == t
58+ return res
59+
60+ # start = findfirst(x -> (x == t), order) # Can we do smarter than that ?
61+ # @assert !isnothing(start)
62+ # return order[start:end]
3963end
0 commit comments