Skip to content

Commit

Permalink
parse constraints and their multipliers (#198)
Browse files Browse the repository at this point in the history
* parse constraints and their multipliers

* some code cleanup

* some code cleanup

* separate files for test problems
  • Loading branch information
PierreMartinon authored Aug 9, 2024
1 parent 99a469a commit 23c7637
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 407 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CTDirect"
uuid = "790bbbee-bee9-49ee-8912-a9de031322d5"
authors = ["Olivier Cots <[email protected]>"]
version = "0.11.0"
version = "0.11.1"

[deps]
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
CTDirect = "790bbbee-bee9-49ee-8912-a9de031322d5"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterMermaid = "a078cd44-4d9c-4618-b545-3ab9d77f9177"
HSL = "34c5aeac-e683-54a6-a0e9-6e0fdc586c50"
Expand Down
27 changes: 5 additions & 22 deletions ext/CTSolveExtMadNLP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,18 @@ function CTDirect.solve_docp(tag::CTDirect.MadNLPTag, docp::CTDirect.DOCP, nlp;
end


function CTBase.OptimalControlSolution(docp, docp_solution_madnlp::MadNLP.MadNLPExecutionStats)

# could pass some status info too (get_status ?)
solution = docp_solution_madnlp.solution

# time grid
N = docp.dim_NLP_steps
T = zeros(N+1)
for i=1:N+1
T[i] = CTDirect.get_unnormalized_time(solution, docp, docp.NLP_normalized_time_grid[i])
end
function CTBase.OptimalControlSolution(docp, docp_solution::MadNLP.MadNLPExecutionStats)

# adjust objective sign for maximization problems
if is_min(docp.ocp)
objective = docp_solution_madnlp.objective
objective = docp_solution.objective
else
objective = - docp_solution_madnlp.objective
objective = - docp_solution.objective
end

# recover primal variables
X, U, v = CTDirect.parse_DOCP_solution_primal(docp, solution)

# recover costate
P = CTDirect.parse_DOCP_solution_dual(docp, docp_solution_madnlp.multipliers)
# call lower level constructor
return OptimalControlSolution(docp, primal=docp_solution.solution, dual=docp_solution.multipliers, objective=objective, iterations=docp_solution.iter, constraints_violation=docp_solution.primal_feas, message="MadNLP", mult_LB=docp_solution.multipliers_L, mult_UB=docp_solution.multipliers_U)

# build and return OCP solution
return CTDirect.OCPSolutionFromDOCP_raw(docp, T, X, U, v, P,
objective=objective, iterations=docp_solution_madnlp.iter,constraints_violation=docp_solution_madnlp.primal_feas,
message="MadNLP")
end


Expand Down
Loading

4 comments on commit 23c7637

@PierreMartinon
Copy link
Member Author

@PierreMartinon PierreMartinon commented on 23c7637 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

Release notes:

  • added parsing of constraints multipliers
  • separate source files for tests problems
  • more streamlined OptimalControlSolution constructors

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112758

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.1 -m "<description of version>" 23c76374fb91f65f8d10c03b7d8ff5c75a5f4076
git push origin v0.11.1

@PierreMartinon
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

Release notes:

  • added parsing of constraints multipliers
  • separate source files for tests problems
  • more streamlined OptimalControlSolution constructors

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/112758

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.1 -m "<description of version>" 23c76374fb91f65f8d10c03b7d8ff5c75a5f4076
git push origin v0.11.1

Please sign in to comment.