Skip to content

Commit 5229143

Browse files
authored
Merge pull request #33 from control-toolbox/32-dev-as_vector-for-constraint
as_vector in constraint!
2 parents 98b14ac + dfef26b commit 5229143

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/constraints.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ function constraint!(
129129
type::Symbol;
130130
rg::Union{OrdinalRange{<:Int},Nothing}=nothing,
131131
f::Union{Function,Nothing}=nothing,
132-
lb::Union{ctVector,Nothing}=nothing,
133-
ub::Union{ctVector,Nothing}=nothing,
132+
lb::Union{ctNumber,ctVector,Nothing}=nothing,
133+
ub::Union{ctNumber,ctVector,Nothing}=nothing,
134134
label::Symbol=__constraint_label(),
135135
)
136136

@@ -156,13 +156,16 @@ function constraint!(
156156
n = dimension(ocp.state)
157157
m = dimension(ocp.control)
158158
q = dimension(ocp.variable)
159-
160159
# add the constraint
161160
return __constraint!(
162-
ocp.constraints, type, n, m, q; rg=rg, f=f, lb=lb, ub=ub, label=label
161+
ocp.constraints, type, n, m, q; rg=rg, f=f, lb=as_vector(lb), ub=as_vector(ub), label=label
163162
)
164163
end
165164

165+
as_vector(x::Nothing) = nothing
166+
as_vector(x::T) where {T <: ctNumber} = [x]
167+
as_vector(x::Vector{T}) where {T <: ctNumber} = x
168+
166169
# ------------------------------------------------------------------------------ #
167170
# GETTERS
168171
# ------------------------------------------------------------------------------ #

0 commit comments

Comments
 (0)