Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace copy! by a constructor #218

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,28 @@ $(TYPEDFIELDS)
infos::Dict{Symbol, Any}=Dict{Symbol, Any}()
end

function Base.copy!(sol::OptimalControlSolution, ocp::OptimalControlModel)
"""
$(TYPEDSIGNATURES)

Constructor from an optimal control problem.
"""
function OptimalControlSolution(ocp::OptimalControlModel;
state::Function,
control::Function,
objective::ctNumber,
costate::Union{Nothing, Function}=nothing,
times::Union{Nothing, TimesDisc}=nothing,
variable::Union{Nothing, Variable}=nothing,
iterations::Union{Nothing, Integer}=nothing,
stopping::Union{Nothing, Symbol}=nothing,
message::Union{Nothing, String}=nothing,
success::Union{Nothing, Bool}=nothing,
infos::Dict{Symbol, Any}=Dict{Symbol, Any}())::OptimalControlSolution

#
sol = OptimalControlSolution()

# data from ocp
sol.initial_time_name = ocp.initial_time_name
sol.final_time_name = ocp.final_time_name
sol.time_name = ocp.time_name
Expand All @@ -1331,4 +1352,20 @@ function Base.copy!(sol::OptimalControlSolution, ocp::OptimalControlModel)
sol.variable_dimension = ocp.variable_dimension
sol.variable_components_names = ocp.variable_components_names
sol.variable_name = ocp.variable_name

# data from args
sol.state = state
sol.control = control
sol.objective = objective
sol.costate = costate
sol.times = times
sol.variable = variable
sol.iterations = iterations
sol.stopping = stopping
sol.message = message
sol.success = success
sol.infos = infos

return sol

end
Loading