Skip to content

Commit 1038438

Browse files
authored
Merge pull request #159 from control-toolbox/auto-juliaformatter-pr
[AUTO] JuliaFormatter.jl run
2 parents 8c70279 + 511c775 commit 1038438

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+870
-678
lines changed

docs/browser.jl

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,7 @@ function initProblemsTable() {
669669
</script>
670670
"""
671671

672-
const TABLE = (
673-
presentation = TABLE_PRESENTATION,
674-
style = TABLE_STYLE,
675-
logic = TABLE_LOGIC,
676-
)
672+
const TABLE = (presentation=TABLE_PRESENTATION, style=TABLE_STYLE, logic=TABLE_LOGIC)
677673

678674
# -------------------------------
679675
# Helpers
@@ -746,35 +742,40 @@ end
746742
function collect_problem_data(problem_sym::Symbol)
747743
ocp = ocp_model(eval(problem_sym)(OptimalControlBackend()))
748744

749-
cost = has_mayer_cost(ocp) && has_lagrange_cost(ocp) ? "Bolza" :
750-
has_mayer_cost(ocp) ? "Mayer" : "Lagrange"
745+
cost = if has_mayer_cost(ocp) && has_lagrange_cost(ocp)
746+
"Bolza"
747+
elseif has_mayer_cost(ocp)
748+
"Mayer"
749+
else
750+
"Lagrange"
751+
end
751752

752753
final_time = has_fixed_final_time(ocp) ? "fixed" : "free"
753754

754755
dims = (
755-
x = CTModels.dim_state_constraints_box(ocp),
756-
u = CTModels.dim_control_constraints_box(ocp),
757-
v = CTModels.dim_variable_constraints_box(ocp),
758-
c = CTModels.dim_path_constraints_nl(ocp),
759-
b = CTModels.dim_boundary_constraints_nl(ocp),
756+
x=CTModels.dim_state_constraints_box(ocp),
757+
u=CTModels.dim_control_constraints_box(ocp),
758+
v=CTModels.dim_variable_constraints_box(ocp),
759+
c=CTModels.dim_path_constraints_nl(ocp),
760+
b=CTModels.dim_boundary_constraints_nl(ocp),
760761
)
761762

762763
total = sum_namedtuple(dims)
763764

764765
return (
765-
Problem = string(problem_sym),
766-
State = state_dimension(ocp),
767-
Control = control_dimension(ocp),
768-
Variable = variable_dimension(ocp),
769-
Cost = cost,
770-
FinalTime = final_time,
771-
DimStateConstraint = dims.x,
772-
DimControlConstraint = dims.u,
773-
DimVariableConstraint = dims.v,
774-
DimPathConstraint = dims.c,
775-
DimBoundaryConstraint = dims.b,
776-
TotalConstraints = total,
777-
ConstraintButtonsHtml = generate_constraint_buttons_html(dims)
766+
Problem=string(problem_sym),
767+
State=state_dimension(ocp),
768+
Control=control_dimension(ocp),
769+
Variable=variable_dimension(ocp),
770+
Cost=cost,
771+
FinalTime=final_time,
772+
DimStateConstraint=dims.x,
773+
DimControlConstraint=dims.u,
774+
DimVariableConstraint=dims.v,
775+
DimPathConstraint=dims.c,
776+
DimBoundaryConstraint=dims.b,
777+
TotalConstraints=total,
778+
ConstraintButtonsHtml=generate_constraint_buttons_html(dims),
778779
)
779780
end
780781

docs/make.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ Draft = false
112112
```
113113
=#
114114
with_problems_browser() do browser_file # generates the problems browser and remove it at the end
115-
116115
makedocs(;
117116
draft=draft,
118117
#remotes=nothing,
@@ -129,20 +128,19 @@ with_problems_browser() do browser_file # generates the problems browser and rem
129128
),
130129
pages=[
131130
"Getting Started" => "index.md",
132-
"Problems" =>
133-
["problems-introduction.md", browser_file, "List of the problems" => PROBLEMS_PAGES],
131+
"Problems" => [
132+
"problems-introduction.md",
133+
browser_file,
134+
"List of the problems" => PROBLEMS_PAGES,
135+
],
134136
"Tutorials" => [
135137
"Get a problem" => "tutorial-get.md",
136138
"Solve a problem" => "tutorial-solve.md",
137139
],
138-
"Developers" => [
139-
"Add a problem" => "dev-add.md",
140-
"API" => "dev-api.md",
141-
],
140+
"Developers" => ["Add a problem" => "dev-add.md", "API" => "dev-api.md"],
142141
],
143142
plugins=[links],
144143
)
145-
146144
end
147145

148146
# ==============================

docs/problems.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ end
2222
# -----------------------------------
2323
# Generate documentation for a problem
2424
# -----------------------------------
25-
function generate_documentation(PROBLEM::String, DESCRIPTION::String; draft::Union{Bool,Nothing})
26-
27-
TITLE = "[" * uppercasefirst(replace(PROBLEM, "_" => " ")) * "](@id description-$PROBLEM)"
25+
function generate_documentation(
26+
PROBLEM::String, DESCRIPTION::String; draft::Union{Bool,Nothing}
27+
)
28+
TITLE =
29+
"[" * uppercasefirst(replace(PROBLEM, "_" => " ")) * "](@id description-$PROBLEM)"
2830
DRAFT = draft_meta(draft)
2931
LEFT_MARGIN = get_left_margin(Symbol(PROBLEM))
3032

@@ -420,9 +422,9 @@ end
420422
# -----------------------------------
421423
# Generate documentation for all problems
422424
# -----------------------------------
423-
function generate_documentation_problems(; draft::Union{Bool,Nothing}=nothing,
424-
exclude_from_draft::Vector{Symbol}=Symbol[])
425-
425+
function generate_documentation_problems(;
426+
draft::Union{Bool,Nothing}=nothing, exclude_from_draft::Vector{Symbol}=Symbol[]
427+
)
426428
problems_list = problems()
427429
problems_pages = map(p -> joinpath("problems", string(p) * ".md"), problems_list)
428430

@@ -433,7 +435,9 @@ function generate_documentation_problems(; draft::Union{Bool,Nothing}=nothing,
433435
mkpath(joinpath(problems_dir, "assets"))
434436

435437
for problem in problems_list
436-
description = read(joinpath(@__DIR__, "..", "ext", "Descriptions", string(problem) * ".md"), String)
438+
description = read(
439+
joinpath(@__DIR__, "..", "ext", "Descriptions", string(problem) * ".md"), String
440+
)
437441
draft_problem = problem exclude_from_draft ? false : draft
438442
contents = generate_documentation(string(problem), description; draft=draft_problem)
439443

@@ -442,4 +446,4 @@ function generate_documentation_problems(; draft::Union{Bool,Nothing}=nothing,
442446
end
443447

444448
return problems_pages
445-
end
449+
end

ext/JuMPModels.jl

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ module JuMPModels
22

33
using OptimalControlProblems
44
using JuMP
5-
import CTModels:
6-
CTModels,
7-
time_grid,
8-
state,
9-
control,
10-
costate,
11-
iterations,
12-
control_components,
5+
import CTModels:
6+
CTModels,
7+
time_grid,
8+
state,
9+
control,
10+
costate,
11+
iterations,
12+
control_components,
1313
control_dimension,
1414
state_components,
1515
state_dimension,
@@ -49,7 +49,6 @@ julia> costate_components(model)
4949
"""
5050
costate_components(model::JuMP.GenericModel) = model[:costate_components]
5151

52-
5352
"""
5453
$(TYPEDSIGNATURES)
5554
@@ -72,7 +71,6 @@ julia> OptimalControlProblems.state_components(model)
7271
"""
7372
OptimalControlProblems.state_components(model::JuMP.GenericModel) = model[:state_components]
7473

75-
7674
"""
7775
$(TYPEDSIGNATURES)
7876
@@ -93,8 +91,9 @@ julia> OptimalControlProblems.control_components(model)
9391
["Fex"]
9492
```
9593
"""
96-
OptimalControlProblems.control_components(model::JuMP.GenericModel) = model[:control_components]
97-
94+
function OptimalControlProblems.control_components(model::JuMP.GenericModel)
95+
model[:control_components]
96+
end
9897

9998
"""
10099
$(TYPEDSIGNATURES)
@@ -116,8 +115,9 @@ julia> OptimalControlProblems.variable_components(model)
116115
["tf", "ddx"]
117116
```
118117
"""
119-
OptimalControlProblems.variable_components(model::JuMP.GenericModel) = model[:variable_components]
120-
118+
function OptimalControlProblems.variable_components(model::JuMP.GenericModel)
119+
model[:variable_components]
120+
end
121121

122122
"""
123123
$(TYPEDSIGNATURES)
@@ -139,11 +139,10 @@ julia> OptimalControlProblems.state_dimension(model)
139139
4
140140
```
141141
"""
142-
function OptimalControlProblems.state_dimension(model::JuMP.GenericModel)
142+
function OptimalControlProblems.state_dimension(model::JuMP.GenericModel)
143143
return length(model[:state_components])
144144
end
145145

146-
147146
"""
148147
$(TYPEDSIGNATURES)
149148
@@ -164,11 +163,10 @@ julia> OptimalControlProblems.control_dimension(model)
164163
1
165164
```
166165
"""
167-
function OptimalControlProblems.control_dimension(model::JuMP.GenericModel)
166+
function OptimalControlProblems.control_dimension(model::JuMP.GenericModel)
168167
return length(model[:control_components])
169168
end
170169

171-
172170
"""
173171
$(TYPEDSIGNATURES)
174172
@@ -189,7 +187,7 @@ julia> OptimalControlProblems.variable_dimension(model)
189187
2
190188
```
191189
"""
192-
function OptimalControlProblems.variable_dimension(model::JuMP.GenericModel)
190+
function OptimalControlProblems.variable_dimension(model::JuMP.GenericModel)
193191
return length(model[:variable_components])
194192
end
195193

@@ -338,7 +336,7 @@ julia> p(0.75)
338336
function OptimalControlProblems.costate(model::JuMP.GenericModel)
339337

340338
# time grid
341-
T = CTModels.time_grid( model)
339+
T = CTModels.time_grid(model)
342340
N = length(T) - 1
343341

344342
# get dimension

ext/JuMPModels/beam.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ julia> model = OptimalControlProblems.beam(JuMPBackend(); N=100)
2828
- Problem formulation available at: https://github.com/control-toolbox/bocop/tree/main/bocop
2929
"""
3030
function OptimalControlProblems.beam(
31-
::JuMPBackend, args...;
32-
grid_size::Int=grid_size_data(:beam),
33-
parameters::Union{Nothing, NamedTuple}=nothing,
34-
kwargs...
31+
::JuMPBackend,
32+
args...;
33+
grid_size::Int=grid_size_data(:beam),
34+
parameters::Union{Nothing,NamedTuple}=nothing,
35+
kwargs...,
3536
)
3637

3738
# parameters
@@ -62,9 +63,9 @@ function OptimalControlProblems.beam(
6263
@variables(
6364
model,
6465
begin
65-
x₁_l x₁[0:N] x₁_u, (start = 0.05)
66-
x₂[0:N], (start = 0.1)
67-
u[0:N], (start = 0.1)
66+
x₁_l x₁[0:N] x₁_u, (start = 0.05)
67+
x₂[0:N], (start = 0.1)
68+
u[0:N], (start = 0.1)
6869
end
6970
)
7071

ext/JuMPModels/bioreactor.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ julia> model = OptimalControlProblems.bioreactor(JuMPBackend(); N=100)
3131
- [control-toolbox/bocop](https://github.com/control-toolbox/bocop/tree/main/bocop)
3232
"""
3333
function OptimalControlProblems.bioreactor(
34-
::JuMPBackend, args...;
35-
grid_size::Int=grid_size_data(:bioreactor),
36-
parameters::Union{Nothing, NamedTuple}=nothing,
37-
kwargs...
34+
::JuMPBackend,
35+
args...;
36+
grid_size::Int=grid_size_data(:bioreactor),
37+
parameters::Union{Nothing,NamedTuple}=nothing,
38+
kwargs...,
3839
)
3940

4041
# parameters

ext/JuMPModels/cart_pendulum.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ julia> model = OptimalControlProblems.cart_pendulum(JuMPBackend(); N=200)
2828
- [Cart–Pendulum Optimal Control Problem](https://arxiv.org/pdf/2303.16746)
2929
"""
3030
function OptimalControlProblems.cart_pendulum(
31-
::JuMPBackend, args...; grid_size::Int=grid_size_data(:cart_pendulum),
32-
parameters::Union{Nothing, NamedTuple}=nothing,
33-
kwargs...
31+
::JuMPBackend,
32+
args...;
33+
grid_size::Int=grid_size_data(:cart_pendulum),
34+
parameters::Union{Nothing,NamedTuple}=nothing,
35+
kwargs...,
3436
)
3537

3638
# parameters
@@ -47,13 +49,13 @@ function OptimalControlProblems.cart_pendulum(
4749
x_u = params[:x_u]
4850
v_l = params[:v_l]
4951
v_u = params[:v_u]
50-
tf_l = params[:tf_l]
52+
tf_l = params[:tf_l]
5153
x_t0 = params[:x_t0]
5254
θ_t0 = params[:θ_t0]
5355
ω_t0 = params[:ω_t0]
5456
θ_tf = params[:θ_tf]
5557
ω_tf = params[:ω_tf]
56-
58+
5759
# model
5860
model = JuMP.Model(args...; kwargs...)
5961

@@ -71,13 +73,13 @@ function OptimalControlProblems.cart_pendulum(
7173
@variables(
7274
model,
7375
begin
74-
tf tf_l, (start = 1.0)
75-
ddx, (start = 0.1)
76-
x_l x[0:N] x_u, (start = 0.1)
77-
v_l v[0:N] v_u, (start = 0.1)
78-
θ[0:N], (start = 0.1)
79-
ω[0:N], (start = 0.1)
80-
Fex_l Fex[0:N] Fex_u, (start = 0.1)
76+
tf tf_l, (start = 1.0)
77+
ddx, (start = 0.1)
78+
x_l x[0:N] x_u, (start = 0.1)
79+
v_l v[0:N] v_u, (start = 0.1)
80+
θ[0:N], (start = 0.1)
81+
ω[0:N], (start = 0.1)
82+
Fex_l Fex[0:N] Fex_u, (start = 0.1)
8183
end
8284
)
8385

@@ -116,7 +118,8 @@ function OptimalControlProblems.cart_pendulum(
116118
dx[i = 0:N], v[i]
117119
dv[i = 0:N], -1 / J * c[i]
118120
dθ[i = 0:N], ω[i]
119-
dω[i = 0:N], 1 / (I + 0.25 * m * L^2) * 0.5 * L * m * (-dv[i] * cos(θ[i]) - g * sin(θ[i]))
121+
dω[i = 0:N],
122+
1 / (I + 0.25 * m * L^2) * 0.5 * L * m * (-dv[i] * cos(θ[i]) - g * sin(θ[i]))
120123
end
121124
)
122125

0 commit comments

Comments
 (0)