Skip to content

Commit c811119

Browse files
authored
Merge pull request #115 from control-toolbox/114-bug-problem-with-variable-length
Fix bug variable scalar
2 parents 376a561 + 6e24877 commit c811119

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CTModels"
22
uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d"
33
authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
4-
version = "0.3.7"
4+
version = "0.3.8"
55

66
[deps]
77
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
@@ -39,4 +39,4 @@ Parameters = "0.12"
3939
Plots = "1.40"
4040
PrettyTables = "2.4"
4141
RecipesBase = "1.3"
42-
julia = "1.10"
42+
julia = "1.10"

src/model.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,26 @@ end
449449
"""
450450
$(TYPEDSIGNATURES)
451451
452+
Get the initial time from the model, for a free initial time.
453+
"""
454+
function initial_time(
455+
ocp::Model{
456+
<:TimesModel{FreeTimeModel,<:AbstractTimeModel},
457+
<:AbstractStateModel,
458+
<:AbstractControlModel,
459+
<:AbstractVariableModel,
460+
<:Function,
461+
<:AbstractObjectiveModel,
462+
<:AbstractConstraintsModel,
463+
},
464+
variable::T,
465+
)::T where {T<:ctNumber}
466+
return initial_time(times(ocp), [variable])
467+
end
468+
469+
"""
470+
$(TYPEDSIGNATURES)
471+
452472
Get the name of the initial time from the model.
453473
"""
454474
function initial_time_name(ocp::Model)::String
@@ -532,6 +552,26 @@ end
532552
"""
533553
$(TYPEDSIGNATURES)
534554
555+
Get the final time from the model, for a free final time.
556+
"""
557+
function final_time(
558+
ocp::Model{
559+
<:TimesModel{<:AbstractTimeModel,FreeTimeModel},
560+
<:AbstractStateModel,
561+
<:AbstractControlModel,
562+
<:AbstractVariableModel,
563+
<:Function,
564+
<:AbstractObjectiveModel,
565+
<:AbstractConstraintsModel,
566+
},
567+
variable::T,
568+
)::T where {T<:ctNumber}
569+
return final_time(times(ocp), [variable])
570+
end
571+
572+
"""
573+
$(TYPEDSIGNATURES)
574+
535575
Get the name of the final time from the model.
536576
"""
537577
function final_time_name(ocp::Model)::String

test/extras/plot_variable.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using CTDirect
2+
using NLPModelsIpopt
3+
using CTModels
4+
using Plots
5+
import CTParser: CTParser, @def
6+
7+
CTParser.set_prefix(:CTModels); # code generated by @def is prefixed by CTModels (not by OptimalControl - the default)
8+
9+
ocp = @def begin
10+
11+
tf R, variable
12+
t [0, tf], time
13+
x = (q, v) R², state
14+
u R, control
15+
16+
tf 0
17+
-1 u(t) 1
18+
19+
q(0) == -1
20+
v(0) == 0
21+
q(tf) == 0
22+
v(tf) == 0
23+
24+
1 v(t)+1 1.8, (1)
25+
26+
(t) == [v(t), u(t)]
27+
28+
tf min
29+
30+
end
31+
32+
sol = CTDirect.solve(ocp; print_level=4)
33+
plot(sol, ocp)

0 commit comments

Comments
 (0)