From 315e3f43f00567a981adcee76526fba072b448db Mon Sep 17 00:00:00 2001 From: Olivier Cots Date: Fri, 21 Jun 2024 00:32:59 +0200 Subject: [PATCH] up CTBase 0.10, v0.4.0 --- Project.toml | 4 ++-- ext/CTFlowsPlots.jl | 4 ++-- test/Project.toml | 2 +- test/manual_plot_goddard.jl | 13 +++++++------ test/runtests.jl | 2 +- test/test_concatenation.jl | 12 ++++++------ test/test_optimal_control_problem.jl | 20 ++++++++++---------- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Project.toml b/Project.toml index 9588e32..8869d3c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CTFlows" uuid = "1c39547c-7794-42f7-af83-d98194f657c2" authors = ["Olivier Cots "] -version = "0.3.7" +version = "0.4.0" [deps] CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd" @@ -17,7 +17,7 @@ CTFlowsODE = "DifferentialEquations" CTFlowsPlots = "Plots" [compat] -CTBase = "0.9" +CTBase = "0.10" DifferentialEquations = "7.13" DocStringExtensions = "0.9" Plots = "1.38" diff --git a/ext/CTFlowsPlots.jl b/ext/CTFlowsPlots.jl index cb27bb1..d64458e 100644 --- a/ext/CTFlowsPlots.jl +++ b/ext/CTFlowsPlots.jl @@ -15,7 +15,7 @@ module CTFlowsPlots function Plots.plot(sol::OptimalControlFlowSolution; style::Symbol=:ocp, kwargs...) ocp_sol = OptimalControlSolution(sol) # from a flow (from ocp and control) solution to an OptimalControlSolution if style==:ocp - CTBase.plot(ocp_sol; kwargs...) + Plots.plot(ocp_sol; kwargs...) else Plots.plot(sol.ode_sol; kwargs...) end @@ -24,7 +24,7 @@ module CTFlowsPlots function Plots.plot!(p::Plots.Plot, sol::OptimalControlFlowSolution; style::Symbol=:ocp, kwargs...) ocp_sol = OptimalControlSolution(sol) # from a flow (from ocp and control) solution to an OptimalControlSolution if style==:ocp - CTBase.plot!(p, ocp_sol; kwargs...) + Plots.plot!(p, ocp_sol; kwargs...) else Plots.plot!(p, sol.ode_sol; kwargs...) end diff --git a/test/Project.toml b/test/Project.toml index 2e801fb..21859fc 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,6 +6,6 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -CTBase = "0.9" +CTBase = "0.10" DifferentialEquations = "7.13" Plots = "1.38" diff --git a/test/manual_plot_goddard.jl b/test/manual_plot_goddard.jl index a2ca021..8210db6 100644 --- a/test/manual_plot_goddard.jl +++ b/test/manual_plot_goddard.jl @@ -1,6 +1,7 @@ using CTBase using CTFlows using DifferentialEquations +using Plots # Parameters Cd = 310 @@ -18,14 +19,14 @@ x0 = [r0, v0, m0] # OCP model ocp = Model(variable=true) variable!(ocp, 1) -time!(ocp, t0, Index(1)) # if not provided, final time is free +time!(ocp, t0=t0, indf=1) # if not provided, final time is free state!(ocp, 3, "x", ["r", "v", "m"]) # state dim control!(ocp, 1) # control dim -constraint!(ocp, :initial, x0) -constraint!(ocp, :control, (u, v) -> u, 0, 1) -constraint!(ocp, :state, (x, v) -> x[1], r0, Inf, :state_con1) -constraint!(ocp, :state, (x, v) -> x[2], 0, vmax, :state_con2) -constraint!(ocp, :state, (x, v) -> x[3], m0, mf, :state_con3) +constraint!(ocp, :initial, lb=x0, ub=x0) +constraint!(ocp, :control, f=(u, v) -> u, lb=0, ub=1) +constraint!(ocp, :state, f=(x, v) -> x[1], lb=r0, ub=Inf, label=:state_con1) +constraint!(ocp, :state, f=(x, v) -> x[2], lb=0, ub=vmax, label=:state_con2) +constraint!(ocp, :state, f=(x, v) -> x[3], lb=m0, ub=mf, label=:state_con3) objective!(ocp, :mayer, (x0, xf, v) -> xf[1], :max) function F0(x) r, v, m = x diff --git a/test/runtests.jl b/test/runtests.jl index 4643b5d..0f95aeb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,8 @@ using Test using CTFlows using DifferentialEquations -using Plots using CTBase +using Plots using LinearAlgebra @testset verbose = true showtiming = true "CTFlows" begin diff --git a/test/test_concatenation.jl b/test/test_concatenation.jl index 01e6d66..d27f5b0 100644 --- a/test/test_concatenation.jl +++ b/test/test_concatenation.jl @@ -280,8 +280,8 @@ function test_concatenation() ocp = Model() state!(ocp, 2) control!(ocp, 2) - time!(ocp, [0, 5]) - constraint!(ocp, :initial, [0, 0]) + time!(ocp, t0=0, tf=5) + constraint!(ocp, :initial, lb=[0, 0], ub=[0, 0]) dynamics!(ocp, (x, u) -> u) objective!(ocp, :mayer, (x0, xf) -> xf) f = Flow(ocp, (x, p) -> [p[1]/2, 0]) @@ -295,10 +295,10 @@ function test_concatenation() ocp = Model() state!(ocp, 1) control!(ocp, 1) - time!(ocp, [0, 1]) - constraint!(ocp, :initial, -1, :initial_constraint) - constraint!(ocp, :final, 0, :final_constraint) - constraint!(ocp, :control, -1, 1, :control_constraint) + time!(ocp, t0=0, tf=1) + constraint!(ocp, :initial, lb=-1, ub=-1, label=:initial_constraint) + constraint!(ocp, :final, lb= 0, ub= 0, label=:final_constraint) + constraint!(ocp, :control, lb=-1, ub= 1, label=:control_constraint) dynamics!(ocp, (x, u) -> -x + u) objective!(ocp, :lagrange, (x, u) -> abs(u)) f0 = Flow(ocp, ControlLaw((x, p) -> 0)) diff --git a/test/test_optimal_control_problem.jl b/test/test_optimal_control_problem.jl index 582b535..6a71533 100644 --- a/test/test_optimal_control_problem.jl +++ b/test/test_optimal_control_problem.jl @@ -11,9 +11,9 @@ function test_optimal_control_problem() ocp = Model() state!(ocp, n) # dimension of the state control!(ocp, m) # dimension of the control - time!(ocp, [t0, tf]) - constraint!(ocp, :initial, x0, :initial_constraint) - constraint!(ocp, :final, xf, :final_constraint) + time!(ocp, t0=t0, tf=tf) + constraint!(ocp, :initial, lb=x0, ub=x0, label=:initial_constraint) + constraint!(ocp, :final, lb=xf, ub=xf, label=:final_constraint) dynamics!(ocp, (x, u) -> [x[2], u]) objective!(ocp, :lagrange, (x, u) -> 0.5u^2) # default is to minimise f = Flow(ocp, (x, p) -> p[2]) @@ -33,9 +33,9 @@ function test_optimal_control_problem() ocp = Model() state!(ocp, n) # dimension of the state control!(ocp, m) # dimension of the control - time!(ocp, [t0, tf]) - constraint!(ocp, :initial, x0) - constraint!(ocp, :mixed, (x,u) -> x + u, -Inf, 0) + time!(ocp, t0=t0, tf=tf) + constraint!(ocp, :initial, lb=x0, ub=x0) + constraint!(ocp, :mixed, f=(x,u) -> x + u, lb=-Inf, ub=0) dynamics!(ocp, (x, u) -> u) objective!(ocp, :lagrange, (x, u) -> -u) @@ -102,10 +102,10 @@ function test_optimal_control_problem() ocp = Model() state!(ocp, n) # dimension of the state control!(ocp, m) # dimension of the control - time!(ocp, [t0, tf]) - constraint!(ocp, :initial, x0) - constraint!(ocp, :final, xf) - constraint!(ocp, :state, Index(1), -Inf, l) + time!(ocp, t0=t0, tf=tf) + constraint!(ocp, :initial, lb=x0, ub=x0) + constraint!(ocp, :final, lb=xf, ub=xf) + constraint!(ocp, :state, rg=Index(1), lb=-Inf, ub=l) A = [ 0 1 0 0 ] B = [ 0