Skip to content

Commit ddd4b31

Browse files
committed
added phase attributes, MultiPhaseIntegral, and changed Derivative
1 parent c790e57 commit ddd4b31

16 files changed

+222
-109
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynOptInterface"
22
uuid = "6c38235a-427b-4736-80fa-cf75909744ec"
33
authors = ["Eduardo M. G. Vila <72969764+e-duar-do@users.noreply.github.com> and contributors"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[deps]
77
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
<!-- [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuDO-dev.github.io/DynOptInterface.jl/stable/) -->
44
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuDO-dev.github.io/DynOptInterface.jl/dev/)
55
[![Build Status](https://github.com/JuDO-dev/DynOptInterface.jl/actions/workflows/CI.yml/badge.svg?branch=dev)](https://github.com/JuDO-dev/DynOptInterface.jl/actions/workflows/CI.yml?query=branch%3Adev)
6-
<!-- [![Coverage](https://codecov.io/gh/JuDO-dev/DynOptInterface.jl/branch/dev/graph/badge.svg)](https://codecov.io/gh/JuDO-dev/DynOptInterface.jl) -->
6+
[![Coverage](https://codecov.io/gh/JuDO-dev/DynOptInterface.jl/branch/dev/graph/badge.svg)](https://codecov.io/gh/JuDO-dev/DynOptInterface.jl)

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DocMeta.setdocmeta!(DynOptInterface, :DocTestSetup, :(import DynOptInterface as
77

88
const _PAGES = [
99
"Home" => "index.md",
10+
"Dynamic Optimization" => "dynamic_optimization.md",
1011
"API Reference" => [
1112
"Dynamic Functions" => [
1213
"reference/dynamic_functions/abstraction.md",

docs/src/assets/dynamic_variable.png

8.64 KB
Loading

docs/src/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ CurrentModule = DynOptInterface
77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
99

10+
## v0.2.0 (August 31, 2024)
11+
12+
- Added phase attributes
13+
- Changed `DynamicVariableDerivative` to `Derivative`, also changing `ExplicitDifferentialFunction`
14+
- Added `MultiPhaseIntegral`
15+
1016
## v0.1.0 (July 26, 2024)
1117

1218
- Initial release

docs/src/dynamic_optimization.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
```@meta
2+
CurrentModule = DynOptInterface
3+
```
4+
5+
# Dynamic Optimization
6+
7+
## Phases and Dynamic Variables
8+
9+
Phases represent intervals $t \in [t_0, t_f]$ on which dynamic variables $t \mapsto \boldsymbol y(t)$ are defined.
10+
11+
![dynamic variable](assets/dynamic_variable.png)
12+
13+
## Problem Formulation
14+
15+
MOI's [Function-in-Set form problem](@extref Standard-form-problem) is extended as follows.
16+
Dynamic Optimization Problems deal with finding variables $x \in \mathbb R^{n_x}$, phase boundaries $t_0^{(i)} \in \mathbb R$, $t_f^{(i)} \in \mathbb R$, and dynamic variables $\boldsymbol y^{(i)} : [t_0^{(i)}, t_f^{(i)}] \rightarrow \mathbb R^{n_y^{(i)}}$ that
17+
18+
```math
19+
\begin{align*}
20+
\begin{array}{rl}
21+
\text{minimize} \quad &
22+
m \big( \boldsymbol y(t_0), \boldsymbol y(t_f), t_0, t_f, x \big) +
23+
\displaystyle{\sum_{i=1}^{n_p} \bigg[
24+
\int_{t_0^{(i)}}^{t_f^{(i)}} \ell^{(i)} \big( \boldsymbol y^{(i)}(t), t, x \big) \textrm{d}t \bigg],}\\
25+
%
26+
\text{subject to} \quad &
27+
\begin{aligned}
28+
f(x) & \in \mathcal S,\\
29+
%
30+
d^{(i)}\big(\dot{\boldsymbol y}^{(i)}(t), \boldsymbol y^{(i)}(t), t, x) & \in \mathcal D^{(i)},
31+
\quad \forall t \in [t_0^{(i)}, t_f^{(i)}],
32+
\quad \forall i \in \{1, 2, ..., n_p\},\\
33+
b(\boldsymbol y(t_0), \boldsymbol y(t_f), t_0, t_f, x) &\in \mathcal B,
34+
\end{aligned}
35+
\end{array}
36+
\end{align*}
37+
```
38+
39+
where:
40+
* ``f`` are [`MOI.AbstractScalarFunction`](@extref MathOptInterface.AbstractScalarFunction)s
41+
* ``\ell`` and ``d`` are [`AbstractDynamicFunction`](@ref)s
42+
* ``m`` and ``b`` are [`AbstractBoundaryFunction`](@ref)s
43+
44+
45+
## Dynamic Functions
46+
47+
* [`PhaseIndex`](@ref)
48+
* [`DynamicVariableIndex`](@ref)
49+
* [`LinearDynamicFunction`](@ref)
50+
* [`PureQuadraticDynamicFunction`](@ref)
51+
* [`NonlinearDynamicFunction`](@ref)
52+
* [`Derivative`](@ref)
53+
* [`ExplicitDifferentialFunction`](@ref)
54+
55+
## Boundary Functions
56+
57+
* [`Initial`](@ref)
58+
* [`Final`](@ref)
59+
* [`Linkage`](@ref)
60+
* [`NonlinearBoundaryFunction`](@ref)
61+
* [`Integral`](@ref)
62+
* [`MultiPhaseIntegral`](@ref)
63+
* [`Bolza`](@ref)

docs/src/reference/boundary_functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ NonlinearBoundaryFunction
3232
## Integrals
3333
```@docs
3434
Integral
35+
MultiPhaseIntegral
3536
Bolza
3637
```

docs/src/reference/dynamic_functions/derivatives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ CurrentModule = DynOptInterface
55
# Derivatives
66

77
```@docs
8-
DynamicVariableDerivative
8+
Derivative
99
ExplicitDifferentialFunction
1010
```

docs/src/reference/dynamic_functions/phases.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ MOI.is_valid(::MOI.ModelLike, ::PhaseIndex)
1414
InvalidPhaseIndex
1515
```
1616

17-
# Attributes
18-
19-
The [`PhaseIndex`](@ref) object is compatible with the following attributes:
20-
* [`MOI.VariableName`](@extref MathOptInterface.VariableName) with value types `String`
21-
* [`MOI.VariablePrimal`](@extref MathOptInterface.VariablePrimal) with value types `Tuple{<:Real,<:Real}`
22-
* [`MOI.VariablePrimalStart`](@extref MathOptInterface.VariablePrimalStart) with value types `Tuple{<:Real,<:Real}`
17+
# Phase Attributes
2318

2419
```@docs
25-
MOI.supports(::MOI.ModelLike, ::MOI.AbstractVariableAttribute, ::Type{PhaseIndex})
26-
MOI.set(::MOI.ModelLike, ::MOI.AbstractVariableAttribute, ::PhaseIndex, ::Any)
27-
MOI.get(::MOI.ModelLike, ::MOI.AbstractVariableAttribute, ::PhaseIndex)
20+
AbstractPhaseAttribute
21+
MOI.supports(::MOI.ModelLike, ::AbstractPhaseAttribute, ::Type{PhaseIndex})
22+
MOI.set(::MOI.ModelLike, ::AbstractPhaseAttribute, ::PhaseIndex, ::Any)
23+
MOI.get(::MOI.ModelLike, ::AbstractPhaseAttribute, ::PhaseIndex)
24+
PhaseName
2825
```

src/boundary_functions.jl

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ abstract type AbstractBoundaryFunction <: MOI.AbstractScalarFunction end
1616
## Initial & Final
1717

1818
"""
19-
Initial{DF}(dyn_fun::DF) where {DF<:AbstractDynamicFunction}
19+
Initial{DF}(evaluand::DF) where {DF<:AbstractDynamicFunction}
2020
2121
Represents the evaluation of an [`AbstractDynamicFunction`](@ref) at the initial
2222
point of its phase.
2323
2424
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The dynamic function is stored
25-
in the `dyn_fun` field.
25+
in the `evaluand` field.
2626
"""
2727
struct Initial{DF<:AbstractDynamicFunction} <: AbstractBoundaryFunction
28-
dyn_fun::DF
28+
evaluand::DF
2929
end
3030

3131
function MOI.Utilities._to_string(
@@ -35,22 +35,22 @@ function MOI.Utilities._to_string(
3535
)
3636
return string(
3737
"Initial(",
38-
MOI.Utilities._to_string(options, model, initial.dyn_fun),
38+
MOI.Utilities._to_string(options, model, initial.evaluand),
3939
")",
4040
)
4141
end
4242

4343
"""
44-
Final{DF}(dyn_fun::DF) where {DF<:AbstractDynamicFunction}
44+
Final{DF}(evaluand::DF) where {DF<:AbstractDynamicFunction}
4545
4646
Represents the evaluation of an [`AbstractDynamicFunction`](@ref) at the final
4747
point of its phase.
4848
4949
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The dynamic function is stored
50-
in the `dyn_fun` field.
50+
in the `evaluand` field.
5151
"""
5252
struct Final{DF<:AbstractDynamicFunction} <: AbstractBoundaryFunction
53-
dyn_fun::DF
53+
evaluand::DF
5454
end
5555

5656
function MOI.Utilities._to_string(
@@ -60,7 +60,7 @@ function MOI.Utilities._to_string(
6060
)
6161
return string(
6262
"Final(",
63-
MOI.Utilities._to_string(options, model, final.dyn_fun),
63+
MOI.Utilities._to_string(options, model, final.evaluand),
6464
")",
6565
)
6666
end
@@ -69,18 +69,18 @@ end
6969

7070
"""
7171
Linkage{DF}(
72-
final::Final{DF},
73-
initial::Initial{DF},
72+
final_evaluand::DF,
73+
initial_evaluand::DF,
7474
) where {DF<:AbstractDynamicFunction}
7575
7676
Represents the expression ``f_f(y(t^f), t^f) - f_0(y(t^0), t^0)``.
7777
7878
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The final function is stored in the
79-
`final` field and the initial function is stored in the `initial` field.
79+
`final_evaluand` field and the initial function is stored in the `initial_evaluand` field.
8080
"""
8181
struct Linkage{DF<:AbstractDynamicFunction} <: AbstractBoundaryFunction
82-
final::Final{DF}
83-
initial::Initial{DF}
82+
final_evaluand::DF
83+
initial_evaluand::DF
8484
end
8585

8686
function MOI.Utilities._to_string(
@@ -89,9 +89,11 @@ function MOI.Utilities._to_string(
8989
linkage::Linkage,
9090
)
9191
return string(
92-
MOI.Utilities._to_string(options, model, linkage.final),
93-
" - ",
92+
"Final(",
93+
MOI.Utilities._to_string(options, model, linkage.final_evaluand),
94+
") - Initial(",
9495
MOI.Utilities._to_string(options, model, linkage.initial),
96+
")",
9597
)
9698
end
9799

@@ -149,14 +151,14 @@ end
149151
## Integrals
150152

151153
"""
152-
Integral{DF}(dyn_fun::AbstractDynamicFunction) where {DF<:AbstractDynamicFunction}
154+
Integral{DF}(integrand::DF) where {DF<:AbstractDynamicFunction}
153155
154156
Represents the integral ``\\int_{t_i^o}^{t_i^f} f_d(\\dot{y}(t_i), y(t_i), t_i, x) \\mathrm{d}t_i``.
155157
156-
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The integrand is stored in the `dyn_fun` field.
158+
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The integrand is stored in the `integrand` field.
157159
"""
158160
struct Integral{DF<:AbstractDynamicFunction} <: AbstractBoundaryFunction
159-
dyn_fun::DF
161+
integrand::DF
160162
end
161163

162164
function MOI.Utilities._to_string(
@@ -166,34 +168,75 @@ function MOI.Utilities._to_string(
166168
)
167169
return string(
168170
"∫(",
169-
MOI.Utilities._to_string(options, model, integral.dyn_fun),
171+
MOI.Utilities._to_string(options, model, integral.integrand),
170172
")d(",
171173
MOI.Utilities._to_string(options, model, phase_index(integral)),
172174
")",
173175
)
174176
end
175177

176-
phase_index(integral::Integral) = phase_index(integral.dyn_fun)
178+
phase_index(integral::Integral) = phase_index(integral.integrand)
179+
180+
"""
181+
MultiPhaseIntegral{DF}(
182+
integrands::Vector{DF},
183+
) where {DF<:AbstractDynamicFunction}
184+
185+
Represents the sum of integrals
186+
``\\sum_i \\big[ \\int_{t_i^o}^{t_i^f} f_d(\\dot{y}(t_i), y(t_i), t_i, x) \\mathrm{d}t_i \\big]``.
187+
188+
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The vector of integrands is
189+
stored in the `integrands` field.
190+
"""
191+
struct MultiPhaseIntegral{DF<:AbstractDynamicFunction} <: AbstractBoundaryFunction
192+
integrands::Vector{DF}
193+
end
194+
195+
function MOI.Utilities._to_string(
196+
options::MOI.Utilities._PrintOptions,
197+
model::MOI.ModelLike,
198+
multi_phase_integral::MultiPhaseIntegral,
199+
)
200+
integrands = multi_phase_integral.integrands
201+
202+
s = string(
203+
"∫(",
204+
MOI.Utilities._to_string(options, model, integrands[1]),
205+
")d(",
206+
MOI.Utilities._to_string(options, model, phase_index(integrands[1])),
207+
")",
208+
)
209+
210+
for i in 2:length(integrands)
211+
s *= string(
212+
" + ∫(",
213+
MOI.Utilities._to_string(options, model, integrands[i]),
214+
")d(",
215+
MOI.Utilities._to_string(options, model, phase_index(integrands[i])),
216+
")",
217+
)
218+
end
219+
return s
220+
end
177221

178222
"""
179-
Bolza{BF,DF}(
223+
Bolza{BF,IF}(
180224
bou_fun::BF,
181-
integral::Integral{DF},
182-
) where {BF<:AbstractBoundaryFunction,DF<:AbstractDynamicFunction}
225+
integral::IF,
226+
) where {BF<:AbstractBoundaryFunction,IF<:Union{Integral,MultiPhaseIntegral}}
183227
184228
```math
185229
f_b(y_0, y_f, t_0, t_f, x) + \\int_{t_i^o}^{t_i^f} f_d(\\dot{y}(t_i), y(t_i), t_i, x) \\mathrm{d}t_i
186230
```
187-
Represents the sum of an [`AbstractBoundaryFunction`](@ref) with the integral of
188-
an [`AbstractDynamicFunction`](@ref).
231+
Represents the sum of an [`AbstractBoundaryFunction`](@ref) with either an [`Integral`](@ref) or a
232+
[`MultiPhaseIntegral`](@ref).
189233
190234
It is a sub-type of [`AbstractBoundaryFunction`](@ref). The boundary function is stored in the `bou_fun`
191235
field and the integral is stored in the `integral` field.
192236
"""
193-
struct Bolza{BF<:AbstractBoundaryFunction,DF<:AbstractDynamicFunction} <:
194-
AbstractBoundaryFunction
237+
struct Bolza{BF<:AbstractBoundaryFunction,IF<:Union{Integral,MultiPhaseIntegral}} <: AbstractBoundaryFunction
195238
bou_fun::BF
196-
integral::Integral{DF}
239+
integral::IF
197240
end
198241

199242
function MOI.Utilities._to_string(

src/dynamic_functions/abstraction.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Abstract super-type for dynamic functions.
66
That is, expressions that may contain:
77
* ``t_i`` -- a [`PhaseIndex`](@ref)
88
* ``y_j(\\cdot)`` -- a [`DynamicVariableIndex`](@ref)
9-
* ``\\dot{y}_j(\\cdot)`` -- a [`DynamicVariableDerivative`](@ref)
10-
Sub-types of [`AbstractDynamicFunction`](@ref) must not contain different
11-
[`PhaseIndex`](@ref)s.
9+
10+
Sub-types of [`AbstractDynamicFunction`](@ref) must be defined on a single
11+
[`PhaseIndex`](@ref).
1212
"""
1313
abstract type AbstractDynamicFunction <: MOI.AbstractScalarFunction end
1414

1515
"""
1616
phase_index(dyn_fun::AbstractDynamicFunction)::PhaseIndex
1717
18-
Returns the [`PhaseIndex`](@ref) ``t_i`` of the dynamic function `dyn_fun`.
18+
Returns the [`PhaseIndex`](@ref) ``t_i`` of a dynamic function `dyn_fun`.
1919
"""
2020
function phase_index(::AbstractDynamicFunction)::PhaseIndex end
2121

0 commit comments

Comments
 (0)