Skip to content

Commit d236221

Browse files
authored
Merge pull request #140 from control-toolbox/103-dev-range-linear-constraint-dimension-check
Add is complete pre ocp
2 parents bf79e6b + f646433 commit d236221

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

src/print.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,21 @@ function Base.show(io::IO, ::MIME"text/plain", ocp::Model)
269269

270270
# print table of settings
271271
header = [
272-
"times*", "state*", "control*", "variable", "dynamics*", "objective*", "constraints"
272+
"variable", "times*", "state*", "control*", "constraints", "dynamics*", "objective*"
273273
]
274-
data = hcat(
274+
begin
275+
(data = hcat(is_variable_dependent ? "V" : "X"))
276+
end
277+
data = hcat(data,
275278
__is_times_set(ocp) ? "V" : "X",
276279
__is_state_set(ocp) ? "V" : "X",
277280
__is_control_set(ocp) ? "V" : "X",
278281
)
279-
begin
280-
(data = hcat(data, is_variable_dependent ? "V" : "X"))
281-
end
282282
data = hcat(
283283
data,
284+
isempty_constraints(ocp) ? "X" : "V",
284285
__is_dynamics_set(ocp) ? "V" : "X",
285286
__is_objective_set(ocp) ? "V" : "X",
286-
isempty_constraints(ocp) ? "X" : "V",
287287
)
288288
println("")
289289
h1 = Highlighter((data, i, j) -> data[i, j] == "X"; bold=true, foreground=:red)
@@ -555,21 +555,21 @@ function Base.show(io::IO, ::MIME"text/plain", ocp::PreModel)
555555

556556
# print table of settings
557557
header = [
558-
"times*", "state*", "control*", "variable", "dynamics*", "objective*", "constraints"
558+
"variable", "times*", "state*", "control*", "constraints", "dynamics*", "objective*"
559559
]
560-
data = hcat(
560+
begin
561+
(data = hcat(is_variable_dependent ? "V" : "X"))
562+
end
563+
data = hcat(data,
561564
__is_times_set(ocp) ? "V" : "X",
562565
__is_state_set(ocp) ? "V" : "X",
563566
__is_control_set(ocp) ? "V" : "X",
564567
)
565-
begin
566-
(data = hcat(data, is_variable_dependent ? "V" : "X"))
567-
end
568568
data = hcat(
569569
data,
570+
Base.isempty(ocp.constraints) ? "X" : "V",
570571
__is_dynamics_set(ocp) ? "V" : "X",
571572
__is_objective_set(ocp) ? "V" : "X",
572-
Base.isempty(ocp.constraints) ? "X" : "V",
573573
)
574574
println("")
575575
h1 = Highlighter((data, i, j) -> data[i, j] == "X"; bold=true, foreground=:red)

src/types.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,21 @@ end
469469
"""
470470
$(TYPEDSIGNATURES)
471471
472+
Return true if the PreModel can be built into a Model.
473+
"""
474+
function __is_complete(ocp::PreModel)::Bool
475+
return __is_times_set(ocp) &&
476+
__is_state_set(ocp) &&
477+
__is_control_set(ocp) &&
478+
__is_dynamics_complete(ocp) &&
479+
__is_objective_set(ocp) &&
480+
__is_definition_set(ocp) &&
481+
__is_autonomous_set(ocp)
482+
end
483+
484+
"""
485+
$(TYPEDSIGNATURES)
486+
472487
Return true if nothing has been set.
473488
"""
474489
function __is_empty(ocp::PreModel)::Bool

test/test_model.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function test_model()
176176
CTModels.dynamics!(pre_ocp, dynamics!)
177177
CTModels.objective!(pre_ocp, :min; mayer=mayer, lagrange=lagrange)
178178
CTModels.definition!(pre_ocp, quote end)
179+
CTModels.time_dependence!(pre_ocp; autonomous=false)
179180
display(pre_ocp)
180181

181182
#
@@ -187,5 +188,6 @@ function test_model()
187188
CTModels.dynamics!(pre_ocp, dynamics!)
188189
CTModels.objective!(pre_ocp, :min; mayer=mayer, lagrange=lagrange)
189190
CTModels.definition!(pre_ocp, quote end)
191+
CTModels.time_dependence!(pre_ocp; autonomous=true)
190192
display(pre_ocp)
191193
end

0 commit comments

Comments
 (0)