Skip to content

Function for identifying predecessor periods #102

Description

@JulStraus

The following function was introduced in EnergyModelsInvestment through PR 58, but not used as it was no longer necessary. It can however be a nice function to have within TimeStruct.

However, in this case, it would be beneficial to also include it for RepresentativePeriods and SimpleTimes (it is not relevant for OperationalScenarios as these are parallel). This issue is just to keep track of the developed code.

"""
    _predecessor_periods(𝒯::TwoLevel)
    _predecessor_periods(𝒯::TwoLevelTree)

Return a dictionary mapping each strategic period to the strategic periods preceding it on
the same scenario path. For a linear time structure, the predecessors are all earlier
strategic periods. For a tree structure, only ancestor periods on the corresponding path
are included.
"""
function _predecessor_periods(𝒯::TwoLevel)
    sps = collect(strat_periods(𝒯))
    return Dict(t_inv => sps[1:(idx-1)] for (idx, t_inv) ∈ enumerate(sps))
end
function _predecessor_periods(𝒯::TwoLevelTree)
    sps_pre = Dict()
    for scenario ∈ strategic_scenarios(𝒯)
        path = collect(strat_periods(scenario))
        for (idx, period) ∈ enumerate(path)
            !haskey(sps_pre, period) && (sps_pre[period] = path[1:(idx-1)])
        end
    end
    return sps_pre
end

Activity

  1. self-assigned this
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions