Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix homogenize #889

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/lib/systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ normalize(::InitialValueProblem)
ReachabilityAnalysis.add_dimension
```

## Homogeneization
## Homogenization

```@docs
homogenize
Expand Down
2 changes: 1 addition & 1 deletion docs/src/man/systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ in `MathematicalSystems.jl` for additional details in second order ODEs types.

## Normalization

## Homogeneization
## Homogenization

## Nonlinear systems

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# ====================================================
# Homogeneization of linear systems
# Homogenization of linear systems
# ====================================================

using ..DiscretizationModule: next_set

# no-op
homogenize(ivp::IVP{LCS{N,MT},ST}) where {N,MT<:AbstractMatrix{N},ST} = ivp
homogenize(sys::LCS{N,MT}) where {N,MT<:AbstractMatrix{N}} = sys

"""
homogenize(ivp::IVP{CLCCS{N,MT,IdentityMultiple{N},XT,ConstantInput{SI}},ST}) where {N, MT<:AbstractMatrix{N}, XT<:LazySet{N}, SI<:Singleton{N}, ST<:LazySet{N}}
homogenize(ivp::IVP{<:CLCCS{N,MTA,MTB,XT,UT},ST}) where {N, MTA<:AbstractMatrix{N},
MTB<:IdentityMultiple{N}, XT<:LazySet{N}, UT<:ConstantInput{<:Singleton{N}}, ST<:LazySet{N}}

Transform an inhomogeneous linear initial-value problem into an homogeneous one
Transform an inhomogeneous linear initial-value problem into a homogeneous one
by introducing auxiliary state variables.

### Input
Expand All @@ -23,33 +26,38 @@ Homogeneous initial-value problem.
### Notes

This function transforms the canonical initial-value problem ``x' = Ax + u``,
``x ∈ X`` with ``u(0) ∈ U = {u}`` (a singleton) into an homogeneous problem
``x ∈ X`` with ``u(0) ∈ U = {u}`` (a singleton) into a homogeneous problem
without inputs ``y' = Â * y``, ``y ∈ Y``.
"""
function homogenize(ivp::IVP{CLCCS{N,MT,IdentityMultiple{N},XT,ConstantInput{SI}},ST}) where {N,
MT<:AbstractMatrix{N},
XT<:LazySet{N},
SI<:Singleton{N},
ST<:LazySet{N}}
function homogenize(ivp::IVP{<:CLCCS{N,MTA,MTB,XT,UT},ST}) where {N,
MTA<:AbstractMatrix{N},
MTB<:IdentityMultiple{N},
XT<:LazySet{N},
UT<:ConstantInput{<:Singleton{N}},
ST<:LazySet{N}}
# homogenized state matrix
B = input_matrix(ivp)
@assert isone(B.M.λ) "input matrix should be normalized"
U = ReachabilityAnalysis.next_set(inputset(ivp))
A = state_matrix(ivp)
 = _homogenize_state_matrix(A, U)

# homogenized input set
# homogenized initial set
X0 = initial_state(ivp)
Y0 = _homogenize_initial_state(X0)

# homogenized state constraint
X = stateset(ivp)
Y = _homogenize_stateset(X)

ivph = IVP(CLCS(Â, Y), Y0)
return ivph
end

"""
homogenize(sys::SOACS)

Transform an inhomogeneous second order system into an homogeneous one
Transform an inhomogeneous second order system into a homogeneous one
by introducing auxiliary state variables.

### Input
Expand Down
2 changes: 1 addition & 1 deletion src/ReachabilityAnalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include("Flowpipes/solutions.jl")
# ===========================================================
include("Continuous/fields.jl")
include("Continuous/normalization.jl")
include("Continuous/homogeneization.jl")
include("Continuous/homogenization.jl")
include("Continuous/linearization.jl")

# ===========================================================
Expand Down
13 changes: 12 additions & 1 deletion test/algorithms/BOX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# continuous algorithm
sol = solve(ivp; tspan=tspan, alg=alg)
@test isa(sol.alg, BOX)
@test setrep(sol) <: Hyperrectangle
@test setrep(sol) == Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}
@test dim(sol) == 1
# discrete algorithm
Expand All @@ -15,6 +14,18 @@
NSTEPS = 500
fp_d = ReachabilityAnalysis.post(alg, ivp_discr, NSTEPS)

# homogenization
A = hcat(state_matrix(ivp))
X = stateset(ivp)
X0 = initial_state(ivp)
B = Id(1, 1.0) # TODO implement for different multiple
U = ConstantInput(Singleton([0.0]))
ivp2 = @ivp(ConstrainedLinearControlContinuousSystem(A, B, X, U), X(0) ∈ X0)
sol2 = solve(ivp2; tspan=(0.0, 1.0), alg=alg, homogenize=true)
@test isa(sol2.alg, BOX)
@test setrep(sol2) == Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}
@test dim(sol2) == 2

# higher-dimensional homogeneous
ivp, tspan = linear5D_homog()
sol = solve(ivp; tspan=tspan, alg=BOX(; δ=0.01))
Expand Down
Loading