@@ -36,10 +36,10 @@ Build a solution from the optimal control problem, the time grid, the state, con
3636function build_solution (
3737 ocp:: Model ,
3838 T:: Vector{Float64} ,
39- X:: Matrix{Float64} ,
40- U:: Matrix{Float64} ,
39+ X:: TX ,
40+ U:: TU ,
4141 v:: Vector{Float64} ,
42- P:: Matrix{Float64} ;
42+ P:: TP ;
4343 objective:: Float64 ,
4444 iterations:: Int ,
4545 constraints_violation:: Float64 ,
@@ -56,7 +56,11 @@ function build_solution(
5656 control_constraints_ub_dual:: Matrix{Float64} = zeros (0 , 0 ),
5757 variable_constraints_lb_dual:: Vector{Float64} = zeros (0 ),
5858 variable_constraints_ub_dual:: Vector{Float64} = zeros (0 ),
59- )
59+ ) where {
60+ TX <: Union{Matrix{Float64}, Function} ,
61+ TU <: Union{Matrix{Float64}, Function} ,
62+ TP <: Union{Matrix{Float64}, Function} ,
63+ }
6064
6165 # get dimensions
6266 dim_x = state_dimension (ocp)
@@ -75,9 +79,10 @@ function build_solution(
7579 end
7680
7781 # variables: remove additional state for lagrange objective
78- x = ctinterpolate (T, matrix2vec (X[:, 1 : dim_x], 1 ))
79- p = ctinterpolate (T[1 : (end - 1 )], matrix2vec (P[:, 1 : dim_x], 1 ))
80- u = ctinterpolate (T, matrix2vec (U[:, 1 : dim_u], 1 ))
82+ x = TX <: Function ? X : ctinterpolate (T, matrix2vec (X[:, 1 : dim_x], 1 ))
83+ p = TU <: Function ? P :
84+ length (T) == 2 ? t -> P[1 , 1 : dim_x] : ctinterpolate (T[1 : (end - 1 )], matrix2vec (P[:, 1 : dim_x], 1 ))
85+ u = TP <: Function ? U : ctinterpolate (T, matrix2vec (U[:, 1 : dim_u], 1 ))
8186
8287 # force scalar output when dimension is 1
8388 fx = (dim_x == 1 ) ? deepcopy (t -> x (t)[1 ]) : deepcopy (t -> x (t))
0 commit comments