Skip to content

Commit

Permalink
Introduce draft for fixing investments (yet untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokochems committed Oct 31, 2023
1 parent fb1c5f7 commit b001fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/oemof/solph/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class Model(BaseModel):
InvestNonConvexFlowBlock,
]

def __init__(self, energysystem, discount_rate=None, **kwargs):
def __init__(self, energysystem, discount_rate=None, fix_investments=False, **kwargs):
if discount_rate is not None:
self.discount_rate = discount_rate
elif (
Expand All @@ -383,6 +383,7 @@ def __init__(self, energysystem, discount_rate=None, **kwargs):
self._set_discount_rate_with_warning()
else:
pass
self.fix_investments = fix_investments
super().__init__(energysystem, **kwargs)

def _set_discount_rate_with_warning(self):
Expand Down
22 changes: 22 additions & 0 deletions src/oemof/solph/flows/_investment_flow_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ def _create(self, group=None):
attribute investment and the associated source (s) and target (t)
of flow e.g. groups=[(s1, t1, f1), (s2, t2, f2),..]
"""
m = self.parent_block()
if group is None:
return None

self._create_sets(group)
self._create_variables(group)
self._create_constraints()
if m.fix_investments:
self._fix_investments()

def _create_sets(self, group):
"""
Expand Down Expand Up @@ -1175,3 +1178,22 @@ def _max_invest_rule(_):
self.maximum_rule_build = BuildAction(rule=_max_invest_rule)

return self.maximum_rule

def _fix_investments(self):
"""Fix investments in case boolean flag `fix_investments` is True"""
m = self.parent_block()
if m.solver_results is not None:
for p in m.PERIODS:
self.invest[p].fix()
self.total[p].fix()
if m.es.periods is not None:
self.old[p].fix()
self.old_end[p].fix()
self.old_exo[p].fix()
else:
msg = (
"Cannot fix investments as model has not yet been solved!\n"
"You have to first solve your model and then set "
"`fix_investments=True` for your model instance."
)
raise ValueError(msg)

0 comments on commit b001fe6

Please sign in to comment.