@@ -2,15 +2,30 @@ using SymbolicUtils: Rewriters
2
2
3
3
const KEEP = typemin (Int)
4
4
5
- function alias_elimination (sys)
5
+ function alias_eliminate_graph (sys:: AbstractSystem )
6
6
sys = initialize_system_structure (sys; quick_cancel= true )
7
7
s = structure (sys)
8
8
9
9
mm = linear_subsys_adjmat (sys)
10
- size (mm, 1 ) == 0 && return sys # No linear subsystems
10
+ size (mm, 1 ) == 0 && return sys, nothing , mm # No linear subsystems
11
11
12
12
ag, mm = alias_eliminate_graph! (s. graph, complete (s. var_to_diff), mm)
13
+ return sys, ag, mm
14
+ end
15
+
16
+ # For debug purposes
17
+ function aag_bareiss (sys:: AbstractSystem )
18
+ sys = initialize_system_structure (sys; quick_cancel= true )
19
+ s = structure (sys)
20
+ mm = linear_subsys_adjmat (sys)
21
+ return aag_bareiss! (s. graph, complete (s. var_to_diff), mm)
22
+ end
23
+
24
+ function alias_elimination (sys)
25
+ sys, ag, mm = alias_eliminate_graph (sys)
26
+ ag === nothing && return sys
13
27
28
+ s = structure (sys)
14
29
@unpack fullvars, graph = s
15
30
16
31
subs = OrderedDict ()
@@ -193,9 +208,7 @@ count_nonzeros(a::AbstractArray) = count(!iszero, a)
193
208
# Here we have a guarantee that they won't, so we can make this identification
194
209
count_nonzeros (a:: SparseVector ) = nnz (a)
195
210
196
- function alias_eliminate_graph! (graph, var_to_diff, mm_orig:: SparseMatrixCLIL )
197
- diff_to_var = invview (var_to_diff)
198
-
211
+ function aag_bareiss! (graph, var_to_diff, mm_orig:: SparseMatrixCLIL )
199
212
mm = copy (mm_orig)
200
213
is_linear_equations = falses (size (AsSubMatrix (mm_orig), 1 ))
201
214
for e in mm_orig. nzrows
@@ -245,10 +258,10 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
245
258
(rank1, rank2, rank3, pivots)
246
259
end
247
260
248
- # mm2 = Array(copy(mm))
249
- # @show do_bareiss!(mm2)
250
- # display(mm2)
261
+ return mm, solvable_variables, do_bareiss! (mm, mm_orig)
262
+ end
251
263
264
+ function alias_eliminate_graph! (graph, var_to_diff, mm_orig:: SparseMatrixCLIL )
252
265
# Step 1: Perform bareiss factorization on the adjacency matrix of the linear
253
266
# subsystem of the system we're interested in.
254
267
#
@@ -261,7 +274,8 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
261
274
# -------------------|------------------------
262
275
# rank3 | [ 0 0 | M₃₃ M₃₄ ] [v₃] = [0]
263
276
# [ 0 0 | 0 0 ] [v₄] = [0]
264
- (rank1, rank2, rank3, pivots) = do_bareiss! (mm, mm_orig)
277
+ mm, solvable_variables, (rank1, rank2, rank3, pivots) =
278
+ aag_bareiss! (graph, var_to_diff, mm_orig)
265
279
266
280
# Step 2: Simplify the system using the Bareiss factorization
267
281
ag = AliasGraph (size (mm, 2 ))
@@ -272,6 +286,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
272
286
# Kind of like the backward substitution, but we don't actually rely on it
273
287
# being lower triangular. We eliminate a variable if there are at most 2
274
288
# variables left after the substitution.
289
+ diff_to_var = invview (var_to_diff)
275
290
function lss! (ei:: Integer )
276
291
vi = pivots[ei]
277
292
# the lowest differentiated variable can be eliminated
0 commit comments