Skip to content

Commit 4269e90

Browse files
authored
Merge pull request #170 from JuliaControl/bump
changed: moved equality constraint function to `transcription.jl` and bump
2 parents 3eebed5 + d25163f commit 4269e90

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
33
authors = ["Francis Gagnon"]
4-
version = "1.4.0"
4+
version = "1.4.1"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/controller/nonlinmpc.jl

-36
Original file line numberDiff line numberDiff line change
@@ -822,42 +822,6 @@ function con_nonlinprog!(g, mpc::NonLinMPC, ::SimModel, x̂0end, Ŷ0, gc, ϵ)
822822
return g
823823
end
824824

825-
"""
826-
con_nonlinprogeq!(
827-
geq, X̂0, Û0, mpc::NonLinMPC, model::NonLinModel, ::MultipleShooting, U0, Z̃
828-
)
829-
830-
Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`](@ref).
831-
832-
The method mutates the `geq`, `X̂0` and `Û0` vectors in argument.
833-
"""
834-
function con_nonlinprogeq!(
835-
geq, X̂0, Û0, mpc::NonLinMPC, model::NonLinModel, ::MultipleShooting, U0, Z̃
836-
)
837-
nx̂, nu, nd, Hp, Hc = mpc.estim.nx̂, model.nu, model.nd, mpc.Hp, mpc.Hc
838-
nΔU, nX̂ = nu*Hc, nx̂*Hp
839-
D̂0 = mpc.D̂0
840-
X̂0_Z̃ = @views Z̃[(nΔU+1):(nΔU+nX̂)]
841-
x̂0 = @views mpc.estim.x̂0[1:nx̂]
842-
d0 = @views mpc.d0[1:nd]
843-
#TODO: allow parallel for loop or threads?
844-
for j=1:Hp
845-
u0 = @views U0[(1 + nu*(j-1)):(nu*j)]
846-
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
847-
x̂0next = @views X̂0[(1 + nx̂*(j-1)):(nx̂*j)]
848-
f̂!(x̂0next, û0, mpc.estim, model, x̂0, u0, d0)
849-
x̂0next .+= mpc.estim.f̂op .- mpc.estim.x̂op
850-
x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*j)]
851-
ŝnext = @views geq[(1 + nx̂*(j-1)):(nx̂*j)]
852-
ŝnext .= x̂0next .- x̂0next_Z̃
853-
x̂0 = x̂0next_Z̃ # using states in Z̃ for next iteration (allow parallel for)
854-
d0 = @views D̂0[(1 + nd*(j-1)):(nd*j)]
855-
end
856-
return geq
857-
end
858-
con_nonlinprogeq!(geq,_,_, ::NonLinMPC, ::NonLinModel, ::SingleShooting, _,_) = geq
859-
con_nonlinprogeq!(geq,_,_, ::NonLinMPC, ::LinModel, ::TranscriptionMethod, _,_) = geq
860-
861825
@doc raw"""
862826
con_custom!(gc, mpc::NonLinMPC, Ue, Ŷe, ϵ) -> gc
863827

src/controller/transcription.jl

+36
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,39 @@ function predict!(
701701
return Ŷ0, x̂0end
702702
end
703703

704+
705+
"""
706+
con_nonlinprogeq!(
707+
geq, X̂0, Û0, mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
708+
)
709+
710+
Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`](@ref).
711+
712+
The method mutates the `geq`, `X̂0` and `Û0` vectors in argument.
713+
"""
714+
function con_nonlinprogeq!(
715+
geq, X̂0, Û0, mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
716+
)
717+
nx̂, nu, nd, Hp, Hc = mpc.estim.nx̂, model.nu, model.nd, mpc.Hp, mpc.Hc
718+
nΔU, nX̂ = nu*Hc, nx̂*Hp
719+
D̂0 = mpc.D̂0
720+
X̂0_Z̃ = @views Z̃[(nΔU+1):(nΔU+nX̂)]
721+
x̂0 = @views mpc.estim.x̂0[1:nx̂]
722+
d0 = @views mpc.d0[1:nd]
723+
#TODO: allow parallel for loop or threads?
724+
for j=1:Hp
725+
u0 = @views U0[(1 + nu*(j-1)):(nu*j)]
726+
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
727+
x̂0next = @views X̂0[(1 + nx̂*(j-1)):(nx̂*j)]
728+
f̂!(x̂0next, û0, mpc.estim, model, x̂0, u0, d0)
729+
x̂0next .+= mpc.estim.f̂op .- mpc.estim.x̂op
730+
x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*j)]
731+
ŝnext = @views geq[(1 + nx̂*(j-1)):(nx̂*j)]
732+
ŝnext .= x̂0next .- x̂0next_Z̃
733+
x̂0 = x̂0next_Z̃ # using states in Z̃ for next iteration (allow parallel for)
734+
d0 = @views D̂0[(1 + nd*(j-1)):(nd*j)]
735+
end
736+
return geq
737+
end
738+
con_nonlinprogeq!(geq,_,_,::PredictiveController,::NonLinModel,::SingleShooting, _,_) = geq
739+
con_nonlinprogeq!(geq,_,_,::PredictiveController,::LinModel,::TranscriptionMethod,_,_) = geq

0 commit comments

Comments
 (0)