Skip to content
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
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ deploy_decision = Documenter.deploy_folder(
with_status_page() do status_file
with_problems_browser() do browser_file
with_api_reference(src_dir, ext_dir) do api_pages
makedocs(;
return makedocs(;
draft=draft,
warnonly=:cross_references,
sitename="OptimalControlProblems.jl",
Expand Down
10 changes: 7 additions & 3 deletions docs/modelings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ for spec in OptimalControlProblems.Modelings.MODELING_SPECS
end

"""The modelings, in the order of the modeling table, as `(spec, adapter)` pairs."""
modelings() =
[(spec, ADAPTERS[spec.name]) for spec in OptimalControlProblems.Modelings.MODELING_SPECS]
function modelings()
return [
(spec, ADAPTERS[spec.name]) for
spec in OptimalControlProblems.Modelings.MODELING_SPECS
]
end

"""The modelings in which `problem` exists, whatever its status there."""
function modelings(problem::Symbol)
Expand All @@ -128,7 +132,7 @@ function model_excerpt(text::AbstractString, start::Regex)
last = findnext(eachindex(lines), first + 1) do i
l = lines[i]
isempty(strip(l)) && return false
length(l) - length(lstrip(l)) == indent && startswith(lstrip(l), r"end|\)")
return length(l) - length(lstrip(l)) == indent && startswith(lstrip(l), r"end|\)")
end
block = lines[first:something(last, length(lines))]
pad = " "^indent
Expand Down
4 changes: 3 additions & 1 deletion docs/problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ function compare_panel(problem::Symbol, mods, refs)
"""
for (i, s) in enumerate(solutions)
counts = map(mods) do (spec, _)
n = count(c -> first(split(c)) == string(spec.name), s["configurations"])
n = count(
c -> first(split(c)) == string(spec.name), s["configurations"]
)
return n == 0 ? "—" : string(n)
end
label = i == 1 ? "best" : "local $(i - 1)"
Expand Down
4 changes: 2 additions & 2 deletions docs/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ function thumbnails(results::SolveResults)
order = [string(spec.name) for (spec, _) in modelings(problem)]
candidates = [
e for e in page_entries(problem) if !isnothing(e["trajectory"]) &&
e["scope"] == e["modeling"] &&
e["modeling"] in order
e["scope"] == e["modeling"] &&
e["modeling"] in order
]
isempty(candidates) && continue
e = first(
Expand Down
6 changes: 3 additions & 3 deletions docs/status.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function status_table()
for problem in OptimalControlProblems.problems(; status=:all)
statuses = OptimalControlProblems.status(problem)
cells = map(mods) do (spec, _)
haskey(statuses, spec.name) ? string(statuses[spec.name]) : "—"
return haskey(statuses, spec.name) ? string(statuses[spec.name]) : "—"
end
refs = references(problem)
table = get(refs, "trapeze", nothing)
Expand Down Expand Up @@ -103,8 +103,8 @@ function reports_section(reports)
# (`new` only says that the configuration was not in the previous run)
notable = [
r for r in rows if r["result"] != "converged" ||
get(r, "solution", "best") ∉ ("best", "") ||
get(r, "change", "") ∉ ("", "new")
get(r, "solution", "best") ∉ ("best", "") ||
get(r, "change", "") ∉ ("", "new")
]
if isempty(notable)
out *= "Every solve converged to the best known solution.\n\n"
Expand Down
4 changes: 1 addition & 3 deletions ext/JuMPModels/beam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ function OptimalControlProblems.beam(
x₂_tf = params[:x₂_tf]

data = ProblemData(;
state=[
Component("x₁"; lower=x₁_l, upper=x₁_u), Component("x₂")
],
state=[Component("x₁"; lower=x₁_l, upper=x₁_u), Component("x₂")],
control=[Component("u")],
costate=["∂x₁", "∂x₂"],
times=v -> (t0, tf),
Expand Down
4 changes: 1 addition & 3 deletions ext/JuMPModels/bioreactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ function OptimalControlProblems.bioreactor(

data = ProblemData(;
state=[
Component("y"; lower=y_l),
Component("s"; lower=s_l),
Component("b"; lower=b_l),
Component("y"; lower=y_l), Component("s"; lower=s_l), Component("b"; lower=b_l)
],
control=[Component("u"; lower=u_l, upper=u_u)],
costate=["∂y", "∂s", "∂b"],
Expand Down
6 changes: 1 addition & 5 deletions ext/JuMPModels/brachistochrone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ function OptimalControlProblems.brachistochrone(
u_max = params[:u_max]

data = ProblemData(;
state=[
Component("px"),
Component("py"),
Component("v"),
],
state=[Component("px"), Component("py"), Component("v")],
control=[Component("u"; lower=-1.57, upper=1.57)],
variable=[Component("tf"; lower=0.1, upper=20.0)],
costate=["∂px", "∂py", "∂v"],
Expand Down
6 changes: 1 addition & 5 deletions ext/JuMPModels/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ function OptimalControlProblems.chain(
x₃_tf = L

data = ProblemData(;
state=[
Component("x₁"),
Component("x₂"),
Component("x₃"),
],
state=[Component("x₁"), Component("x₂"), Component("x₃")],
control=[Component("u")],
costate=["∂x₁", "∂x₂", "∂x₃"],
times=v -> (t0, tf),
Expand Down
4 changes: 3 additions & 1 deletion ext/JuMPModels/dielectrophoretic_particle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function OptimalControlProblems.dielectrophoretic_particle(
],
)
# initial guess: from the metadata (#377), unless given
init = OptimalControlProblems.Metadata._initial_guess(:dielectrophoretic_particle, params, init)
init = OptimalControlProblems.Metadata._initial_guess(
:dielectrophoretic_particle, params, init
)
return build(data, grid_size, scheme, ordering, args...; init=init, kwargs...)
end
3 changes: 1 addition & 2 deletions ext/JuMPModels/moonlander.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ function OptimalControlProblems.moonlander(
Component("dθ"),
],
control=[
Component("F₁"; lower=F₁_l, upper=F₁_u),
Component("F₂"; lower=F₂_l, upper=F₂_u),
Component("F₁"; lower=F₁_l, upper=F₁_u), Component("F₂"; lower=F₂_l, upper=F₂_u)
],
variable=[Component("tf"; lower=tf_l, upper=tf_u)],
costate=["∂p₁", "∂p₂", "∂dp₁", "∂dp₂", "∂θ", "∂dθ"],
Expand Down
6 changes: 1 addition & 5 deletions ext/JuMPModels/robbins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ function OptimalControlProblems.robbins(
x₃_tf = params[:x₃_tf]

data = ProblemData(;
state=[
Component("x₁"; lower=x₁_l),
Component("x₂"),
Component("x₃"),
],
state=[Component("x₁"; lower=x₁_l), Component("x₂"), Component("x₃")],
control=[Component("u")],
costate=["∂x₁", "∂x₂", "∂x₃"],
times=v -> (t0, tf),
Expand Down
2 changes: 1 addition & 1 deletion ext/JuMPModels/schemes/tableaux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function stage_positions(tab::ButcherTableau)
θ = map(1:s) do j
iszero(tab.A[j, :]) && return 0.0
tab.A[j, :] == tab.b && return 1.0
throw(
return throw(
CTBase.Exceptions.NotImplemented(
"Stage $j of the tableau $(tab.name) is not a node of the step";
required_method="stage unknowns in the JuMP models",
Expand Down
5 changes: 1 addition & 4 deletions ext/JuMPModels/steering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ function OptimalControlProblems.steering(
x₄_tf = params[:x₄_tf]

data = ProblemData(;
state=[
Component("x$(c)") for
(k, c) in enumerate("₁₂₃₄")
],
state=[Component("x$(c)") for (k, c) in enumerate("₁₂₃₄")],
control=[Component("u"; lower=u_min, upper=u_max)],
variable=[Component("tf"; lower=tf_l)],
costate=["∂x₁", "∂x₂", "∂x₃", "∂x₄"],
Expand Down
9 changes: 6 additions & 3 deletions ext/MetaData/balanced_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ balanced_field_meta = OrderedDict(
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid),
# initial guess of every modeling (#377), from the parameters
:init => p -> (
state=[p.r_t0, p.v_t0 + 10.0, p.h_tf / 2.0, p.γ_tf], control=0.1, variable=10.0
),
:init =>
p -> (
state=[p.r_t0, p.v_t0 + 10.0, p.h_tf / 2.0, p.γ_tf],
control=0.1,
variable=10.0,
),
)
8 changes: 7 additions & 1 deletion ext/MetaData/beam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ beam_meta = OrderedDict(
:init => p -> (state=[0.05, 0.1], control=0.1),
:reference_solution =>
p -> _bryson_denham_solution(
p.t0, p.tf, (p.x₁_t0, p.x₂_t0), (p.x₁_tf, p.x₂_tf), p.x₁_u; weight=1, lower=p.x₁_l
p.t0,
p.tf,
(p.x₁_t0, p.x₂_t0),
(p.x₁_tf, p.x₂_tf),
p.x₁_u;
weight=1,
lower=p.x₁_l,
),
)
22 changes: 12 additions & 10 deletions ext/MetaData/brachistochrone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ brachistochrone_meta = OrderedDict(
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid),
# initial guess of every modeling (#377), from the parameters
:init => p -> begin
(; t0, x0, y0, v0, xf, yf) = p
tf = 2.0
s(t) = (t - t0) / (tf - t0)
return (
state=t -> [x0 + s(t) * (xf - x0), y0 + s(t) * (yf - y0), v0 + s(t) * 10.0],
control=1.57,
variable=tf,
)
end,
:init =>
p -> begin
(; t0, x0, y0, v0, xf, yf) = p
tf = 2.0
s(t) = (t - t0) / (tf - t0)
return (
state=t ->
[x0 + s(t) * (xf - x0), y0 + s(t) * (yf - y0), v0 + s(t) * 10.0],
control=1.57,
variable=tf,
)
end,
)
29 changes: 15 additions & 14 deletions ext/MetaData/glider.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ glider_meta = OrderedDict(
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid),
# initial guess of every modeling (#377), from the parameters
:init => p -> begin
(; x_t0, y_t0, y_tf, vx_t0, vx_tf, vy_t0, vy_tf) = p
tf = 100.0
return (
state=t -> [
x_t0 + (t / tf) * 1248.0,
y_t0 + (t / tf) * (y_tf - y_t0),
vx_t0 + (t / tf) * (vx_tf - vx_t0),
vy_t0 + (t / tf) * (vy_tf - vy_t0),
],
control=1.0,
variable=tf,
)
end,
:init =>
p -> begin
(; x_t0, y_t0, y_tf, vx_t0, vx_tf, vy_t0, vy_tf) = p
tf = 100.0
return (
state=t -> [
x_t0 + (t / tf) * 1248.0,
y_t0 + (t / tf) * (y_tf - y_t0),
vx_t0 + (t / tf) * (vx_tf - vx_t0),
vy_t0 + (t / tf) * (vy_tf - vy_t0),
],
control=1.0,
variable=tf,
)
end,
)
7 changes: 6 additions & 1 deletion ext/MetaData/jackson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ jackson_meta = OrderedDict(
b_t0=0,
x₃_t0=0,
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid, ModelingToolkit=:valid),
:status => (
OptimalControl=:valid,
OptimalControlScalarized=:valid,
JuMP=:valid,
ModelingToolkit=:valid,
),
# initial guess of every modeling (#377), from the parameters
:init => p -> (state=[0.1, 0.1, 0.1], control=0.1),
)
7 changes: 6 additions & 1 deletion ext/MetaData/robbins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ robbins_meta = OrderedDict(
x₂_tf=0,
x₃_tf=0,
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid, ModelingToolkit=:valid),
:status => (
OptimalControl=:valid,
OptimalControlScalarized=:valid,
JuMP=:valid,
ModelingToolkit=:valid,
),
# initial guess of every modeling (#377), from the parameters
:init => p -> (state=[0.1, 0.1, 0.1], control=0.1),
)
25 changes: 14 additions & 11 deletions ext/MetaData/robot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ robot_meta = OrderedDict(
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid),
# initial guess of every modeling (#377), from the parameters
:init => p -> begin
(; t0, ρ_t0, θ_t0, ϕ_t0, ρ_tf, θ_tf, ϕ_tf) = p
tf = 9.1
function state(t)
s = clamp((t - t0) / (tf - t0), 0.0, 1.0)
ϕ = ϕ_t0 + s * (ϕ_tf - ϕ_t0)
abs(ϕ) < 1e-6 && (ϕ = 1e-6) # away from zero: the dynamics divide by sin(ϕ)²
return [ρ_t0 + s * (ρ_tf - ρ_t0), 0.0, θ_t0 + s * (θ_tf - θ_t0), 0.0, ϕ, 0.0]
end
return (state=state, control=[0.0, 0.0, 0.0], variable=tf)
end,
:init =>
p -> begin
(; t0, ρ_t0, θ_t0, ϕ_t0, ρ_tf, θ_tf, ϕ_tf) = p
tf = 9.1
function state(t)
s = clamp((t - t0) / (tf - t0), 0.0, 1.0)
ϕ = ϕ_t0 + s * (ϕ_tf - ϕ_t0)
abs(ϕ) < 1e-6 && (ϕ = 1e-6) # away from zero: the dynamics divide by sin(ϕ)²
return [
ρ_t0 + s * (ρ_tf - ρ_t0), 0.0, θ_t0 + s * (θ_tf - θ_t0), 0.0, ϕ, 0.0
]
end
return (state=state, control=[0.0, 0.0, 0.0], variable=tf)
end,
)
24 changes: 13 additions & 11 deletions ext/MetaData/rocket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ rocket_meta = OrderedDict(
(t0=0, h_t0=1, v_t0=0, m_t0=1, g0=1, Tc=3.5, hc=500, vc=620, mc=0.6, T_l=0, tf_l=0),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid),
# initial guess of every modeling (#377), from the parameters
:init => p -> begin
(; m_t0, mc, Tc, g0) = p
tf = 1
m_tf = mc * m_t0
Tmax = Tc * m_t0 * g0
return (
state=t -> [1, (t / tf) * (1 - t / tf), (m_tf - m_t0) * (t / tf) + m_t0],
control=Tmax / 2,
variable=tf,
)
end,
:init =>
p -> begin
(; m_t0, mc, Tc, g0) = p
tf = 1
m_tf = mc * m_t0
Tmax = Tc * m_t0 * g0
return (
state=t ->
[1, (t / tf) * (1 - t / tf), (m_tf - m_t0) * (t / tf) + m_t0],
control=Tmax / 2,
variable=tf,
)
end,
)
37 changes: 19 additions & 18 deletions ext/MetaData/space_shuttle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,23 @@ space_shuttle_meta = OrderedDict(
),
:status => (OptimalControl=:valid, OptimalControlScalarized=:valid, JuMP=:valid),
# initial guess of every modeling (#377), from the parameters
:init => p -> begin
(; t0, h_t0, ϕ_t0, θ_t0, v_t0, γ_t0, ψ_t0, h_tf, v_tf, γ_tf, α_s, β_s) = p
# linear interpolation for h, v, γ, constant for the rest
tf = 2000
s(t) = (t - t0) / (tf - t0)
return (
state=t -> [
h_t0 + s(t) * (h_tf - h_t0),
ϕ_t0,
θ_t0,
v_t0 + s(t) * (v_tf - v_t0),
γ_t0 + s(t) * (γ_tf - γ_t0),
ψ_t0,
],
control=[α_s, β_s],
variable=tf,
)
end,
:init =>
p -> begin
(; t0, h_t0, ϕ_t0, θ_t0, v_t0, γ_t0, ψ_t0, h_tf, v_tf, γ_tf, α_s, β_s) = p
# linear interpolation for h, v, γ, constant for the rest
tf = 2000
s(t) = (t - t0) / (tf - t0)
return (
state=t -> [
h_t0 + s(t) * (h_tf - h_t0),
ϕ_t0,
θ_t0,
v_t0 + s(t) * (v_tf - v_t0),
γ_t0 + s(t) * (γ_tf - γ_t0),
ψ_t0,
],
control=[α_s, β_s],
variable=tf,
)
end,
)
Loading
Loading