Skip to content

Commit 1f7851c

Browse files
refactor: improve observed_dependency_graph and add docstrings
1 parent 0f527f2 commit 1f7851c

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
@@ -998,29 +998,27 @@ function is_variable_floatingpoint(sym)
998998
T <: AbstractArray{<:AbstractFloat}
999999
end
10001000

1001+
"""
1002+
$(TYPEDSIGNATURES)
1003+
1004+
Return the `DiCMOBiGraph` denoting the dependencies between observed equations `eqs`.
1005+
"""
10011006
function observed_dependency_graph(eqs::Vector{Equation})
10021007
for eq in eqs
10031008
if symbolic_type(eq.lhs) == NotSymbolic()
10041009
error("All equations must be observed equations of the form `var ~ expr`. Got $eq")
10051010
end
10061011
end
1007-
1008-
idxmap = Dict(eq.lhs => i for (i, eq) in enumerate(eqs))
1009-
g = SimpleDiGraph(length(eqs))
1010-
1011-
syms = Set()
1012-
for (i, eq) in enumerate(eqs)
1013-
vars!(syms, eq)
1014-
for sym in syms
1015-
idx = get(idxmap, sym, nothing)
1016-
idx === nothing && continue
1017-
add_edge!(g, i, idx)
1018-
end
1019-
end
1020-
1021-
return g
1012+
graph, assigns = observed2graph(eqs, getproperty.(eqs, (:lhs,)))
1013+
matching = complete(Matching(Vector{Union{Unassigned, Int}}(assigns)))
1014+
return DiCMOBiGraph{false}(graph, matching)
10221015
end
10231016

1017+
"""
1018+
$(TYPEDSIGNATURES)
1019+
1020+
Return the indexes of observed equations of `sys` used by expression `exprs`.
1021+
"""
10241022
function observed_equations_used_by(sys::AbstractSystem, exprs)
10251023
obs = observed(sys)
10261024

0 commit comments

Comments
 (0)