Skip to content

Commit

Permalink
Fix activity status in initial steps
Browse files Browse the repository at this point in the history
This allows to go back to the indexing we used before.
  • Loading branch information
p-snft committed Nov 27, 2023
1 parent b12a24f commit b9aa489
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/oemof/solph/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def __init__(
for attribute, value in custom_attributes.items():
setattr(self, attribute, value)

self.first_flexible_timestep = max(minimum_uptime, minimum_downtime)

@property
def max_up_down(self):
"""Return maximum of minimum_uptime and minimum_downtime.
Expand Down
15 changes: 7 additions & 8 deletions src/oemof/solph/flows/_non_convex_flow_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ def _create_variables(self):
self.status = Var(self.NONCONVEX_FLOWS, m.TIMESTEPS, within=Binary)
for o, i in self.NONCONVEX_FLOWS:
if m.flows[o, i].nonconvex.initial_status is not None:
self.status[o, i, m.TIMESTEPS.at(1)] = m.flows[
o, i
].nonconvex.initial_status
self.status[o, i, m.TIMESTEPS.at(1)].fix()
for t in range(0, m.flows[o, i].nonconvex.first_flexible_timestep):
self.status[o, i, t] = m.flows[o, i].nonconvex.initial_status
self.status[o, i, t].fix()

# `status_nominal` is a parameter which represents the
# multiplication of a binary variable (`status`)
Expand Down Expand Up @@ -471,10 +470,10 @@ def min_downtime_rule(_, i, o, t):
"""
Rule definition for min-downtime constraints of non-convex flows.
"""
if t < m.TIMESTEPS.at(-1):
if m.flows[i, o].nonconvex.first_flexible_timestep < t < m.TIMESTEPS.at(-1):
expr = 0
expr += (
self.status[i, o, t] - self.status[i, o, t + 1]
self.status[i, o, t - 1] - self.status[i, o, t]
) * m.flows[i, o].nonconvex.minimum_downtime
expr += -m.flows[i, o].nonconvex.minimum_downtime
expr += sum(
Expand Down Expand Up @@ -517,10 +516,10 @@ def _min_uptime_rule(_, i, o, t):
"""
Rule definition for min-uptime constraints of non-convex flows.
"""
if t < m.TIMESTEPS.at(-1):
if m.flows[i, o].nonconvex.first_flexible_timestep < t < m.TIMESTEPS.at(-1):
expr = 0
expr += (
self.status[i, o, t + 1] - self.status[i, o, t]
self.status[i, o, t] - self.status[i, o, t - 1]
) * m.flows[i, o].nonconvex.minimum_uptime
expr += -sum(
self.status[i, o, u]
Expand Down

0 comments on commit b9aa489

Please sign in to comment.