diff --git a/docs/problems.jl b/docs/problems.jl index 919eefd8..7c89890d 100644 --- a/docs/problems.jl +++ b/docs/problems.jl @@ -116,7 +116,7 @@ function generate_documentation( nlp_oc_sol = NLPModelsIpopt.ipopt(nlp_oc; max_iter=0) # Build OptimalControl solution - ocp_sol = build_ocp_solution(docp, nlp_oc_sol) + ocp_sol = build_OCP_solution(docp, nlp_oc_sol) # get dimensions n = state_dimension(ocp_oc) @@ -292,7 +292,7 @@ function generate_documentation( function print_numerical_comparisons(problem, docp, nlp_oc_sol, nlp_jp) # get relevant data from OptimalControl model - ocp_sol = build_ocp_solution(docp, nlp_oc_sol) + ocp_sol = build_OCP_solution(docp, nlp_oc_sol) t_oc = time_grid(ocp_sol) x_oc = state(ocp_sol).(t_oc) u_oc = control(ocp_sol).(t_oc) @@ -376,7 +376,7 @@ function generate_documentation( ```@example main # build an ocp solution to use the plot from OptimalControl package - ocp_sol = build_ocp_solution(docp, nlp_oc_sol) + ocp_sol = build_OCP_solution(docp, nlp_oc_sol) # dimensions n = state_dimension(ocp_sol) diff --git a/docs/src/tutorial-solve.md b/docs/src/tutorial-solve.md index f81caf9a..565937b4 100644 --- a/docs/src/tutorial-solve.md +++ b/docs/src/tutorial-solve.md @@ -49,7 +49,7 @@ nlp_sol.objective To recover the state, control, and costate, we recommend building an optimal control solution and using the associated getters (you can also retrieve the number of iterations and the objective value from the OCP solution): ```@example main -ocp_sol = build_ocp_solution(docp, nlp_sol) +ocp_sol = build_OCP_solution(docp, nlp_sol) t = time_grid(ocp_sol) # t0, ..., tN = tf x = state(ocp_sol) # function of time diff --git a/src/OptimalControlProblems.jl b/src/OptimalControlProblems.jl index fdf74e61..30c8b055 100644 --- a/src/OptimalControlProblems.jl +++ b/src/OptimalControlProblems.jl @@ -21,24 +21,6 @@ using OrderedCollections: OrderedDict using SolverCore import ADNLPModels: ADNLPModels, ADNLPModel -# ----------------- -# SHOULD NO BE HERE ("triiiiiiiiiiiiiiit !!!" - bruit de sifflet) -function build_ocp_solution( - docp::CTDirect.DOCP, nlp_solution::SolverCore.AbstractExecutionStats -) - nlp_model_backend = if docp.nlp isa ADNLPModel - CTDirect.ADNLPBackend() - elseif docp.nlp isa ExaModel - CTDirect.ExaBackend() - else - throw(CTBase.IncorrectArgument("The NLP model is of unknown type.")) - end - return CTDirect.build_OCP_solution(docp, nlp_solution; nlp_model=nlp_model_backend) -end - -export build_ocp_solution -# - """ $(TYPEDEF) diff --git a/test/Project.toml b/test/Project.toml index 5183c77b..945f79b9 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -22,7 +22,7 @@ Ipopt = "1" JuMP = "1" MadNLPMumps = "0.5" NLPModels = "0.21" -NLPModelsIpopt = "0.10" +NLPModelsIpopt = "0.11" OptimalControl = "1" Plots = "1" Printf = "1" diff --git a/test/figures/init/beam.pdf b/test/figures/init/beam.pdf index 51c756cc..8e88dc9b 100644 Binary files a/test/figures/init/beam.pdf and b/test/figures/init/beam.pdf differ diff --git a/test/figures/init/chain.pdf b/test/figures/init/chain.pdf index 23db459f..261dfc8f 100644 Binary files a/test/figures/init/chain.pdf and b/test/figures/init/chain.pdf differ diff --git a/test/figures/init/double_oscillator.pdf b/test/figures/init/double_oscillator.pdf index daeb8c19..0beae3b9 100644 Binary files a/test/figures/init/double_oscillator.pdf and b/test/figures/init/double_oscillator.pdf differ diff --git a/test/figures/init/ducted_fan.pdf b/test/figures/init/ducted_fan.pdf index ee01eb91..8818e64b 100644 Binary files a/test/figures/init/ducted_fan.pdf and b/test/figures/init/ducted_fan.pdf differ diff --git a/test/figures/init/electric_vehicle.pdf b/test/figures/init/electric_vehicle.pdf index 77f7fe81..ece37f31 100644 Binary files a/test/figures/init/electric_vehicle.pdf and b/test/figures/init/electric_vehicle.pdf differ diff --git a/test/figures/init/glider.pdf b/test/figures/init/glider.pdf index 3ed4210d..651a08ad 100644 Binary files a/test/figures/init/glider.pdf and b/test/figures/init/glider.pdf differ diff --git a/test/figures/init/insurance.pdf b/test/figures/init/insurance.pdf index c66051d6..a8783283 100644 Binary files a/test/figures/init/insurance.pdf and b/test/figures/init/insurance.pdf differ diff --git a/test/figures/init/jackson.pdf b/test/figures/init/jackson.pdf index a83e7568..9ea1725c 100644 Binary files a/test/figures/init/jackson.pdf and b/test/figures/init/jackson.pdf differ diff --git a/test/figures/init/robbins.pdf b/test/figures/init/robbins.pdf index fb4e0dd4..09d7d91c 100644 Binary files a/test/figures/init/robbins.pdf and b/test/figures/init/robbins.pdf differ diff --git a/test/figures/init/robot.pdf b/test/figures/init/robot.pdf index c5faba0e..04a2597e 100644 Binary files a/test/figures/init/robot.pdf and b/test/figures/init/robot.pdf differ diff --git a/test/figures/init/rocket.pdf b/test/figures/init/rocket.pdf index dea45751..54f39f5a 100644 Binary files a/test/figures/init/rocket.pdf and b/test/figures/init/rocket.pdf differ diff --git a/test/figures/init/space_shuttle.pdf b/test/figures/init/space_shuttle.pdf index 942f460b..26c9d610 100644 Binary files a/test/figures/init/space_shuttle.pdf and b/test/figures/init/space_shuttle.pdf differ diff --git a/test/figures/init/steering.pdf b/test/figures/init/steering.pdf index 2306324d..ef5b95a5 100644 Binary files a/test/figures/init/steering.pdf and b/test/figures/init/steering.pdf differ diff --git a/test/figures/init/vanderpol.pdf b/test/figures/init/vanderpol.pdf index 812ec21d..81eb1ce5 100644 Binary files a/test/figures/init/vanderpol.pdf and b/test/figures/init/vanderpol.pdf differ diff --git a/test/figures/solution/beam.pdf b/test/figures/solution/beam.pdf index 4b75e9b1..c42556a1 100644 Binary files a/test/figures/solution/beam.pdf and b/test/figures/solution/beam.pdf differ diff --git a/test/figures/solution/chain.pdf b/test/figures/solution/chain.pdf index 48d54152..f8a1c12a 100644 Binary files a/test/figures/solution/chain.pdf and b/test/figures/solution/chain.pdf differ diff --git a/test/figures/solution/double_oscillator.pdf b/test/figures/solution/double_oscillator.pdf index 628542dd..787ac9d4 100644 Binary files a/test/figures/solution/double_oscillator.pdf and b/test/figures/solution/double_oscillator.pdf differ diff --git a/test/figures/solution/ducted_fan.pdf b/test/figures/solution/ducted_fan.pdf index bdafed3d..050533f2 100644 Binary files a/test/figures/solution/ducted_fan.pdf and b/test/figures/solution/ducted_fan.pdf differ diff --git a/test/figures/solution/electric_vehicle.pdf b/test/figures/solution/electric_vehicle.pdf index 9ad456c2..c586681b 100644 Binary files a/test/figures/solution/electric_vehicle.pdf and b/test/figures/solution/electric_vehicle.pdf differ diff --git a/test/figures/solution/glider.pdf b/test/figures/solution/glider.pdf index 69205b7a..4803cb35 100644 Binary files a/test/figures/solution/glider.pdf and b/test/figures/solution/glider.pdf differ diff --git a/test/figures/solution/insurance.pdf b/test/figures/solution/insurance.pdf index eed6a523..3b41638a 100644 Binary files a/test/figures/solution/insurance.pdf and b/test/figures/solution/insurance.pdf differ diff --git a/test/figures/solution/jackson.pdf b/test/figures/solution/jackson.pdf index 599f7b09..2294a7e6 100644 Binary files a/test/figures/solution/jackson.pdf and b/test/figures/solution/jackson.pdf differ diff --git a/test/figures/solution/robbins.pdf b/test/figures/solution/robbins.pdf index 54215222..41a9b7d1 100644 Binary files a/test/figures/solution/robbins.pdf and b/test/figures/solution/robbins.pdf differ diff --git a/test/figures/solution/robot.pdf b/test/figures/solution/robot.pdf index 00e68d9d..5f3563d9 100644 Binary files a/test/figures/solution/robot.pdf and b/test/figures/solution/robot.pdf differ diff --git a/test/figures/solution/rocket.pdf b/test/figures/solution/rocket.pdf index eb5f8948..dafebb92 100644 Binary files a/test/figures/solution/rocket.pdf and b/test/figures/solution/rocket.pdf differ diff --git a/test/figures/solution/space_shuttle.pdf b/test/figures/solution/space_shuttle.pdf index 4e574f53..8ea5b5dd 100644 Binary files a/test/figures/solution/space_shuttle.pdf and b/test/figures/solution/space_shuttle.pdf differ diff --git a/test/figures/solution/steering.pdf b/test/figures/solution/steering.pdf index c715f95a..af57b7fe 100644 Binary files a/test/figures/solution/steering.pdf and b/test/figures/solution/steering.pdf differ diff --git a/test/figures/solution/vanderpol.pdf b/test/figures/solution/vanderpol.pdf index a69f922c..2024087d 100644 Binary files a/test/figures/solution/vanderpol.pdf and b/test/figures/solution/vanderpol.pdf differ diff --git a/test/runtests.jl b/test/runtests.jl index 703d12f2..2e41616b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,13 +26,17 @@ const MAX_WALL_TIME = 500.0 list_of_problems = OptimalControlProblems.problems() # Remove from the tests the following problems -# problems_to_exclude = [ -# :bioreactor, # no need to remove here since already removed in OptimalControlProblems.jl -# :cart_pendulum, # no need to remove here since already removed in OptimalControlProblems.jl -# :dielectrophoretic_particle, # no need to remove here since already removed in OptimalControlProblems.jl -# :moonlander, # no need to remove here since already removed in OptimalControlProblems.jl -# ] -# list_of_problems = setdiff(list_of_problems, problems_to_exclude) +problems_to_exclude = [ + # :bioreactor, # no need to remove here since already removed in OptimalControlProblems.jl + # :cart_pendulum, # no need to remove here since already removed in OptimalControlProblems.jl + # :dielectrophoretic_particle, # no need to remove here since already removed in OptimalControlProblems.jl + # :moonlander, # no need to remove here since already removed in OptimalControlProblems.jl + :ducted_fan, + :insurance, + :robot, + :space_shuttle, +] +list_of_problems = setdiff(list_of_problems, problems_to_exclude) # list_of_problems = [ # :jackson, @@ -55,8 +59,8 @@ const VERBOSE = true # print or not details during tests :OptimalControl, # convergence tests for OptimalControl models :OptimalControl_s, # convergence tests for OptimalControl models :init, # comparison between OptimalControl and JuMP: init - # :solution, # comparison between OptimalControl and JuMP: solution - # :quick, # quick comparison: objective rel error only + :solution, # comparison between OptimalControl and JuMP: solution + :quick, # quick comparison: objective rel error only :parameters, # tests with different parameters values, does no depend on `list_of_problems` ) @testset "$(name)" verbose=VERBOSE begin @@ -74,7 +78,7 @@ const VERBOSE = true # print or not details during tests display(problems()); println() - @testset "available_problems" verbose=VERBOSE begin - @test LIST_OF_PROBLEMS_FINAL == problems() - end + # @testset "available_problems" verbose=VERBOSE begin + # @test LIST_OF_PROBLEMS_FINAL == problems() + # end end diff --git a/test/test_quick.jl b/test/test_quick.jl index bc179e67..0b3bb3cb 100644 --- a/test/test_quick.jl +++ b/test/test_quick.jl @@ -54,7 +54,7 @@ function test_quick() ) nlp = nlp_model(docp) nlp_sol = NLPModelsIpopt.ipopt(nlp; kwargs_ipopt...) - sol = build_ocp_solution(docp, nlp_sol) + sol = build_OCP_solution(docp, nlp_sol) o_oc = objective(sol) ########## OptimalControl_s ########## @@ -64,8 +64,8 @@ function test_quick() nlp = nlp_model(docp) ocp = ocp_model(docp) nlp_sol = madnlp(nlp; kwargs_madnlp...) - sol = build_ocp_solution(docp, nlp_sol) - o_os = criterion(ocp) == :min ? objective(sol) : -objective(sol) + sol = build_OCP_solution(docp, nlp_sol) + o_os = objective(sol) ############### TEST ############### DEBUG && println("├─ objective") diff --git a/test/utils.jl b/test/utils.jl index 2741210c..0f103cdb 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -302,7 +302,7 @@ function comparison(; max_iter, test_name) nlp_oc = nlp_model(docp) ocp_oc = ocp_model(docp) nlp_sol = NLPModelsIpopt.ipopt(nlp_oc; options_ipopt...) - sol_oc = build_ocp_solution(docp, nlp_sol) + sol_oc = build_OCP_solution(docp, nlp_sol) t_oc = time_grid(sol_oc) x_oc = state(sol_oc).(t_oc) @@ -324,12 +324,12 @@ function comparison(; max_iter, test_name) nlp_os = nlp_model(docp) ocp_os = ocp_model(docp) nlp_sol = madnlp(nlp_os; options_madnlp...) - sol_os = build_ocp_solution(docp, nlp_sol) + sol_os = build_OCP_solution(docp, nlp_sol) t_os = time_grid(sol_os) x_os = state(sol_os).(t_os) u_os = control(sol_os).(t_os) - o_os = criterion(ocp_os) == :min ? objective(sol_os) : -objective(sol_os) + o_os = objective(sol_os) i_os = iterations(sol_os) v_os = variable(sol_os) nb_var_os = get_nvar(nlp_os)