Skip to content

Commit 1750670

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ebb8055 commit 1750670

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

graphs/edmonds_blossom_algorithm.py

+35-20
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
class BlossomAuxData:
55
"""Class to hold auxiliary data during the blossom algorithm's execution."""
66

7-
def __init__(self, queue: deque, parent: list[int], base: list[int],
8-
in_blossom: list[bool],
9-
match: list[int], in_queue: list[bool]) -> None:
7+
def __init__(
8+
self,
9+
queue: deque,
10+
parent: list[int],
11+
base: list[int],
12+
in_blossom: list[bool],
13+
match: list[int],
14+
in_queue: list[bool],
15+
) -> None:
1016
"""
1117
Initializes the BlossomAuxData instance.
1218
@@ -29,9 +35,13 @@ def __init__(self, queue: deque, parent: list[int], base: list[int],
2935
class BlossomData:
3036
"""Class to encapsulate data related to a blossom in the graph."""
3137

32-
def __init__(self, aux_data: BlossomAuxData,
33-
vertex_u: int, vertex_v: int,
34-
lowest_common_ancestor: int) -> None:
38+
def __init__(
39+
self,
40+
aux_data: BlossomAuxData,
41+
vertex_u: int,
42+
vertex_v: int,
43+
lowest_common_ancestor: int,
44+
) -> None:
3545
"""
3646
Initializes the BlossomData instance.
3747
@@ -152,16 +162,17 @@ def maximum_matching(edges: list[list[int]], vertex_count: int) -> list[list[int
152162
# Create result list of matched pairs
153163
matching_result: list[list[int]] = []
154164
for v in range(vertex_count):
155-
if (match[v] != EdmondsBlossomAlgorithm.UNMATCHED
156-
and v < match[v]): # Ensure pairs are unique
165+
if (
166+
match[v] != EdmondsBlossomAlgorithm.UNMATCHED and v < match[v]
167+
): # Ensure pairs are unique
157168
matching_result.append([v, match[v]])
158169

159170
return matching_result
160171

161172
@staticmethod
162-
def update_matching(match: list[int],
163-
parent: list[int],
164-
matched_vertex: int) -> None:
173+
def update_matching(
174+
match: list[int], parent: list[int], matched_vertex: int
175+
) -> None:
165176
"""
166177
Updates the matching based on the augmenting path found.
167178
@@ -178,9 +189,9 @@ def update_matching(match: list[int],
178189
matched_vertex = next_match # Move to the next vertex
179190

180191
@staticmethod
181-
def find_base(base: list[int],
182-
parent: list[int],
183-
vertex_u: int, vertex_v: int) -> int:
192+
def find_base(
193+
base: list[int], parent: list[int], vertex_u: int, vertex_v: int
194+
) -> int:
184195
"""
185196
Finds the base of the blossom.
186197
@@ -223,18 +234,22 @@ def contract_blossom(blossom_data: BlossomData) -> None:
223234
blossom_data: The data related to the blossom to be contracted.
224235
"""
225236
# Mark vertices in the blossom
226-
for x in range(blossom_data.vertex_u,
227-
blossom_data.aux_data.base
228-
[blossom_data.vertex_u] != blossom_data.lowest_common_ancestor):
237+
for x in range(
238+
blossom_data.vertex_u,
239+
blossom_data.aux_data.base[blossom_data.vertex_u]
240+
!= blossom_data.lowest_common_ancestor,
241+
):
229242
base_x = blossom_data.aux_data.base[x]
230243
match_base_x = blossom_data.aux_data.base[blossom_data.aux_data.match[x]]
231244
# Mark the base as in a blossom
232245
blossom_data.aux_data.in_blossom[base_x] = True
233246
blossom_data.aux_data.in_blossom[match_base_x] = True
234247

235-
for x in range(blossom_data.vertex_v,
236-
blossom_data.aux_data.base
237-
[blossom_data.vertex_v] != blossom_data.lowest_common_ancestor):
248+
for x in range(
249+
blossom_data.vertex_v,
250+
blossom_data.aux_data.base[blossom_data.vertex_v]
251+
!= blossom_data.lowest_common_ancestor,
252+
):
238253
base_x = blossom_data.aux_data.base[x]
239254
match_base_x = blossom_data.aux_data.base[blossom_data.aux_data.match[x]]
240255
# Mark the base as in a blossom

0 commit comments

Comments
 (0)