@@ -45,10 +45,10 @@ constraints = OrderedDict(
4545 :c1 => (:path, f1, [0.0], [1.0]),
4646 :c2 => (:state, 1:2, [-1.0, -1.0], [1.0, 1.0])
4747)
48- model = build_constraints (constraints)
48+ model = build (constraints)
4949```
5050"""
51- function build_constraints (constraints:: ConstraintsDictType ):: ConstraintsModel
51+ function build (constraints:: ConstraintsDictType ):: ConstraintsModel
5252 LocalNumber = Float64
5353
5454 path_cons_nl_f = Vector {Function} () # nonlinear path constraints
240240"""
241241$(TYPEDSIGNATURES)
242242
243- Builds a concrete `Model` from a `PreModel `.
243+ Converts a mutable `PreModel` into an immutable `Model `.
244244
245245This function finalizes a pre-defined optimal control problem (`PreModel`) by verifying that all necessary components (times, state, control, dynamics) are set. It then constructs a `Model` instance, incorporating optional components like objective and constraints if they are defined.
246246
@@ -257,10 +257,10 @@ times!(pre_ocp, 0.0, 1.0, 100)
257257state!(pre_ocp, 2, "x", ["x1", "x2"])
258258control!(pre_ocp, 1, "u", ["u1"])
259259dynamics!(pre_ocp, (dx, t, x, u, v) -> dx .= x + u)
260- model = build_model (pre_ocp)
260+ model = build (pre_ocp)
261261```
262262"""
263- function build_model (pre_ocp:: PreModel ):: Model
263+ function build (pre_ocp:: PreModel ; build_examodel = nothing ):: Model
264264 @ensure __is_times_set (pre_ocp) CTBase. UnauthorizedCall (
265265 " the times must be set before building the model."
266266 )
@@ -297,13 +297,13 @@ function build_model(pre_ocp::PreModel)::Model
297297 __build_dynamics_from_parts (pre_ocp. dynamics)
298298 end
299299 objective = pre_ocp. objective
300- constraints = build_constraints (pre_ocp. constraints)
300+ constraints = build (pre_ocp. constraints)
301301 definition = pre_ocp. definition
302302 TD = is_autonomous (pre_ocp) ? Autonomous : NonAutonomous
303303
304304 # create the model
305305 model = Model {TD} (
306- times, state, control, variable, dynamics, objective, constraints, definition
306+ times, state, control, variable, dynamics, objective, constraints, definition, build_examodel
307307 )
308308
309309 return model
@@ -329,6 +329,7 @@ function is_autonomous(
329329 <: Function ,
330330 <: AbstractObjectiveModel ,
331331 <: AbstractConstraintsModel ,
332+ <: Union{Function,Nothing} ,
332333 },
333334)
334335 return true
@@ -344,6 +345,7 @@ function is_autonomous(
344345 <: Function ,
345346 <: AbstractObjectiveModel ,
346347 <: AbstractConstraintsModel ,
348+ <: Union{Function,Nothing} ,
347349 },
348350)
349351 return false
@@ -365,6 +367,7 @@ function state(
365367 <: Function ,
366368 <: AbstractObjectiveModel ,
367369 <: AbstractConstraintsModel ,
370+ <: Union{Function,Nothing} ,
368371 },
369372):: T where {T<: AbstractStateModel }
370373 return ocp. state
@@ -413,6 +416,7 @@ function control(
413416 <: Function ,
414417 <: AbstractObjectiveModel ,
415418 <: AbstractConstraintsModel ,
419+ <: Union{Function,Nothing} ,
416420 },
417421):: T where {T<: AbstractControlModel }
418422 return ocp. control
@@ -461,6 +465,7 @@ function variable(
461465 <: Function ,
462466 <: AbstractObjectiveModel ,
463467 <: AbstractConstraintsModel ,
468+ <: Union{Function,Nothing} ,
464469 },
465470):: T where {T<: AbstractVariableModel }
466471 return ocp. variable
@@ -509,6 +514,7 @@ function times(
509514 <: Function ,
510515 <: AbstractObjectiveModel ,
511516 <: AbstractConstraintsModel ,
517+ <: Union{Function,Nothing} ,
512518 },
513519):: T where {T<: TimesModel }
514520 return ocp. times
@@ -548,6 +554,7 @@ function initial_time(
548554 <: Function ,
549555 <: AbstractObjectiveModel ,
550556 <: AbstractConstraintsModel ,
557+ <: Union{Function,Nothing} ,
551558 },
552559):: T where {T<: Time }
553560 return initial_time (times (ocp))
@@ -568,6 +575,7 @@ function initial_time(
568575 <: Function ,
569576 <: AbstractObjectiveModel ,
570577 <: AbstractConstraintsModel ,
578+ <: Union{Function,Nothing} ,
571579 },
572580 variable:: AbstractVector{T} ,
573581):: T where {T<: ctNumber }
@@ -589,6 +597,7 @@ function initial_time(
589597 <: Function ,
590598 <: AbstractObjectiveModel ,
591599 <: AbstractConstraintsModel ,
600+ <: Union{Function,Nothing} ,
592601 },
593602 variable:: T ,
594603):: T where {T<: ctNumber }
@@ -654,6 +663,7 @@ function final_time(
654663 <: Function ,
655664 <: AbstractObjectiveModel ,
656665 <: AbstractConstraintsModel ,
666+ <: Union{Function,Nothing} ,
657667 },
658668):: T where {T<: Time }
659669 return final_time (times (ocp))
@@ -674,6 +684,7 @@ function final_time(
674684 <: Function ,
675685 <: AbstractObjectiveModel ,
676686 <: AbstractConstraintsModel ,
687+ <: Union{Function,Nothing} ,
677688 },
678689 variable:: AbstractVector{T} ,
679690):: T where {T<: ctNumber }
@@ -695,6 +706,7 @@ function final_time(
695706 <: Function ,
696707 <: AbstractObjectiveModel ,
697708 <: AbstractConstraintsModel ,
709+ <: Union{Function,Nothing} ,
698710 },
699711 variable:: T ,
700712):: T where {T<: ctNumber }
@@ -744,6 +756,7 @@ function objective(
744756 <: Function ,
745757 O,
746758 <: AbstractConstraintsModel ,
759+ <: Union{Function,Nothing} ,
747760 },
748761):: O where {O<: AbstractObjectiveModel }
749762 return ocp. objective
@@ -778,6 +791,7 @@ function mayer(
778791 <: Function ,
779792 <: MayerObjectiveModel{M} ,
780793 <: AbstractConstraintsModel ,
794+ <: Union{Function,Nothing} ,
781795 },
782796):: M where {M<: Function }
783797 return mayer (objective (ocp))
@@ -798,6 +812,7 @@ function mayer(
798812 <: Function ,
799813 <: BolzaObjectiveModel{M,<:Function} ,
800814 <: AbstractConstraintsModel ,
815+ <: Union{Function,Nothing} ,
801816 },
802817):: M where {M<: Function }
803818 return mayer (objective (ocp))
@@ -832,6 +847,7 @@ function lagrange(
832847 <: Function ,
833848 LagrangeObjectiveModel{L},
834849 <: AbstractConstraintsModel ,
850+ <: Union{Function,Nothing} ,
835851 },
836852):: L where {L<: Function }
837853 return lagrange (objective (ocp))
@@ -852,6 +868,7 @@ function lagrange(
852868 <: Function ,
853869 <: BolzaObjectiveModel{<:Function,L} ,
854870 <: AbstractConstraintsModel ,
871+ <: Union{Function,Nothing} ,
855872 },
856873):: L where {L<: Function }
857874 return lagrange (objective (ocp))
@@ -882,11 +899,55 @@ function dynamics(
882899 D,
883900 <: AbstractObjectiveModel ,
884901 <: AbstractConstraintsModel ,
902+ <: Union{Function,Nothing} ,
885903 },
886904):: D where {D<: Function }
887905 return ocp. dynamics
888906end
889907
908+ # build_examodel
909+ """
910+ $(TYPEDSIGNATURES)
911+
912+ Get the build_examodel from the model.
913+ """
914+ function get_build_examodel (
915+ ocp:: Model {
916+ <: TimeDependence ,
917+ <: AbstractTimesModel ,
918+ <: AbstractStateModel ,
919+ <: AbstractControlModel ,
920+ <: AbstractVariableModel ,
921+ <: Function ,
922+ <: AbstractObjectiveModel ,
923+ <: AbstractConstraintsModel ,
924+ <: Function ,
925+ },
926+ )
927+ return ocp. build_examodel
928+ end
929+
930+ """
931+ $(TYPEDSIGNATURES)
932+
933+ Return an error (UnauthorizedCall) since the model is not built with the :exa backend.
934+ """
935+ function get_build_examodel (
936+ :: Model {
937+ <: TimeDependence ,
938+ <: AbstractTimesModel ,
939+ <: AbstractStateModel ,
940+ <: AbstractControlModel ,
941+ <: AbstractVariableModel ,
942+ <: Function ,
943+ <: AbstractObjectiveModel ,
944+ <: AbstractConstraintsModel ,
945+ <: Nothing ,
946+ },
947+ )
948+ throw (CTBase. UnauthorizedCall (" first parse with :exa backend" ))
949+ end
950+
890951# Constraints
891952"""
892953$(TYPEDSIGNATURES)
@@ -903,6 +964,7 @@ function constraints(
903964 <: Function ,
904965 <: AbstractObjectiveModel ,
905966 C,
967+ <: Union{Function,Nothing} ,
906968 },
907969):: C where {C<: AbstractConstraintsModel }
908970 return ocp. constraints
@@ -932,6 +994,7 @@ function path_constraints_nl(
932994 <: Function ,
933995 <: AbstractObjectiveModel ,
934996 <: ConstraintsModel{TP,<:Tuple,<:Tuple,<:Tuple,<:Tuple} ,
997+ <: Union{Function,Nothing} ,
935998 },
936999):: TP where {TP<: Tuple }
9371000 return constraints (ocp). path_nl
@@ -952,6 +1015,7 @@ function boundary_constraints_nl(
9521015 <: Function ,
9531016 <: AbstractObjectiveModel ,
9541017 <: ConstraintsModel{<:Tuple,TB,<:Tuple,<:Tuple,<:Tuple} ,
1018+ <: Union{Function,Nothing} ,
9551019 },
9561020):: TB where {TB<: Tuple }
9571021 return constraints (ocp). boundary_nl
@@ -972,6 +1036,7 @@ function state_constraints_box(
9721036 <: Function ,
9731037 <: AbstractObjectiveModel ,
9741038 <: ConstraintsModel{<:Tuple,<:Tuple,TS,<:Tuple,<:Tuple} ,
1039+ <: Union{Function,Nothing} ,
9751040 },
9761041):: TS where {TS<: Tuple }
9771042 return constraints (ocp). state_box
@@ -992,6 +1057,7 @@ function control_constraints_box(
9921057 <: Function ,
9931058 <: AbstractObjectiveModel ,
9941059 <: ConstraintsModel{<:Tuple,<:Tuple,<:Tuple,TC,<:Tuple} ,
1060+ <: Union{Function,Nothing} ,
9951061 },
9961062):: TC where {TC<: Tuple }
9971063 return constraints (ocp). control_box
@@ -1012,6 +1078,7 @@ function variable_constraints_box(
10121078 <: Function ,
10131079 <: AbstractObjectiveModel ,
10141080 <: ConstraintsModel{<:Tuple,<:Tuple,<:Tuple,<:Tuple,TV} ,
1081+ <: Union{Function,Nothing} ,
10151082 },
10161083):: TV where {TV<: Tuple }
10171084 return constraints (ocp). variable_box
0 commit comments