1- struct PredictiveControllerBuffer{NT<: Real ,M <: AbstractMatrix{NT} }
1+ struct PredictiveControllerBuffer{NT<: Real }
22 u :: Vector{NT}
33 Z̃ :: Vector{NT}
44 D̂ :: Vector{NT}
55 Ŷ :: Vector{NT}
66 U :: Vector{NT}
77 Ẽ :: Matrix{NT}
8- P̃u:: M
8+ P̃u:: Matrix{NT}
99 empty:: Vector{NT}
1010end
1111
@@ -29,19 +29,14 @@ function PredictiveControllerBuffer(
2929 Ẽ = Matrix {NT} (undef, ny* Hp, nZ̃)
3030 P̃u = Matrix {NT} (undef, nu* Hp, nZ̃)
3131 empty = Vector {NT} (undef, 0 )
32- return PredictiveControllerBuffer {NT,typeof(P̃u) } (u, Z̃, D̂, Ŷ, U, Ẽ, P̃u, empty)
32+ return PredictiveControllerBuffer {NT} (u, Z̃, D̂, Ŷ, U, Ẽ, P̃u, empty)
3333end
3434
3535" Include all the objective function weights of [`PredictiveController`](@ref)"
36- struct ControllerWeights{
37- NT<: Real ,
38- H1<: Hermitian{NT, <:AbstractMatrix{NT}} ,
39- H2<: Hermitian{NT, <:AbstractMatrix{NT}} ,
40- H3<: Hermitian{NT, <:AbstractMatrix{NT}} ,
41- }
42- M_Hp:: H1
43- Ñ_Hc:: H2
44- L_Hp:: H3
36+ struct ControllerWeights{NT<: Real }
37+ M_Hp:: Hermitian{NT, Matrix{NT}}
38+ Ñ_Hc:: Hermitian{NT, Matrix{NT}}
39+ L_Hp:: Hermitian{NT, Matrix{NT}}
4540 E :: NT
4641 iszero_M_Hp:: Vector{Bool}
4742 iszero_Ñ_Hc:: Vector{Bool}
@@ -51,15 +46,15 @@ struct ControllerWeights{
5146 model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt= Inf , Ewt= 0
5247 ) where NT<: Real
5348 validate_weights (model, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt)
54- M_Hp = Hermitian (convert .(NT, M_Hp), :L )
55- N_Hc = Hermitian (convert .(NT, N_Hc), :L )
56- L_Hp = Hermitian (convert .(NT, L_Hp), :L )
49+ # convert `Diagonal` to normal `Matrix` if required:
50+ M_Hp = Hermitian (convert (Matrix{NT}, M_Hp), :L )
51+ N_Hc = Hermitian (convert (Matrix{NT}, N_Hc), :L )
52+ L_Hp = Hermitian (convert (Matrix{NT}, L_Hp), :L )
5753 nΔU = size (N_Hc, 1 )
5854 C = Cwt
5955 if ! isinf (Cwt)
6056 # ΔŨ = [ΔU; ϵ] (ϵ is the slack variable)
61- # Ñ_Hc = Hermitian([N_Hc zeros(NT, nΔU, 1); zeros(NT, 1, nΔU) C], :L)
62- Ñ_Hc = Hermitian (blockdiag (sparse (N_Hc), sparse (Diagonal ([C]))), :L )
57+ Ñ_Hc = Hermitian ([N_Hc zeros (NT, nΔU, 1 ); zeros (NT, 1 , nΔU) C], :L )
6358 else
6459 # ΔŨ = ΔU (only hard constraints)
6560 Ñ_Hc = N_Hc
@@ -69,7 +64,7 @@ struct ControllerWeights{
6964 iszero_Ñ_Hc = [iszero (Ñ_Hc)]
7065 iszero_L_Hp = [iszero (L_Hp)]
7166 iszero_E = iszero (E)
72- return new {NT,typeof(M_Hp),typeof(Ñ_Hc),typeof(L_Hp) } (M_Hp, Ñ_Hc, L_Hp, E, iszero_M_Hp, iszero_Ñ_Hc, iszero_L_Hp, iszero_E)
67+ return new {NT} (M_Hp, Ñ_Hc, L_Hp, E, iszero_M_Hp, iszero_Ñ_Hc, iszero_L_Hp, iszero_E)
7368 end
7469end
7570
@@ -589,10 +584,10 @@ function relaxU(Pu::Matrix{NT}, C_umin, C_umax, nϵ) where NT<:Real
589584 # ϵ impacts Z → U conversion for constraint calculations:
590585 A_Umin, A_Umax = - [Pu C_umin], [Pu - C_umax]
591586 # ϵ has no impact on Z → U conversion for prediction calculations:
592- P̃u = sparse_hcat ( sparse (Pu), spzeros (NT, size (Pu, 1 )))
587+ P̃u = [Pu zeros (NT, size (Pu, 1 ))]
593588 else # Z̃ = Z (only hard constraints)
594589 A_Umin, A_Umax = - Pu, Pu
595- P̃u = sparse (Pu)
590+ P̃u = Pu
596591 end
597592 return A_Umin, A_Umax, P̃u
598593end
@@ -626,17 +621,17 @@ bound, which is more precise than a linear inequality constraint. However, it is
626621convenient to treat it as a linear inequality constraint since the optimizer `OSQP.jl` does
627622not support pure bounds on the decision variables.
628623"""
629- function relaxΔU (PΔu:: AbstractMatrix {NT} , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) where NT<: Real
624+ function relaxΔU (PΔu:: Matrix {NT} , C_Δumin, C_Δumax, ΔUmin, ΔUmax, nϵ) where NT<: Real
630625 nZ = size (PΔu, 2 )
631626 if nϵ == 1 # Z̃ = [Z; ϵ]
632627 ΔŨmin, ΔŨmax = [ΔUmin; NT[0.0 ]], [ΔUmax; NT[Inf ]] # 0 ≤ ϵ ≤ ∞
633628 A_ϵ = [zeros (NT, 1 , nZ) NT[1.0 ]]
634629 A_ΔŨmin, A_ΔŨmax = - [PΔu C_Δumin; A_ϵ], [PΔu - C_Δumax; A_ϵ]
635- P̃Δu = blockdiag ( sparse (PΔu), spdiagm ([ one (NT)]))
630+ P̃Δu = [PΔu zeros (NT, size (PΔu, 1 ), 1 ); zeros (NT, 1 , size (PΔu, 2 )) NT[ 1.0 ]]
636631 else # Z̃ = Z (only hard constraints)
637632 ΔŨmin, ΔŨmax = ΔUmin, ΔUmax
638633 A_ΔŨmin, A_ΔŨmax = - PΔu, PΔu
639- P̃Δu = sparse ( PΔu)
634+ P̃Δu = PΔu
640635 end
641636 return A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, P̃Δu
642637end
0 commit comments