Skip to content

[Bug] Flow example #384

Open
Open
@jbcaillau

Description

@jbcaillau

hi @oameye (cc @ocots @PierreMartinon); moving your separate example here (different issue compared to #369). The example below converges with the commented version of the cost, not with the uncommented one (which is not exactly what you posted), but runs without any AD error:

  • can you please confirm which (new) cost you want to minimise?
  • in any case, I suggest to replace your mysqrt by the asqrt function below (smoothed and symmetrised)
using OptimalControl
using NLPModelsIpopt
using LinearAlgebra

T = 50  # Time horizon

# Define the vector field
f(u, v) = [u - u^3 - 10*u*v^2,  -(1 - u^2)*v]
f(x) = f(x...)

asqrt(x; ε=1e-9) = sqrt(sqrt(x^2 + ε^2))

@def action begin
    t  [0, T], time
    x  R², state
    u  R², control
    x(0) == [-1, 0]    # Starting point (left well)
    x(T) == [1, 0]     # End point (right well)
    (t) == u(t)       # Path dynamics
    #∫( sum((u(t) - f(x(t))).^2) ) → min  # Minimize deviation from deterministic flow
    ( asqrt(sum((u(t) - f(x(t))).^2)) )  min  # Minimize deviation from deterministic flow
end

# Linear interpolation for x₁
x1(t) = -(1 - t/T) + t/T
# Parabolic guess for x₂
x2(t) = 0.3(-x1(t)^2 + 1)
x(t) = [x1(t), x2(t)]
u(t) = f(x(t))
init = (state=x, control=u)

sol = solve(action; init=init, grid_size=50)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions