Skip to content
Merged
2 changes: 2 additions & 0 deletions docs/src/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ withprev
withnext
chunk
chunk_duration
partition_duration
```

## [Properties of time periods](@id api-prop_per)
Expand All @@ -78,6 +79,7 @@ end_oper_time
```@docs
FixedProfile
OperationalProfile
PartitionProfile
RepresentativeProfile
ScenarioProfile
StrategicProfile
Expand Down
7 changes: 6 additions & 1 deletion src/TimeStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ include("utils.jl")
include("discount.jl")
include("profiles.jl")

include("partitions/strat_periods.jl")
include("partitions/rep_periods.jl")
include("partitions/opscenarios.jl")

export TimeStructure
export SimpleTimes
export CalendarTimes
Expand All @@ -40,6 +44,7 @@ export TreeNode
export TimeProfile
export FixedProfile
export OperationalProfile
export PartitionProfile
export ScenarioProfile
export StrategicProfile
export StrategicStochasticProfile
Expand All @@ -49,7 +54,7 @@ export opscenarios
export repr_periods
export strat_periods, strategic_periods
export regular_tree, strat_nodes, strategic_scenarios
export withprev, withnext, chunk, chunk_duration
export withprev, withnext, chunk, chunk_duration, partition_duration
export isfirst, duration, duration_strat, multiple
export probability, probability_branch, probability_scen
export multiple_strat
Expand Down
23 changes: 23 additions & 0 deletions src/partitions/opscenarios.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Add generic partition duration type
abstract type AbstractOpScenPart{T} <: PeriodPartition{T} end

ScenarioIndexable(::Type{<:AbstractOpScenPart}) = HasScenarioIndex()
_opscen(pd::AbstractOpScenPart) = pd.scen

# Add partition type with constructor for indexing when operational scenarios are present
struct OpScenPart{N,T} <: AbstractOpScenPart{T}
scen::Int
part::Int
chunk::NTuple{N,T}
end
PeriodPartition(itr::OperationalScenario, part, chunk) = OpScenPart(itr.scen, part, chunk)
eltype(::Type{PartitionDurationIterator{I}}) where {I<:OperationalScenario} = OpScenPart

Base.show(io::IO, pd::OpScenPart) = print(io, "sc$(pd.scen)-part$(pd.part)")

# Add function for generation of partitions from higher level
function partition_duration(ts::OperationalScenarios, dur)
return collect(
Iterators.flatten(partition_duration(osc, dur) for osc in opscenarios(ts)),
)
end
Comment thread
JulStraus marked this conversation as resolved.
48 changes: 48 additions & 0 deletions src/partitions/rep_periods.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Add generic partition duration type
abstract type AbstractReprPart{T} <: PeriodPartition{T} end

RepresentativeIndexable(::Type{<:AbstractReprPart}) = HasReprIndex()
_rper(pd::AbstractReprPart) = pd.rp

# Add partition type with constructor for indexing when representative periods are present
struct ReprPart{N,T} <: AbstractReprPart{T}
rp::Int
part::Int
chunk::NTuple{N,T}
end
PeriodPartition(itr::RepresentativePeriod, part, chunk) = ReprPart(itr.rp, part, chunk)
eltype(::Type{PartitionDurationIterator{I}}) where {I<:RepresentativePeriod} = ReprPart

Base.show(io::IO, pd::ReprPart) = print(io, "rp$(pd.rp)-part$(pd.part)")

# Add partition type with constructor for indexing when representative periods and operational
# scenarios are present
struct ReprOpScenPart{N,T} <: AbstractReprPart{T}
rp::Int
scen::Int
part::Int
chunk::NTuple{N,T}
end
function PeriodPartition(itr::ReprOpScenario, part, chunk)
return ReprOpScenPart(itr.rp, itr.scen, part, chunk)
end
eltype(::Type{PartitionDurationIterator{I}}) where {I<:ReprOpScenario} = ReprOpScenPart

Base.show(io::IO, pd::ReprOpScenPart) = print(io, "rp$(pd.rp)-sc$(pd.scen)-part$(pd.part)")
ScenarioIndexable(::Type{<:ReprOpScenPart}) = HasScenarioIndex()
_opscen(pd::ReprOpScenPart) = pd.scen

# Add function for generation of partitions from higher level
function partition_duration(ts::RepresentativePeriods, dur)
return collect(
Iterators.flatten(partition_duration(rp, dur) for rp in repr_periods(ts)),
)
end
Comment thread
JulStraus marked this conversation as resolved.
function partition_duration(
ts::RepresentativePeriod{T,OP},
dur,
) where {T,OP<:OperationalScenarios}
return collect(
Iterators.flatten(partition_duration(osc, dur) for osc in opscenarios(ts)),
)
end
107 changes: 107 additions & 0 deletions src/partitions/strat_periods.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Add generic partition duration type
abstract type AbstractStratPart{T} <: PeriodPartition{T} end

