Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future: declaration of time, state, control and variable in the abstract syntax #257

Open
ocots opened this issue Aug 22, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ocots
Copy link
Member

ocots commented Aug 22, 2024

The idea of this issue is to add possibilities of declaration of time, state, control and variable.

For instance, this current declaration

@def begin
    tf  R, variable
    t  [0, tf], time
    x = (q, v)  R², state
    u  R, control
    tf  0 
    v(t)  1
    -1  u(t)  1
end

must be equivalent to

@def begin
    tf  R₊, variable
    t  [0, tf], time
    x = (q, v)  (-∞, 1] × R, state
    u  [-1, 1], control
end

In the comments below, you will find:

@ocots ocots changed the title Declaration of time, state and control in the abstract syntax Declaration of time, state, control and variable in the abstract syntax Aug 22, 2024
@ocots
Copy link
Member Author

ocots commented Aug 22, 2024

Preliminaries

To define an optimal control problem with the abstract syntax, one must use the @def macro:

macro def(e)

The key internal function is the one which in one pass parse the code:

parse!(p, ocp, e; log=false) = begin

Every line of the code is parsed to in order to call the right functional method to construct the model of OptimalControlModel type of the optimal control problem.

For instance,

ocp = @def t  [0, 1], time

is transformed into

time!(ocp, t0=0, tf=1)

from

thanks to the internal function p_time!. See

:( $t [ $t0, $tf ], time ) => p_time!(p, ocp, t, t0, tf; log)

and

p_time!(p, ocp, t, t0, tf; log=false) = begin

@ocots
Copy link
Member Author

ocots commented Aug 22, 2024

Current possibilities

Variable

In order to declare a variable we have:

:( $v  R^$q, variable ) 
:( $v  R   , variable ) 

Example.

@def begin
    v  R², variable
end

Aliases v₁, v₂ (and v1, v2) are automatically defined and can be used in subsequent expressions instead of v[1] and v[2]. The user can also define her own aliases for the components (one alias per dimension):

@def begin
    v = (a, b)  R², variable
end

A one dimensional variable can be declared according to

@def begin
    v  R, variable
end

Time

In order to declare the time we have:

:( $t  [$t0, $tf], time ) 

The independent variable or time is a scalar bound to a given interval. Its name is arbitrary.

t0 = 1
tf = 5
@def begin
    t  [t0, tf], time
end

One (or even the two bounds) can be variable, typically for minimum time problems (see Mayer cost section):

@def begin
    v = (T, λ)  R², variable
    t  [0, T], time
end

State

:( $x  R^$n, state ) 
:( $x  R   , state ) 

The state declaration defines the name and the dimension of the state:

@def begin
    x  R⁴, state
end

As for the variable, there are automatic aliases (x₁ and x1 for x[1], etc.) and the user can define her own aliases (one per scalar component of the state):

@def begin
    x = (q₁, q₂, v₁, v₂)  R⁴, state
end

Control

:( $u  R^$m, control ) 
:( $u  R   , control ) 

The control declaration defines the name and the dimension of the control:

@def begin
    u  R², control
end

As before, there are automatic aliases (u₁ and u1 for u[1], etc.) and the user can define her own aliases (one per scalar component of the state):

@def begin
    u = (α, β)  R², control
end

Constraints

:( $e1 == $e2        ) 
:( $e1   $e2   $e3 ) 
:(        $e2   $e3 ) 
:( $e3   $e2   $e1 ) 
:( $e2   $e1        ) 

Admissible constraints can be

  • five types: boundary, control, state, mixed, variable,
  • linear (ranges) or nonlinear (not ranges),
  • equalities or (one or two-sided) inequalities.

Boundary conditions are detected when the expression contains evaluations of the state at initial and / or final time bounds (e.g., x(0)), and may not involve the control. Conversely control, state or mixed constraints will involve control, state or both evaluated at the declared time (e.g., x(t) + u(t)).
Other combinations should be detected as incorrect by the parser 🤞🏾. The variable may be involved in any of the four previous constraints. Constraints involving the variable only are variable constraints, either linear or nonlinear.
In the example below, there are

  • two linear boundary constraints,
  • one linear variable constraint,
  • one linear state constraint,
  • one (two-sided) nonlinear control constraint.
@def begin
    tf  R, variable
    t  [0, tf], time
    x  R², state
    u  R, control
    x(0) == [-1, 0]
    x(tf) == [0, 0]
    (t) == [x₂(t), u(t)]
    tf  0 
    x₂(t)  1
    u(t)^2  1
end

Note

Symbols like <= or >= are also authorised:

@ocots
Copy link
Member Author

ocots commented Aug 22, 2024

Todo

To declare the time, state, control and variable, I propose the following possibilities:

@def begin
  t  [ 0, 1 ], time
  x  R³, state
  u  R², control
end

# or

@def begin
  (t, x, u)  [ 0, 1 ] ××end
@def begin
  v  R², variable
  t  [ 0, v₂ ], time
  x  R³, state
  u  R², control
end

# or

@def begin
  (t, x, u, v)  [ 0, v₂ ] ×××end
@def begin
  t  [ 0, 1 ], time
  x = (a, b, c)  R³, state
  u  R², control
  u₁(t)  0
  0  c(t)  1
end

# or

@def begin
  t  [ 0, 1 ], time
  x = (a, b, c) × [ 0, 1 ] , state
  u  R₊ × R, control
end

# or

@def begin
  t  [ 0, 1 ], time
  x = (a, b, c)  R × R × [ 0, 1 ] , state
  u  [ 0, +∞) × R, control
end

@ocots ocots added enhancement New feature or request good first issue Good for newcomers labels Aug 22, 2024
@ocots
Copy link
Member Author

ocots commented Aug 24, 2024

Need also to add: R₋ = (-∞, 0].

@jbcaillau jbcaillau changed the title Declaration of time, state, control and variable in the abstract syntax Future: declaration of time, state, control and variable in the abstract syntax Aug 29, 2024
@jbcaillau
Copy link
Member

@ocots not a big fan of everything in the same line as in

  (t, x, u, v)  [ 0, v₂ ] ×××

and not at all top priority I would say... but: if you want it, add it 🙂!

@jbcaillau jbcaillau mentioned this issue Aug 29, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants