Skip to content

Commit a0b0679

Browse files
authored
Merge pull request #771 from control-toolbox/macro-free-def
Macro free documentation
2 parents 4c22d34 + 9c72060 commit a0b0679

12 files changed

Lines changed: 1017 additions & 12 deletions

File tree

docs/make.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ with_api_reference(src_dir, ext_dir) do api_pages
193193
format=Documenter.HTML(;
194194
repolink="https://" * repo_url,
195195
prettyurls=false,
196+
example_size_threshold=2_000_000,
197+
size_threshold_warn=2_000_000,
198+
size_threshold=2_000_000,
196199
assets=[
197200
asset("https://control-toolbox.org/assets/css/documentation.css"),
198201
asset("https://control-toolbox.org/assets/js/documentation.js"),
@@ -213,7 +216,10 @@ with_api_reference(src_dir, ext_dir) do api_pages
213216
"State constraint" => "example-state-constraint.md",
214217
],
215218
"Manual" => [
216-
"Define a problem" => "manual-abstract.md",
219+
"Define a problem" => [
220+
"Abstract syntax (@def)" => "manual-abstract.md",
221+
"Functional API (macro-free)" => "manual-macro-free.md",
222+
],
217223
"Use AI" => "manual-ai-llm.md",
218224
"Problem characteristics" => "manual-model.md",
219225
"Set an initial guess" => "manual-initial-guess.md",

docs/src/api/public.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ boundary_constraints_dual
4141
boundary_constraints_nl
4242
bypass
4343
components
44-
constraint
44+
CTModels.OCP.constraint
4545
constraints
4646
constraints_violation
4747
control
@@ -66,7 +66,7 @@ dim_path_constraints_nl
6666
dim_state_constraints_box
6767
dim_variable_constraints_box
6868
dimension
69-
discretize
69+
CTDirect.discretize
7070
dual
7171
dynamics
7272
export_ocp_solution
@@ -112,11 +112,11 @@ lagrange
112112
mayer
113113
message
114114
metadata
115-
methods
115+
methods()
116116
model
117117
name
118118
nlp_model
119-
objective
119+
CTModels.OCP.objective
120120
ocp_model
121121
ocp_solution
122122
option_default
@@ -149,7 +149,7 @@ time
149149
time_grid
150150
time_name
151151
times
152-
variable
152+
CTModels.OCP.variable
153153
variable_components
154154
variable_constraints_box
155155
variable_constraints_lb_dual

docs/src/assets/custom.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,43 @@
3333
.responsive-columns-left-priority > div:first-child {
3434
flex: 1 1 100%;
3535
}
36+
}
37+
38+
/* 30% / 70% two-column layout */
39+
.responsive-columns-30-70 {
40+
display: flex;
41+
gap: 1rem;
42+
align-items: flex-start;
43+
margin-bottom: 1em;
44+
}
45+
46+
.responsive-columns-30-70 > div:first-child {
47+
flex: 3;
48+
min-width: 0;
49+
transition: opacity 0.5s ease-in-out, flex 0.5s ease-in-out, max-width 0.5s ease-in-out, max-height 0.5s ease-in-out;
50+
}
51+
52+
.responsive-columns-30-70 > div:last-child {
53+
flex: 7;
54+
min-width: 0;
55+
opacity: 1;
56+
max-width: 100%;
57+
max-height: none;
58+
transition: opacity 0.5s ease-in-out, flex 0.5s ease-in-out, max-width 0.5s ease-in-out, max-height 0.5s ease-in-out;
59+
}
60+
61+
@media (max-width: 700px) {
62+
.responsive-columns-30-70 > div:last-child {
63+
opacity: 0;
64+
max-width: 0;
65+
max-height: 0;
66+
flex: 0 0 0;
67+
overflow: hidden;
68+
margin: 0;
69+
padding: 0;
70+
}
71+
72+
.responsive-columns-30-70 > div:first-child {
73+
flex: 1 1 100%;
74+
}
3675
}

docs/src/index.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,57 @@ plot(sol)
4343
- The [`solve`](@ref) function has many options. See the [solve tutorial](@ref manual-solve).
4444
- The [`plot`](@ref) function is flexible. See the [plot tutorial](@ref manual-plot).
4545

46+
## [Mathematical formulation](@id math-formulation)
47+
48+
An optimal control problem (OCP) with fixed initial and final times can be described as minimising the cost functional (in Bolza form)
49+
50+
```math
51+
J(x, u) = g(x(t_0), x(t_f)) + \int_{t_0}^{t_f} f^{0}(t, x(t), u(t))\,\mathrm{d}t
52+
```
53+
54+
where the state $x$ and the control $u$ are functions of time $t$, subject for $t \in [t_0, t_f]$ to the differential constraint
55+
56+
```math
57+
\dot{x}(t) = f(t, x(t), u(t))
58+
```
59+
60+
and other constraints such as
61+
62+
```math
63+
\begin{array}{llcll}
64+
x_{\mathrm{lower}} & \le & x(t) & \le & x_{\mathrm{upper}}, \\
65+
u_{\mathrm{lower}} & \le & u(t) & \le & u_{\mathrm{upper}}, \\
66+
c_{\mathrm{lower}} & \le & c(t, x(t), u(t)) & \le & c_{\mathrm{upper}}, \\
67+
b_{\mathrm{lower}} & \le & b(x(t_0), x(t_f)) & \le & b_{\mathrm{upper}}.
68+
\end{array}
69+
```
70+
71+
If $g = 0$, the cost is said to be in **Lagrange form**; if $f^0 = 0$, it is in **Mayer form**.
72+
73+
### Free times and extra variables
74+
75+
The initial time $t_0$ and the final time $t_f$ may also be free, that is part of the optimisation variables:
76+
77+
```math
78+
J(x, u, t_0, t_f) \to \min.
79+
```
80+
81+
More generally, a vector $v \in \mathbb{R}^k$ of $k$ additional variables can be introduced (it may contain $t_0$, $t_f$, or any other free parameter). The cost, dynamics, and constraints then all depend on $v$:
82+
83+
```math
84+
J(x, u, v) = g(x(t_0), x(t_f), v) + \int_{t_0}^{t_f} f^{0}(t, x(t), u(t), v)\,\mathrm{d}t \to \min,
85+
```
86+
87+
```math
88+
\dot{x}(t) = f(t, x(t), u(t), v),
89+
```
90+
91+
with, in addition, box constraints on $v$:
92+
93+
```math
94+
v_{\mathrm{lower}} \le v \le v_{\mathrm{upper}}.
95+
```
96+
4697
## Citing us
4798

4899
If you use OptimalControl.jl in your work, please cite us:

docs/src/manual-initial-guess.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ nothing # hide
565565

566566
!!! tip "Interactions with an optimal control solution"
567567

568-
Please check [`state`](@ref), [`costate`](@ref), [`control`](@ref) and [`variable`](@ref variable(::Solution)) to get data from the solution. The functions `state`, `costate` and `control` return functions of time and `variable` returns a vector.
568+
Please check [`state`](@ref), [`costate`](@ref), [`control`](@ref) and [`variable`](@ref CTModels.OCP.variable) to get data from the solution. The functions `state`, `costate` and `control` return functions of time and `variable` returns a vector.
569569

570570
## Costate / multipliers
571571

0 commit comments

Comments
 (0)