Skip to content

Commit 9a3b275

Browse files
refactor: improve observed_dependency_graph and add docstrings
1 parent e9d1ab8 commit 9a3b275

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
@@ -1009,29 +1009,27 @@ function is_variable_floatingpoint(sym)
10091009
T <: AbstractArray{<:AbstractFloat}
10101010
end
10111011

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

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

0 commit comments

Comments
 (0)