Skip to content

Commit

Permalink
Move Node functionality from Entity to Node
Browse files Browse the repository at this point in the history
This cleanup seems to have been forgotten when the Entity was
introduced to replace the former Node that was parent to Edge.
  • Loading branch information
p-snft committed Sep 29, 2023
1 parent 2c298a7 commit 1effd37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
29 changes: 1 addition & 28 deletions src/oemof/network/network/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

from functools import total_ordering

from .helpers import Inputs
from .helpers import Outputs


@total_ordering
class Entity:
"""Represents an Entity in an energy system graph.
Expand Down Expand Up @@ -50,12 +46,10 @@ class Entity:
information.
"""

__slots__ = ["_label", "_in_edges", "_inputs", "_outputs"]
__slots__ = ["_label"]

def __init__(self, *args, **kwargs):
args = list(args)
self._inputs = Inputs(self)
self._outputs = Outputs(self)
for optional in ["label"]:
if optional in kwargs:
if args:
Expand Down Expand Up @@ -107,24 +101,3 @@ def label(self):
@label.setter
def label(self, label):
self._label = label

@property
def inputs(self):
"""dict:
Dictionary mapping input :class:`Entities <Entity>` :obj:`n` to
:class:`Edge`s from :obj:`n` into :obj:`self`.
If :obj:`self` is an :class:`Edge`, returns a dict containing the
:class:`Edge`'s single input node as the key and the flow as the value.
"""
return self._inputs

@property
def outputs(self):
"""dict:
Dictionary mapping output :class:`Entities <Entity>` :obj:`n` to
:class:`Edges` from :obj:`self` into :obj:`n`.
If :obj:`self` is an :class:`Edge`, returns a dict containing the
:class:`Edge`'s single output node as the key and the flow as the
value.
"""
return self._outputs
27 changes: 27 additions & 0 deletions src/oemof/network/network/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from .edge import Edge
from .entity import Entity
from .helpers import Inputs
from .helpers import Outputs


class Node(Entity):
Expand All @@ -29,9 +31,13 @@ class Node(Entity):
output nodes to corresponding outflows (i.e. output values).
"""

__slots__ = ["_in_edges", "_inputs", "_outputs"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self._inputs = Inputs(self)
self._outputs = Outputs(self)
self._in_edges = set()

msg = "{} {!r} of {!r} not an instance of Node but of {}."
Expand All @@ -58,6 +64,27 @@ def __init__(self, *args, **kwargs):
edge.input = self
edge.output = o

@property
def inputs(self):
"""dict:
Dictionary mapping input :class:`Entities <Entity>` :obj:`n` to
:class:`Edge`s from :obj:`n` into :obj:`self`.
If :obj:`self` is an :class:`Edge`, returns a dict containing the
:class:`Edge`'s single input node as the key and the flow as the value.
"""
return self._inputs

@property
def outputs(self):
"""dict:
Dictionary mapping output :class:`Entities <Entity>` :obj:`n` to
:class:`Edges` from :obj:`self` into :obj:`n`.
If :obj:`self` is an :class:`Edge`, returns a dict containing the
:class:`Edge`'s single output node as the key and the flow as the
value.
"""
return self._outputs


class Bus(Node):
pass
Expand Down

0 comments on commit 1effd37

Please sign in to comment.