-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontinuous.jl
306 lines (259 loc) · 8.11 KB
/
continuous.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
"""
ContinuousIdentitySystem <: AbstractContinuousSystem
Trivial identity continuous-time system of the form
```math
x' = 0.
```
"""
struct ContinuousIdentitySystem <: AbstractContinuousSystem
statedim::Int
end
statedim(s::ContinuousIdentitySystem) = s.statedim
inputdim(s::ContinuousIdentitySystem) = 0
"""
ConstrainedContinuousIdentitySystem <: AbstractContinuousSystem
Trivial identity continuous-time system with state constraints of the form
```math
x' = 0, x(t) ∈ \\mathcal{X}.
```
"""
struct ConstrainedContinuousIdentitySystem{ST} <: AbstractContinuousSystem
statedim::Int
X::ST
end
statedim(s::ConstrainedContinuousIdentitySystem) = s.statedim
stateset(s::ConstrainedContinuousIdentitySystem) = s.X
inputdim(s::ConstrainedContinuousIdentitySystem) = 0
"""
LinearContinuousSystem
Continuous-time linear system of the form
```math
x' = A x.
```
### Fields
- `A` -- square matrix
"""
struct LinearContinuousSystem{T, MT <: AbstractMatrix{T}} <: AbstractContinuousSystem
A::MT
end
@static if VERSION < v"0.7-"
LinearContinuousSystem{T, MT <: AbstractMatrix{T}}(A::MT) = LinearContinuousSystem{T, MT}(A)
end
statedim(s::LinearContinuousSystem) = checksquare(s.A)
inputdim(s::LinearContinuousSystem) = 0
"""
AffineContinuousSystem
Continuous-time affine system of the form
```math
x' = A x + b.
```
### Fields
- `A` -- square matrix
- `b` -- vector
"""
struct AffineContinuousSystem{T, MT <: AbstractMatrix{T}, VT <: AbstractVector{T}} <: AbstractContinuousSystem
A::MT
b::VT
function AffineContinuousSystem(A::MT, b::VT) where {T, MT <: AbstractMatrix{T}, VT <: AbstractVector{T}}
@assert checksquare(A) == length(b)
return new{T, MT, VT}(A, b)
end
end
statedim(s::AffineContinuousSystem) = length(s.b)
inputdim(s::AffineContinuousSystem) = 0
"""
LinearControlContinuousSystem
Continuous-time linear control system of the form
```math
x' = A x + B u.
```
### Fields
- `A` -- square matrix
- `B` -- matrix
"""
struct LinearControlContinuousSystem{T, MT <: AbstractMatrix{T}} <: AbstractContinuousSystem
A::MT
B::MT
function LinearControlContinuousSystem(A::MT, B::MT) where {T, MT <: AbstractMatrix{T}}
@assert checksquare(A) == size(B, 1)
return new{T, MT}(A, B)
end
end
statedim(s::LinearControlContinuousSystem) = checksquare(s.A)
inputdim(s::LinearControlContinuousSystem) = size(s.B, 2)
"""
ConstrainedLinearContinuousSystem
Continuous-time linear system with state constraints of the form
```math
x' = A x, x(t) ∈ \\mathcal{X}.
```
### Fields
- `A` -- square matrix
- `X` -- state constraints
"""
struct ConstrainedLinearContinuousSystem{T, MT <: AbstractMatrix{T}, ST} <: AbstractContinuousSystem
A::MT
X::ST
end
@static if VERSION < v"0.7-"
ConstrainedLinearContinuousSystem{T, MT <: AbstractMatrix{T}, ST}(A::MT, X::ST) = ConstrainedLinearContinuousSystem{T, MT, ST}(A, X)
end
statedim(s::ConstrainedLinearContinuousSystem) = checksquare(s.A)
stateset(s::ConstrainedLinearContinuousSystem) = s.X
inputdim(s::ConstrainedLinearContinuousSystem) = 0
"""
ConstrainedAffineContinuousSystem
Continuous-time affine system with state constraints of the form
```math
x' = A x + b, x(t) ∈ \\mathcal{X}.
```
### Fields
- `A` -- square matrix
- `b` -- vector
- `X` -- state constraints
"""
struct ConstrainedAffineContinuousSystem{T, MT <: AbstractMatrix{T}, VT <: AbstractVector{T}, ST} <: AbstractContinuousSystem
A::MT
b::VT
X::ST
function ConstrainedAffineContinuousSystem(A::MT, b::VT, X::ST) where {T, MT <: AbstractMatrix{T}, VT <: AbstractVector{T}, ST}
@assert checksquare(A) == length(b)
return new{T, MT, VT, ST}(A, b, X)
end
end
statedim(s::ConstrainedAffineContinuousSystem) = length(s.b)
stateset(s::ConstrainedAffineContinuousSystem) = s.X
inputdim(s::ConstrainedAffineContinuousSystem) = 0
"""
ConstrainedAffineControlContinuousSystem
Continuous-time affine control system with state constraints of the form
```math
x' = A x + B u + c, x(t) ∈ \\mathcal{X}, u(t) ∈ \\mathcal{U} \\text{ for all } t,
```
and ``c`` a vector.
### Fields
- `A` -- square matrix
- `B` -- matrix
- `c` -- vector
- `X` -- state constraints
- `U` -- input constraints
"""
struct ConstrainedAffineControlContinuousSystem{T, MT <: AbstractMatrix{T}, VT <: AbstractVector{T}, ST, UT} <: AbstractContinuousSystem
A::MT
B::MT
c::VT
X::ST
U::UT
function ConstrainedAffineControlContinuousSystem(A::MT, B::MT, c::VT, X::ST, U::UT) where {T, MT <: AbstractMatrix{T}, VT <: AbstractVector{T}, ST, UT}
@assert checksquare(A) == length(c) == size(B, 1)
return new{T, MT, VT, ST, UT}(A, B, c, X, U)
end
end
statedim(s::ConstrainedAffineControlContinuousSystem) = length(s.c)
stateset(s::ConstrainedAffineControlContinuousSystem) = s.X
inputdim(s::ConstrainedAffineControlContinuousSystem) = size(s.B, 2)
inputset(s::ConstrainedAffineControlContinuousSystem) = s.U
"""
ConstrainedLinearControlContinuousSystem
Continuous-time linear control system with state constraints of the form
```math
x' = A x + B u, x(t) ∈ \\mathcal{X}, u(t) ∈ \\mathcal{U} \\text{ for all } t.
```
### Fields
- `A` -- square matrix
- `B` -- matrix
- `X` -- state constraints
- `U` -- input constraints
"""
struct ConstrainedLinearControlContinuousSystem{T, MT <: AbstractMatrix{T}, ST, UT} <: AbstractContinuousSystem
A::MT
B::MT
X::ST
U::UT
function ConstrainedLinearControlContinuousSystem(A::MT, B::MT, X::ST, U::UT) where {T, MT <: AbstractMatrix{T}, ST, UT}
@assert checksquare(A) == size(B, 1)
return new{T, MT, ST, UT}(A, B, X, U)
end
end
statedim(s::ConstrainedLinearControlContinuousSystem) = checksquare(s.A)
stateset(s::ConstrainedLinearControlContinuousSystem) = s.X
inputdim(s::ConstrainedLinearControlContinuousSystem) = size(s.B, 2)
inputset(s::ConstrainedLinearControlContinuousSystem) = s.U
"""
LinearAlgebraicContinuousSystem
Continuous-time linear algebraic system of the form
```math
E x' = A x.
```
### Fields
- `A` -- matrix
- `E` -- matrix, same size as `A`
"""
struct LinearAlgebraicContinuousSystem{T, MT <: AbstractMatrix{T}} <: AbstractContinuousSystem
A::MT
E::MT
function LinearAlgebraicContinuousSystem(A::MT, E::MT) where {T, MT <: AbstractMatrix{T}}
@assert size(A) == size(E)
return new{T, MT}(A, E)
end
end
statedim(s::LinearAlgebraicContinuousSystem) = size(s.A, 1)
inputdim(s::LinearAlgebraicContinuousSystem) = 0
"""
ConstrainedLinearAlgebraicContinuousSystem
Continuous-time linear system with state constraints of the form
```math
E x' = A x, x(t) ∈ \\mathcal{X}.
```
### Fields
- `A` -- matrix
- `E` -- matrix, same size as `A`
- `X` -- state constraints
"""
struct ConstrainedLinearAlgebraicContinuousSystem{T, MT <: AbstractMatrix{T}, ST} <: AbstractContinuousSystem
A::MT
E::MT
X::ST
function ConstrainedLinearAlgebraicContinuousSystem(A::MT, E::MT, X::ST) where {T, MT <: AbstractMatrix{T}, ST}
@assert size(A) == size(E)
return new{T, MT, ST}(A, E, X)
end
end
statedim(s::ConstrainedLinearAlgebraicContinuousSystem) = size(s.A, 1)
stateset(s::ConstrainedLinearAlgebraicContinuousSystem) = s.X
inputdim(s::ConstrainedLinearAlgebraicContinuousSystem) = 0
"""
PolynomialContinuousSystem
Continuous-time polynomial system of the form
```math
x' = p(x).
```
### Fields
- `p` -- polynomial
- `statedim` -- number of state variables
"""
struct PolynomialContinuousSystem{PT} <: AbstractContinuousSystem
p::PT
statedim::Int
end
statedim(s::PolynomialContinuousSystem) = s.statedim
inputdim(s::PolynomialContinuousSystem) = 0
"""
ConstrainedPolynomialContinuousSystem
Continuous-time polynomial system with state constraints,
```math
x' = p(x), x(t) ∈ \\mathcal{X}
```
### Fields
- `p` -- polynomial
- `X` -- constraint set
- `statedim` -- number of state variables
"""
struct ConstrainedPolynomialContinuousSystem{PT, ST} <: AbstractContinuousSystem
p::PT
statedim::Int
X::ST
end
statedim(s::ConstrainedPolynomialContinuousSystem) = s.statedim
stateset(s::ConstrainedPolynomialContinuousSystem) = s.X
inputdim(s::ConstrainedPolynomialContinuousSystem) = 0