Skip to content

Commit

Permalink
rename method to .in_branches
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 369498b commit e81346f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 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,10 +73,10 @@ 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."""
def in_branches(self, node_id: int) -> Generator[tuple[int, int], None, None]:
"""Return all branches that have the node as an endpoint."""
int_node_id = self.external_to_internal(node_id)
internal_edges = self._in_edges(int_node_id=int_node_id)
internal_edges = self._in_branches(int_node_id=int_node_id)
return (
(self.internal_to_external(source), self.internal_to_external(target)) for source, target in internal_edges
)
Expand Down Expand Up @@ -194,9 +194,9 @@ def tmp_remove_nodes(self, nodes: list[int]) -> Generator:
"""
edge_list = []
for node in nodes:
internal_node = self.external_to_internal(node)
edge_list += list(self.in_edges(node))
self._delete_node(internal_node)
edge_list += list(self.in_branches(node))
self.delete_node(node)

yield

for node in nodes:
Expand Down Expand Up @@ -311,7 +311,7 @@ def _branch_is_relevant(self, branch: BranchArray) -> bool:
return True

@abstractmethod
def _in_edges(self, int_node_id: int) -> Generator[tuple[int, int], None, None]:
def _in_branches(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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _get_connected(self, node_id: int, nodes_to_ignore: list[int], inclusive: bo

return connected_nodes

def _in_edges(self, int_node_id: int) -> Generator[tuple[int, int], None, None]:
def _in_branches(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]]:
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/model/graphs/test_graph_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def test_graph_all_branches_parallel(graph):
assert [(1, 2), (1, 2), (2, 1)] == list(graph.all_branches)


def test_graph_in_edges(graph):
def test_graph_in_branches(graph):
graph.add_node(1)
graph.add_node(2)
graph.add_branch(1, 2)
graph.add_branch(1, 2)
graph.add_branch(2, 1)

assert [(2, 1), (2, 1), (2, 1)] == list(graph.in_edges(1))
assert [(1, 2), (1, 2), (1, 2)] == list(graph.in_edges(2))
assert [(2, 1), (2, 1), (2, 1)] == list(graph.in_branches(1))
assert [(1, 2), (1, 2), (1, 2)] == list(graph.in_branches(2))


def test_graph_delete_branch(graph):
Expand Down

0 comments on commit e81346f

Please sign in to comment.