Skip to content

Commit c10f533

Browse files
authored
Merge pull request #223 from JuliaReach/ueliwechsler/221
Fix affine system corner case
2 parents 80abafb + c4cbc4a commit c10f533

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/macros.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,20 @@ function _parse_system(exprs::NTuple{N, Expr}) where {N}
280280
dynamic_equation = stripped
281281
state_var = subject
282282
AT = abstract_system_type
283-
# if the system has the structure x_ = A_*x_ + B_*u_ ,
284-
# handle u_ as input variable
283+
# if the stripped system has the structure x_ = A_*x_ + B_*u_ or
284+
# one of the other patterns, handle u_ as input variable
285285
if @capture(stripped, (x_ = A_*x_ + B_*u_) |
286286
(x_ = x_ + B_*u_) |
287287
(x_ = A_*x_ + B_*u_ + c_) |
288288
(x_ = x_ + B_*u_ + c_) |
289289
(x_ = f_(x_, u_)) )
290-
input_var = u
290+
if (f == :+) || (f == :-) || (f == :*)
291+
# pattern x_ = f_(x_, u_) also catches the cases:
292+
# x_ = x_ + u_, x_ = x_ - u_ and x_ = x_*u_
293+
# where u_ doesn't necessarily need to be the input
294+
else
295+
input_var = u
296+
end
291297
end
292298

293299
elseif @capture(ex, (dim = (f_dims_)) | (dims = (f_dims_)))
@@ -407,14 +413,13 @@ function extract_dyn_equation_parameters(equation, state, input, noise, dim, AT)
407413
rhs = rhscode
408414
end
409415

410-
# if rhs is a sum, => affine system which is controlled, noisy or both
416+
# if rhs is parsed as addition => affine system which is controlled, noisy or both
411417
if @capture(rhs, A_ + B__)
412418
# parse summands of rhs and add * if needed
413419
summands = add_asterisk.([A, B...], Ref(state), Ref(input), Ref(noise))
414420
push!(rhs_params, extract_sum(summands, state, input, noise)...)
415-
416-
# If rhs is function call => black-box system
417-
elseif @capture(rhs, f_(a__)) && f != :(*) && f != :(-)
421+
# if rhs is a function call except `*` or `-` => black-box system
422+
elseif @capture(rhs, f_(a__)) && f != :(*) && f != :(-)
418423
# the dimension argument needs to be a iterable
419424
(dim == nothing) && throw(ArgumentError("for a blackbox system, the dimension has to be defined"))
420425
dim_vec = [dim...]

test/@system.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ end
139139
end
140140

141141
@testset "@system for affine continuous systems" begin
142-
@test @system(x' = A*x + c) == AffineContinuousSystem(A, c)
142+
b = [1.0]
143+
@test @system(x' = x + b) == AffineContinuousSystem(I(1), b)
144+
@test @system(x' = A*x + c) == AffineContinuousSystem(A, c)
143145
sys = @system(z_1' = A*z_1 + B*v_1 + c1, z_1 X, v_1 U1, input:v_1)
144146
@test sys == ConstrainedAffineControlContinuousSystem(A, B, c1, X, U1)
145147
@test_throws ArgumentError @system(x' = Ax + Bu + c) # not a system type

0 commit comments

Comments
 (0)