Skip to content

Commit f0dc472

Browse files
refactor: move constraints to abstractsystem.jl
1 parent 27a9b1f commit f0dc472

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/systems/abstractsystem.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,30 @@ function cost(sys::AbstractSystem)
17531753
return consolidate(cs, subcosts)
17541754
end
17551755

1756+
namespace_constraint(eq::Equation, sys) = namespace_equation(eq, sys)
1757+
1758+
namespace_constraint(ineq::Inequality, sys) = namespace_inequality(ineq, sys)
1759+
1760+
function namespace_inequality(ineq::Inequality, sys, n = nameof(sys))
1761+
_lhs = namespace_expr(ineq.lhs, sys, n)
1762+
_rhs = namespace_expr(ineq.rhs, sys, n)
1763+
Inequality(_lhs,
1764+
_rhs,
1765+
ineq.relational_op)
1766+
end
1767+
1768+
function namespace_constraints(sys)
1769+
cstrs = constraints(sys)
1770+
isempty(cstrs) && return Vector{Union{Equation, Inequality}}(undef, 0)
1771+
map(cstr -> namespace_constraint(cstr, sys), cstrs)
1772+
end
1773+
1774+
function constraints(sys)
1775+
cs = get_constraints(sys)
1776+
systems = get_systems(sys)
1777+
isempty(systems) ? cs : [cs; reduce(vcat, namespace_constraints.(systems))]
1778+
end
1779+
17561780
"""
17571781
$(TYPEDSIGNATURES)
17581782

0 commit comments

Comments
 (0)