|
| 1 | +# Add generic partition duration type |
| 2 | +abstract type AbstractStratPart{T} <: PeriodPartition{T} end |
| 3 | + |
| 4 | +StrategicIndexable(::Type{<:AbstractStratPart}) = HasStratIndex() |
| 5 | +_strat_per(pd::AbstractStratPart) = pd.sp |
| 6 | + |
| 7 | +# Add partition type with constructor for indexing when strategic periods are present |
| 8 | +struct StratPart{N,T} <: AbstractStratPart{T} |
| 9 | + sp::Int |
| 10 | + part::Int |
| 11 | + chunk::NTuple{N,T} |
| 12 | +end |
| 13 | +PeriodPartition(itr::StrategicPeriod, part, chunk) = StratPart(itr.sp, part, chunk) |
| 14 | +eltype(::Type{PartitionDurationIterator{I}}) where {I<:StrategicPeriod} = StratPart |
| 15 | + |
| 16 | +Base.show(io::IO, pd::StratPart) = print(io, "sp$(pd.sp)-part$(pd.part)") |
| 17 | + |
| 18 | +# Add partition type with constructor for indexing when strategic and representative periods |
| 19 | +# are present |
| 20 | +struct StratReprPart{N,T} <: AbstractStratPart{T} |
| 21 | + sp::Int |
| 22 | + rp::Int |
| 23 | + part::Int |
| 24 | + chunk::NTuple{N,T} |
| 25 | +end |
| 26 | +function PeriodPartition(itr::StratReprPeriod, part, chunk) |
| 27 | + return StratReprPart(itr.sp, itr.rp, part, chunk) |
| 28 | +end |
| 29 | +eltype(::Type{PartitionDurationIterator{I}}) where {I<:StratReprPeriod} = StratReprPart |
| 30 | + |
| 31 | +Base.show(io::IO, pd::StratReprPart) = print(io, "sp$(pd.sp)-rp$(pd.rp)-part$(pd.part)") |
| 32 | +RepresentativeIndexable(::Type{<:StratReprPart}) = HasReprIndex() |
| 33 | +_rper(pd::StratReprPart) = pd.rp |
| 34 | + |
| 35 | +# Add partition type with constructor for indexing when strategic periods and operational |
| 36 | +# scenarios are present |
| 37 | +struct StratOpScenPart{N,T} <: AbstractStratPart{T} |
| 38 | + sp::Int |
| 39 | + scen::Int |
| 40 | + part::Int |
| 41 | + chunk::NTuple{N,T} |
| 42 | +end |
| 43 | +function PeriodPartition(itr::StratOpScenario, part, chunk) |
| 44 | + return StratOpScenPart(itr.sp, itr.scen, part, chunk) |
| 45 | +end |
| 46 | +eltype(::Type{PartitionDurationIterator{I}}) where {I<:StratOpScenario} = StratOpScenPart |
| 47 | + |
| 48 | +function Base.show(io::IO, pd::StratOpScenPart) |
| 49 | + return print(io, "sp$(pd.sp)-sc$(pd.scen)-part$(pd.part)") |
| 50 | +end |
| 51 | +ScenarioIndexable(::Type{<:StratOpScenPart}) = HasScenarioIndex() |
| 52 | +_opscen(pd::StratOpScenPart) = pd.scen |
| 53 | + |
| 54 | +# Add partition type with constructor for indexing when strategic periods, representative |
| 55 | +# periods and operational scenarios are present |
| 56 | +struct StratReprOpScenPart{N,T} <: AbstractStratPart{T} |
| 57 | + sp::Int |
| 58 | + rp::Int |
| 59 | + scen::Int |
| 60 | + part::Int |
| 61 | + chunk::NTuple{N,T} |
| 62 | +end |
| 63 | +function PeriodPartition(itr::StratReprOpScenario, part, chunk) |
| 64 | + return StratReprOpScenPart(itr.sp, itr.rp, itr.scen, part, chunk) |
| 65 | +end |
| 66 | +function eltype(::Type{PartitionDurationIterator{I}}) where {I<:StratReprOpScenario} |
| 67 | + return StratReprOpScenPart |
| 68 | +end |
| 69 | + |
| 70 | +function Base.show(io::IO, pd::StratReprOpScenPart) |
| 71 | + return print(io, "sp$(pd.sp)-rp$(pd.rp)-sc$(pd.scen)-part$(pd.part)") |
| 72 | +end |
| 73 | +RepresentativeIndexable(::Type{<:StratReprOpScenPart}) = HasReprIndex() |
| 74 | +ScenarioIndexable(::Type{<:StratReprOpScenPart}) = HasScenarioIndex() |
| 75 | +_rper(pd::StratReprOpScenPart) = pd.rp |
| 76 | +_opscen(pd::StratReprOpScenPart) = pd.scen |
| 77 | + |
| 78 | +# Add function for generation of partitions from higher level |
| 79 | +function partition_duration(ts::TwoLevel, dur) |
| 80 | + return collect( |
| 81 | + Iterators.flatten(partition_duration(sp, dur) for sp in strategic_periods(ts)), |
| 82 | + ) |
| 83 | +end |
| 84 | +function partition_duration( |
| 85 | + ts::StrategicPeriod{S,T,OP}, |
| 86 | + dur, |
| 87 | +) where {S,T,OP<:RepresentativePeriods} |
| 88 | + return collect( |
| 89 | + Iterators.flatten(partition_duration(rp, dur) for rp in repr_periods(ts)), |
| 90 | + ) |
| 91 | +end |
| 92 | +function partition_duration( |
| 93 | + ts::StrategicPeriod{S,T,OP}, |
| 94 | + dur, |
| 95 | +) where {S,T,OP<:OperationalScenarios} |
| 96 | + return collect( |
| 97 | + Iterators.flatten(partition_duration(osc, dur) for osc in opscenarios(ts)), |
| 98 | + ) |
| 99 | +end |
| 100 | +function partition_duration( |
| 101 | + ts::StratReprPeriod{T,RepresentativePeriod{T,OP}}, |
| 102 | + dur, |
| 103 | +) where {T,OP<:OperationalScenarios} |
| 104 | + return collect( |
| 105 | + Iterators.flatten(partition_duration(osc, dur) for osc in opscenarios(ts)), |
| 106 | + ) |
| 107 | +end |
0 commit comments