Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Node functionality from Entity to Node #30

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions src/oemof/network/network/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

from functools import total_ordering

from .helpers import Inputs
from .helpers import Outputs


@total_ordering
class Entity:
Expand Down Expand Up @@ -56,9 +53,6 @@ class Entity:

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

Expand All @@ -67,8 +61,6 @@ def __init__(self, label=None, *, custom_properties=None, **kwargs):
if custom_properties is None:
custom_properties = {}
self.custom_properties = custom_properties
self._inputs = Inputs(self)
self._outputs = Outputs(self)

def __eq__(self, other):
return id(self) == id(other)
Expand Down Expand Up @@ -105,24 +97,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 @@ -15,6 +15,8 @@

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


class Node(Entity):
Expand All @@ -40,9 +42,13 @@ class Node(Entity):
A dictionary mapping output nodes to corresponding outflows.
"""

__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 @@ -69,6 +75,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


_deprecation_warning = (
"Usage of {} is deprecated. Use oemof.network.Node instead."
Expand Down
Loading