Skip to content

Commit f17fd8e

Browse files
authored
Merge pull request #122 from control-toolbox/auto-juliaformatter-pr
[AUTO] JuliaFormatter.jl run
2 parents 8400039 + 7b69fd7 commit f17fd8e

20 files changed

+270
-222
lines changed

ext/CTFlowsODE.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Alias for `CTFlows.ctVector`, representing cotangent vectors in continuous-time
1818
1919
Used for denoting adjoint states or costates in optimal control formulations.
2020
"""
21-
const CoTangent = CTFlows.ctVector
21+
const CoTangent = CTFlows.ctVector
2222

2323
"""
2424
Alias for `CTFlows.ctVector`, representing derivative cotangent vectors.

ext/concatenation.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ function __concat_feedback_control(F::AbstractFlow, G::AbstractFlow, t_switch::T
125125
G.feedback_control(t, x, u, v)
126126
end
127127
end
128-
feedback_control = CTFlows.ControlLaw(_feedback_control, CTFlows.NonAutonomous, CTFlows.NonFixed)
128+
feedback_control = CTFlows.ControlLaw(
129+
_feedback_control, CTFlows.NonAutonomous, CTFlows.NonFixed
130+
)
129131
return feedback_control
130132
end
131133

ext/ext_default.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ function __thevariable(t0, x0, p0, tf, ocp)
2727
CTModels.has_free_final_time(ocp) && CTModels.variable_dimension(ocp) == 1 && return tf
2828

2929
# if t0 is free and ocp has only one variable, then return t0
30-
CTModels.has_free_initial_time(ocp) && CTModels.variable_dimension(ocp) == 1 && return t0
30+
CTModels.has_free_initial_time(ocp) &&
31+
CTModels.variable_dimension(ocp) == 1 &&
32+
return t0
3133

3234
# if t0 and tf are free and ocp has only two variables, then return [t0, tf]
3335
CTModels.has_free_final_time(ocp) &&
34-
CTModels.has_free_initial_time(ocp) &&
35-
CTModels.variable_dimension(ocp) == 2 &&
36-
return [t0, tf]
36+
CTModels.has_free_initial_time(ocp) &&
37+
CTModels.variable_dimension(ocp) == 2 &&
38+
return [t0, tf]
3739

3840
# otherwise return an empty vector of right type to avoid warning performance message from OrdinaryDiffEq
3941
z0 = [x0; p0]

ext/ext_types.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const ctNumber = CTModels.ctNumber
22
const ctVector = Union{ctNumber,CTModels.ctVector}
3-
const Time = ctNumber
4-
const Times = AbstractVector{<:Time}
5-
const State = ctVector
6-
const Costate = ctVector
7-
const Control = ctVector
3+
const Time = ctNumber
4+
const Times = AbstractVector{<:Time}
5+
const State = ctVector
6+
const Costate = ctVector
7+
const Control = ctVector
88
const Variable = ctVector
9-
const DState = ctVector
9+
const DState = ctVector
1010
const DCostate = ctVector
1111

1212
# ---------------------------------------------------------------------------------------------------
@@ -239,7 +239,7 @@ function CTModels.Solution(ocfs::OptimalControlFlowSolution; kwargs...)
239239
message="Solution obtained from flow",
240240
status=:nostatusmessage,
241241
successful=true,
242-
kwargs_OCS...
242+
kwargs_OCS...,
243243
)
244244

245245
return sol

