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

187 oc upgrade #192

Merged
merged 16 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@ jobs:
strategy:
matrix:
version:
#- '1.8'
- '1.9'
- '1.10'
os:
- ubuntu-latest
#- macOS-latest
##- windows-latest
#- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/add-julia-registry@v1
- uses: julia-actions/add-julia-registry@v2
with:
key: ${{ secrets.SSH_KEY }}
registry: control-toolbox/ct-registry
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-uploadcodecov@latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
- uses: julia-actions/add-julia-registry@v1
- uses: julia-actions/add-julia-registry@v2
with:
key: ${{ secrets.SSH_KEY }}
registry: control-toolbox/ct-registry
- uses: julia-actions/julia-buildpkg@v1
with:
version: '1.8'
version: '1.10'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
GKSwstype: 100 # To make GitHub Action work, disable showing a plot window with the GR backend of the Plots package
run: julia --project=docs/ docs/make.jl
run: julia --project=docs/ docs/make.jl
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CTFlows = "1c39547c-7794-42f7-af83-d98194f657c2"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"

[compat]
CTBase = "0.9"
CTDirect = "0.6"
CTFlows = "0.3"
julia = "1.8"
CTBase = "0.11"
CTDirect = "0.9"
CTFlows = "0.4"
julia = "1.10"
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
CTDirect = "790bbbee-bee9-49ee-8912-a9de031322d5"
CTFlows = "1c39547c-7794-42f7-af83-d98194f657c2"
CTProblems = "45d9ea3f-a92f-411f-833f-222dd4fb9cd8"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MINPACK = "4854310b-de5a-5eb6-a2a5-c1dee2bd17f9"
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
4 changes: 0 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ makedocs(
"tutorial-plot.md",
"tutorial-lqr-basic.md",
"tutorial-iss.md",
#"tutorial-model.md",
#"tutorial-solvers.md",
#"tutorial-flows.md",
#"tutorial-ct_repl.md",
],
"Applications" => [
"tutorial-batch.md",
Expand Down
19 changes: 7 additions & 12 deletions docs/src/tutorial-basic-example-f.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,24 @@ starting from the condition $x(0) = (-1, 0)$ and with the goal to reach the targ
[Double integrator: energy minimisation](https://control-toolbox.org/docs/ctproblems/stable/problems/double_integrator_energy.html#DIE)
for the analytical solution and details about this problem.

```@setup main
using Plots
using Plots.PlotMeasures
plot(args...; kwargs...) = Plots.plot(args...; kwargs..., leftmargin=25px)
```

First, we need to import the `OptimalControl.jl` package:
First, we need to import the `OptimalControl.jl` package to define and solve the optimal control problem. We also need to import the `Plots.jl` package to plot the solution.

```@example main
using OptimalControl
using Plots
```

Then, we can define the problem

```@example main
ocp = Model() # empty optimal control problem

time!(ocp, [ 0, 1 ]) # time interval
time!(ocp, t0=0, tf=1) # initial and final times
state!(ocp, 2) # dimension of the state
control!(ocp, 1) # dimension of the control

constraint!(ocp, :initial, [ -1, 0 ]) # initial condition
constraint!(ocp, :final, [ 0, 0 ]) # final condition
constraint!(ocp, :initial; lb=[ -1, 0 ], ub=[ -1, 0 ]) # initial condition
constraint!(ocp, :final; lb=[ 0, 0 ], ub=[ 0, 0 ]) # final condition

dynamics!(ocp, (x, u) -> [ x[2], u ]) # dynamics of the double integrator

Expand All @@ -62,7 +57,7 @@ nothing # hide

There are two ways to define an optimal control problem:
- using functions like in this example, see also the [`Model` documentation](https://control-toolbox.org/docs/ctbase/stable/api-model.html) for more details.
- using an abstract formulation. You can compare both ways taking a look at the abstract version of this [basic example](@ref basic).
- using an abstract formulation, see for instance [basic example](@ref basic) to compare.

Solve it

Expand All @@ -74,5 +69,5 @@ nothing # hide
and plot the solution

```@example main
plot(sol, size=(600, 450))
plot(sol)
```
13 changes: 4 additions & 9 deletions docs/src/tutorial-basic-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We denote by $x = (x_1, x_2)$ the state of the wagon, that is its position $x_1$
We assume that the mass is constant and unitary and that there is no friction. The dynamics we consider is given by

```math
\dot x_1(t) = x_2(t), \quad \dot x_2(t) = u(t), , \quad u(t) \in \R,
\dot x_1(t) = x_2(t), \quad \dot x_2(t) = u(t),\quad u(t) \in \R,
```

which is simply the [double integrator](https://en.wikipedia.org/w/index.php?title=Double_integrator&oldid=1071399674) system.
Expand All @@ -28,16 +28,11 @@ starting from the condition $x(0) = (-1, 0)$ and with the goal to reach the targ
[Double integrator: energy minimisation](https://control-toolbox.org/docs/ctproblems/stable/problems/double_integrator_energy.html#DIE)
for the analytical solution and details about this problem.

```@setup main
using Plots
using Plots.PlotMeasures
plot(args...; kwargs...) = Plots.plot(args...; kwargs..., leftmargin=25px)
```

First, we need to import the `OptimalControl.jl` package:
First, we need to import the `OptimalControl.jl` package to define and solve the optimal control problem. We also need to import the `Plots.jl` package to plot the solution.

```@example main
using OptimalControl
using Plots
```

Then, we can define the problem
Expand Down Expand Up @@ -65,5 +60,5 @@ nothing # hide
and plot the solution

```@example main
plot(sol, size=(600, 450))
plot(sol)
```
11 changes: 8 additions & 3 deletions docs/src/tutorial-batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ w_R(p) = \frac{k_R\,p}{K_r + p}\,, \quad w_M(s) = \frac{k_m s}{K_m + s}\cdot

## Biomass maximisation

We are interested in maximising the biomass production [^3] (final volume of the bacterial population) over a finite time horizon $[0,t_f]$. To solve the problem, we first set up the boundary values,
We first import the needed packages.

```@example main
using OptimalControl
using Plots
```

We are interested in maximising the biomass production [^3] (final volume of the bacterial population) over a finite time horizon $[0,t_f]$. To solve the problem, we first set up the boundary values,

```@example main
t0 = 0
tf = 90
s0 = 0.1
Expand Down Expand Up @@ -148,8 +153,8 @@ println("Objective ", sol2.objective, " after ", sol2.iterations, " iterations")
We eventually plot the solutions (raw grid + finer grid) and observe that the control exhibits the expected structure with a Fuller-in arc followed by a singular one, then a Fuller-out arc:

```@example main
plot(sol1, size=(800, 800))
plot!(sol2)
plot(sol1; solution_label="(N=20)", size=(800, 1000)) # N is the grid size
plot!(sol2; solution_label="(N=1000)")
```

## References
Expand Down
3 changes: 0 additions & 3 deletions docs/src/tutorial-ct_repl.md

This file was deleted.

26 changes: 17 additions & 9 deletions docs/src/tutorial-double-integrator.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,38 @@ a line without fricton.
<img src="./assets/chariot.png" style="display: block; margin: 0 auto 20px auto;" width="300px">
```

First, we need to import the `OptimalControl.jl` package:
First, we need to import the `OptimalControl.jl` package to define and solve the optimal control problem. We also need to import the `Plots.jl` package to plot the solution.

```@example main
using OptimalControl
using Plots
```

Then, we can define the problem

```@example main
@def ocp begin
tf ∈ R, variable
t ∈ [ 0, tf ], time

tf ∈ R, variable
t ∈ [ 0, tf ], time
x = (q, v) ∈ R², state
u ∈ R, control
u ∈ R, control

tf ≥ 0
-1 ≤ u(t) ≤ 1
q(0) == 1
v(0) == 2

q(0) == 1
v(0) == 2
q(tf) == 0
v(tf) == 0
0 ≤ q(t) ≤ 5, (1)
-2 ≤ v(t) ≤ 3, (2)

0 ≤ q(t) ≤ 5, (1)
-2 ≤ v(t) ≤ 3, (2)

ẋ(t) == [ v(t), u(t) ]

tf → min

end
nothing # hide
```
Expand All @@ -65,5 +73,5 @@ nothing # hide
and plot the solution

```@example main
plot(sol, size=(600, 450))
plot(sol)
```
3 changes: 0 additions & 3 deletions docs/src/tutorial-flows.md

This file was deleted.

18 changes: 8 additions & 10 deletions docs/src/tutorial-goddard.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ $v(t) \leq v_{\max}$. The initial state is fixed while only the final mass is pr
## Direct method

```@setup main
using Plots
using Plots.PlotMeasures
plot(args...; kwargs...) = Plots.plot(args...; kwargs..., leftmargin=25px)
using Suppressor # to suppress warnings
```

We import the `OptimalControl.jl` package:
We import the `OptimalControl.jl` package to define and solve the optimal control problem. We import the `Plots.jl` package to plot the solution. The `DifferentialEquations.jl` package is used to define the shooting function for the indirect method and the `MINPACK.jl` package permits solve the shooting equation.

```@example main
using OptimalControl
using Plots
using DifferentialEquations # to get the Flow function
using MINPACK # NLE solver
```

We define the problem
Expand Down Expand Up @@ -99,14 +99,14 @@ nothing # hide
We then solve it

```@example main
direct_sol = solve(ocp, grid_size=100)
direct_sol = OptimalControl.solve(ocp, grid_size=100)
nothing # hide
```

and plot the solution

```@example main
plt = plot(direct_sol, size=(600, 600))
plt = plot(direct_sol, solution_label="(direct)", size=(800, 800))
```

## Indirect method
Expand All @@ -130,7 +130,7 @@ u_plot = plot(t, u, label = "u(t)")
H1_plot = plot(t, φ, label = "H₁(x(t), p(t))")
g_plot = plot(t, g ∘ x, label = "g(x(t))")

plot(u_plot, H1_plot, g_plot, layout=(3,1), size=(600,450))
plot(u_plot, H1_plot, g_plot, layout=(3,1), size=(500, 500))
```

We are now in position to solve the problem by an indirect shooting method. We first define
Expand Down Expand Up @@ -268,8 +268,6 @@ println("Norm of the shooting function: ‖s‖ = ", norm(s), "\n")
Finally, we can solve the shooting equations thanks to the [MINPACK](https://docs.sciml.ai/NonlinearSolve/stable/solvers/NonlinearSystemSolvers/#MINPACK.jl) solver.

```@example main
using MINPACK # NLE solver

nle = (s, ξ) -> shoot!(s, ξ[1:3], ξ[4], ξ[5], ξ[6], ξ[7]) # auxiliary function
# with aggregated inputs
ξ = [ p0 ; t1 ; t2 ; t3 ; tf ] # initial guess
Expand Down Expand Up @@ -306,7 +304,7 @@ We plot the solution of the indirect solution (in red) over the solution of the
f = f1 * (t1, fs) * (t2, fb) * (t3, f0) # concatenation of the flows
flow_sol = f((t0, tf), x0, p0) # compute the solution: state, costate, control...

plot!(plt, flow_sol)
plot!(plt, flow_sol, solution_label="(indirect)")
```

## References
Expand Down
3 changes: 3 additions & 0 deletions docs/src/tutorial-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ We present in this tutorial the different possibilities to provide an initial gu

```@example main
using OptimalControl
using Plots
```

```@example main
t0 = 0
tf = 10
α = 5
Expand Down
9 changes: 8 additions & 1 deletion docs/src/tutorial-iss.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Let us start by importing the necessary packages.

```@example main
using OptimalControl
using MINPACK # NLE solver
using Plots
using DifferentialEquations # to get the Flow function from OptimalControl
using MINPACK # NLE solver: we get the fsolve function
```

Let us consider the following optimal control problem:
Expand All @@ -35,13 +37,18 @@ x0 = -1
xf = 0
α = 1.5
@def ocp begin

t ∈ [ t0, tf ], time
x ∈ R, state
u ∈ R, control

x(t0) == x0
x(tf) == xf

ẋ(t) == -x(t) + α * x(t)^2 + u(t)

∫( 0.5u(t)^2 ) → min

end;
nothing # hide
```
Expand Down
Loading
Loading