Hello all,
I am a new Julia user coming from a Modelica background and I am trying to experiment with Modeling Toolkit and dynamic optimisation.
I was trying to follow this example ([Solving Dynamic Optimization Problems] => [Free final time problems]) in the official documentation page and I noticed something strange. While the tutorial says that the starting values provided in the u0map will be considered as guesses it seems that the problem is formulated with extra equations resulting in an overdetermined system. Now running the test I still get the results presented but the warning is that a least squares problem is solved instead. My intention is to expand on the example with my own model to impose periodic conditions but given this behaviour I could not see a workaround.
Just for reference running the code in the example I get :
┌ Warning: The control problem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by op) exceeds the total number of states. The solvers will default to doing a nonlinear least-squares optimization.
└ @ ModelingToolkitBase C:\Users\chris\.julia\packages\ModelingToolkitBase\fjBdh\src\systems\optimal_control_interface.jl:96
┌ Warning: The control problem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by op) exceeds the total number of states. The solvers will default to doing a nonlinear least-squares optimization.
└ @ ModelingToolkitBase C:\Users\chris\.julia\packages\ModelingToolkitBase\fjBdh\src\systems\optimal_control_interface.jl:96
Hi @PhysicsBender, welcome to this Julia forum. Although I cannot offer advice, I can at least confirm that I can reproduce the problem too. For convenience of others, I include the code here. It is from Solving Dynamic Optimization Problems · ModelingToolkit.jl, but I inserted the import InfiniteOpt, Ipopt towards the end.
using ModelingToolkit
t = ModelingToolkit.t_nounits
D = ModelingToolkit.D_nounits
@variables begin
x(..)
v(..)
u(..), [bounds = (-1.0, 1.0), input = true]
end
@parameters tf
constr = [v(tf) ~ 0, x(tf) ~ 0]
cost = [tf] # Minimize time
@named block = System(
[D(x(t)) ~ v(t), D(v(t)) ~ u(t)], t; costs = cost, constraints = constr)
block = mtkcompile(block; inputs = [u(t)])
u0map = [x(t) => 1.0, v(t) => 0.0]
tspan = (0.0, tf)
parammap = [u(t) => 0.0, tf => 1.0]
import InfiniteOpt, Ipopt
iprob = InfiniteOptDynamicOptProblem(block, [u0map; parammap], tspan; steps = 100)
isol = solve(iprob, InfiniteOptCollocation(Ipopt.Optimizer))
This is the warning I get after the last but one line:
julia> iprob = InfiniteOptDynamicOptProblem(block, [u0map; parammap], tspan; steps = 100)
┌ Warning: The control problem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by op) exceeds the total number of states. The solvers will default to doing a nonlinear least-squares optimization.
└ @ ModelingToolkitBase ~/.julia/packages/ModelingToolkitBase/fjBdh/src/systems/optimal_control_interface.jl:96
┌ Warning: The control problem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by op) exceeds the total number of states. The solvers will default to doing a nonlinear least-squares optimization.
└ @ ModelingToolkitBase ~/.julia/packages/ModelingToolkitBase/fjBdh/src/systems/optimal_control_interface.jl:96
InfiniteOptDynamicOptProblem with uType Vector{Float64} and tType Float64. In-place: true
Non-trivial mass matrix: false
timespan: (0.0, tf)
u0: 2-element Vector{Float64}:
0.0
1.0
Please open an issue so we can discuss it there.