Skip to content

Commit 8ce1efd

Browse files
committed
More comments
1 parent 5ce2514 commit 8ce1efd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/structural_transformation/pantelides.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,20 @@ function computed_highest_diff_variables(structure, ag::Union{AliasGraph, Nothin
104104
varwhitelist = falses(nvars)
105105
for var in 1:nvars
106106
if var_to_diff[var] === nothing && !varwhitelist[var]
107+
# This variable is structurally highest-differentiated, but may not actually appear in the
108+
# system (complication 1 above). Ascend the differentiation graph to find the highest
109+
# differentiated variable that does appear in the system or the alias graph).
107110
while isempty(𝑑neighbors(graph, var)) && (ag === nothing || !haskey(ag, var))
108111
var′ = invview(var_to_diff)[var]
109112
var′ === nothing && break
110113
var = var′
111114
end
115+
# If we don't have an alias graph, we are done. If we do have an alias graph, we may
116+
# have to keep going along the stem, for as long as our differentiation path
117+
# matches that of the stem (see complication 2 above). Note that we may end up
118+
# whitelisting multiple differentiation levels of the stem here from different
119+
# starting points that all map to the same stem. We clean that up in a post-processing
120+
# pass below.
112121
if ag !== nothing && haskey(ag, var)
113122
(_, stem) = ag[var]
114123
stem == 0 && continue
@@ -134,7 +143,7 @@ function computed_highest_diff_variables(structure, ag::Union{AliasGraph, Nothin
134143
end
135144

136145
# Remove any variables from the varwhitelist for whom a higher-differentiated
137-
# var is already on the whitelist
146+
# var is already on the whitelist.
138147
for var in 1:nvars
139148
varwhitelist[var] || continue
140149
var′ = var

0 commit comments

Comments
 (0)