Skip to content

Commit 442443c

Browse files
committed
added: test for nonnegative values for diagonal weights
1 parent 950bfce commit 442443c

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/controller/construct.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,12 @@ function validate_weights(model, Hp, Hc, M_Hp, N_Hc, L_Hp, C, E=nothing)
817817
size(M_Hp) (nM,nM) && throw(ArgumentError("M_Hp size $(size(M_Hp)) ≠ (ny*Hp, ny*Hp) ($nM,$nM)"))
818818
size(N_Hc) (nN,nN) && throw(ArgumentError("N_Hc size $(size(N_Hc)) ≠ (nu*Hc, nu*Hc) ($nN,$nN)"))
819819
size(L_Hp) (nL,nL) && throw(ArgumentError("L_Hp size $(size(L_Hp)) ≠ (nu*Hp, nu*Hp) ($nL,$nL)"))
820-
!ishermitian(M_Hp) && throw(ArgumentError("M_Hp should be a positive semidefinite hermitian"))
821-
!ishermitian(N_Hc) && throw(ArgumentError("N_Hc should be a positive semidefinite hermitian"))
822-
!ishermitian(L_Hp) && throw(ArgumentError("L_Hp should be a positive semidefinite hermitian"))
820+
(isdiag(M_Hp) && any(diag(M_Hp) .< 0)) && throw(ArgumentError("Mwt values should be nonnegative"))
821+
(isdiag(N_Hc) && any(diag(N_Hc) .< 0)) && throw(ArgumentError("Nwt values should be nonnegative"))
822+
(isdiag(L_Hp) && any(diag(L_Hp) .< 0)) && throw(ArgumentError("Lwt values should be nonnegative"))
823+
!ishermitian(M_Hp) && throw(ArgumentError("M_Hp should be hermitian"))
824+
!ishermitian(N_Hc) && throw(ArgumentError("N_Hc should be hermitian"))
825+
!ishermitian(L_Hp) && throw(ArgumentError("L_Hp should be hermitian"))
823826
size(C) () && throw(ArgumentError("Cwt should be a real scalar"))
824827
C < 0 && throw(ArgumentError("Cwt weight should be ≥ 0"))
825828
!isnothing(E) && size(E) () && throw(ArgumentError("Ewt should be a real scalar"))

src/controller/linmpc.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ in which the weight matrices are repeated ``H_p`` or ``H_c`` times by default:
103103
\mathbf{L}_{H_p} &= \text{diag}\mathbf{(L,L,...,L)}
104104
\end{aligned}
105105
```
106-
Time-varying weights over the horizons are also supported. The ``\mathbf{ΔU}`` includes the
107-
input increments ``\mathbf{Δu}(k+j) = \mathbf{u}(k+j) - \mathbf{u}(k+j-1)`` from ``j=0`` to
106+
Time-varying and non-diagonal weights are also supported. Modify the last block in
107+
``\mathbf{M}_{H_p}`` to specify a terminal weight. The ``\mathbf{ΔU}`` includes the input
108+
increments ``\mathbf{Δu}(k+j) = \mathbf{u}(k+j) - \mathbf{u}(k+j-1)`` from ``j=0`` to
108109
``H_c-1``, the ``\mathbf{Ŷ}`` vector, the output predictions ``\mathbf{ŷ}(k+j)`` from
109110
``j=1`` to ``H_p``, and the ``\mathbf{U}`` vector, the manipulated inputs ``\mathbf{u}(k+j)``
110111
from ``j=0`` to ``H_p-1``. The slack variable ``ϵ`` relaxes the constraints, as described
@@ -120,9 +121,9 @@ arguments.
120121
- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\mathbf{M}`` weight matrix (vector).
121122
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\mathbf{N}`` weight matrix (vector).
122123
- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\mathbf{L}`` weight matrix (vector).
123-
- `M_Hp=diagm(repeat(Mwt,Hp))` : positive semidefinite symmetric weight ``\mathbf{M}_{H_p}``.
124-
- `N_Hc=diagm(repeat(Nwt,Hc))` : positive semidefinite symmetric weight ``\mathbf{N}_{H_c}``.
125-
- `L_Hp=diagm(repeat(Lwt,Hp))` : positive semidefinite symmetric weight ``\mathbf{L}_{H_p}``.
124+
- `M_Hp=diagm(repeat(Mwt,Hp))` : positive semidefinite symmetric matrix ``\mathbf{M}_{H_p}``.
125+
- `N_Hc=diagm(repeat(Nwt,Hc))` : positive semidefinite symmetric matrix ``\mathbf{N}_{H_c}``.
126+
- `L_Hp=diagm(repeat(Lwt,Hp))` : positive semidefinite symmetric matrix ``\mathbf{L}_{H_p}``.
126127
- `Cwt=1e5` : slack variable weight ``C`` (scalar), use `Cwt=Inf` for hard constraints only.
127128
- `optim=JuMP.Model(OSQP.MathOptInterfaceOSQP.Optimizer)` : quadratic optimizer used in
128129
the predictive controller, provided as a [`JuMP.Model`](https://jump.dev/JuMP.jl/stable/api/JuMP/#JuMP.Model)

src/controller/nonlinmpc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ This method uses the default state estimator :
131131
- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\mathbf{M}`` weight matrix (vector).
132132
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\mathbf{N}`` weight matrix (vector).
133133
- `Lwt=fill(0.0,model.nu)` : main diagonal of ``\mathbf{L}`` weight matrix (vector).
134-
- `M_Hp=diagm(repeat(Mwt,Hp))` : positive semidefinite symmetric weight ``\mathbf{M}_{H_p}``.
135-
- `N_Hc=diagm(repeat(Nwt,Hc))` : positive semidefinite symmetric weight ``\mathbf{N}_{H_c}``.
136-
- `L_Hp=diagm(repeat(Lwt,Hp))` : positive semidefinite symmetric weight ``\mathbf{L}_{H_p}``.
134+
- `M_Hp=diagm(repeat(Mwt,Hp))` : positive semidefinite symmetric matrix ``\mathbf{M}_{H_p}``.
135+
- `N_Hc=diagm(repeat(Nwt,Hc))` : positive semidefinite symmetric matrix ``\mathbf{N}_{H_c}``.
136+
- `L_Hp=diagm(repeat(Lwt,Hp))` : positive semidefinite symmetric matrix ``\mathbf{L}_{H_p}``.
137137
- `Cwt=1e5` : slack variable weight ``C`` (scalar), use `Cwt=Inf` for hard constraints only.
138138
- `Ewt=0.0` : economic costs weight ``E`` (scalar).
139139
- `JE=(_,_,_)->0.0` : economic function ``J_E(\mathbf{U}_E, \mathbf{Ŷ}_E, \mathbf{D̂}_E)``.

0 commit comments

Comments
 (0)