Skip to content

feat: create JuMPControlProblem for optimal control #3549

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

vyudu
Copy link
Member

@vyudu vyudu commented Apr 8, 2025

will add optimal control tests here when the interface for inputs and stuff is settled.

@vyudu
Copy link
Member Author

vyudu commented Apr 10, 2025

@ChrisRackauckas assuming this passes stuff I think it's ready.

@vyudu
Copy link
Member Author

vyudu commented Apr 18, 2025

Requires SciML/SciMLBase.jl#996

@testset "ODE Solution, no cost" begin
# Test solving without anything attached.
@parameters α=1.5 β=1.0 γ=3.0 δ=1.0
@variables x(..) y(..)
Copy link
Contributor

@baggepinnen baggepinnen Apr 22, 2025

Choose a reason for hiding this comment

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

Do I have to define the variables to optimize over using x(..)? What if I want to solve an OC problem with components defined in MTKstdlib? Those components have x(t) variables. It would be nice to have a test for that use case as well since component-based modeling would be the fundamental reason to use MTK over any other tool

Copy link
Member

Choose a reason for hiding this comment

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

No, that's just if you also want to evaluate them at a point, since this just late binds t. We could also make an evaluate operator or something that is the same as evaluate(x(t), 0.2) == x(0.2)

Copy link
Contributor

@baggepinnen baggepinnen left a comment

Choose a reason for hiding this comment

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

there appears to be no tests that the dynamics are satisfied, testing the transcription. This could be tested by simulating the system using the found optimal control included with an interpolation

Comment on lines +80 to +87
function is_bangbang(input_sol, lbounds, ubounds, rtol = 1e-4)
bangbang = true
for v in 1:(length(input_sol.u[1]) - 1)
all(i -> (i[v], bounds[v]; rtol) || (i[v], bounds[u]; rtol), input_sol.u) ||
(bangbang = false)
end
bangbang
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function is_bangbang(input_sol, lbounds, ubounds, rtol = 1e-4)
bangbang = true
for v in 1:(length(input_sol.u[1]) - 1)
all(i -> (i[v], bounds[v]; rtol) || (i[v], bounds[u]; rtol), input_sol.u) ||
(bangbang = false)
end
bangbang
end
function is_bangbang(input_sol, lbounds, ubounds, rtol = 1e-4)
for v in 1:(length(input_sol.u[1]) - 1)
all(i -> (i[v], bounds[v]; rtol) || (i[v], bounds[u]; rtol), input_sol.u) ||
return false
end
true
end

JuMPControlProblem(sys::ODESystem, u0, tspan, p; dt)
Convert an ODESystem representing an optimal control system into a JuMP model
for solving using optimization. Must provide `dt` for determining the length
Copy link
Contributor

@baggepinnen baggepinnen Apr 22, 2025

Choose a reason for hiding this comment

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

dt is presumably not defined as "determining the length of the interpolation arrays". Instead of mentioning why a variable is required, maybe mention what the variable represents?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants