Skip to content

Commit

Permalink
added test for init=() and init=nothing (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMartinon authored Jul 4, 2024
1 parent 05b5813 commit 67653c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions test/suite/initial_guess.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
println("Test: initial guess options\n")
println("Test: initial guess options")

# use 0 iterations to check initial guess, >0 to check cv
maxiter = 0
Expand Down Expand Up @@ -48,10 +48,18 @@ u_vec = [0, 0.3, .1]
# 1 Pass initial guess to all-in-one solve call

# 1.a default initial guess
@testset verbose = true showtiming = true ":default_init" begin
@testset verbose = true showtiming = true ":default_init_no_arg" begin
sol = solve(ocp, print_level=0, max_iter=maxiter)
@test(check_xf(sol, [0.1, 0.1]) && check_uf(sol, 0.1) && check_v(sol, 0.1))
end
@testset verbose = true showtiming = true ":default_init_()" begin
sol = solve(ocp, print_level=0, init=(), max_iter=maxiter)
@test(check_xf(sol, [0.1, 0.1]) && check_uf(sol, 0.1) && check_v(sol, 0.1))
end
@testset verbose = true showtiming = true ":default_init_nothing" begin
sol = solve(ocp, print_level=0, init=nothing,max_iter=maxiter)
@test(check_xf(sol, [0.1, 0.1]) && check_uf(sol, 0.1) && check_v(sol, 0.1))
end

# 1.b constant initial guess
@testset verbose = true showtiming = true ":constant_x" begin
Expand Down
14 changes: 13 additions & 1 deletion test/test_initial_guess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ if maxiter > 0
else
println(check_xf(sol, [0.1, 0.1]) && check_uf(sol, 0.1) && check_v(sol, 0.1))
end
sol = solve(ocp, print_level=0, init=(), max_iter=maxiter)
if maxiter > 0
@printf("%-56s %.3f at %d iterations\n", "Default initial guess", sol.objective, sol.iterations)
else
println(check_xf(sol, [0.1, 0.1]) && check_uf(sol, 0.1) && check_v(sol, 0.1))
end
sol = solve(ocp, print_level=0, init=nothing, max_iter=maxiter)
if maxiter > 0
@printf("%-56s %.3f at %d iterations\n", "Default initial guess", sol.objective, sol.iterations)
else
println(check_xf(sol, [0.1, 0.1]) && check_uf(sol, 0.1) && check_v(sol, 0.1))
end

# 1.b constant initial guess
sol = solve(ocp, print_level=0, init=(state=x_const,), max_iter=maxiter)
Expand Down Expand Up @@ -110,7 +122,7 @@ else
println(check_xf(sol, x_const) && check_uf(sol, u_const) && check_v(sol, v_const))
end

# 1. functional initial guess
# 1.c functional initial guess
sol = solve(ocp, print_level=0, init=(state=x_func,), max_iter=maxiter)
if maxiter > 0
@printf("%-56s %.3f at %d iterations\n", "Functional x; default u,v", sol.objective, sol.iterations)
Expand Down

0 comments on commit 67653c5

Please sign in to comment.