StrategicIndexable(::Type{<:AbstractStratPart}) = HasStratIndex()
_strat_per(pd::AbstractStratPart) = pd.sp

# Add partition type with constructor for indexing when strategic periods are present
struct StratPart{N,T} <: AbstractStratPart{T}
sp::Int
part::Int
chunk::NTuple{N,T}
end
PeriodPartition(itr::StrategicPeriod, part, chunk) = StratPart(itr.sp, part, chunk)
eltype(::Type{PartitionDurationIterator{I}}) where {I<:StrategicPeriod} = StratPart

Base.show(io::IO, pd::StratPart) = print(io, "sp$(pd.sp)-part$(pd.part)")

# Add partition type with constructor for indexing when strategic and representative periods
# are present
struct StratReprPart{N,T} <: AbstractStratPart{T}
sp::Int
rp::Int
part::Int
chunk::NTuple{N,T}
end
function PeriodPartition(itr::StratReprPeriod, part, chunk)
return StratReprPart(itr.sp, itr.rp, part, chunk)
end
eltype(::Type{PartitionDurationIterator{I}}) where {I<:StratReprPeriod} = StratReprPart

Base.show(io::IO, pd::StratReprPart) = print(io, "sp$(pd.sp)-rp$(pd.rp)-part$(pd.part)")
RepresentativeIndexable(::Type{<:StratReprPart}) = HasReprIndex()
_rper(pd::StratReprPart) = pd.rp

# Add partition type with constructor for indexing when strategic periods and operational
# scenarios are present
struct StratOpScenPart{N,T} <: AbstractStratPart{T}
sp::Int
scen::Int
part::Int
chunk::NTuple{N,T}
end
function PeriodPartition(itr::StratOpScenario, part, chunk)
return StratOpScenPart(itr.sp, itr.scen, part, chunk)
end
eltype(::Type{PartitionDurationIterator{I}}) where {I<:StratOpScenario} = StratOpScenPart

function Base.show(io::IO, pd::StratOpScenPart)
return print(io, "sp$(pd.sp)-sc$(pd.scen)-part$(pd.part)")
end
ScenarioIndexable(::Type{<:StratOpScenPart}) = HasScenarioIndex()
_opscen(pd::StratOpScenPart) = pd.scen

# Add partition type with constructor for indexing when strategic periods, representative
# periods and operational scenarios are present
struct StratReprOpScenPart{N,T} <: AbstractStratPart{T}
sp::Int
rp::Int
scen::Int
part::Int
chunk::NTuple{N,T}
end
function PeriodPartition(itr::StratReprOpScenario, part, chunk)
return StratReprOpScenPart(itr.sp, itr.rp, itr.scen, part, chunk)
end
function eltype(::Type{PartitionDurationIterator{I}}) where {I<:StratReprOpScenario}
return StratReprOpScenPart
end

function Base.show(io::IO, pd::StratReprOpScenPart)
return print(io, "sp$(pd.sp)-rp$(pd.rp)-sc$(pd.scen)-part$(pd.part)")
end
RepresentativeIndexable(::Type{<:StratReprOpScenPart}) = HasReprIndex()
ScenarioIndexable(::Type{<:StratReprOpScenPart}) = HasScenarioIndex()
_rper(pd::StratReprOpScenPart) = pd.rp
_opscen(pd::StratReprOpScenPart) = pd.scen

# Add function for generation of partitions from higher level
function partition_duration(ts::TwoLevel, dur)
return collect(
Iterators.flatten(partition_duration(sp, dur) for sp in strategic_periods(ts)),
)
end
Comment thread
JulStraus marked this conversation as resolved.
function partition_duration(
ts::StrategicPeriod{S,T,OP},
dur,
) where {S,T,OP<:RepresentativePeriods}
return collect(
Iterators.flatten(partition_duration(rp, dur) for rp in repr_periods(ts)),
)
end
function partition_duration(
ts::StrategicPeriod{S,T,OP},
dur,
) where {S,T,OP<:OperationalScenarios}
return collect(
Iterators.flatten(partition_duration(osc, dur) for osc in opscenarios(ts)),
)
end
function partition_duration(
ts::StratReprPeriod{T,RepresentativePeriod{T,OP}},
dur,
) where {T,OP<:OperationalScenarios}
return collect(
Iterators.flatten(partition_duration(osc, dur) for osc in opscenarios(ts)),
)
end
Loading
Loading