diff --git a/src/oemof/solph/_options.py b/src/oemof/solph/_options.py index b57c153d6..e1720ead2 100644 --- a/src/oemof/solph/_options.py +++ b/src/oemof/solph/_options.py @@ -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. diff --git a/src/oemof/solph/flows/_non_convex_flow_block.py b/src/oemof/solph/flows/_non_convex_flow_block.py index fea5a0a8f..100f4ea91 100644 --- a/src/oemof/solph/flows/_non_convex_flow_block.py +++ b/src/oemof/solph/flows/_non_convex_flow_block.py @@ -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`) @@ -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( @@ -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]