Skip to content

Commit

Permalink
Adjust Sink DSM objective functions alike
Browse files Browse the repository at this point in the history
  • Loading branch information
jokochems committed Oct 6, 2023
1 parent 6f999c0 commit f29af6d
Showing 1 changed file with 72 additions and 138 deletions.
210 changes: 72 additions & 138 deletions src/oemof/solph/components/experimental/_sink_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,10 @@ def _objective_expression(self):
"social planner point of view and does not reflect "
"microeconomic interest requirements."
)

duration_last_period = m.es.get_period_duration(-1)
end_of_optimization = m.es.periods_years[-1] + duration_last_period

for g in self.investdsm:
if g.investment.ep_costs is not None:
lifetime = g.investment.lifetime
Expand All @@ -1338,31 +1342,16 @@ def _objective_expression(self):
n=lifetime,
wacc=interest,
)
investment_costs_increment = (
self.invest[g, p]
* annuity
* lifetime
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
duration = min(
end_of_optimization - m.es.periods_years[p],
lifetime,
)
remaining_value = 0
if lifetime > m.es.periods_matrix[p, -1]:
remaining_lifetime = (
lifetime - m.es.periods_matrix[p, -1]
)
remaining_annuity = economics.annuity(
capex=g.investment.ep_costs[-1],
n=lifetime,
wacc=interest,
)
remaining_value = (
self.invest[g, p]
* remaining_annuity
* remaining_lifetime
) * (
(1 + m.discount_rate)
** (-m.es.periods_years[-1])
)
investment_costs_increment -= remaining_value
present_value_factor = 1 / economics.annuity(
capex=1, n=duration, wacc=m.discount_rate
)
investment_costs_increment = (
self.invest[g, p] * annuity * present_value_factor
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])
investment_costs += investment_costs_increment
period_investment_costs[
p
Expand All @@ -1375,55 +1364,44 @@ def _objective_expression(self):
self.dsm_up[g, t]
* m.objective_weighting[t]
* g.cost_dsm_up[t]
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
* (1 + m.discount_rate) ** (-m.es.periods_years[p])
)
variable_costs += (
(
self.dsm_do_shift[g, t] * g.cost_dsm_down_shift[t]
+ self.dsm_do_shed[g, t] * g.cost_dsm_down_shed[t]
)
* m.objective_weighting[t]
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
* (1 + m.discount_rate) ** (-m.es.periods_years[p])
)

if g.investment.fixed_costs[0] is not None:
lifetime = g.investment.lifetime
for p in m.PERIODS:
range_limit = min(
end_of_optimization,
m.es.periods_years[p] + lifetime,
)
fixed_costs += sum(
self.invest[g, p]
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
* (1 + m.discount_rate) ** (-pp)
for pp in range(
m.es.periods_years[p],
m.es.periods_years[p] + lifetime,
)
) * ((1 + m.discount_rate) ** -m.es.periods_years[p])
if lifetime > m.es.periods_matrix[p, -1]:
fixed_costs -= sum(
self.invest[g, p]
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(
m.es.periods_years[-1],
m.es.periods_years[p] + lifetime,
)
) * (
(1 + m.discount_rate)
** (-m.es.periods_years[-1])
range_limit,
)
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])

for g in self.EXISTING_INVESTDSM:
if g.investment.fixed_costs[0] is not None:
lifetime = g.investment.lifetime
age = g.investment.age
range_limit = min(
m.es.periods_matrix[0, -1], lifetime - age
)
range_limit = min(end_of_optimization, lifetime - age)
fixed_costs += sum(
g.investment.existing
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(0, range_limit)
* (1 + m.discount_rate) ** (-pp)
for pp in range(range_limit)
)

self.variable_costs = Expression(expr=variable_costs)
Expand Down Expand Up @@ -3073,6 +3051,10 @@ def _objective_expression(self):
"social planner point of view and does not reflect "
"microeconomic interest requirements."
)

duration_last_period = m.es.get_period_duration(-1)
end_of_optimization = m.es.periods_years[-1] + duration_last_period

for g in self.investdsm:
if g.investment.ep_costs is not None:
lifetime = g.investment.lifetime
Expand All @@ -3089,31 +3071,16 @@ def _objective_expression(self):
n=lifetime,
wacc=interest,
)
investment_costs_increment = (
self.invest[g, p]
* annuity
* lifetime
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
duration = min(
end_of_optimization - m.es.periods_years[p],
lifetime,
)
remaining_value = 0
if lifetime > m.es.periods_matrix[p, -1]:
remaining_lifetime = (
lifetime - m.es.periods_matrix[p, -1]
)
remaining_annuity = economics.annuity(
capex=g.investment.ep_costs[-1],
n=lifetime,
wacc=interest,
)
remaining_value = (
self.invest[g, p]
* remaining_annuity
* remaining_lifetime
) * (
(1 + m.discount_rate)
** (-m.es.periods_years[-1])
)
investment_costs_increment -= remaining_value
present_value_factor = 1 / economics.annuity(
capex=1, n=duration, wacc=m.discount_rate
)
investment_costs_increment = (
self.invest[g, p] * annuity * present_value_factor
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])
investment_costs += investment_costs_increment
period_investment_costs[
p
Expand All @@ -3126,7 +3093,7 @@ def _objective_expression(self):
self.dsm_up[g, t]
* m.objective_weighting[t]
* g.cost_dsm_up[t]
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
* (1 + m.discount_rate) ** (-m.es.periods_years[p])
)
variable_costs += (
(
Expand All @@ -3138,47 +3105,36 @@ def _objective_expression(self):
+ self.dsm_do_shed[g, t] * g.cost_dsm_down_shed[t]
)
* m.objective_weighting[t]
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
* (1 + m.discount_rate) ** (-m.es.periods_years[p])
)

