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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:
with:
depwarn: error
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Format check
shell: julia --color=yes {0}
run: |
using Pkg
# If you update the version, also update the style guide docs.
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
using JuliaFormatter
format("src", verbose=true)
format("test", verbose=true)
Expand Down
12 changes: 11 additions & 1 deletion src/calendar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ struct CalendarTimes{T<:Union{Dates.DateTime,TimeZones.ZonedDateTime}} <:
start_date::T
length::Int
period::Dates.Period
total_duration::Float64
function CalendarTimes(
start_date::T,
length::Integer,
period::Dates.Period,
) where {T<:Union{Dates.DateTime,TimeZones.ZonedDateTime}}
end_date = start_date + length * period
total_duration = Dates.value(Dates.Hour(end_date - start_date))
return new{T}(start_date, length, period, total_duration)
end
end

function CalendarTimes(
Expand Down Expand Up @@ -61,7 +71,7 @@ function CalendarTimes(
return CalendarTimes(first, length, period)
end

_total_duration(ts::CalendarTimes) = sum(duration(t) for t in ts)
_total_duration(ts::CalendarTimes) = ts.total_duration

# Add basic functions of iterators
Base.length(ts::CalendarTimes) = ts.length
Expand Down
10 changes: 8 additions & 2 deletions src/op_scenarios/core_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct OperationalScenarios{T,OP<:TimeStructure{T}} <: TimeStructure{T}
len::Int
scenarios::Vector{OP}
probability::Vector{Float64}
total_duration::T
function OperationalScenarios(
len::Integer,
scenarios::Vector{OP},
Expand All @@ -59,7 +60,12 @@ struct OperationalScenarios{T,OP<:TimeStructure{T}} <: TimeStructure{T}
"This can lead to unexpected behavior."
)
end
return new{T,OP}(len, scenarios, convert(Vector{Float64}, probability))
return new{T,OP}(
len,
scenarios,
convert(Vector{Float64}, probability),
maximum(_total_duration(osc) for osc in scenarios),
)
end
end
function OperationalScenarios(len::Integer, oper::TimeStructure{T}) where {T}
Expand All @@ -73,7 +79,7 @@ function OperationalScenarios(oper::Vector{<:TimeStructure{T}}) where {T}
end

function _total_duration(oscs::OperationalScenarios)
return maximum(_total_duration(osc) for osc in oscs.scenarios)
return oscs.total_duration
end

function _multiple_adj(oscs::OperationalScenarios, scen)
Expand Down
5 changes: 3 additions & 2 deletions src/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ varying = SimpleTimes([2, 2, 2, 4, 10]) # 5 periods of varying length
struct SimpleTimes{T} <: TimeStructure{T}
len::Int
duration::Vector{T}
total_duration::T
function SimpleTimes(len::Integer, duration::Vector{T}) where {T<:Duration}
if len > length(duration)
throw(
Expand All @@ -27,7 +28,7 @@ struct SimpleTimes{T} <: TimeStructure{T}
),
)
else
new{T}(len, duration)
new{T}(len, duration, sum(duration))
end
end
end
Expand All @@ -36,7 +37,7 @@ function SimpleTimes(len::Integer, duration::Duration)
end
SimpleTimes(dur::Vector{T}) where {T<:Duration} = SimpleTimes(length(dur), dur)

_total_duration(st::SimpleTimes) = sum(st.duration)
_total_duration(st::SimpleTimes) = st.total_duration

# Add basic functions of iterators
Base.length(st::SimpleTimes) = st.len
Expand Down
8 changes: 5 additions & 3 deletions src/strat_scenarios/strat_scenarios.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ When the `TimeStructure` is a [`StrategicScenario`](@ref), `strat_periods` retur

These are equivalent to a [`StrategicPeriod`](@ref) of a [`TwoLevel`](@ref) time structure.
"""
strat_periods(ts::StrategicScenario) = StratTreeNodes(
TwoLevelTree(length(ts), first(ts), [n for n in ts.nodes], ts.op_per_strat),
)
function strat_periods(ts::StrategicScenario)
return StratTreeNodes(
TwoLevelTree(length(ts), first(ts), [n for n in ts.nodes], ts.op_per_strat),
)
end

"""
struct StratScens{S,T,OP<:AbstractTreeNode{S,T}} <: AbstractStratScens{T}
Expand Down