Skip to content

Commit

Permalink
Merge pull request #18 from control-toolbox/final_version
Browse files Browse the repository at this point in the history
new
  • Loading branch information
AnasXbouali authored Aug 24, 2024
2 parents bcbb3e8 + 23b7031 commit fac8137
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 416 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"julia.environmentPath": "c:\\Users\\Anas\\Desktop\\control-loss"
}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "ControlLoss"
uuid = "6a3a0e7e-9c90-4c26-bc64-8dd630726a7b"
authors = ["Olivier Cots <[email protected]>"]
version = "0.1.4"
version = "0.1.5"
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
OptimalControl = "5f98b655-cc9a-415a-b60e-744165666948"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand Down
6 changes: 4 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ makedocs(
sitename = "Control loss",
format = Documenter.HTML(
prettyurls = false,
size_threshold_ignore = ["statement.md", "numerical.md","zermelo.md", "ho.md"],
size_threshold_ignore = ["statement.md", "numerical.md","zermelo1.md","zermelo2.md", "ho.md"],
assets=[
asset("https://control-toolbox.org/assets/css/documentation.css"),
asset("https://control-toolbox.org/assets/js/documentation.js"),
Expand All @@ -15,7 +15,9 @@ makedocs(
"Introduction" => "index.md",
"Statement of the problem" => "statement.md",
"Numerical approach" => "numerical.md",
"Zermelo navigation problem" => "zermelo.md",
"Zermelo navigation problem: Example 1" => "zermelo1.md",
"Zermelo navigation problem: Example 2" => "zermelo2.md",

"Harmonic oscillator problem" => "ho.md",

]
Expand Down
43 changes: 21 additions & 22 deletions docs/src/ho.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ println(" p2(t1+) - p2(t1-) = ", jmp1)
println(" p2(t2+) - p2(t2-) = ", jmp2)
```

## Indirect Method


```@example main
using NLsolve
using Animations
using NonlinearSolve
using OrdinaryDiffEq
using Animations
```

```@example main
Expand Down Expand Up @@ -260,33 +263,29 @@ nothing # hide
```

```@example main
S(ξ) = shoot(ξ[1:2], ξ[3], ξ[4], ξ[5],ξ[6],ξ[7],ξ[8], ξ[9], ξ[10]);
nle! = (ξ, λ) -> shoot(ξ[1:2], ξ[3], ξ[4], ξ[5],ξ[6],ξ[7],ξ[8], ξ[9], ξ[10])
ξ_guess = [p1(0) , p2(0), t1, t2, tstar , t3, a, jmp1, jmp2, t4]; # initial guess
S(ξ_guess)
prob = NonlinearProblem(nle!, ξ_guess)
```

```@example main
# Solve
#solve
indirect_sol = solve(prob; abstol=1e-8, reltol=1e-8, show_trace=Val(true))
```

indirect_sol = nlsolve(S, ξ_guess; xtol=1e-8, method=:trust_region, show_trace=true)
println(indirect_sol)

```@example main
# Retrieves solution
if indirect_sol.f_converged || indirect_sol.x_converged
pp0 = indirect_sol.zero[1:2]
tt1 = indirect_sol.zero[3]
tt2 = indirect_sol.zero[4]
ttstar = indirect_sol.zero[5]
tt3 = indirect_sol.zero[6]
b11 = indirect_sol.zero[7]
jmp1 = indirect_sol.zero[8]
jmp2 = indirect_sol.zero[9]
T1 = indirect_sol.zero[10]
else
error("Not converged")
end
nothing # hide
pp0 = indirect_sol[1:2]
tt1 = indirect_sol[3]
tt2 = indirect_sol[4]
ttstar = indirect_sol[5]
tt3 = indirect_sol[6]
b11 = indirect_sol[7]
jmp1 = indirect_sol[8]
jmp2 = indirect_sol[9]
T1 = indirect_sol[10]
nothing # hide
```

```@example main
Expand Down
4 changes: 2 additions & 2 deletions docs/src/numerical.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ for all $x\in \R^n$, where $\mathrm{d}_{j}: \R^n \to \R$ stands for the distance
## Description of the indirect method

Recall that the direct method has captured the structure of the optimal pair $(x^*,u^*)$. In the indirect method, we address each arc separately.
We begin by defining the **flow** of the Hamiltonian associated with each arc. To accomplish this, we use the function `Flow` that can be found in the [`CTFlows.jl`](https://github.com/control-toolbox/CTFlows.jl) package. This latter allows to solve the Hamiltonian system over a given time interval from given initial values of the state and the adjoint vector. This function requires necessary libraries such as \texttt{ForwardDiff} for calculating gradients and Jacobians and `OrdinaryDiffEq` for solving ordinary differential equations.
We begin by defining the **flow** of the Hamiltonian associated with each arc. To accomplish this, we use the function `Flow` that can be found in the [CTFlows.jl](https://github.com/control-toolbox/CTFlows.jl) package. This latter allows to solve the Hamiltonian system over a given time interval from given initial values of the state and the adjoint vector. This function requires necessary libraries such as ForwardDiff for calculating gradients and Jacobians and OrdinaryDiffEq for solving ordinary differential equations.

In the setting of the present paper (including control regions and loss control regions), we distinguish between two types of Hamiltonian flows:

- **Hamiltonian flows in control regions** We recall that the Hamiltonian $H$ associated with the optimal control problem given above is defined by
```math
H(x,u,p) := \langle p, f(x,u)\rangle_{\R^n},
```
for all $(x,u,p)\in \mathbb{R}^n \times \mathbb{R}^m \times \mathbb{R}^n$. Using the theorem given above and more specifically the Hamiltonian maximization condition, we obtain an expression of the control $u^*$ which can generate a sequence of arcs. Then it remains to define a \textit{pseudo-Hamiltonian}\footnote{the pseudo-Hamiltonian stands for the Hamiltonian flow associated with each arc.} associated with each arc. Finally we define the flow associated with each arc, which allows the resolution of the boundary value problem on a time interval satisfied by the pair $(x^*,p)$ with an initial condition.
for all $(x,u,p)\in \mathbb{R}^n \times \mathbb{R}^m \times \mathbb{R}^n$. Using the theorem given above and more specifically the Hamiltonian maximization condition, we obtain an expression of the control $u^*$ which can generate a sequence of arcs. Then it remains to define a **pseudo-Hamiltonian** (the pseudo-Hamiltonian stands for the Hamiltonian flow associated with each arc). associated with each arc. Finally we define the flow associated with each arc, which allows the resolution of the boundary value problem on a time interval satisfied by the pair $(x^*,p)$ with an initial condition.

- **Hamiltonian flows in loss control regions** Recall that, in loss control regions, $u^*$ satisfies an averaged Hamiltonian gradient condition (see Theorem above). Here, the difficulty lies in the fact that this condition is given in an integral and implicit form. Therefore, to overcome this difficulty, we first introduce new states $\lambda$ and $y$. First, the state $\lambda$ comes from the augmentation technique (we refer to [^3] for more details) to handle the constant value $u^*_k$, so it satisfies the dynamics $\dot{\lambda}(t)=0$ and the initial condition $\lambda(\tau^*_{k-1}) = u^*_k$. Second, the state $y$ satisfies $\dot{y}(t) = 0$ and $y(\tau^*_{k-1})=0$ (and thus $y=0$). Now we define the new Hamiltonian $\tilde{H}$ as follows:
```math
Expand Down
2 changes: 1 addition & 1 deletion docs/src/statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ u \text{ is constant when } x \text{ is in a loss control region}.
The PMP with loss control regions is based on some regularity assumptions made on the optimal pair of the optimal control problem with loss control regions given above at each of its crossing times. These hypotheses are made more precise in the next definition.

!!! note "Definition (Regular solution to (CS))"
Following the notations introduced in Definition given above, a solution $(x,u) \in \mathrm{AC}([0,T],\R^n) \times \mathrm{L}^\infty([0,T],\R^m)$ to(CS), associated with a finite number $N \in \mathbb{N}^*$, a partition $\mathbb{T} = \{ \tau_k \}_{k=0,\ldots,N}$ and a switching sequence $\{j(1), \ldots, j(N)\}$, is said to be *regular* if the following conditions are both satisfied:
Following the notations introduced in Definition given above, a solution $(x,u) \in \mathrm{AC}([0,T],\R^n) \times \mathrm{L}^\infty([0,T],\R^m)$ to (CS), associated with a finite number $N \in \mathbb{N}^*$, a partition $\mathbb{T} = \{ \tau_k \}_{k=0,\ldots,N}$ and a switching sequence $\{j(1), \ldots, j(N)\}$, is said to be *regular* if the following conditions are both satisfied:
- At each crossing time $\tau_k$, there exists a $\mathrm{C}^1$ function $F_k : \R^n \to \R$ such that
```math
\begin{equation}
Expand Down
Loading

0 comments on commit fac8137

Please sign in to comment.