From ea3be6964e086779489133c9f5caec9a76f3eacf Mon Sep 17 00:00:00 2001 From: Pierre Martinon Date: Fri, 14 Jun 2024 17:26:21 +0200 Subject: [PATCH] ok for free times, objective type and variable indicators --- src/CTBase.jl | 1 + src/model.jl | 22 ++++++++++++++++++++++ src/types.jl | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/CTBase.jl b/src/CTBase.jl index 44d30887..a93c210b 100644 --- a/src/CTBase.jl +++ b/src/CTBase.jl @@ -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 diff --git a/src/model.jl b/src/model.jl index 99b3edc1..b3feba2b 100644 --- a/src/model.jl +++ b/src/model.jl @@ -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 diff --git a/src/types.jl b/src/types.jl index 04fea379..a6e87e21 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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