Skip to content

Bug tf variable #189

@ocots

Description

@ocots

It seems that this is not correct:

julia> @def ocp begin
        tf  R, variable
        t  [0, tf], time
        x  R, state
        u  R, control
        (t) == tf * u(t)
        x(0) == 0
        x(tf) == 1
        tf + 0.5(u(t)^2)  min
        end

The (autonomous) optimal control problem is given by:

    tf  R, variable
    t  [0, tf], time
    x  R, state
    u  R, control
    (t) == tf * u(t)
    x(0) == 0
    x(tf) == 1
    tf + 0.5 * (u(t) ^ 2)  min

The (autonomous) optimal control problem is of the form:

    minimize  J(x, u, tf) = g(x(0), x(tf), tf) +f⁰(x(t), u(t), tf) dt, over [0, tf]

    subject to

        (t) = f(x(t), u(t), tf), t in [0, tf] a.e.,

        ϕl  ϕ(x(0), x(tf), tf)  ϕu, 

    where x(t)  R, u(t)  R and tf  R.

Declarations (* required):

╭────────┬────────┬──────────┬──────────┬───────────┬────────────┬─────────────╮
│ times* │ state* │ control* │ variable │ dynamics* │ objective* │ constraints │
├────────┼────────┼──────────┼──────────┼───────────┼────────────┼─────────────┤
│   V    │   V    │    V     │    V     │     V     │     V      │      V      │
╰────────┴────────┴──────────┴──────────┴───────────┴────────────┴─────────────╯


julia> sol = solve(ocp)
This is Ipopt version 3.14.16, running with linear solver MUMPS 5.7.3.

Number of nonzeros in equality constraint Jacobian...:     1003
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:      203

Total number of variables............................:      304
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:      203
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  2.0000000e-01 9.00e-01 4.91e-03   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  2.3319855e-01 8.99e-01 3.84e-01 -11.0 3.36e+01    -  1.00e+00 9.77e-04h 11
   2  3.1063422e-01 8.96e-01 1.15e+00 -11.0 1.94e+01    -  1.00e+00 3.91e-03h  9
   3  5.7872626e-01 8.82e-01 1.03e+00 -11.0 1.74e+01  -2.0 1.00e+00 1.56e-02h  7
   4  8.6337333e-01 8.68e-01 7.24e-01 -11.0 1.83e+01  -0.7 1.00e+00 1.56e-02h  7
   5  1.2396253e+00 8.14e-01 1.02e+00 -11.0 6.07e+00    -  1.00e+00 6.25e-02h  5
   6  8.3728076e-01 7.10e-03 4.56e+00 -11.0 9.76e-01  -1.1 1.00e+00 1.00e+00h  1
   7  1.6241923e+00 1.05e-02 6.93e+00 -11.0 1.43e+00    -  1.00e+00 1.00e+00h  1
   8  1.5839909e+00 2.95e-04 6.23e-01 -11.0 1.00e-01  -0.7 1.00e+00 1.00e+00h  1
   9  1.2672905e+00 1.12e-02 4.91e-01 -11.0 1.95e+00    -  1.00e+00 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  1.3583706e+00 2.54e-03 3.59e-03 -11.0 6.11e-01    -  1.00e+00 1.00e+00h  1
  11  1.4778821e+00 1.13e-04 9.96e-03 -11.0 9.02e-02    -  1.00e+00 1.00e+00h  1
  12  1.4755675e+00 1.90e-07 1.54e-06 -11.0 4.38e-03    -  1.00e+00 1.00e+00h  1
  13  1.4755759e+00 5.11e-12 2.99e-10 -11.0 2.27e-05    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 13

                                   (scaled)                 (unscaled)
Objective...............:   1.4755758928406426e+00    1.4755758928406426e+00
Dual infeasibility......:   2.9935254275414991e-10    2.9935254275414991e-10
Constraint violation....:   5.1116888499791457e-12    5.1116888499791457e-12
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   2.9935254275414991e-10    2.9935254275414991e-10


Number of objective function evaluations             = 47
Number of objective gradient evaluations             = 14
Number of equality constraint evaluations            = 53
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 14
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 13
Total seconds in IPOPT                               = 0.190

EXIT: Optimal Solution Found.
CTBase.OptimalControlSolution

julia> p0 = sol.costate(0)
0.7377879463735035

julia> tf = sol.variable
1.1066819197577107

Metadata

Metadata

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions