11
22using . BipartiteGraphs: Label, BipartiteAdjacencyList
3+
4+ struct SSAUses{T}
5+ eqs:: Vector{T} # equation uses
6+ vars:: Vector{T} # variable uses
7+ end
8+ Base. eltype(info:: SSAUses{T} ) where {T} = T
9+ Base. copy(uses:: SSAUses ) = SSAUses(copy(uses. eqs), copy(uses. vars))
10+
11+ ssa_uses(:: SystemStructure ) = nothing
12+
313struct SystemStructurePrintMatrix < :
414 AbstractMatrix{Union{Label, BipartiteAdjacencyList}}
515 bpg:: BipartiteGraph
616 highlight_graph:: Union{Nothing, BipartiteGraph}
717 var_to_diff:: DiffGraph
818 eq_to_diff:: DiffGraph
919 var_eq_matching:: Union{Matching, Nothing}
20+ ssa_uses:: Union{Nothing, SSAUses}
1021end
1122
1223"""
@@ -19,31 +30,36 @@ function SystemStructurePrintMatrix(s::SystemStructure)
1930 complete(s. solvable_graph),
2031 complete(s. var_to_diff),
2132 complete(s. eq_to_diff),
22- nothing )
33+ nothing ,
34+ ssa_uses(s))
2335end
24- Base. size(bgpm:: SystemStructurePrintMatrix ) = (max(nsrcs(bgpm. bpg), ndsts(bgpm. bpg)) + 1 , 9 )
36+ Base. size(bgpm:: SystemStructurePrintMatrix ) = (max(nsrcs(bgpm. bpg), ndsts(bgpm. bpg)) + 1 , 9 + 2 (bgpm . ssa_uses != = nothing ) )
2537function compute_diff_label(diff_graph, i, symbol)
2638 di = i - 1 <= length(diff_graph) ? diff_graph[i - 1 ] : nothing
2739 return di === nothing ? Label(" " ) : Label(string(di, symbol))
2840end
2941function Base. getindex(bgpm:: SystemStructurePrintMatrix , i:: Integer , j:: Integer )
3042 checkbounds(bgpm, i, j)
43+ if bgpm. ssa_uses === nothing
44+ # Skip SSAUse-related columns.
45+ j += j ≥ 5 + j ≥ 11
46+ end
3147 if i <= 1
32- return (Label.((" # eq" , " ∂ₜ" , " " , " " , " " , " # v" , " ∂ₜ" , " " , " " )))[j]
33- elseif j == 5
48+ return (Label.((" # eq" , " ∂ₜ" , " " , " " , " % " , " " , " # v" , " ∂ₜ" , " " , " " , " % " )))[j]
49+ elseif j == 6
3450 colors = Base. text_colors
3551 return Label(" |" , :light_black)
3652 elseif j == 2
3753 return compute_diff_label(bgpm. eq_to_diff, i, ' ↑' )
3854 elseif j == 3
3955 return compute_diff_label(invview(bgpm. eq_to_diff), i, ' ↓' )
40- elseif j == 7
41- return compute_diff_label(bgpm. var_to_diff, i, ' ↑' )
4256 elseif j == 8
57+ return compute_diff_label(bgpm. var_to_diff, i, ' ↑' )
58+ elseif j == 9
4359 return compute_diff_label(invview(bgpm. var_to_diff), i, ' ↓' )
4460 elseif j == 1
4561 return Label((i - 1 <= length(bgpm. eq_to_diff)) ? string(i - 1 ) : " " )
46- elseif j == 6
62+ elseif j == 7
4763 return Label((i - 1 <= length(bgpm. var_to_diff)) ? string(i - 1 ) : " " )
4864 elseif j == 4
4965 return BipartiteAdjacencyList(
@@ -56,7 +72,11 @@ function Base.getindex(bgpm::SystemStructurePrintMatrix, i::Integer, j::Integer)
5672 bgpm. var_eq_matching != = nothing &&
5773 (i - 1 <= length(invview(bgpm. var_eq_matching))) ?
5874 invview(bgpm. var_eq_matching)[i - 1 ] : unassigned)
59- elseif j == 9
75+ elseif j == 5
76+ return get(bgpm. ssa_uses. eqs, i - 1 , Label(" " ))
77+ elseif j == 11
78+ return get(bgpm. ssa_uses. vars, i - 1 , Label(" " ))
79+ elseif j == 10
6080 match = unassigned
6181 if bgpm. var_eq_matching != = nothing && i - 1 <= length(bgpm. var_eq_matching)
6282 match = bgpm. var_eq_matching[i - 1 ]
95115struct MatchedSystemStructure
96116 structure:: SystemStructure
97117 var_eq_matching:: Matching
118+ ssa_uses:: Union{Nothing, SSAUses}
98119end
120+ MatchedSystemStructure(structure, var_eq_matching) = MatchedSystemStructure(structure, var_eq_matching, nothing )
121+
122+ ssa_uses(ms:: MatchedSystemStructure ) = ms. ssa_uses
99123
100124"""
101125Create a SystemStructurePrintMatrix to display the contents
@@ -106,12 +130,12 @@ function SystemStructurePrintMatrix(ms::MatchedSystemStructure)
106130 complete(ms. structure. solvable_graph),
107131 complete(ms. structure. var_to_diff),
108132 complete(ms. structure. eq_to_diff),
109- complete(ms. var_eq_matching,
110- nsrcs( ms. structure . graph)) )
133+ complete(ms. var_eq_matching, nsrcs(ms . structure . graph)),
134+ ms. ssa_uses )
111135end
112136
113137function Base. copy(ms:: MatchedSystemStructure )
114- MatchedSystemStructure(Base . copy(ms. structure), Base . copy(ms. var_eq_matching))
138+ MatchedSystemStructure(copy(ms. structure), copy(ms. var_eq_matching), copy(ms . ssa_uses ))
115139end
116140
117141function Base. show(io:: IO , mime:: MIME"text/plain" , ms:: MatchedSystemStructure )
@@ -136,4 +160,11 @@ function Base.show(io::IO, mime::MIME"text/plain", ms::MatchedSystemStructure)
136160 printstyled(io, string(" " , symbol); color)
137161 printstyled(io, string(" " , label))
138162 end
163+ if ms. ssa_uses != = nothing
164+ T = eltype(ms. ssa_uses)
165+ (symbol, label, color) = BipartiteGraphs. overview_label(T)
166+ print(io, " | " )
167+ printstyled(io, string(" " , symbol); color)
168+ printstyled(io, string(" " , label))
169+ end
139170end
0 commit comments