Skip to content

Commit

Permalink
Merge pull request #68 from oemof/feature/excess-attributes
Browse files Browse the repository at this point in the history
Add functionality to Excess similar as Shortage
  • Loading branch information
jnnr committed Nov 23, 2022
2 parents b173f30 + d5e63d3 commit 049c4f0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
30 changes: 28 additions & 2 deletions src/oemof/tabular/facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,35 @@ def __init__(self, *args, **kwargs):

self.bus = kwargs.get("bus")

self.marginal_cost = kwargs.get("marginal_cost")
self.marginal_cost = kwargs.get("marginal_cost", 0)

self.capacity = kwargs.get("capacity")

self.capacity_potential = kwargs.get(
"capacity_potential", float("+inf")
)

self.capacity_cost = kwargs.get("capacity_cost")

self.capacity_minimum = kwargs.get("capacity_minimum")

self.expandable = bool(kwargs.get("expandable", False))

self.input_parameters = kwargs.get("input_parameters", {})

self.build_solph_components()

def build_solph_components(self):
"""
"""
f = Flow(
nominal_value=self._nominal_value(),
variable_costs=self.marginal_cost,
investment=self._investment(),
**self.input_parameters
)

self.inputs.update({self.bus: Flow(variable_costs=self.marginal_cost)})
self.inputs.update({self.bus: f})


class Shortage(Dispatchable):
Expand Down
30 changes: 30 additions & 0 deletions tests/_files/lp_files/excess.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
\* Source Pyomo model name=Model *\

min
objective:
+10 flow(electricity_excess_0)
+10 flow(electricity_excess_1)
+10 flow(electricity_excess_2)

s.t.

c_e_Bus_balance(electricity_0)_:
+1 flow(electricity_excess_0)
= 0

c_e_Bus_balance(electricity_1)_:
+1 flow(electricity_excess_1)
= 0

c_e_Bus_balance(electricity_2)_:
+1 flow(electricity_excess_2)
= 0

c_e_ONE_VAR_CONSTANT:
ONE_VAR_CONSTANT = 1.0

bounds
0 <= flow(electricity_excess_0) <= 1000
0 <= flow(electricity_excess_1) <= 1000
0 <= flow(electricity_excess_2) <= 1000
end
21 changes: 18 additions & 3 deletions tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import pandas as pd

from oemof import solph
from oemof.solph import helpers
import oemof.solph as solph

from oemof.tabular.facades import (BackpressureTurbine, Commodity, Conversion,
Dispatchable, ExtractionTurbine, Link, Load,
Reservoir, Storage, Volatile)
Dispatchable, Excess, ExtractionTurbine,
Link, Load, Reservoir, Storage, Volatile)


def chop_trailing_whitespace(lines):
Expand Down Expand Up @@ -345,6 +345,21 @@ def test_dispatchable(self):

self.compare_to_reference_lp("dispatchable.lp")

def test_excess(self):
bus = solph.Bus("electricity")

excess = Excess(
label='excess',
bus=bus,
carrier='electricity',
tech='excess',
capacity=1000,
marginal_cost=10,
)
self.energysystem.add(bus, excess)

self.compare_to_reference_lp("excess.lp")

def test_link(self):
r"""
"""
Expand Down
5 changes: 1 addition & 4 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import importlib
import pathlib

import pkg_resources as pkg

from oemof.network.energy_system import EnergySystem as ES

from oemof.tabular.facades import TYPEMAP

# The import below is only used to monkey patch `EnergySystem`.
# Hence the `noqa` because otherwise, style checkers would complain about an
# unused import.
Expand Down Expand Up @@ -70,7 +68,6 @@ def test_custom_foreign_keys(monkeypatch):
"OEMOF_TABULAR_FOREIGN_KEYS_FILE",
ROOT_DIR / "tests" / "custom_foreign_keys.json"
)
import importlib
importlib.reload(oemof.tabular.config.config)
oemof.tabular.datapackage.building.infer_metadata(
path=str(
Expand Down

0 comments on commit 049c4f0

Please sign in to comment.