Skip to content

Commit b8610ae

Browse files
authored
Merge pull request #249 from control-toolbox/244-getters
refactoring + add getters and setters
2 parents abf85ab + 25dab34 commit b8610ae

17 files changed

+1270
-1116
lines changed

ext/plot.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ Get the data for plotting.
470470
function __get_data_plot(sol::OptimalControlSolution,
471471
xx::Union{Symbol,Tuple{Symbol,Integer}}; time::Symbol=:default)
472472

473-
T = sol.times
473+
T = sol.time_grid
474474
X = sol.state.(T)
475475
U = sol.control.(T)
476476
P = sol.costate.(T)

src/CTBase.jl

+20-15
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,28 @@ const DCostate = ctVector
196196
#
197197
include("exception.jl")
198198
include("description.jl")
199-
include("callback.jl")
200199
include("default.jl")
201200
include("types.jl")
201+
include("functions.jl")
202202
include("utils.jl")
203+
204+
# Optimal Control Model
205+
include("optimal_control_model-type.jl")
206+
include("optimal_control_model-getters.jl")
207+
include("optimal_control_model-setters.jl")
208+
209+
# Optimal Control Solution
210+
include("optimal_control_solution-type.jl")
211+
include("optimal_control_solution-getters.jl")
212+
include("optimal_control_solution-setters.jl")
213+
203214
#
204-
include("checking.jl")
205-
#
206-
include("print.jl")
207-
#
208-
include("functions.jl")
209-
include("model.jl")
210215
include("differential_geometry.jl")
211-
#
212216
include("ctparser_utils.jl")
213217
include("onepass.jl")
214218
include("repl.jl")
215-
#
216219
include("init.jl")
220+
include("print.jl")
217221

218222
# numeric types
219223
export ctNumber, ctVector, Time, Times, TimesDisc
@@ -223,10 +227,6 @@ export DState, DCostate
223227
export TimeDependence, Autonomous, NonAutonomous
224228
export VariableDependence, NonFixed, Fixed
225229

226-
# callback
227-
export CTCallback, CTCallbacks, PrintCallback, StopCallback
228-
export get_priority_print_callbacks, get_priority_stop_callbacks
229-
230230
# description
231231
export Description, add, getFullDescription, remove
232232

@@ -248,10 +248,13 @@ export OptimalControlModel
248248
export Model
249249
export __OCPModel # redirection to Model to avoid confusion with other Model functions from other packages. Due to @def macro
250250
export variable!, time!, constraint!, dynamics!, objective!, state!, control!, remove_constraint!, constraint
251-
export is_autonomous, is_fixed, is_time_independent, is_time_dependent, is_min, is_max, is_variable_dependent, is_variable_independent
251+
export is_autonomous, is_fixed, is_time_independent, is_time_dependent, is_min, is_max
252+
export is_variable_dependent, is_variable_independent
252253
export nlp_constraints!, constraints_labels
253254
export has_free_final_time, has_free_initial_time, has_lagrange_cost, has_mayer_cost
254-
export dim_control_constraints, dim_state_constraints, dim_mixed_constraints, dim_path_constraints, dim_boundary_constraints, dim_variable_constraints, dim_control_range, dim_state_range, dim_variable_range
255+
export dim_control_constraints, dim_state_constraints, dim_mixed_constraints, dim_path_constraints
256+
export dim_boundary_constraints, dim_variable_constraints, dim_control_range
257+
export dim_state_range, dim_variable_range
255258
export model_expression, initial_time, initial_time_name, final_time, final_time_name, time_name
256259
export control_dimension, control_components_names, control_name
257260
export state_dimension, state_components_names, state_name
@@ -260,6 +263,8 @@ export lagrange, mayer, criterion, dynamics
260263

261264
# solution
262265
export OptimalControlSolution
266+
export time_grid, control, state, variable, costate, objective
267+
export iterations, stopping, message, success, infos
263268

264269
# initialization
265270
export OptimalControlInit

src/callback.jl

-117
This file was deleted.

src/checking.jl

-75
This file was deleted.

src/differential_geometry.jl

+20-20
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ julia> @Lie {H0, H1}(1, [1, 2, 3], [1, 0, 7], 2)
552552
"""
553553
macro Lie(expr::Expr)
554554

555-
fun(x) = @match (@capture(x, [a_, b_]),@capture(x, {c_, d_})) begin
555+
fun(x) = @match (@capture(x, [a_, b_]), @capture(x, {c_, d_})) begin
556556
(true, false) => :( Lie($a, $b))
557557
(false, true) => :(Poisson($c, $d))
558558
(false, false) => x
@@ -593,26 +593,26 @@ macro Lie(expr::Expr, arg1, arg2)
593593
local variable=false
594594

595595
@match arg1 begin
596-
:( Autonomous ) => begin autonomous=true end
597-
:( NonAutonomous ) => begin autonomous=false end
598-
:( autonomous = $a ) => begin autonomous=a end
599-
:( NonFixed ) => begin variable=true end
600-
:( Fixed ) => begin variable=false end
601-
:( variable = $a ) => begin variable=a end
596+
:( Autonomous ) => begin autonomous = true end
597+
:( NonAutonomous ) => begin autonomous = false end
598+
:( autonomous = $a ) => begin autonomous = a end
599+
:( NonFixed ) => begin variable = true end
600+
:( Fixed ) => begin variable = false end
601+
:( variable = $a ) => begin variable = a end
602602
_ => throw(IncorrectArgument("Invalid argument: " * string(arg1)))
603603
end
604604

605605
@match arg2 begin
606-
:( Autonomous ) => begin autonomous=true end
607-
:( NonAutonomous ) => begin autonomous=false end
608-
:( autonomous = $a ) => begin autonomous=a end
609-
:( NonFixed ) => begin variable=true end
610-
:( Fixed ) => begin variable=false end
611-
:( variable = $a ) => begin variable=a end
606+
:( Autonomous ) => begin autonomous = true end
607+
:( NonAutonomous ) => begin autonomous = false end
608+
:( autonomous = $a ) => begin autonomous = a end
609+
:( NonFixed ) => begin variable = true end
610+
:( Fixed ) => begin variable = false end
611+
:( variable = $a ) => begin variable = a end
612612
_ => throw(IncorrectArgument("Invalid argument: " * string(arg2)))
613613
end
614614

615-
fun(x) = @match (@capture(x, [a_, b_]),@capture(x, {c_, d_})) begin
615+
fun(x) = @match (@capture(x, [a_, b_]), @capture(x, {c_, d_})) begin
616616
#(true, false) => :( Lie($a, $b; autonomous=$autonomous, variable=$variable))
617617
(false, true) => quote
618618
($c isa Function && $d isa Function) ?
@@ -649,12 +649,12 @@ macro Lie(expr::Expr, arg)
649649
local variable=false
650650

651651
@match arg begin
652-
:( Autonomous ) => begin autonomous=true end
653-
:( NonAutonomous ) => begin autonomous=false end
654-
:( autonomous = $a ) => begin autonomous=a end
655-
:( NonFixed ) => begin variable=true end
656-
:( Fixed ) => begin variable=false end
657-
:( variable = $a ) => begin variable=a end
652+
:( Autonomous ) => begin autonomous = true end
653+
:( NonAutonomous ) => begin autonomous = false end
654+
:( autonomous = $a ) => begin autonomous = a end
655+
:( NonFixed ) => begin variable = true end
656+
:( Fixed ) => begin variable = false end
657+
:( variable = $a ) => begin variable = a end
658658
_ => throw(IncorrectArgument("Invalid argument: " * string(arg)))
659659
end
660660

0 commit comments

Comments
 (0)