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

build_solution #207

Merged
merged 1 commit into from
Jul 9, 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
13 changes: 6 additions & 7 deletions docs/src/tutorial-nlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We describe here some more advanced operations related to the discretized optima
When calling ```solve(ocp)``` three steps are performed internally:
- first, the OCP is discretized into a DOCP (a nonlinear optimization problem) with *direct_transcription*
- then, this DOCP is solved, also with the method *solve*
- finally, a functional solution of the OCP is rebuilt from the solution of the discretized problem, with *ocp_solution_from_docp*
- finally, a functional solution of the OCP is rebuilt from the solution of the discretized problem, with *build_solution*

These steps can also be done separately, for instance if you want to use your own NLP solver. Let us load the modules

Expand Down Expand Up @@ -45,18 +45,17 @@ nlp = get_nlp(docp)
```
You could then use a custom solver that would return the solution for the NLP problem, such as
```
nlpsol = MySolver(getNLP(docp))
nlp_sol = MySolver(get_nlp(docp))
```
For illustrative purpose we can mimick this by using the *solve* from *CTDirect* on the DOCP, and extract the NLP solution alone, without the multipliers and other informations
For illustrative purpose we can mimick this by using the *solve* from *CTDirect* on the DOCP, and extract the NLP solution and multipliers
```@example main
using CTDirect
dsol = CTDirect.solve(docp, display=false)
nlpsol = dsol.solution
nlp_sol = CTDirect.solve(docp, display=false)
nothing # hide
```
Then we can rebuild and plot an OCP solution (note that the costate has not been retrieved in this case)
Then we can rebuild and plot an OCP solution (note that the multipliers are optional, but the OCP costate will not be retrieved if the multipliers are not provided)
```@example main
sol = ocp_solution_from_nlp(docp, nlpsol)
sol = build_solution(docp, primal=nlp_sol.solution, dual=nlp_sol.multipliers)
plot(sol)
```

Expand Down
2 changes: 1 addition & 1 deletion src/OptimalControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export *
export direct_transcription
export get_nlp
export set_initial_guess
export ocp_solution_from_docp
export build_solution
export save
export load
export export_ocp_solution
Expand Down
Loading