7979@testset " Linear systems" begin
8080 function is_bangbang (input_sol, lbounds, ubounds, rtol = 1e-4 )
8181 bangbang = true
82- for v in 1 : length (input_sol. u[1 ]) - 1
83- all (i -> ≈ (i[v], bounds[v]; rtol) || ≈ (i[v], bounds[u]; rtol), input_sol. u) || (bangbang = false )
82+ for v in 1 : (length (input_sol. u[1 ]) - 1 )
83+ all (i -> ≈ (i[v], bounds[v]; rtol) || ≈ (i[v], bounds[u]; rtol), input_sol. u) ||
84+ (bangbang = false )
8485 end
8586 bangbang
8687 end
8788
8889 # Double integrator
8990 t = M. t_nounits
9091 D = M. D_nounits
91- @variables x (.. ) [bounds = (0. , 0.25 )] v (.. )
92- @variables u (t) [bounds = (- 1. , 1. ), input = true ]
92+ @variables x (.. ) [bounds = (0.0 , 0.25 )] v (.. )
93+ @variables u (t) [bounds = (- 1.0 , 1.0 ), input = true ]
9394 constr = [v (1.0 ) ~ 0.0 ]
9495 cost = [- x (1.0 )] # Maximize the final distance.
95- @named block = ODESystem ([D (x (t)) ~ v (t), D (v (t)) ~ u], t; costs = cost, constraints = constr)
96- block, input_idxs = structural_simplify (block, ([u],[]))
96+ @named block = ODESystem (
97+ [D (x (t)) ~ v (t), D (v (t)) ~ u], t; costs = cost, constraints = constr)
98+ block, input_idxs = structural_simplify (block, ([u], []))
9799
98- u0map = [x (t) => 0. , v (t) => 0. ]
99- tspan = (0. , 1. )
100- parammap = [u => 0. ]
100+ u0map = [x (t) => 0.0 , v (t) => 0.0 ]
101+ tspan = (0.0 , 1.0 )
102+ parammap = [u => 0.0 ]
101103 jprob = JuMPControlProblem (block, u0map, tspan, parammap; dt = 0.01 )
102104 jsol = solve (jprob, Ipopt. Optimizer, :Verner8 )
103105 # Linear systems have bang-bang controls
104- @test is_bangbang (jsol. input_sol, [- 1. ], [1. ])
106+ @test is_bangbang (jsol. input_sol, [- 1.0 ], [1.0 ])
105107 # Test reached final position.
106108 @test ≈ (jsol. sol. u[end ][1 ], 0.25 , rtol = 1e-5 )
107109
108110 iprob = InfiniteOptControlProblem (block, u0map, tspan, parammap; dt = 0.01 )
109111 isol = solve (iprob, Ipopt. Optimizer; silent = true )
110- @test is_bangbang (isol. input_sol, [- 1. ], [1. ])
112+ @test is_bangbang (isol. input_sol, [- 1.0 ], [1.0 ])
111113 @test ≈ (isol. sol. u[end ][1 ], 0.25 , rtol = 1e-5 )
112114
113115 # ##################
@@ -118,21 +120,21 @@ end
118120 @parameters b c μ s ν
119121
120122 tspan = (0 , 4 )
121- eqs = [D (w (t)) ~ - μ* w (t) + b* s * α * w (t),
122- D (q (t)) ~ - ν* q (t) + c* (1 - α)* s * w (t)]
123+ eqs = [D (w (t)) ~ - μ * w (t) + b * s * α * w (t),
124+ D (q (t)) ~ - ν * q (t) + c * (1 - α) * s * w (t)]
123125 costs = [- q (tspan[2 ])]
124-
126+
125127 @named beesys = ODESystem (eqs, t; costs)
126- beesys, input_idxs = structural_simplify (beesys, ([α],[]))
128+ beesys, input_idxs = structural_simplify (beesys, ([α], []))
127129 u0map = [w (t) => 40 , q (t) => 2 ]
128130 pmap = [b => 1 , c => 1 , μ => 1 , s => 1 , ν => 1 , α => 1 ]
129131
130132 jprob = JuMPControlProblem (beesys, u0map, tspan, pmap, dt = 0.01 )
131133 jsol = solve (jprob, Ipopt. Optimizer, :Tsitouras5 )
132- @test is_bangbang (jsol. input_sol, [0. ], [1. ])
134+ @test is_bangbang (jsol. input_sol, [0.0 ], [1.0 ])
133135 iprob = InfiniteOptControlProblem (beesys, u0map, tspan, pmap, dt = 0.01 )
134136 isol = solve (jprob, Ipopt. Optimizer, :Tsitouras5 )
135- @test is_bangbang (isol. input_sol, [0. ], [1. ])
137+ @test is_bangbang (isol. input_sol, [0.0 ], [1.0 ])
136138end
137139
138140@testset " Rocket launch" begin
@@ -144,18 +146,20 @@ end
144146 drag (h, v) = D_c * v^ 2 * exp (- h_c * (h - h₀) / h₀)
145147 gravity (h) = g₀ * (h₀ / h)
146148
147- eqs = [D (h (t)) ~ v (t),
148- D (v (t)) ~ (T (t) - drag (h (t), v (t))) / m (t) - gravity (h (t)),
149- D (m (t)) ~ - T (t) / c]
149+ eqs = [D (h (t)) ~ v (t),
150+ D (v (t)) ~ (T (t) - drag (h (t), v (t))) / m (t) - gravity (h (t)),
151+ D (m (t)) ~ - T (t) / c]
150152
151- (ts, te) = (0. , 0.2 )
153+ (ts, te) = (0.0 , 0.2 )
152154 costs = [- h (te)]
153155 constraints = [T (te) ~ 0 ]
154156 @named rocket = ODESystem (eqs, t; costs, constraints)
155157 rocket, input_idxs = structural_simplify (rocket, ([T (t)], []))
156158
157159 u0map = [h (t) => h₀, m (t) => m₀, v (t) => 0 ]
158- pmap = [g₀ => 1 , m₀ => 1.0 , h_c => 500 , c => 0.5 *√ (g₀* h₀), D_c => 0.5 * 620 * m₀/ g₀, Tₘ => 3.5 * g₀* m₀, T (t) => 0. , h₀ => 1 , m_c => 0.6 ]
160+ pmap = [
161+ g₀ => 1 , m₀ => 1.0 , h_c => 500 , c => 0.5 * √ (g₀ * h₀), D_c => 0.5 * 620 * m₀ / g₀,
162+ Tₘ => 3.5 * g₀ * m₀, T (t) => 0.0 , h₀ => 1 , m_c => 0.6 ]
159163 jprob = JuMPControlProblem (rocket, u0map, (ts, te), pmap; dt = 0.005 , cse = false )
160164 jsol = solve (jprob, Ipopt. Optimizer, :RadauIA3 )
161165 @test jsol. sol. u[end ][1 ] > 1.012
@@ -165,17 +169,17 @@ end
165169 t = M. t_nounits
166170 D = M. D_nounits
167171
168- @variables x (.. ) u (.. ) [input = true , bounds = (0 ,1 )]
172+ @variables x (.. ) u (.. ) [input = true , bounds = (0 , 1 )]
169173 @parameters tf
170- eqs = [D (x (t)) ~ - 2 + 0.5 * u (t)]
174+ eqs = [D (x (t)) ~ - 2 + 0.5 * u (t)]
171175 # Integral cost function
172- costs = [- ∫ (x (t)- u (t)), - x (tf)]
176+ costs = [- ∫ (x (t) - u (t)), - x (tf)]
173177 consolidate (u) = u[1 ] + u[2 ]
174178 @named rocket = ODESystem (eqs, t; costs, consolidate)
175179 rocket, input_idxs = structural_simplify (rocket, ([u (t)], []))
176180
177181 u0map = [x (t) => 17.5 ]
178- pmap = [u (t) => 0. , tf => 8 ]
182+ pmap = [u (t) => 0.0 , tf => 8 ]
179183 jprob = JuMPControlProblem (rocket, u0map, (0 , tf), pmap; steps = 201 )
180184 jsol = solve (jprob, Ipopt. Optimizer, :Tsitouras5 )
181185 @test isapprox (jsol. sol. t[end ], 10.0 , rtol = 1e-3 )
0 commit comments