Skip to content

Commit beb7070

Browse files
refactor: improve observed_dependency_graph and add docstrings
1 parent 26269d9 commit beb7070

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/utils.jl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,29 +1008,27 @@ function is_variable_floatingpoint(sym)
10081008
T <: AbstractArray{<:AbstractFloat}
10091009
end
10101010

1011+
"""
1012+
$(TYPEDSIGNATURES)
1013+
1014+
Return the `DiCMOBiGraph` denoting the dependencies between observed equations `eqs`.
1015+
"""
10111016
function observed_dependency_graph(eqs::Vector{Equation})
10121017
for eq in eqs
10131018
if symbolic_type(eq.lhs) == NotSymbolic()
10141019
error("All equations must be observed equations of the form `var ~ expr`. Got $eq")
10151020
end
10161021
end
1017-
1018-
idxmap = Dict(eq.lhs => i for (i, eq) in enumerate(eqs))
1019-
g = SimpleDiGraph(length(eqs))
1020-
1021-
syms = Set()
1022-
for (i, eq) in enumerate(eqs)
1023-
vars!(syms, eq)
1024-
for sym in syms
1025-
idx = get(idxmap, sym, nothing)
1026-
idx === nothing && continue
1027-
add_edge!(g, i, idx)
1028-
end
1029-
end
1030-
1031-
return g
1022+
graph, assigns = observed2graph(eqs, getproperty.(eqs, (:lhs,)))
1023+
matching = complete(Matching(Vector{Union{Unassigned, Int}}(assigns)))
1024+
return DiCMOBiGraph{false}(graph, matching)
10321025
end
10331026

1027+
"""
1028+
$(TYPEDSIGNATURES)
1029+
1030+
Return the indexes of observed equations of `sys` used by expression `exprs`.
1031+
"""
10341032
function observed_equations_used_by(sys::AbstractSystem, exprs)
10351033
obs = observed(sys)
10361034

0 commit comments

Comments
 (0)