@@ -2,18 +2,72 @@ using SymbolicUtils: Rewriters
2
2
3
3
const KEEP = typemin (Int)
4
4
5
- function alias_eliminate_graph (sys)
5
+ function alias_eliminate (sys)
6
6
sys = flatten (sys)
7
7
s = get_structure (sys)
8
8
if ! (s isa SystemStructure)
9
9
sys = initialize_system_structure (sys)
10
10
s = structure (sys)
11
11
end
12
+ is_linear_equations, eadj, cadj = find_linear_equations (sys)
13
+
14
+ sys, v_eliminated, v_types, n_null_vars, degenerate_equations, linear_equations = alias_eliminate_graph (
15
+ s, is_linear_equations, eadj, cadj
16
+ )
17
+
18
+ s = structure (sys)
19
+ @unpack fullvars = s
20
+
21
+ subs = Dict ()
22
+ if length (v_eliminated) - n_null_vars > 0
23
+ for v in v_eliminated[n_null_vars+ 1 : end ]
24
+ subs[fullvars[v]] = iszeroterm (v_types, v) ? 0.0 :
25
+ isalias (v_types, v) ? fullvars[alias (v_types, v)] :
26
+ - fullvars[negalias (v_types, v)]
27
+ end
28
+ end
29
+
30
+ dels = Int[]
31
+ eqs = copy (equations (sys))
32
+ for (ei, e) in enumerate (linear_equations)
33
+ vs = 𝑠vertices (graph, e)
34
+ if isempty (vs)
35
+ push! (dels, e)
36
+ else
37
+ rhs = 0
38
+ for vj in eachindex (vs)
39
+ var = fullvars[vs[vj]]
40
+ rhs += cadj[ei][vj] * var
41
+ end
42
+ eqs[e] = 0 ~ rhs
43
+ end
44
+ end
45
+ deleteat! (eqs, dels)
46
+
47
+ for (ieq, eq) in enumerate (eqs)
48
+ if ! isdiffeq (eq) && ! _iszero (eq. lhs)
49
+ eq = 0 ~ eq. rhs - eq. lhs
50
+ end
51
+ eqs[ieq] = eq. lhs ~ fixpoint_sub (eq. rhs, dict)
52
+ end
12
53
54
+ newstates = []
55
+ sts = states (sys)
56
+ for j in eachindex (sts)
57
+ if isirreducible (v_types, j)
58
+ isdervar (s, j) || push! (newstates, fullvars[j])
59
+ end
60
+ end
61
+
62
+ @set sys. structure = nothing
63
+ @set sys. states = newstates
64
+ return sys
65
+ end
66
+
67
+ function alias_eliminate_graph (s:: SystemStructure , is_linear_variables, eadj, cadj)
13
68
@unpack graph, varassoc = s
14
69
invvarassoc = inverse_mapping (varassoc)
15
70
16
- is_linear_equations, eadj, cadj = find_linear_equations (sys)
17
71
old_cadj = map (copy, cadj)
18
72
19
73
is_not_potential_state = iszero .(varassoc)
@@ -94,7 +148,7 @@ function alias_eliminate_graph(sys)
94
148
end
95
149
96
150
degenerate_equations = rank3 < length (linear_equations) ? linear_equations[rank3+ 1 : end ] : Int[]
97
- return v_eliminated, v_types, n_null_vars, degenerate_equations
151
+ return v_eliminated, v_types, n_null_vars, degenerate_equations, linear_equations
98
152
end
99
153
100
154
iszeroterm (v_types, v) = v_types[v] == 0
0 commit comments