@@ -28,8 +28,13 @@ function ascend_dg_all(xs, dg, level, maxlevel)
2828 return r
2929end
3030
31- function pss_graph_modia!(structure:: SystemStructure , maximal_top_matching, varlevel,
32- inv_varlevel, inv_eqlevel)
31+ struct DiffData
32+ varlevel:: Vector{Int}
33+ inv_varlevel:: Vector{Int}
34+ inv_eqlevel:: Vector{Int}
35+ end
36+
37+ function pss_graph_modia!(structure:: SystemStructure , maximal_top_matching, diff_data:: Union{Nothing, DiffData} = nothing )
3338 @unpack eq_to_diff, var_to_diff, graph, solvable_graph = structure
3439
3540 # var_eq_matching is a maximal matching on the top-differentiated variables.
@@ -47,19 +52,19 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
4752 eqs = [maximal_top_matching[var]
4853 for var in vars if maximal_top_matching[var] != = unassigned]
4954 isempty(eqs) && continue
50- maxeqlevel = maximum(map(x -> inv_eqlevel[x], eqs))
51- maxvarlevel = level = maximum(map(x -> inv_varlevel[x], vars))
55+ maxeqlevel = diff_data === nothing ? 0 : maximum(map(x -> diff_data . inv_eqlevel[x], eqs))
56+ maxvarlevel = level = diff_data === nothing ? 0 : maximum(map(x -> diff_data . inv_varlevel[x], vars))
5257 old_level_vars = ()
5358 ict = IncrementalCycleTracker(
5459 DiCMOBiGraph{true }(graph,
5560 complete(Matching(ndsts(graph)), nsrcs(graph))),
5661 dir = :in)
5762
5863 while level >= 0
59- to_tear_eqs_toplevel = filter(eq -> inv_eqlevel[eq] >= level, eqs)
64+ to_tear_eqs_toplevel = level == 0 ? eqs : filter(eq -> diff_data . inv_eqlevel[eq] >= level, eqs)
6065 to_tear_eqs = ascend_dg(to_tear_eqs_toplevel, invview(eq_to_diff), level)
6166
62- to_tear_vars_toplevel = filter(var -> inv_varlevel[var] >= level, vars)
67+ to_tear_vars_toplevel = level == 0 ? vars : filter(var -> diff_data . inv_varlevel[var] >= level, vars)
6368 to_tear_vars = ascend_dg(to_tear_vars_toplevel, invview(var_to_diff), level)
6469
6570 assigned_eqs = Int[]
@@ -163,8 +168,8 @@ function partial_state_selection_graph!(structure::SystemStructure, var_eq_match
163168 end
164169
165170 var_eq_matching = pss_graph_modia!(structure,
166- complete(var_eq_matching), varlevel, inv_varlevel,
167- inv_eqlevel)
171+ complete(var_eq_matching), DiffData( varlevel, inv_varlevel,
172+ inv_eqlevel))
168173
169174 var_eq_matching
170175end
0 commit comments