Skip to content

Commit

Permalink
up CTBase 0.10, v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ocots committed Jun 20, 2024
1 parent 69a3c14 commit 315e3f4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CTFlows"
uuid = "1c39547c-7794-42f7-af83-d98194f657c2"
authors = ["Olivier Cots <[email protected]>"]
version = "0.3.7"
version = "0.4.0"

[deps]
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
Expand All @@ -17,7 +17,7 @@ CTFlowsODE = "DifferentialEquations"
CTFlowsPlots = "Plots"

[compat]
CTBase = "0.9"
CTBase = "0.10"
DifferentialEquations = "7.13"
DocStringExtensions = "0.9"
Plots = "1.38"
Expand Down
4 changes: 2 additions & 2 deletions ext/CTFlowsPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 7 additions & 6 deletions test/manual_plot_goddard.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CTBase
using CTFlows
using DifferentialEquations
using Plots

# Parameters
Cd = 310
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/test_concatenation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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))
Expand Down
20 changes: 10 additions & 10 deletions test/test_optimal_control_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 315e3f4

Please sign in to comment.