Skip to content

Commit 23c010b

Browse files
committed
Correct number of srcs in complete
When constructing the inverse match, `complete` was allocating a vector with length of the forward match. This isn't quite the right number. What you want is to use the actual number of srcs (or failing that the maximum number that appears in the matching). In practice, this was mostly working out, because an overestimate is fine here and usually there are more variables than equations, but there don't have to be in all places where Matching is used. Fix that by defaulting `complete` to the maximum used src and explicitly passing the correct number of sources in a few places.
1 parent 4b81cfa commit 23c010b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/bipartite_graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function Base.push!(m::Matching, v)
8888
end
8989
end
9090

91-
function complete(m::Matching{U}, N = length(m.match)) where {U}
91+
function complete(m::Matching{U}, N = maximum((x for x in m.match if isa(x, Int)); init=0)) where {U}
9292
m.inv_match !== nothing && return m
9393
inv_match = Union{U, Int}[unassigned for _ in 1:N]
9494
for (i, eq) in enumerate(m.match)

src/structural_transformation/partial_state_selection.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
5151
old_level_vars = ()
5252
ict = IncrementalCycleTracker(
5353
DiCMOBiGraph{true}(graph,
54-
complete(Matching(ndsts(graph))));
54+
complete(Matching(ndsts(graph)), nsrcs(graph))),
5555
dir = :in)
5656

5757
while level >= 0
@@ -124,7 +124,7 @@ function pss_graph_modia!(structure::SystemStructure, maximal_top_matching, varl
124124
level -= 1
125125
end
126126
end
127-
return complete(var_eq_matching)
127+
return complete(var_eq_matching, nsrcs(graph))
128128
end
129129

130130
struct SelectedUnknown end

0 commit comments

Comments
 (0)