66
77module TestDoubleIntegratorEnergy
88
9- import Test
10- import OptimalControl
9+ using Test : Test
10+ using OptimalControl : OptimalControl
1111import NonlinearSolve: NonlinearProblem, solve
1212import LinearAlgebra: norm
1313import OrdinaryDiffEq: OrdinaryDiffEq
@@ -21,11 +21,11 @@ const SHOWTIMING = isdefined(Main, :TestOptions) ? Main.TestOptions.SHOWTIMING :
2121
2222function test_double_integrator_energy ()
2323 Test. @testset " Double Integrator Energy Minimization" verbose= VERBOSE showtiming= SHOWTIMING begin
24-
24+
2525 # ====================================================================
2626 # INTEGRATION TEST - Unconstrained Energy Minimization
2727 # ====================================================================
28-
28+
2929 Test. @testset " Unconstrained singular control" begin
3030 # Get problem from TestProblems
3131 prob_data = TestProblems. DoubleIntegratorEnergy ()
@@ -35,36 +35,36 @@ function test_double_integrator_energy()
3535 t0 = prob_data. t0
3636 tf = prob_data. tf
3737 obj_ref = prob_data. obj
38-
38+
3939 # Singular control: u(x, p) = p₂
4040 u (x, p) = p[2 ]
41-
41+
4242 # Hamiltonian flow
4343 f = OptimalControl. Flow (ocp, u)
44-
44+
4545 # State projection
4646 π ((x, p)) = x
47-
47+
4848 # Shooting function
4949 S (p0) = π (f (t0, x0, p0, tf)) - xf
50-
50+
5151 # Known solution (from documentation)
5252 p0_ref = [12.0 , 6.0 ]
53-
53+
5454 # Test shooting function with known solution
5555 s = S (p0_ref)
56-
56+
5757 # Verify solution (should be close to zero)
5858 Test. @test norm (s) < 1e-6
59-
59+
6060 # Note: We don't test the objective value directly here since
6161 # we're testing the shooting method, not the full solution
6262 end
63-
63+
6464 # ====================================================================
6565 # INTEGRATION TEST - Constrained Energy Minimization
6666 # ====================================================================
67-
67+
6868 Test. @testset " Constrained three-arc structure" begin
6969 # Get problem from TestProblems
7070 prob_data = TestProblems. DoubleIntegratorEnergyConstrained ()
@@ -74,18 +74,20 @@ function test_double_integrator_energy()
7474 t0 = prob_data. t0
7575 tf = prob_data. tf
7676 v_max = prob_data. v_max
77-
77+
7878 # Flow for unconstrained extremals (singular control u = p₂)
7979 f_interior = OptimalControl. Flow (ocp, (x, p) -> p[2 ])
80-
80+
8181 # Boundary control and constraint
8282 ub = 0.0 # boundary control
8383 g (x) = v_max - x[2 ] # constraint: g(x) ≥ 0
8484 μ (p) = p[1 ] # dual variable
85-
85+
8686 # Flow for boundary extremals
87- f_boundary = OptimalControl. Flow (ocp, (x, p) -> ub, (x, u) -> g (x), (x, p) -> μ (p))
88-
87+ f_boundary = OptimalControl. Flow (
88+ ocp, (x, p) -> ub, (x, u) -> g (x), (x, p) -> μ (p)
89+ )
90+
8991 # Shooting function
9092 function shoot! (s, p0, t1, t2)
9193 x_t0, p_t0 = x0, p0
@@ -96,19 +98,19 @@ function test_double_integrator_energy()
9698 s[3 ] = g (x_t1) # constraint activation at entry
9799 s[4 ] = p_t1[2 ] # switching condition
98100 end
99-
101+
100102 # Known solution (from documentation)
101103 p0_ref = [38.4 , 9.6 ]
102104 t1_ref = 0.25
103105 t2_ref = 0.75
104-
106+
105107 # Test shooting function with known solution
106108 s = zeros (4 )
107109 shoot! (s, p0_ref, t1_ref, t2_ref)
108-
110+
109111 # Verify solution (should be close to zero)
110112 Test. @test norm (s) < 1e-6
111-
113+
112114 # Note: obj_ref is nothing for this problem (no reference value available)
113115 end
114116 end
0 commit comments