OptimalControl.jl icon indicating copy to clipboard operation
OptimalControl.jl copied to clipboard

Getters of multipliers associated to labeled constraints

Open ocots opened this issue 2 years ago • 6 comments

A user should have the possibility to get the dual variables of a constraint he has labeled, as in JuMP (cf. the dual function). See also #131

ocots avatar Mar 03 '23 10:03 ocots

Current state in CTDirect:

  • [ ] retrieve and pass to the OCP solution the multipliers for specific types of constraints (tested on state, should be identical for control and mixed constraints)
  • [ ] same for box multipliers (need to parse them first but we do have the values returned by ipopt so there should be no difficulty)
  • [ ] retrieve the corresponding labels from ocp

PierreMartinon avatar Mar 30 '23 08:03 PierreMartinon

Small update: in the latest version only the adjoints are retrieved, other multipliers are skipped. Putting them back is easy since the previous code is still there.

While we're at it, it would be nice to add proper fields in OptimalControlSolution for these multipliers (I used to dump them in info).

@ocots, @jbcaillau I let you pick the names and add the fields, then I complete the parsing back ?

PierreMartinon avatar Jul 26 '24 09:07 PierreMartinon

@PierreMartinon I guess we should stick to the current vocabulary (check constraint! here):

  • boundary (nonlinear fun of $([t_0,]x_0,[t_f],x_f)$
  • control (pure)
  • state (pure)
  • mixed
  • variable

Choose whatever name you want as long as you don't mix CamlCase_and_snake 🙃...

jbcaillau avatar Jul 26 '24 09:07 jbcaillau

By the way we probably want to retrieve the different constraints as well (parsing is the same so there is no extra effort). So maybe something like this, to keep reasonably short names:

  • [mult_]boundary_constraints
  • [mult_]state_constraints
  • [mult_]control_constraints
  • [mult_]mixed_constraints
  • [mult_]variable_constraints

PierreMartinon avatar Jul 31 '24 16:07 PierreMartinon

@PierreMartinon as pointed by @ocots there is still an interest in having labels for our constraints (abstract form) as one might want to retrieve the constraint associated with such a specific label:

@def ocp begin
    t ∈ [ 0, 1 ], time
    x ∈ R², state
    u ∈ R, control
    x(0) == [ -1, 0 ], (1)
    x(1) == [ 0, 0 ]
    ẋ(t) == [ x₂(t), u(t) ]
    ∫( 0.5u(t)^2 ) → min
end

jbcaillau avatar Jul 31 '24 22:07 jbcaillau

Ok, in the solution parsing I can sort the different kinds of constraints and their associated multipliers, then interpolate the functions as we already do for the state and control (and costate) variables.

For the labels part, I guess it would be the same as retrieving a state/control by its name ?

By the way this will need a joint release of CTDirect / CTBase.

PierreMartinon avatar Aug 01 '24 17:08 PierreMartinon

See https://github.com/control-toolbox/CTModels.jl/issues/47

ocots avatar Apr 28 '25 21:04 ocots