if g.investment.fixed_costs[0] is not None:
lifetime = g.investment.lifetime
for p in m.PERIODS:
range_limit = min(
end_of_optimization,
m.es.periods_years[p] + lifetime,
)
fixed_costs += sum(
self.invest[g, p]
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(
m.es.periods_years[p],
m.es.periods_years[p] + lifetime,
)
) * ((1 + m.discount_rate) ** -m.es.periods_years[p])
if lifetime > m.es.periods_matrix[p, -1]:
fixed_costs -= sum(
self.invest[g, p]
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(
m.es.periods_years[-1],
m.es.periods_years[p] + lifetime,
)
) * (
(1 + m.discount_rate)
** (-m.es.periods_years[-1])
range_limit,
)
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])

for g in self.EXISTING_INVESTDSM:
if g.investment.fixed_costs[0] is not None:
lifetime = g.investment.lifetime
age = g.investment.age
range_limit = min(
m.es.periods_matrix[0, -1], lifetime - age
)
range_limit = min(end_of_optimization, lifetime - age)
fixed_costs += sum(
g.investment.existing
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(0, range_limit)
* (1 + m.discount_rate) ** (-pp)
for pp in range(range_limit)
)

self.variable_costs = Expression(expr=variable_costs)
Expand Down Expand Up @@ -5466,6 +5422,10 @@ def _objective_expression(self):
"social planner point of view and does not reflect "
"microeconomic interest requirements."
)

duration_last_period = m.es.get_period_duration(-1)
end_of_optimization = m.es.periods_years[-1] + duration_last_period

for g in self.INVESTDR:
if g.investment.ep_costs is not None:
lifetime = g.investment.lifetime
Expand All @@ -5482,31 +5442,16 @@ def _objective_expression(self):
n=lifetime,
wacc=interest,
)
investment_costs_increment = (
self.invest[g, p]
* annuity
* lifetime
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
duration = min(
end_of_optimization - m.es.periods_years[p],
lifetime,
)
remaining_value = 0
if lifetime > m.es.periods_matrix[p, -1]:
remaining_lifetime = (
lifetime - m.es.periods_matrix[p, -1]
)
remaining_annuity = economics.annuity(
capex=g.investment.ep_costs[-1],
n=lifetime,
wacc=interest,
)
remaining_value = (
self.invest[g, p]
* remaining_annuity
* remaining_lifetime
) * (
(1 + m.discount_rate)
** (-m.es.periods_years[-1])
)
investment_costs_increment -= remaining_value
present_value_factor = 1 / economics.annuity(
capex=1, n=duration, wacc=m.discount_rate
)
investment_costs_increment = (
self.invest[g, p] * annuity * present_value_factor
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])
investment_costs += investment_costs_increment
period_investment_costs[
p
Expand All @@ -5525,7 +5470,7 @@ def _objective_expression(self):
* g.cost_dsm_up[t]
)
* m.objective_weighting[t]
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
* (1 + m.discount_rate) ** (-m.es.periods_years[p])
)
variable_costs += (
(
Expand All @@ -5538,47 +5483,36 @@ def _objective_expression(self):
+ self.dsm_do_shed[g, t] * g.cost_dsm_down_shed[t]
)
* m.objective_weighting[t]
* ((1 + m.discount_rate) ** -m.es.periods_years[p])
* (1 + m.discount_rate) ** (-m.es.periods_years[p])
)

if g.investment.fixed_costs[0] is not None:
lifetime = g.investment.lifetime
for p in m.PERIODS:
range_limit = min(
end_of_optimization,
m.es.periods_years[p] + lifetime,
)
fixed_costs += sum(
self.invest[g, p]
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(
m.es.periods_years[p],
m.es.periods_years[p] + lifetime,
)
) * ((1 + m.discount_rate) ** -m.es.periods_years[p])
if lifetime > m.es.periods_matrix[p, -1]:
fixed_costs -= sum(
self.invest[g, p]
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(
m.es.periods_years[-1],
m.es.periods_years[p] + lifetime,
)
) * (
(1 + m.discount_rate)
** (-m.es.periods_years[-1])
range_limit,
)
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])

for g in self.EXISTING_INVESTDSM:
if g.investment.fixed_costs[0] is not None:
lifetime = g.investment.lifetime
age = g.investment.age
range_limit = min(
m.es.periods_matrix[0, -1], lifetime - age
)
range_limit = min(end_of_optimization, lifetime - age)
fixed_costs += sum(
g.investment.existing
* g.investment.fixed_costs[pp]
* ((1 + m.discount_rate) ** (-pp))
for pp in range(0, range_limit)
for pp in range(range_limit)
)

self.variable_costs = Expression(expr=variable_costs)
Expand Down

0 comments on commit f29af6d

Please sign in to comment.