diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8d41ca86..4f4b2996 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,6 +13,7 @@ jobs: version: - '1.10' - '1.11' + - '1.12' os: - ubuntu-latest arch: diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..21a27c0e --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,4 @@ +{ + "MD046": false, + "MD013": false +} diff --git a/Project.toml b/Project.toml index ae45bce0..76aefc81 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CTModels" uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d" authors = ["Olivier Cots "] -version = "0.6.8" +version = "0.6.9" [deps] CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd" diff --git a/docs/Project.toml b/docs/Project.toml index ae4ce306..250d5486 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -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" diff --git a/docs/src/plot.md b/docs/src/plot.md index e8f674f1..f8b06442 100644 --- a/docs/src/plot.md +++ b/docs/src/plot.md @@ -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"] -``` \ No newline at end of file +``` diff --git a/docs/src/print.md b/docs/src/print.md index c410ccee..5b53d2d7 100644 --- a/docs/src/print.md +++ b/docs/src/print.md @@ -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"] -``` \ No newline at end of file +``` diff --git a/ext/plot.jl b/ext/plot.jl index b1aac278..a2aeb715 100644 --- a/ext/plot.jl +++ b/ext/plot.jl @@ -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. @@ -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) + 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 @@ -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 diff --git a/src/CTModels.jl b/src/CTModels.jl index 397f4992..52675531 100644 --- a/src/CTModels.jl +++ b/src/CTModels.jl @@ -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} diff --git a/src/default.jl b/src/default.jl index 9bffebc9..a98510af 100644 --- a/src/default.jl +++ b/src/default.jl @@ -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) diff --git a/src/types.jl b/src/types.jl index be891612..6915db52 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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 # ------------------------------------------------------------------------------ # diff --git a/test/extras/plot_duals.jl b/test/extras/plot_duals.jl index d9af85bc..78668c22 100644 --- a/test/extras/plot_duals.jl +++ b/test/extras/plot_duals.jl @@ -1,3 +1,4 @@ +using Revise using CTModels using Plots import CTParser: CTParser, @def diff --git a/test/test_times.jl b/test/test_times.jl index 29a51030..45546aa4 100644 --- a/test/test_times.jl +++ b/test/test_times.jl @@ -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)