# Free final time problem formulation using ModelingToolkit and InfiniteOpt

**URL:** <https://discourse.julialang.org/t/free-final-time-problem-formulation-using-modelingtoolkit-and-infiniteopt/134735>\
**Category:** Modelling & Simulations\
**Tags:** sciml, modelingtoolkit\
**Created:** [December 25, 2025, 3:26pm UTC](https://discourse.julialang.org/t/free-final-time-problem-formulation-using-modelingtoolkit-and-infiniteopt/134735 "2025-12-25T15:26:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhysicsBender](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/physicsbender/32/220077_2.png) [@PhysicsBender](https://discourse.julialang.org/u/PhysicsBender)\
**Post date:** [December 25, 2025, 3:26pm UTC](https://discourse.julialang.org/t/free-final-time-problem-formulation-using-modelingtoolkit-and-infiniteopt/134735/1 "2025-12-25T15:26:15Z")

</div>

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 :

```julia-auto
┌ 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

```

```julia-auto
┌ 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

```

---

<div class="post-metadata">

**Author:** ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)\
**Post date:** [December 25, 2025, 11:16pm UTC](https://discourse.julialang.org/t/free-final-time-problem-formulation-using-modelingtoolkit-and-infiniteopt/134735/2 "2025-12-25T23:16:22Z")

</div>

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](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/dynamic_optimization/#Free-final-time-problems), but I inserted the `import InfiniteOpt, Ipopt` towards the end.

```julia
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
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

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 26, 2025, 8:54am UTC](https://discourse.julialang.org/t/free-final-time-problem-formulation-using-modelingtoolkit-and-infiniteopt/134735/3 "2025-12-26T08:54:06Z")

</div>

Please open an issue so we can discuss it there.
