Skip to content

Commit 28942c7

Browse files
authored
Merge pull request #173 from control-toolbox/172-dev-solver-info
Replace stopping by status and success by successful
2 parents 2e4b2ca + 3a2e7d1 commit 28942c7

11 files changed

Lines changed: 83 additions & 70 deletions

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CTModels"
22
uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d"
33
authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
4-
version = "0.5.4"
4+
version = "0.6.0"
55

66
[deps]
77
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"

ext/CTModelsJSON.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function CTModels.export_ocp_solution(
4545
"iterations" => CTModels.iterations(sol),
4646
"constraints_violation" => CTModels.constraints_violation(sol),
4747
"message" => CTModels.message(sol),
48-
"stopping" => CTModels.stopping(sol),
49-
"success" => CTModels.success(sol),
48+
"status" => CTModels.status(sol),
49+
"successful" => CTModels.successful(sol),
5050
"path_constraints_dual" =>
5151
CTModels.discretize(CTModels.path_constraints_dual(sol), T),
5252
"state_constraints_lb_dual" =>
@@ -218,8 +218,8 @@ function CTModels.import_ocp_solution(
218218
iterations=blob.iterations,
219219
constraints_violation=Float64(blob.constraints_violation),
220220
message=blob.message,
221-
stopping=Symbol(blob.stopping),
222-
success=blob.success,
221+
status=Symbol(blob.status),
222+
successful=blob.successful,
223223
path_constraints_dual=path_constraints_dual,
224224
state_constraints_lb_dual=state_constraints_lb_dual,
225225
state_constraints_ub_dual=state_constraints_ub_dual,

src/solution.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Build a solution from the optimal control problem, the time grid, the state, con
1414
- `objective::Float64`: the objective value.
1515
- `iterations::Int`: the number of iterations.
1616
- `constraints_violation::Float64`: the constraints violation.
17-
- `message::String`: the message associated to the stopping criterion.
18-
- `stopping::Symbol`: the stopping criterion.
19-
- `success::Bool`: the success status.
17+
- `message::String`: the message associated to the status criterion.
18+
- `status::Symbol`: the status criterion.
19+
- `successful::Bool`: the successful status.
2020
- `path_constraints_dual::Matrix{Float64}`: the dual of the path constraints.
2121
- `boundary_constraints_dual::Vector{Float64}`: the dual of the boundary constraints.
2222
- `state_constraints_lb_dual::Matrix{Float64}`: the lower bound dual of the state constraints.
@@ -42,8 +42,8 @@ function build_solution(
4242
iterations::Int,
4343
constraints_violation::Float64,
4444
message::String,
45-
stopping::Symbol,
46-
success::Bool,
45+
status::Symbol,
46+
successful::Bool,
4747
path_constraints_dual::TPCD=__constraints(),
4848
boundary_constraints_dual::Union{Vector{Float64},Nothing}=__constraints(),
4949
state_constraints_lb_dual::Union{Matrix{Float64},Nothing}=__constraints(),
@@ -214,7 +214,7 @@ function build_solution(
214214
variable_constraints_ub_dual,
215215
)
216216
solver_infos = SolverInfos(
217-
iterations, stopping, message, success, constraints_violation, infos
217+
iterations, status, message, successful, constraints_violation, infos
218218
)
219219

220220
return Solution(
@@ -523,17 +523,17 @@ end
523523
"""
524524
$(TYPEDSIGNATURES)
525525
526-
Return the stopping criterion (a Symbol).
526+
Return the status criterion (a Symbol).
527527
528528
"""
529-
function stopping(sol::Solution)::Symbol
530-
return sol.solver_infos.stopping
529+
function status(sol::Solution)::Symbol
530+
return sol.solver_infos.status
531531
end
532532

533533
"""
534534
$(TYPEDSIGNATURES)
535535
536-
Return the message associated to the stopping criterion.
536+
Return the message associated to the status criterion.
537537
538538
"""
539539
function message(sol::Solution)::String
@@ -543,11 +543,11 @@ end
543543
"""
544544
$(TYPEDSIGNATURES)
545545
546-
Return the success status.
546+
Return the successful status.
547547
548548
"""
549-
function success(sol::Solution)::Bool
550-
return sol.solver_infos.success
549+
function successful(sol::Solution)::Bool
550+
return sol.solver_infos.successful
551551
end
552552

553553
"""
@@ -704,50 +704,50 @@ function Base.show(io::IO, ::MIME"text/plain", sol::Solution)
704704
println(io, "────────────────────────")
705705

706706
# Status
707-
println(io, "Success : ", success(sol))
708-
println(io, "Stopping : ", stopping(sol))
709-
println(io, "• Message : ", message(sol))
710-
println(io, "• Iterations : ", iterations(sol))
711-
println(io, "• Objective : ", objective(sol))
707+
println(io, "Successful : ", successful(sol))
708+
println(io, "Status : ", status(sol))
709+
println(io, "• Message : ", message(sol))
710+
println(io, "• Iterations : ", iterations(sol))
711+
println(io, "• Objective : ", objective(sol))
712712
println(io, "• Constraint violation: ", constraints_violation(sol))
713713

714714
println(io)
715715
println(io, "Time")
716716
println(io, "────")
717-
println(io, "• Name : ", time_name(sol))
718-
println(io, "• Grid : ", time_grid(sol))
719-
println(io, "• Grid length : ", length(time_grid(sol)))
717+
println(io, "• Name : ", time_name(sol))
718+
println(io, "• Grid : ", time_grid(sol))
719+
println(io, "• Grid length : ", length(time_grid(sol)))
720720

721721
println(io)
722722
println(io, "State")
723723
println(io, "─────")
724-
println(io, "• Name : ", state_name(sol))
725-
println(io, "• Dimension : ", state_dimension(sol))
726-
println(io, "• Components : ", join(state_components(sol), ", "))
724+
println(io, "• Name : ", state_name(sol))
725+
println(io, "• Dimension : ", state_dimension(sol))
726+
println(io, "• Components : ", join(state_components(sol), ", "))
727727

728728
println(io)
729729
println(io, "Control")
730730
println(io, "───────")
731-
println(io, "• Name : ", control_name(sol))
732-
println(io, "• Dimension : ", control_dimension(sol))
733-
println(io, "• Components : ", join(control_components(sol), ", "))
731+
println(io, "• Name : ", control_name(sol))
732+
println(io, "• Dimension : ", control_dimension(sol))
733+
println(io, "• Components : ", join(control_components(sol), ", "))
734734

735735
# Variable block (optional)
736736
v_dim = variable_dimension(sol)
737737
if v_dim > 0
738738
println(io)
739739
println(io, "Variable")
740740
println(io, "────────")
741-
println(io, "• Name : ", variable_name(sol))
742-
println(io, "• Dimension : ", v_dim)
743-
println(io, "• Components : ", join(variable_components(sol), ", "))
744-
println(io, "• Value : ", variable(sol))
741+
println(io, "• Name : ", variable_name(sol))
742+
println(io, "• Dimension : ", v_dim)
743+
println(io, "• Components : ", join(variable_components(sol), ", "))
744+
println(io, "• Value : ", variable(sol))
745745
end
746746

747747
println(io)
748748
println(io, "Duals")
749749
println(io, "─────")
750-
println(io, "• Boundary constraints dual : ", boundary_constraints_dual(sol))
750+
println(io, "• Boundary constraints dual: ", boundary_constraints_dual(sol))
751751
if v_dim > 0
752752
println(io, "• Variable constraints dual (lb): ", variable_constraints_lb_dual(sol))
753753
println(io, "• Variable constraints dual (ub): ", variable_constraints_ub_dual(sol))

src/types.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ $(TYPEDFIELDS)
554554
"""
555555
struct SolverInfos{TI<:Dict{Symbol,Any}} <: AbstractSolverInfos
556556
iterations::Int # number of iterations
557-
stopping::Symbol # the stopping criterion
558-
message::String # the message corresponding to the stopping criterion
559-
success::Bool # whether or not the method has finished successfully: CN1, stagnation vs iterations max
557+
status::Symbol # the status criterion
558+
message::String # the message corresponding to the status criterion
559+
successful::Bool # whether or not the method has finished successfully: CN1, stagnation vs iterations max
560560
constraints_violation::Float64 # the constraints violation
561561
infos::TI # additional informations
562562
end

test/Project.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
33
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
4-
CTDirect = "790bbbee-bee9-49ee-8912-a9de031322d5"
5-
CTParser = "32681960-a1b1-40db-9bff-a1ca817385d1"
64
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
75
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
86
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
@@ -12,8 +10,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1210
[compat]
1311
Aqua = "0.8"
1412
CTBase = "0.16"
15-
CTDirect = "0.14"
16-
CTParser = "0.4"
1713
JLD2 = "0.5"
1814
JSON3 = "1"
1915
NLPModelsIpopt = "0.10"

test/extras/plot_duals.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function SOL(ocp, t0, tf)
5151
iterations=-1,
5252
constraints_violation=0.0,
5353
message="",
54-
stopping=:optimal,
55-
success=true,
54+
status=:optimal,
55+
successful=true,
5656
path_constraints_dual=path_constraints_dual,
5757
)
5858

test/extras/plot_manual.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ function get_solution()
106106
message = "Solve_Succeeded"
107107

108108
# Stopping: Symbol
109-
stopping = :Solve_Succeeded
109+
status = :Solve_Succeeded
110110

111111
# Success: Bool
112-
success = true
112+
successful = true
113113

114114
# solution
115115
sol = CTModels.build_solution(
@@ -123,8 +123,8 @@ function get_solution()
123123
iterations=iterations,
124124
constraints_violation=constraints_violation,
125125
message=message,
126-
stopping=stopping,
127-
success=success,
126+
status=status,
127+
successful=successful,
128128
)
129129

130130
return sol

test/runtests.jl

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ using Aqua
33
using CTBase
44
using CTModels
55

6-
using CTDirect
7-
using NLPModelsIpopt
8-
import CTParser: CTParser, @def
9-
CTParser.prefix!(:CTModels); # code generated by @def is prefixed by CTModels (not by OptimalControl - the default)
10-
116
#
127
include("solution_example.jl")
13-
include("solution_example_path_constraints.jl")
148

159
#
1610
@testset verbose = true showtiming = true "CTModels tests" begin
@@ -29,8 +23,6 @@ include("solution_example_path_constraints.jl")
2923
:init,
3024
:utils,
3125
:solution,
32-
:plot,
33-
:export_import,
3426
)
3527
@testset "$(name)" begin
3628
test_name = Symbol(:test_, name)
@@ -40,3 +32,28 @@ include("solution_example_path_constraints.jl")
4032
end
4133
end
4234
end
35+
36+
# test with CTDirect and CTParser: must be commented if new version of CTModels, that is breaking
37+
38+
# using CTDirect
39+
# using NLPModelsIpopt
40+
# import CTParser: CTParser, @def
41+
# CTParser.prefix!(:CTModels); # code generated by @def is prefixed by CTModels (not by OptimalControl - the default)
42+
43+
# #
44+
# include("solution_example_path_constraints.jl")
45+
46+
47+
# @testset verbose = true showtiming = true "CTModels tests" begin
48+
# for name in (
49+
# :plot,
50+
# :export_import,
51+
# )
52+
# @testset "$(name)" begin
53+
# test_name = Symbol(:test_, name)
54+
# println("testing: ", string(name))
55+
# include("$(test_name).jl")
56+
# @eval $test_name()
57+
# end
58+
# end
59+
# end

test/solution_example.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ function solution_example(; fun=false)
118118
message = "Solve_Succeeded"
119119

120120
# Stopping: Symbol
121-
stopping = :Solve_Succeeded
121+
status = :Solve_Succeeded
122122

123123
# Success: Bool
124-
success = true
124+
successful = true
125125

126126
# Path constraints: Matrix{Float64}
127127
path_constraints = nothing
@@ -165,8 +165,8 @@ function solution_example(; fun=false)
165165
iterations=iterations,
166166
constraints_violation=constraints_violation,
167167
message=message,
168-
stopping=stopping,
169-
success=success,
168+
status=status,
169+
successful=successful,
170170
path_constraints_dual=path_constraints_dual,
171171
boundary_constraints_dual=boundary_constraints_dual,
172172
state_constraints_lb_dual=state_constraints_lb_dual,

test/solution_example_path_constraints.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function solution_example_path_constraints()
4444
iterations=-1,
4545
constraints_violation=0.0,
4646
message="",
47-
stopping=:optimal,
48-
success=true,
47+
status=:optimal,
48+
successful=true,
4949
path_constraints_dual=path_constraints_dual,
5050
)
5151

0 commit comments

Comments
 (0)