Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
version:
- '1.10'
- '1.11'
- '1.12'
os:
- ubuntu-latest
arch:
Expand Down
4 changes: 4 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MD046": false,
"MD013": false
}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CTModels"
uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d"
authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
version = "0.6.8"
version = "0.6.9"

[deps]
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
CTParser = "32681960-a1b1-40db-9bff-a1ca817385d1"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
Expand Down
38 changes: 37 additions & 1 deletion docs/src/plot.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,46 @@ Order = [:module, :constant, :type, :function, :macro]
julia> private_fun(x)
```

## Simple example

```@example
using CTModels, Plots
import CTParser: @def

t0, tf, x0 = 0.0, 1.0, -1.0

ocp = @def begin
t ∈ [t0, tf], time
x ∈ R, state
u ∈ R, control
x(t0) == x0
-Inf ≤ x(t) + u(t) ≤ 0, (mixed_con)
ẋ(t) == u(t)
∫(0.5u(t)^2) → min
end

sol = CTModels.build_solution(
ocp,
collect(range(t0, tf; length=201)),
t -> x0 * exp(-t),
t -> -x0 * exp(-t),
Float64[],
t -> exp(t - tf) - 1;
objective = exp(-1) - 1,
iterations = 0,
constraints_violation = 0.0,
message = "",
status = :optimal,
successful = true,
)

plot(sol)
```

## Documentation

```@autodocs
Modules = [CTModelsPlots]
Order = [:module, :constant, :type, :function, :macro]
Pages = ["plot.jl", "plot_utils.jl", "plot_default.jl", "CTModelsPlots.jl"]
```
```
21 changes: 20 additions & 1 deletion docs/src/print.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,29 @@ Modules = [CTModels, Base]
Order = [:module, :constant, :type, :function, :macro]
```

## Simple example

```@example
using CTModels, Plots
import CTParser: @def

t0, tf, x0 = 0.0, 1.0, -1.0

ocp = @def begin
t ∈ [t0, tf], time
x ∈ R, state
u ∈ R, control
x(t0) == x0
-Inf ≤ x(t) + u(t) ≤ 0, (mixed_con)
ẋ(t) == u(t)
∫(0.5u(t)^2) → min
end
```

## Documentation

```@autodocs
Modules = [CTModels]
Order = [:module, :constant, :type, :function, :macro]
Pages = ["print.jl"]
```
```
31 changes: 8 additions & 23 deletions ext/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,6 @@ end
"""
$(TYPEDSIGNATURES)

Return an expression `a{r*h}` to control relative plot height when using custom layouts.

Used for vertical space control in plot trees.
"""
function __height(r::Real)::Expr
i = Expr(:call, :*, r, :h)
a = Expr(:curly, :a, i)
return a
end

"""
$(TYPEDSIGNATURES)

Return an empty plot for a `PlotLeaf`.

Used as a placeholder in layout trees.
Expand Down Expand Up @@ -382,11 +369,10 @@ function __initial_plot(
nblines = 0
if (!(node_xp isa EmptyPlot) && !(node_u isa EmptyPlot))
nblines = n + l
a = __height(round(n / nblines; digits=2))
@eval lay = @layout [
$a
b
]
h = round(n / nblines; digits=2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks better 👍🏽 @ocots

lay = Matrix{Any}(undef, 2, 1)
lay[1, 1] = (label = :a, width = :auto, height = h)
lay[2, 1] = (label = :b, blank = false)
root = PlotNode(lay, [node_xp, node_u])
elseif !(node_xp isa EmptyPlot)
root = node_xp
Expand Down Expand Up @@ -428,11 +414,10 @@ function __initial_plot(
# update the root node
if !(node_cocp isa EmptyPlot)
nblines += nc
c = __height(round(nc / nblines; digits=2))
@eval lay = @layout [
a
$c
]
h = round(nc / nblines; digits=2)
lay = Matrix{Any}(undef, 2, 1)
lay[1, 1] = (label = :a, blank = false)
lay[2, 1] = (label = :b, width = :auto, height = h)
root = PlotNode(lay, [root, node_cocp])
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/CTModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ See also: [`Time`](@ref), [`Times`](@ref).
const TimesDisc = Union{Times,StepRangeLen}

"""
Type alias for a dictionnary of constraints. This is used to store constraints before building the model.
Type alias for a dictionary of constraints. This is used to store constraints before building the model.

```@example
julia> const TimesDisc = Union{Times, StepRangeLen}
Expand Down
4 changes: 2 additions & 2 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ __format() = :JLD
$(TYPEDSIGNATURES)

Used to set the default value of the label of a constraint.
A unique value is given to each constraint using the `gensym` function and prefixing by `:unamed`.
A unique value is given to each constraint using the `gensym` function and prefixing by `:unnamed`.
"""
__constraint_label() = gensym(:unamed)
__constraint_label() = gensym(:unnamed)

"""
$(TYPEDSIGNATURES)
Expand Down
2 changes: 1 addition & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ struct SolverInfos{TI<:Dict{Symbol,Any}} <: AbstractSolverInfos
message::String # the message corresponding to the status criterion
successful::Bool # whether or not the method has finished successfully: CN1, stagnation vs iterations max
constraints_violation::Float64 # the constraints violation
infos::TI # additional informations
infos::TI # additional information
end

# ------------------------------------------------------------------------------ #
Expand Down
1 change: 1 addition & 0 deletions test/extras/plot_duals.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Revise
using CTModels
using Plots
import CTParser: CTParser, @def
Expand Down
2 changes: 1 addition & 1 deletion test/test_times.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function test_times()
@test_throws CTBase.UnauthorizedCall CTModels.time!(ocp, t0=0.0, indf=1)
@test_throws CTBase.UnauthorizedCall CTModels.time!(ocp, ind0=1, indf=2)

# index must statisfy 1 <= index <= q
# index must satisfy 1 <= index <= q
ocp = CTModels.PreModel()
CTModels.variable!(ocp, 2)
@test_throws CTBase.IncorrectArgument CTModels.time!(ocp, ind0=0, tf=10.0)
Expand Down
Loading