Skip to content

Commit

Permalink
Merge pull request #40 from ErikQQY/qqy/constructor
Browse files Browse the repository at this point in the history
Add docs for constructors and populate docs
  • Loading branch information
aarontrowbridge committed Jun 3, 2024
2 parents 03753f9 + d92a6c0 commit ba6587f
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 4 deletions.
29 changes: 29 additions & 0 deletions docs/literate/man/constructors.jl
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# # Constructors

# To construct a `NamedTrajectory` using NamedTrajectories.jl, we simply need to utilize the `NamedTrajectory` constructor.

using NamedTrajectories

## define number of timesteps and timestep
T = 10
dt = 0.1

# build named tuple of components and data matrices.

components = (
x = rand(3, T),
u = rand(2, T),
Δt = fill(dt, 1, T),
)

# we must specify a timestep and control variable for the trajectory.

timestep = 0.1
control = :u

# we can now create a `NamedTrajectory` object.

traj = NamedTrajectory(components; timestep=timestep, controls=control)

# Construct `NamedTrajectory` from previous constructed one.

traj = NamedTrajectory(components, traj)
7 changes: 4 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ push!(LOAD_PATH, joinpath(@__DIR__, "..", "src"))
pages = [
"Home" => "index.md",
"Quickstart Guide" => "generated/quickstart.md",
# "Manual" => [
# "generated/man/constructors.md",
"Manual" => [
"generated/man/constructors.md",
# "generated/man/retrieval.md",
# "generated/man/add_remove.md",
# "generated/man/updating.md",
# "generated/man/times.md",
# "generated/man/operations.md",
# ],
],
"Plotting" => "generated/plotting.md",
"Library" => "lib.md"
]
Expand Down Expand Up @@ -63,6 +63,7 @@ makedocs(;
modules=[NamedTrajectories],
authors="Aaron Trowbridge <aaron.j.trowbridge@gmail.com> and contributors",
sitename="NamedTrajectories.jl",
warnonly = [:missing_docs],
format=format,
pages=pages,
)
Expand Down
39 changes: 39 additions & 0 deletions docs/src/generated/man/constructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,45 @@ EditURL = "../../../literate/man/constructors.jl"

# Constructors

To construct a `NamedTrajectory` using NamedTrajectories.jl, we simply need to utilize the `NamedTrajectory` constructor.

````@example constructors
using NamedTrajectories
# define number of timesteps and timestep
T = 10
dt = 0.1
````

build named tuple of components and data matrices.

````@example constructors
components = (
x = rand(3, T),
u = rand(2, T),
Δt = fill(dt, 1, T),
)
````

we must specify a timestep and control variable for the trajectory.

````@example constructors
timestep = 0.1
control = :u
````

we can now create a `NamedTrajectory` object.

````@example constructors
traj = NamedTrajectory(components; timestep=timestep, controls=control)
````

Construct `NamedTrajectory` from previous constructed one.

````@example constructors
traj = NamedTrajectory(components, traj)
````

---

*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
Expand Down
66 changes: 65 additions & 1 deletion src/struct_named_trajectory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ using OrderedCollections

const BoundType = Tuple{AbstractVector{<:Real}, AbstractVector{<:Real}}

"""
NamedTrajectory constructor
"""
mutable struct NamedTrajectory{R <: Real}
data::AbstractMatrix{R}
datavec::AbstractVector{R}
Expand All @@ -25,7 +28,18 @@ mutable struct NamedTrajectory{R <: Real}
control_names::Tuple{Vararg{Symbol}}
end


"""
NamedTrajectory(comp_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `comp_data::NamedTuple{names, <:Tuple{Vararg{vals}}} where {names, vals <: AbstractMatrix{R}}`: Components data.
- `controls`: The control variable in comp_data, should be type of `Symbol` among `comp_data`.
- `timestep`: Discretizing time step in `comp_data`, should be type of `Symbol` among `comp_data`.
- `bounds`: Bounds of the trajectory.
- `initial`: Initial values.
- `final`: Final values.
- `goal`: Goal for the states.
"""
function NamedTrajectory(
comp_data::NamedTuple{names, <:Tuple{Vararg{vals}}} where
{names, vals <: AbstractMatrix{R}};
Expand Down Expand Up @@ -159,6 +173,13 @@ function NamedTrajectory(
)
end

"""
NamedTrajectory(comps; kwargs...)
# Arguments
- `comp_data::NamedTuple{names, <:Tuple{Vararg{vals}}} where {names, vals <: AbstractMatrix{R}}`: Components data.
- `kwargs...`: The other key word arguments.
"""
function NamedTrajectory(
comps::NamedTuple;
kwargs...
Expand All @@ -173,7 +194,20 @@ end



"""
NamedTrajectory(datavec, T, comp_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `datavec::AbstractVector{R} where R <: Real`: Trajectory data.
- `T::Int`: Numbers of time step.
- `comp_data::NamedTuple{names, <:Tuple{Vararg{vals}}} where {names, vals <: AbstractMatrix{R}}`: components data.
- `controls`: The control variable in comp_data, should be type of `Symbol` among `comp_data`.
- `timestep`: Discretizing time step in `comp_data`, should be type of `Symbol` among `comp_data`.
- `bounds`: Bounds of the trajectory.
- `initial`: Initial values.
- `final`: Final values.
- `goal`: Goal for the states.
"""
function NamedTrajectory(
datavec::AbstractVector{R},
T::Int,
Expand Down Expand Up @@ -263,6 +297,13 @@ function NamedTrajectory(
)
end

"""
NamedTrajectory(comp_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `datavec::AbstractVector{R} where R <: Real`: Trajectory data.
- `z`: Constructed `NamedTrajectory`.
"""
function NamedTrajectory(
datavec::AbstractVector{R},
Z::NamedTrajectory
Expand Down Expand Up @@ -293,6 +334,13 @@ function NamedTrajectory(
)
end

"""
NamedTrajectory(data, traj)
# Arguments
- `data`: Trajectory data.
- `traj`: Constructed `NamedTrajectory`.
"""
function NamedTrajectory(
data::AbstractMatrix{R},
traj::NamedTrajectory
Expand Down Expand Up @@ -323,6 +371,14 @@ function NamedTrajectory(
)
end

"""
NamedTrajectory(data, componets; kwargs...)
# Arguments
- `data::AbstractMatrix{R}`: Trajectory data.
- `components::NamedTuple{names, <:Tuple{Vararg{AbstractVector{Int}}}} where names`: components data.
- `kwargs...` : The other key word arguments.
"""
function NamedTrajectory(
data::AbstractMatrix{R},
components::NamedTuple{
Expand All @@ -336,6 +392,14 @@ function NamedTrajectory(
return NamedTrajectory(datavec, T, components; kwargs...)
end

"""
NamedTrajectory(comp_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `comps::NamedTuple{names, <:Tuple{Vararg{AbstractMatrix{R}}}} where {names}`: components data.
- `traj`: Constructed NamedTrajectory.
- `goal`: Goal for the states.
"""
function NamedTrajectory(
comps::NamedTuple{
names,
Expand Down

0 comments on commit ba6587f

Please sign in to comment.