Skip to content

Commit

Permalink
ok for free times, objective type and variable indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMartinon committed Jun 14, 2024
1 parent 0414e27 commit ea3be69
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CTBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export Model
export variable!, time!, constraint!, dynamics!, objective!, state!, control!, remove_constraint!, constraint
export is_time_independent, is_time_dependent, is_min, is_max, is_variable_dependent, is_variable_independent
export nlp_constraints, constraints_labels
export has_free_final_time, has_free_initial_time, has_lagrange_cost, has_mayer_cost

# solution
export OptimalControlSolution
Expand Down
22 changes: 22 additions & 0 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,28 @@ function nlp_constraints(ocp::OptimalControlModel)
return val
end

# set specific constraints dimensions
ocp.dim_control_constraints = length(ξf)
ocp.dim_state_constraints = length(ηf)
ocp.dim_mixed_constraints = length(ψf)
ocp.dim_path_constraints = ocp.dim_control_constraints + ocp.dim_state_constraints + ocp.dim_mixed_constraints
ocp.dim_boundary_conditions = length(ϕf)
ocp.dim_variable_constraints = length(θf)
ocp.dim_control_box = length(uind)
ocp.dim_state_box = length(xind)
ocp.dim_variable_box = length(vind)

return (ξl, ξ, ξu), (ηl, η, ηu), (ψl, ψ, ψu), (ϕl, ϕ, ϕu), (θl, θ, θu), (ul, uind, uu), (xl, xind, xu), (vl, vind, vu)

end

# getters for constraints dimensions
dim_control_constraints(ocp::OptimalControlModel) = ocp.dim_control_constraints
dim_state_constraints(ocp::OptimalControlModel) = ocp.dim_state_constraints
dim_mixed_constraints(ocp::OptimalControlModel) = ocp.dim_mixed_constraints
dim_path_constraints(ocp::OptimalControlModel) = ocp.dim_path_constraints
dim_boundary_conditions(ocp::OptimalControlModel) = ocp.dim_boundary_conditions
dim_variable_constraints(ocp::OptimalControlModel) = ocp.dim_variable_constraints
dim_control_box(ocp::OptimalControlModel) = ocp.dim_control_box
dim_state_box(ocp::OptimalControlModel) = ocp.dim_state_box
dim_variable_box(ocp::OptimalControlModel) = ocp.dim_variable_box
11 changes: 11 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,17 @@ $(TYPEDFIELDS)
criterion::Union{Symbol,Nothing}=nothing
dynamics::Union{Dynamics,Nothing}=nothing
constraints::Dict{Symbol, Tuple{Vararg{Any}}}=Dict{Symbol, Tuple{Vararg{Any}}}()

# internal dimensions for constraints
dim_control_constraints::Int64=0
dim_state_constraints::Int64=0
dim_mixed_constraints::Int64=0
dim_path_constraints::Int64=0
dim_boundary_conditions::Int64=0
dim_variable_constraints::Int64=0
dim_control_box::Int64=0
dim_state_box::Int64=0
dim_variable_box::Int64=0
end

# used for checkings
Expand Down

0 comments on commit ea3be69

Please sign in to comment.