Skip to content

Commit ddf9b59

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

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

graphs/edmonds_blossom_algorithm.py

+38-18
Original file line numberDiff line numberDiff line change
@@ -4,8 +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], match: list[int], in_queue: list[bool]):
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+
):
916
self.queue = queue
1017
self.parent = parent
1118
self.base = base
@@ -87,9 +94,9 @@ def maximum_matching(edges: list[list[int]], vertex_count: int) -> list[list[int
8794
parent[y] = current # Update the parent
8895
augmenting_path_found = True
8996
# Augment along this path
90-
EdmondsBlossomAlgorithm.update_matching(match,
91-
parent,
92-
y)
97+
EdmondsBlossomAlgorithm.update_matching(
98+
match, parent, y
99+
)
93100
break
94101

95102
# Case 2: y is matched; add y's match to the queue
@@ -102,16 +109,25 @@ def maximum_matching(edges: list[list[int]], vertex_count: int) -> list[list[int
102109
else:
103110
# Case 3: Both current and y have a parent;
104111
# check for a cycle/blossom
105-
base_u = EdmondsBlossomAlgorithm.find_base(base,
106-
parent,
107-
current,
108-
y)
112+
base_u = EdmondsBlossomAlgorithm.find_base(
113+
base, parent, current, y
114+
)
109115
if base_u != EdmondsBlossomAlgorithm.UNMATCHED:
110-
EdmondsBlossomAlgorithm.contract_blossom(BlossomData(
111-
BlossomAuxData(queue, parent,
112-
base, in_blossom,
113-
match, in_queue),
114-
current, y, base_u))
116+
EdmondsBlossomAlgorithm.contract_blossom(
117+
BlossomData(
118+
BlossomAuxData(
119+
queue,
120+
parent,
121+
base,
122+
in_blossom,
123+
match,
124+
in_queue,
125+
),
126+
current,
127+
y,
128+
base_u,
129+
)
130+
)
115131

116132
# Create result list of matched pairs
117133
matching_result = []
@@ -181,16 +197,20 @@ def contract_blossom(blossom_data: BlossomData):
181197
blossom_data: The data related to the blossom to be contracted.
182198
"""
183199
# Mark vertices in the blossom
184-
for x in range(blossom_data.u,
185-
blossom_data.aux_data.base[blossom_data.u] != blossom_data.lca):
200+
for x in range(
201+
blossom_data.u,
202+
blossom_data.aux_data.base[blossom_data.u] != blossom_data.lca,
203+
):
186204
base_x = blossom_data.aux_data.base[x]
187205
match_base_x = blossom_data.aux_data.base[blossom_data.aux_data.match[x]]
188206
# Mark the base as in a blossom
189207
blossom_data.aux_data.in_blossom[base_x] = True
190208
blossom_data.aux_data.in_blossom[match_base_x] = True
191209

192-
for x in range(blossom_data.v,
193-
blossom_data.aux_data.base[blossom_data.v] != blossom_data.lca):
210+
for x in range(
211+
blossom_data.v,
212+
blossom_data.aux_data.base[blossom_data.v] != blossom_data.lca,
213+
):
194214
base_x = blossom_data.aux_data.base[x]
195215
match_base_x = blossom_data.aux_data.base[blossom_data.aux_data.match[x]]
196216
# Mark the base as in a blossom

0 commit comments

Comments
 (0)