Skip to content

Commit d1f29d1

Browse files
authored
Merge pull request #289 from control-toolbox/auto-juliaformatter-pr
[AUTO] JuliaFormatter.jl run
2 parents ee8532e + 2e3fed1 commit d1f29d1

10 files changed

Lines changed: 115 additions & 47 deletions

File tree

ext/CTModelsJSON.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ function CTModels.import_ocp_solution(
332332
"control_constraints_ub_dual" => control_constraints_ub_dual,
333333
"variable_constraints_lb_dual" => variable_constraints_lb_dual,
334334
"variable_constraints_ub_dual" => variable_constraints_ub_dual,
335-
"control_interpolation" => get(blob, "control_interpolation", string(__control_interpolation())),
335+
"control_interpolation" =>
336+
get(blob, "control_interpolation", string(__control_interpolation())),
336337
)
337338

338339
# Add time grid data (format detection handled by helper)

ext/plot.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,25 @@ function __plot_time!(
9696

9797
#
9898
f(; kwargs...) = kwargs
99-
99+
100100
# Default seriestype for controls (user can override with kwargs)
101101
# Use :steppost for constant interpolation, :path for linear interpolation
102102
default_seriestype = if s == :control || s == :control_norm
103103
CTModels.control_interpolation(sol) == :constant ? :steppost : :path
104104
else
105105
:path
106106
end
107-
107+
108108
kwargs_plot = if isnothing(color)
109-
f(; ylims=:auto, xlabel=t_label, ylabel=y_label, linewidth=2, z_order=:front, seriestype=default_seriestype, kwargs...)
109+
f(;
110+
ylims=:auto,
111+
xlabel=t_label,
112+
ylabel=y_label,
113+
linewidth=2,
114+
z_order=:front,
115+
seriestype=default_seriestype,
116+
kwargs...,
117+
)
110118
else
111119
f(;
112120
color=color,

src/Display/print.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ Generate ANSI escape sequence for the specified color and formatting.
77
"""
88
function _ansi_color(color::Symbol, bold::Bool=false)
99
color_codes = Dict(
10-
:black => 30, :red => 31, :green => 32, :yellow => 33,
11-
:blue => 34, :magenta => 35, :cyan => 36, :white => 37,
12-
:default => 39
10+
:black => 30,
11+
:red => 31,
12+
:green => 32,
13+
:yellow => 33,
14+
:blue => 34,
15+
:magenta => 35,
16+
:cyan => 36,
17+
:white => 37,
18+
:default => 39,
1319
)
14-
20+
1521
code = get(color_codes, color, 39)
1622
return bold ? "\033[1;$(code)m" : "\033[$(code)m"
1723
end
@@ -22,7 +28,9 @@ _ansi_reset() = "\033[0m"
2228
"""
2329
Print text with ANSI color formatting for Documenter compatibility.
2430
"""
25-
function _print_ansi_styled(io, text::Union{String,Symbol,Type}, color::Symbol, bold::Bool=false)
31+
function _print_ansi_styled(
32+
io, text::Union{String,Symbol,Type}, color::Symbol, bold::Bool=false
33+
)
2634
print(io, _ansi_color(color, bold), string(text), _ansi_reset())
2735
end
2836
"""

src/OCP/Building/interpolation_helpers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function _interpolate_from_data(
8686
N = size(data, 1)
8787
cols = isnothing(dim) ? (:) : (1:dim)
8888
V = matrix2vec(data[:, cols], 1)
89-
89+
9090
# Choose interpolation method
9191
if interpolation == :linear
9292
return ctinterpolate(T[1:N], V)

src/OCP/Building/solution.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ function build_solution(
251251
# Note: costate uses its own grid (T_costate)
252252
# Note: control uses configurable interpolation (constant for direct methods, linear for indirect methods)
253253
fx = build_interpolated_function(X, T_state, dim_x, TX; expected_dim=dim_x)
254-
fu = build_interpolated_function(U, T_control, dim_u, TU; expected_dim=dim_u, interpolation=control_interpolation)
254+
fu = build_interpolated_function(
255+
U, T_control, dim_u, TU; expected_dim=dim_u, interpolation=control_interpolation
256+
)
255257
fp = build_interpolated_function(
256258
P, T_costate, dim_x, TP; constant_if_two_points=true, expected_dim=dim_x
257259
)
@@ -307,7 +309,9 @@ function build_solution(
307309

308310
# build Models
309311
state = StateModelSolution(state_name(ocp), state_components(ocp), fx)
310-
control = ControlModelSolution(control_name(ocp), control_components(ocp), fu, control_interpolation)
312+
control = ControlModelSolution(
313+
control_name(ocp), control_components(ocp), fu, control_interpolation
314+
)
311315
variable = VariableModelSolution(variable_name(ocp), variable_components(ocp), var)
312316
dual = DualModel(
313317
fpcd,

src/Serialization/reconstruction_helpers.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ function _reconstruct_solution_from_data(
4646
infos=nothing,
4747
)
4848
# Extract control_interpolation (backward compatibility: use default method)
49-
control_interpolation = Symbol(get(data, "control_interpolation", string(__control_interpolation())))
49+
control_interpolation = Symbol(
50+
get(data, "control_interpolation", string(__control_interpolation()))
51+
)
5052

5153
# Detect format and extract time grids
5254
if haskey(data, "time_grid_state")

src/Utils/interpolation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function ctinterpolate(x, f) # default for interpolation of the initialization
3636
return f[end]
3737
end
3838
# Linear interpolation: f[i] + (f[i+1] - f[i]) * (t - x[i]) / (x[i+1] - x[i])
39-
α = (t - x[i]) / (x[i+1] - x[i])
40-
return f[i] + α * (f[i+1] - f[i])
39+
α = (t - x[i]) / (x[i + 1] - x[i])
40+
return f[i] + α * (f[i + 1] - f[i])
4141
end
4242
end
4343
return linear_interp

test/suite/ocp/test_interpolation_helpers.jl

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,12 @@ function test_interpolation_helpers()
215215
U_control = [5.0 6.0; 4.0 5.0; 3.0 4.0] # 3x2 matrix
216216

217217
fu = OCP.build_interpolated_function(
218-
U_control, T_control, 2, Matrix{Float64};
219-
expected_dim=2, interpolation=:constant
218+
U_control,
219+
T_control,
220+
2,
221+
Matrix{Float64};
222+
expected_dim=2,
223+
interpolation=:constant,
220224
)
221225

222226
# Test at knots
@@ -262,8 +266,7 @@ function test_interpolation_helpers()
262266
U_1d = [5.0; 4.0; 3.0]
263267

264268
fu = OCP.build_interpolated_function(
265-
U_1d, T_1d, 1, Matrix{Float64};
266-
expected_dim=1, interpolation=:constant
269+
U_1d, T_1d, 1, Matrix{Float64}; expected_dim=1, interpolation=:constant
267270
)
268271

269272
# Should extract scalar
@@ -291,7 +294,7 @@ function test_interpolation_helpers()
291294
Test.@testset "INTEGRATION: build_solution - piecewise constant control" begin
292295
# 🧪 **Applying Testing Rule**: Integration testing with build_solution
293296
# Create a simple OCP and solution to verify control interpolation behavior
294-
297+
295298
# Build a minimal OCP
296299
pre_ocp = CTModels.PreModel()
297300
CTModels.time!(pre_ocp; t0=0.0, tf=1.0)
@@ -314,13 +317,18 @@ function test_interpolation_helpers()
314317
P = [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0]
315318

316319
sol = CTModels.build_solution(
317-
ocp, T, X, U, v, P;
320+
ocp,
321+
T,
322+
X,
323+
U,
324+
v,
325+
P;
318326
objective=0.5,
319327
iterations=10,
320328
constraints_violation=0.0,
321329
message="test",
322330
status=:success,
323-
successful=true
331+
successful=true,
324332
)
325333

326334
u_func = CTModels.control(sol)
@@ -356,7 +364,7 @@ function test_interpolation_helpers()
356364

357365
Test.@testset "INTEGRATION: build_solution - multi-dimensional constant control" begin
358366
# Test with 2D control to verify vector-valued constant interpolation
359-
367+
360368
pre_ocp = CTModels.PreModel()
361369
CTModels.time!(pre_ocp; t0=0.0, tf=1.0)
362370
CTModels.state!(pre_ocp, 2)
@@ -376,13 +384,18 @@ function test_interpolation_helpers()
376384
P = [0.0 0.0; 0.0 0.0; 0.0 0.0]
377385

378386
sol = CTModels.build_solution(
379-
ocp, T, X, U, v, P;
387+
ocp,
388+
T,
389+
X,
390+
U,
391+
v,
392+
P;
380393
objective=0.5,
381394
iterations=10,
382395
constraints_violation=0.0,
383396
message="test",
384397
status=:success,
385-
successful=true
398+
successful=true,
386399
)
387400

388401
u_func = CTModels.control(sol)
@@ -457,13 +470,18 @@ function test_interpolation_helpers()
457470

458471
# Build solution without specifying control_interpolation (should default to :constant)
459472
sol = CTModels.build_solution(
460-
ocp, T, X, U, v, P;
473+
ocp,
474+
T,
475+
X,
476+
U,
477+
v,
478+
P;
461479
objective=0.5,
462480
iterations=10,
463481
constraints_violation=0.0,
464482
message="test",
465483
status=:success,
466-
successful=true
484+
successful=true,
467485
)
468486

469487
# Verify default is :constant
@@ -499,18 +517,23 @@ function test_interpolation_helpers()
499517
P = [0.0 0.0; 0.0 0.0; 2.0 0.0]
500518

501519
sol = CTModels.build_solution(
502-
ocp, T, X, U, v, P;
520+
ocp,
521+
T,
522+
X,
523+
U,
524+
v,
525+
P;
503526
objective=0.5,
504527
iterations=10,
505528
constraints_violation=0.0,
506529
message="test",
507530
status=:success,
508531
successful=true,
509-
control_interpolation=:constant
532+
control_interpolation=:constant,
510533
)
511534

512535
Test.@test CTModels.control_interpolation(sol) == :constant
513-
536+
514537
# Verify piecewise constant behavior
515538
u_func = CTModels.control(sol)
516539
Test.@test u_func(0.0) 1.0
@@ -548,18 +571,23 @@ function test_interpolation_helpers()
548571
P = [0.0 0.0; 0.0 0.0; 2.0 0.0]
549572

550573
sol = CTModels.build_solution(
551-
ocp, T, X, U, v, P;
574+
ocp,
575+
T,
576+
X,
577+
U,
578+
v,
579+
P;
552580
objective=0.5,
553581
iterations=10,
554582
constraints_violation=0.0,
555583
message="test",
556584
status=:success,
557585
successful=true,
558-
control_interpolation=:linear
586+
control_interpolation=:linear,
559587
)
560588

561589
Test.@test CTModels.control_interpolation(sol) == :linear
562-
590+
563591
# Verify piecewise linear behavior
564592
u_func = CTModels.control(sol)
565593
Test.@test u_func(0.0) 1.0
@@ -599,14 +627,19 @@ function test_interpolation_helpers()
599627

600628
# Should throw IncorrectArgument for invalid interpolation type
601629
Test.@test_throws Exceptions.IncorrectArgument CTModels.build_solution(
602-
ocp, T, X, U, v, P;
630+
ocp,
631+
T,
632+
X,
633+
U,
634+
v,
635+
P;
603636
objective=0.5,
604637
iterations=10,
605638
constraints_violation=0.0,
606639
message="test",
607640
status=:success,
608641
successful=true,
609-
control_interpolation=:cubic
642+
control_interpolation=:cubic,
610643
)
611644
end
612645
end

0 commit comments

Comments
 (0)