-
Notifications
You must be signed in to change notification settings - Fork 3
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
Remove Index type #299
Remove Index type #299
Conversation
@jbcaillau On pourrait aussi avoir dans le @with_kw mutable struct OptimalControlModel{
time_dependence <: TimeDependence,
variable_dependence <: VariableDependence,
} <: AbstractOptimalControlModel
initial_time::Union{Time, Val, Nothing} = nothing
initial_time_index::Union{Int, Nothing} = nothing
final_time::Union{Time, Val, Nothing} = nothing
final_time_index::Union{Int, Nothing} = nothing
... et avoir les getters associés. On pourrait aussi fournir une méthode : function initial_time(ocp::OptimalControlModel{<:TimeDependence, NonFixed}, v::Variable)
return v[ocp.initial_time_index]
end et pareil pour le temps final. |
@ocots thanks for the update. |
Hi guys,
with initialization
then the relevant one is used in the getter
Maybe there was a more elegant way to get stable types, but this one seems to work, and I'll just replace Index with Int if you merge this PR :-) I am currently investigating if I also need to split the |
We already have this for instance with About the initial time for instance. The only thing I don't like with the use of the same field for index and time is that the user can think that the returned value for the initial time is a time but it is an index. If we have two fields, this cannot happen. A possibility is to have only one field but to make a parametric type and use multiple dispatch: mutable struct OptimalControlModel{
time_dependence <: TimeDependence,
variable_dependence <: VariableDependence,
initial_time <: VariableDependence,
final_time <: VariableDependence,
}
...
initial_time::Union{Time, Index, Nothing} = nothing
...
end
function initial_time(
ocp::OptimalControlModel{
<: TimeDependence,
<: VariableDependence,
Fixed,
<: VariableDependence
}
)
return ocp.initial_time
end
function initial_time(
ocp::OptimalControlModel{
<: TimeDependence,
<: VariableDependence,
NonFixed,
<: VariableDependence
},
v::Variable
)
return v[ocp.initial_time]
end |
@ocots @PierreMartinon hi! two things:
Can we conclude? |
So, to avoid union types, we would have 2 sets of variables, one for fixed times values and one for free times indices ? For each OCP half the variables would be unused, but the getters would be type stable. |
@PierreMartinon |
@jbcaillau
Index
type from range constraints and replaced it byInt
.Index
for initial and final free times byVal
. To remove thisCTBase.jl/src/types.jl
Lines 1154 to 1172 in 285afa2
I have made the choice to return an
Int
if the initial time is aVal
. SeeCTBase.jl/src/optimal_control_model-getters.jl
Line 485 in a27a83b
and
CTBase.jl/src/utils.jl
Lines 259 to 261 in a27a83b
This should imply no changes in
CTDirect.jl
since we can see how @PierreMartinon does here:https://github.com/control-toolbox/CTDirect.jl/blob/1433c9a87430cd75ab21cb9a366675f115f4772c/src/utils.jl#L30-L36