ext/optimal_control_problem.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ julia> f = Flow(ocp, (t, x, p) -> t + p, (t, x, u) -> x - 1, (t, x, p) -> x+p)
131131
function CTFlows.Flow(
132132
ocp::CTModels.Model,
133133
u::Union{CTFlows.ControlLaw{<:Function,T,V},CTFlows.FeedbackControl{<:Function,T,V}},
134-
g::Union{CTFlows.MixedConstraint{<:Function,T,V},CTFlows.StateConstraint{<:Function,T,V}},
134+
g::Union{
135+
CTFlows.MixedConstraint{<:Function,T,V},CTFlows.StateConstraint{<:Function,T,V}
136+
},
135137
μ::Union{CTFlows.Multiplier{<:Function,T,V}};
136138
alg=__alg(),
137139
abstol=__abstol(),
@@ -222,6 +224,13 @@ function __ocp_Flow(
222224
)
223225
rhs! = rhs(h)
224226
f = hamiltonian_usage(alg, abstol, reltol, saveat, internalnorm; kwargs_Flow...)
225-
kwargs_Flow = (kwargs_Flow..., alg=alg, abstol=abstol, reltol=reltol, saveat=saveat, internalnorm=internalnorm)
227+
kwargs_Flow = (
228+
kwargs_Flow...,
229+
alg=alg,
230+
abstol=abstol,
231+
reltol=reltol,
232+
saveat=saveat,
233+
internalnorm=internalnorm,
234+
)
226235
return OptimalControlFlow(f, rhs!, u, ocp, kwargs_Flow)
227236
end

src/differential_geometry.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function Lift(X::VectorField)::HamiltonianLift
3232
return HamiltonianLift(X)
3333
end
3434

35-
3635
"""
3736
$(TYPEDSIGNATURES)
3837
@@ -63,7 +62,9 @@ julia> H2 = Lift((t, x, v) -> 2x + t - v, autonomous=false, variable=true)
6362
julia> H2(1, 1, 1, 1) # returns 2
6463
```
6564
"""
66-
function Lift(X::Function; autonomous::Bool=__autonomous(), variable::Bool=__variable())::Function
65+
function Lift(
66+
X::Function; autonomous::Bool=__autonomous(), variable::Bool=__variable()
67+
)::Function
6768
return @match (autonomous, variable) begin
6869
(true, false) => (x, p) -> p' * X(x)
6970
(true, true) => (x, p, v) -> p' * X(x, v)
@@ -205,9 +206,7 @@ function ⅋(
205206
ctgradient(y -> Y(y, args...), x) * X(x, args...)
206207
else
207208
ctjacobian(y -> Y(y, args...), x) * X(x, args...)
208-
end,
209-
Autonomous,
210-
V,
209+
end, Autonomous, V
211210
)
212211
end
213212

@@ -313,13 +312,13 @@ function Poisson(
313312
ff, gg = @match n begin
314313
1 => (z -> f(z[1], z[2], args...), z -> g(z[1], z[2], args...))
315314
_ => (
316-
z -> f(z[1:n], z[n+1:2n], args...),
317-
z -> g(z[1:n], z[n+1:2n], args...),
315+
z -> f(z[1:n], z[(n + 1):2n], args...),
316+
z -> g(z[1:n], z[(n + 1):2n], args...),
318317
)
319318
end
320319
df = ctgradient(ff, [x; p])
321320
dg = ctgradient(gg, [x; p])
322-
return df[n+1:2n]' * dg[1:n] - df[1:n]' * dg[n+1:2n]
321+
return df[(n + 1):2n]' * dg[1:n] - df[1:n]' * dg[(n + 1):2n]
323322
end
324323
return Hamiltonian(fg, Autonomous, V)
325324
end
@@ -349,13 +348,13 @@ function Poisson(
349348
ff, gg = @match n begin
350349
1 => (z -> f(t, z[1], z[2], args...), z -> g(t, z[1], z[2], args...))
351350
_ => (
352-
z -> f(t, z[1:n], z[n+1:2n], args...),
353-
z -> g(t, z[1:n], z[n+1:2n], args...),
351+
z -> f(t, z[1:n], z[(n + 1):2n], args...),
352+
z -> g(t, z[1:n], z[(n + 1):2n], args...),
354353
)
355354
end
356355
df = ctgradient(ff, [x; p])
357356
dg = ctgradient(gg, [x; p])
358-
return df[n+1:2n]' * dg[1:n] - df[1:n]' * dg[n+1:2n]
357+
return df[(n + 1):2n]' * dg[1:n] - df[1:n]' * dg[(n + 1):2n]
359358
end
360359
return Hamiltonian(fg, NonAutonomous, V)
361360
end
@@ -618,7 +617,7 @@ macro Lie(expr::Expr, args...)
618617
for arg in args
619618
@match arg begin
620619
:(autonomous = $a) => (autonomous = a)
621-
:(variable = $a) => (variable = a)
620+
:(variable = $a) => (variable = a)
622621
_ => throw(ArgumentError("Invalid argument: $arg"))
623622
end
624623
end
@@ -639,7 +638,9 @@ macro Lie(expr::Expr, args...)
639638
postwalk(walker, x)
640639

641640
if has_lie[] && has_poisson[]
642-
throw(ArgumentError("Cannot mix Lie and Poisson brackets in the same expression."))
641+
throw(
642+
ArgumentError("Cannot mix Lie and Poisson brackets in the same expression.")
643+
)
643644
end
644645
return nothing
645646
end
@@ -658,8 +659,8 @@ macro Lie(expr::Expr, args...)
658659
return quote
659660
if isa($c, Function) && isa($d, Function)
660661
Poisson(
661-
Hamiltonian($c; autonomous=$(autonomous), variable=$(variable)),
662-
Hamiltonian($d; autonomous=$(autonomous), variable=$(variable))
662+
Hamiltonian($c; autonomous=($(autonomous)), variable=($(variable))),
663+
Hamiltonian($d; autonomous=($(autonomous)), variable=($(variable))),
663664
)
664665
else
665666
Poisson($c, $d)

src/optimal_control_problem_utils.jl

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ wrapped to return either a scalar or vector depending on the model's state dimen
1717
"""
1818
function __dynamics(ocp::CTModels.Model)
1919
n = CTModels.state_dimension(ocp)
20-
dyn = (t, x, u, v) -> (r = zeros(eltype(x), n); CTModels.dynamics(ocp)(r, t, x, u, v); n==1 ? r[1] : r)
20+
dyn =
21+
(t, x, u, v) ->
22+
(r=zeros(eltype(x), n); CTModels.dynamics(ocp)(r, t, x, u, v); n==1 ? r[1] : r)
2123
return Dynamics(dyn, NonAutonomous, NonFixed)
2224
end
2325

@@ -55,10 +57,14 @@ The Hamiltonian is built using model dynamics (and possibly a running cost) and
5557
5658
Returns a tuple `(H, u)` where `H` is the Hamiltonian function and `u` is the control law.
5759
"""
58-
function __create_hamiltonian(ocp::CTModels.Model, u::ControlLaw{<:Function,T,V}) where {T,V}
60+
function __create_hamiltonian(
61+
ocp::CTModels.Model, u::ControlLaw{<:Function,T,V}
62+
) where {T,V}
5963
f, f⁰, p⁰, s = __get_data_for_ocp_flow(ocp) # data
6064
@assert f nothing "no dynamics in ocp"
61-
h = Hamiltonian(f⁰ nothing ? makeH(f, u, f⁰, p⁰, s) : makeH(f, u), NonAutonomous, NonFixed)
65+
h = Hamiltonian(
66+
f⁰ nothing ? makeH(f, u, f⁰, p⁰, s) : makeH(f, u), NonAutonomous, NonFixed
67+
)
6268
return h, u
6369
end
6470

@@ -69,12 +75,14 @@ Helper method to construct the Hamiltonian when control is given as a plain func
6975
7076
The function is wrapped in a `ControlLaw`, and the flags `autonomous` and `variable` define its behavior type.
7177
"""
72-
function __create_hamiltonian(ocp::CTModels.Model, u::Function; autonomous::Bool, variable::Bool)
78+
function __create_hamiltonian(
79+
ocp::CTModels.Model, u::Function; autonomous::Bool, variable::Bool
80+
)
7381
T, V = @match (autonomous, variable) begin
74-
(true, false) => (Autonomous, Fixed)
75-
(true, true) => (Autonomous, NonFixed)
76-
(false, false) => (NonAutonomous, Fixed)
77-
_ => (NonAutonomous, NonFixed)
82+
(true, false) => (Autonomous, Fixed)
83+
(true, true) => (Autonomous, NonFixed)
84+
(false, false) => (NonAutonomous, Fixed)
85+
_ => (NonAutonomous, NonFixed)
7886
end
7987
return __create_hamiltonian(ocp, ControlLaw(u, T, V))
8088
end
@@ -147,12 +155,14 @@ $(TYPEDSIGNATURES)
147155
148156
Overload for control law as a raw function with autonomous and variable flags.
149157
"""
150-
function __create_hamiltonian(ocp::CTModels.Model, u::Function, g, μ; autonomous::Bool, variable::Bool)
158+
function __create_hamiltonian(
159+
ocp::CTModels.Model, u::Function, g, μ; autonomous::Bool, variable::Bool
160+
)
151161
T, V = @match (autonomous, variable) begin
152-
(true, false) => (Autonomous, Fixed)
153-
(true, true) => (Autonomous, NonFixed)
154-
(false, false) => (NonAutonomous, Fixed)
155-
_ => (NonAutonomous, NonFixed)
162+
(true, false) => (Autonomous, Fixed)
163+
(true, true) => (Autonomous, NonFixed)
164+
(false, false) => (NonAutonomous, Fixed)
165+
_ => (NonAutonomous, NonFixed)
156166
end
157167
return __create_hamiltonian(ocp, ControlLaw(u, T, V), g, μ)
158168
end
@@ -191,7 +201,10 @@ $(TYPEDSIGNATURES)
191201
Overload that converts StateConstraint objects into MixedConstraint with appropriate signature adaptation.
192202
"""
193203
function __create_hamiltonian(
194-
ocp::CTModels.Model, u::ControlLaw{<:Function,T,V}, g_::StateConstraint{<:Function,T,V}, μ
204+
ocp::CTModels.Model,
205+
u::ControlLaw{<:Function,T,V},
206+
g_::StateConstraint{<:Function,T,V},
207+
μ,
195208
) where {T,V}
196209
g = @match (T, V) begin
197210
(Autonomous, Fixed) => MixedConstraint((x, u) -> g_(x), T, V)
@@ -208,7 +221,10 @@ $(TYPEDSIGNATURES)
208221
Overload that wraps multiplier functions into Multiplier objects.
209222
"""
210223
function __create_hamiltonian(
211-
ocp::CTModels.Model, u::ControlLaw{<:Function,T,V}, g::MixedConstraint{<:Function,T,V}, μ::Function
224+
ocp::CTModels.Model,
225+
u::ControlLaw{<:Function,T,V},
226+
g::MixedConstraint{<:Function,T,V},
227+
μ::Function,
212228
) where {T,V}
213229
return __create_hamiltonian(ocp, u, g, Multiplier(μ, T, V))
214230
end

0 commit comments

Comments
 (0)