1
+ # todo: use design pattern to generate functions in nlp_constraints!
1
2
"""
2
3
$(TYPEDSIGNATURES)
3
4
@@ -865,18 +866,21 @@ Return a 6-tuple of tuples:
865
866
- `(xl, xind, xu)` are state linear constraints of a subset of indices
866
867
- `(vl, vind, vu)` are variable linear constraints of a subset of indices
867
868
869
+ and update information about constraints dimensions of `ocp`.
870
+
868
871
!!! note
869
872
870
- - The dimensions of the state and control must be set before calling `nlp_constraints`.
873
+ - The dimensions of the state and control must be set before calling `nlp_constraints!`.
874
+ - For a `Fixed` problem, dimensions associated with constraints on the variable are set to zero.
871
875
872
876
# Example
873
877
874
878
```jldoctest
875
879
julia> (ξl, ξ, ξu), (ηl, η, ηu), (ψl, ψ, ψu), (ϕl, ϕ, ϕu), (θl, θ, θu),
876
- (ul, uind, uu), (xl, xind, xu), (vl, vind, vu) = nlp_constraints(ocp)
880
+ (ul, uind, uu), (xl, xind, xu), (vl, vind, vu) = nlp_constraints! (ocp)
877
881
```
878
882
"""
879
- function nlp_constraints (ocp:: OptimalControlModel )
883
+ function nlp_constraints! (ocp:: OptimalControlModel )
880
884
881
885
# we check if the dimensions and times have been set
882
886
__check_all_set (ocp)
@@ -965,12 +969,6 @@ function nlp_constraints(ocp::OptimalControlModel)
965
969
return val
966
970
end
967
971
968
- function _η (t, x, v) # nonlinear state constraints
969
- val = Vector {ctNumber} ()
970
- for i ∈ 1 : length (ηf) append! (val, ηf[i](t, x, v)) end
971
- return val
972
- end
973
-
974
972
function ψ (t, x, u, v) # nonlinear mixed constraints
975
973
dim = length (ψl)
976
974
val = zeros (ctNumber, dim)
@@ -984,13 +982,7 @@ function nlp_constraints(ocp::OptimalControlModel)
984
982
return val
985
983
end
986
984
987
- function _ψ (t, x, u, v) # nonlinear mixed constraints
988
- val = Vector {ctNumber} ()
989
- for i ∈ 1 : length (ψf) append! (val, ψf[i](t, x, u, v)) end
990
- return val
991
- end
992
-
993
- function ϕ (x0, xf, v) # nonlinear mixed constraints
985
+ function ϕ (x0, xf, v) # nonlinear boundary constraints
994
986
dim = length (ϕl)
995
987
val = zeros (ctNumber, dim)
996
988
j = 1
@@ -1003,13 +995,7 @@ function nlp_constraints(ocp::OptimalControlModel)
1003
995
return val
1004
996
end
1005
997
1006
- function _ϕ (x0, xf, v) # nonlinear boundary constraints
1007
- val = Vector {ctNumber} ()
1008
- for i ∈ 1 : length (ϕf) append! (val, ϕf[i](x0, xf, v)) end
1009
- return val
1010
- end
1011
-
1012
- function θ (v) # nonlinear mixed constraints
998
+ function θ (v) # nonlinear variable constraints
1013
999
dim = length (θl)
1014
1000
val = zeros (ctNumber, dim)
1015
1001
j = 1
@@ -1022,12 +1008,96 @@ function nlp_constraints(ocp::OptimalControlModel)
1022
1008
return val
1023
1009
end
1024
1010
1025
- function _θ (v) # nonlinear variable constraints
1026
- val = Vector {ctNumber} ()
1027
- for i ∈ 1 : length (θf) append! (val, θf[i](v)) end
1028
- return val
1029
- end
1011
+ ocp. dim_control_constraints = length (ξl)
1012
+ ocp. dim_state_constraints = length (ηl)
1013
+ ocp. dim_mixed_constraints = length (ψl)
1014
+ ocp. dim_boundary_constraints = length (ϕl)
1015
+ ocp. dim_variable_constraints = length (θl)
1016
+ ocp. dim_control_range = length (ul)
1017
+ ocp. dim_state_range = length (xl)
1018
+ ocp. dim_variable_range = length (vl)
1030
1019
1031
1020
return (ξl, ξ, ξu), (ηl, η, ηu), (ψl, ψ, ψu), (ϕl, ϕ, ϕu), (θl, θ, θu), (ul, uind, uu), (xl, xind, xu), (vl, vind, vu)
1032
1021
1033
- end
1022
+ end
1023
+
1024
+
1025
+ """
1026
+ $(TYPEDSIGNATURES)
1027
+
1028
+ Return the dimension of nonlinear state constraints (`nothing` if not knonw).
1029
+ Information is updated after `nlp_constraints!` is called.
1030
+ """
1031
+ dim_state_constraints (ocp:: OptimalControlModel ) = ocp. dim_state_constraints
1032
+
1033
+ """
1034
+ $(TYPEDSIGNATURES)
1035
+
1036
+ Return the dimension of nonlinear control constraints (`nothing` if not knonw).
1037
+ Information is updated after `nlp_constraints!` is called.
1038
+ """
1039
+ dim_control_constraints (ocp:: OptimalControlModel ) = ocp. dim_control_constraints
1040
+
1041
+ """
1042
+ $(TYPEDSIGNATURES)
1043
+
1044
+ Return the dimension of nonlinear mixed constraints (`nothing` if not knonw).
1045
+ Information is updated after `nlp_constraints!` is called.
1046
+ """
1047
+ dim_mixed_constraints (ocp:: OptimalControlModel ) = ocp. dim_mixed_constraints
1048
+
1049
+ """
1050
+ $(TYPEDSIGNATURES)
1051
+
1052
+ Return the dimension of nonlinear path (state + control + mixed) constraints (`nothing` if one of them is not knonw).
1053
+ Information is updated after `nlp_constraints!` is called.
1054
+ """
1055
+ function dim_path_constraints (ocp:: OptimalControlModel )
1056
+ isnothing (ocp. dim_control_constraints) && return nothing
1057
+ isnothing (ocp. dim_state_constraints) && return nothing
1058
+ isnothing (ocp. dim_mixed_constraints) && return nothing
1059
+ return ocp. dim_state_constraints + ocp. dim_control_constraints + ocp. dim_mixed_constraints
1060
+ end
1061
+
1062
+ """
1063
+ $(TYPEDSIGNATURES)
1064
+
1065
+ Return the dimension of the boundary constraints (`nothing` if not knonw).
1066
+ Information is updated after `nlp_constraints!` is called.
1067
+ """
1068
+ dim_boundary_constraints (ocp:: OptimalControlModel ) = ocp. dim_boundary_constraints
1069
+
1070
+ """
1071
+ $(TYPEDSIGNATURES)
1072
+
1073
+ Return the dimension of nonlinear variable constraints (`nothing` if not knonw).
1074
+ Information is updated after `nlp_constraints!` is called.
1075
+ """
1076
+ dim_variable_constraints (ocp:: OptimalControlModel ) = ocp. dim_variable_constraints
1077
+
1078
+ """
1079
+ $(TYPEDSIGNATURES)
1080
+
1081
+ Return the dimension of range constraints on state (`nothing` if not knonw).
1082
+ Information is updated after `nlp_constraints!` is called.
1083
+ """
1084
+ dim_state_range (ocp:: OptimalControlModel ) = ocp. dim_state_range
1085
+ dim_state_box = dim_state_range # alias, CTDirect.jl compatibility
1086
+
1087
+ """
1088
+ $(TYPEDSIGNATURES)
1089
+
1090
+ Return the dimension of range constraints on control (`nothing` if not knonw).
1091
+ Information is updated after `nlp_constraints!` is called.
1092
+ """
1093
+ dim_control_range (ocp:: OptimalControlModel ) = ocp. dim_control_range
1094
+ dim_control_box = dim_control_range # alias, CTDirect.jl compatibility
1095
+
1096
+ """
1097
+ $(TYPEDSIGNATURES)
1098
+
1099
+ Return the dimension of range constraints on variable (`nothing` if not knonw).
1100
+ Information is updated after `nlp_constraints!` is called.
1101
+ """
1102
+ dim_variable_range (ocp:: OptimalControlModel ) = ocp. dim_variable_range
1103
+ dim_variable_box = dim_variable_range # alias, CTDirect.jl compatibility
0 commit comments