Skip to content

Commit d4eb3f2

Browse files
committed
wip: shrink g_min and g_max when there is ±Inf bounds
1 parent 34d818b commit d4eb3f2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/controller/nonlinmpc.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ function init_optimization!(
557557

558558

559559

560-
560+
# TODO: transfer all the following in set_nonlincon!, including a copy-paste
561+
# of all the vectors above.
561562
function gfunc!(g, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, geq)
562563
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
563564
return nothing
@@ -584,20 +585,19 @@ function init_optimization!(
584585
end
585586
function gfunc_set!(g_arg, Z̃_arg)
586587
update_con!(g, ∇g, Z̃_∇g, Z̃_arg)
587-
g_arg .= g
588+
g_arg .= @views g[mpc.con.i_g]
588589
return nothing
589590
end
590591
function ∇gfunc_set!(∇g_arg, Z̃_arg)
591592
update_con!(g, ∇g, Z̃_∇g, Z̃_arg)
592-
diffmat2vec!(∇g_arg, ∇g)
593+
diffmat2vec!(∇g_arg, @views ∇g[mpc.con.i_g, :])
593594
return nothing
594595
end
595596

596-
g_min = fill(-myInf, ng)
597-
g_max = fill(+myInf, ng)
598-
g_max[end-nc+1:end] .= 0 # custom constraints, if any, are always upper bounded
597+
g_min = fill(-myInf, sum(mpc.con.i_g))
598+
g_max = zeros(JNT, sum(mpc.con.i_g))
599599

600-
∇g_structure = init_diffstructure(∇g)
600+
∇g_structure = init_diffstructure(∇g[mpc.con.i_g, :])
601601

602602
g_set = Ipopt._VectorNonlinearOracle(;
603603
dimension = nZ̃,
@@ -609,6 +609,8 @@ function init_optimization!(
609609
)
610610
@constraint(optim, Z̃var in g_set)
611611

612+
613+
612614
function geqfunc!(geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g)
613615
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
614616
return nothing

0 commit comments

Comments
 (0)