diff --git a/src/bipartite_graph.jl b/src/bipartite_graph.jl index 6b73628007..5e7f637227 100644 --- a/src/bipartite_graph.jl +++ b/src/bipartite_graph.jl @@ -422,7 +422,7 @@ return `false` may not be matched. """ function maximal_matching(g::BipartiteGraph, srcfilter = vsrc -> true, dstfilter = vdst -> true, ::Type{U} = Unassigned) where {U} - matching = Matching{U}(ndsts(g)) + matching = Matching{U}(max(nsrcs(g), ndsts(g))) foreach(Iterators.filter(srcfilter, 𝑠vertices(g))) do vsrc construct_augmenting_path!(matching, g, vsrc, dstfilter) end diff --git a/src/systems/nonlinear/initializesystem.jl b/src/systems/nonlinear/initializesystem.jl index 07f3d3d135..3c9c14459b 100644 --- a/src/systems/nonlinear/initializesystem.jl +++ b/src/systems/nonlinear/initializesystem.jl @@ -14,7 +14,7 @@ function initializesystem(sys::ODESystem; name = nameof(sys), guesses = Dict(), u0 = Vector{Pair}(undef, 0) defs = ModelingToolkit.defaults(sys) - full_states = [sts;getfield.((observed(sys)),:lhs)] + full_states = [sts; getfield.((observed(sys)), :lhs)] # Refactor to ODESystem construction # should be ModelingToolkit.guesses(sys) @@ -28,26 +28,28 @@ function initializesystem(sys::ODESystem; name = nameof(sys), guesses = Dict(), def = defs[st] if def isa Equation - st ∉ keys(guesses) && error("Invalid setup: unknown $(st) has an initial condition equation with no guess.") - push!(eqs_ics,def) - push!(u0,st => guesses[st]) + st ∉ keys(guesses) && + error("Invalid setup: unknown $(st) has an initial condition equation with no guess.") + push!(eqs_ics, def) + push!(u0, st => guesses[st]) else - push!(eqs_ics,st ~ def) + push!(eqs_ics, st ~ def) push!(u0, st => def) end elseif st ∈ keys(guesses) - push!(u0,st => guesses[st]) + push!(u0, st => guesses[st]) else error("Invalid setup: unknown $(st) has no default value or initial guess") end end pars = parameters(sys) + nleqs = [eqs_ics; observed(sys)] - sys_nl = NonlinearSystem([eqs_ics; observed(sys)], + sys_nl = NonlinearSystem(nleqs, full_states, pars; - defaults = merge(ModelingToolkit.defaults(sys),todict(u0)), + defaults = merge(ModelingToolkit.defaults(sys), todict(u0)), name, kwargs...)