Skip to content

Add tutorials on free times #25

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

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cp(
repo_url = "github.com/control-toolbox/Tutorials.jl"

makedocs(;
draft=false, # if draft is true, then the julia code from .md is not executed
draft=true, # if draft is true, then the julia code from .md is not executed
# to disable the draft mode in a specific markdown file, use the following:
# ```@meta
# Draft = false
Expand All @@ -38,6 +38,12 @@ makedocs(;
"Tutorials and Advanced Features" => [
"Discrete continuation" => "tutorial-continuation.md",
"Discretisation methods" => "tutorial-discretisation.md",
"Free times" => [
"Final time" => "tutorial-free-times-final.md",
"Initial time" => "tutorial-free-times-initial.md",
"Final and initial times" => "tutorial-free-times-final-initial.md",
"Orbital transfer min time" => "tutorial-free-times-orbital.md",
],
"NLP manipulations" => "tutorial-nlp.md",
"Indirect simple shooting" => "tutorial-iss.md",
"Goddard: direct, indirect" => "tutorial-goddard.md",
Expand Down
3 changes: 2 additions & 1 deletion docs/src/tutorial-continuation.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Discrete continuation

By using the warm start option, it is easy to implement a basic discrete continuation method, in which a sequence of problems is solved by using each solution as the initial guess for the next problem.
Expand Down Expand Up @@ -53,7 +54,7 @@ Then we perform the continuation with a simple *for* loop, using each solution t
init = ()
data = DataFrame(T=Float64[], Objective=Float64[], Iterations=Int[])
for T ∈ range(1, 2, length=5)
ocp = problem(T)
ocp = problem(T)
sol = solve(ocp; init=init, display=false)
global init = sol
push!(data, (T=T, Objective=objective(sol), Iterations=iterations(sol)))
Expand Down
54 changes: 54 additions & 0 deletions docs/src/tutorial-free-times-final-initial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
```@meta
Draft = false
```

# [Optimal control problem with free initial and free final times](@id tutorial-free-times-final-initial)

In this tutorial, we explore optimal control problems with free initial time `t₀` and final time `t_f`.


## Here are the required packages for the tutorial:

```@example both_time
using OptimalControl
using NLPModelsIpopt
using BenchmarkTools
using DataFrames
using Plots
using Printf
```
## Definition of the problem

```@example both_time

@def ocp begin
v=(t0, tf) ∈ R², variable
t ∈ [t0, tf], time
x ∈ R², state
u ∈ R, control
-1 ≤ u(t) ≤ 1
x(t0) == [0, 0]
x(tf) == [1, 0]
0.05 ≤ t0 ≤ 10
0.05 ≤ tf ≤ 10
0.01 ≤ tf - t0 ≤ Inf
ẋ(t) == [x₂(t), u(t)]
t0 → max
end

nothing # hide
```

# Direct resolution with both final and inital times being free:


We now solve the problem using a direct method, with automatic treatment of the free initial time.

```@example both_time
sol = solve(ocp; grid_size=100)
```
And plot the solution.

```@example both_time
plot(sol; label="direct", size=(800, 800))
```
Loading
Loading