Skip to content

Commit

Permalink
make .in_edges a public method
Browse files Browse the repository at this point in the history
Signed-off-by: Thijs Baaijen <[email protected]>
  • Loading branch information
Thijss committed Jan 28, 2025
1 parent 4cb80a4 commit 3a10746
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/power_grid_model_ds/_core/model/graphs/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def has_node(self, node_id: int) -> bool:

return self._has_node(node_id=internal_node_id)

def in_edges(self, node_id: int) -> Generator[tuple[int, int], None, None]:
"""Return all edges a node occurs in."""
int_node_id = self.external_to_internal(node_id)
internal_edges = self._in_edges(int_node_id=int_node_id)
return ((self.internal_to_external(source), self.internal_to_external(target)) for source, target in internal_edges)

Check failure on line 80 in src/power_grid_model_ds/_core/model/graphs/models/base.py

View workflow job for this annotation

GitHub Actions / check-code-quality

Ruff (E501)

src/power_grid_model_ds/_core/model/graphs/models/base.py:80:121: E501 Line too long (124 > 120)

def add_node(self, ext_node_id: int, raise_on_fail: bool = True) -> None:
"""Add a node to the graph."""
if self.has_node(ext_node_id):
Expand Down Expand Up @@ -187,11 +193,7 @@ def tmp_remove_nodes(self, nodes: list[int]) -> Generator:
edge_list = []
for node in nodes:
internal_node = self.external_to_internal(node)
node_edges = [
(self.internal_to_external(source), self.internal_to_external(target))
for source, target in self._in_edges(internal_node)
]
edge_list += node_edges
edge_list += list(self.in_edges(node))
self._delete_node(internal_node)
yield

Expand Down Expand Up @@ -307,10 +309,10 @@ def _branch_is_relevant(self, branch: BranchArray) -> bool:
return True

@abstractmethod
def _in_edges(self, internal_node: int) -> list[tuple[int, int]]:
def _in_edges(self, int_node_id: int) -> Generator[tuple[int, int], None, None]:
"""Return all edges a node occurs in.
Return a list of tuples with the source and target node id. These are internal node ids.
Return a list of tuples with the source and target node id.
These are internal node ids.
"""

@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def _get_connected(self, node_id: int, nodes_to_ignore: list[int], inclusive: bo

return connected_nodes

def _in_edges(self, internal_node: int) -> list[tuple[int, int]]:
return [(source, target) for source, target, _ in self._graph.in_edges(internal_node)]
def _in_edges(self, int_node_id: int) -> Generator[tuple[int, int], None, None]:
return ((source, target) for source, target, _ in self._graph.in_edges(int_node_id))

def _find_fundamental_cycles(self) -> list[list[int]]:
"""Find all fundamental cycles in the graph using Rustworkx.
Expand Down

0 comments on commit 3a10746

Please sign in to comment.