mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-02 17:31:08 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
a547676800
commit
ddf9b59866
|
@ -4,8 +4,15 @@ from collections import deque
|
|||
class BlossomAuxData:
|
||||
"""Class to hold auxiliary data during the blossom algorithm's execution."""
|
||||
|
||||
def __init__(self, queue: deque, parent: list[int], base: list[int],
|
||||
in_blossom: list[bool], match: list[int], in_queue: list[bool]):
|
||||
def __init__(
|
||||
self,
|
||||
queue: deque,
|
||||
parent: list[int],
|
||||
base: list[int],
|
||||
in_blossom: list[bool],
|
||||
match: list[int],
|
||||
in_queue: list[bool],
|
||||
):
|
||||
self.queue = queue
|
||||
self.parent = parent
|
||||
self.base = base
|
||||
|
@ -87,9 +94,9 @@ class EdmondsBlossomAlgorithm:
|
|||
parent[y] = current # Update the parent
|
||||
augmenting_path_found = True
|
||||
# Augment along this path
|
||||
EdmondsBlossomAlgorithm.update_matching(match,
|
||||
parent,
|
||||
y)
|
||||
EdmondsBlossomAlgorithm.update_matching(
|
||||
match, parent, y
|
||||
)
|
||||
break
|
||||
|
||||
# Case 2: y is matched; add y's match to the queue
|
||||
|
@ -102,16 +109,25 @@ class EdmondsBlossomAlgorithm:
|
|||
else:
|
||||
# Case 3: Both current and y have a parent;
|
||||
# check for a cycle/blossom
|
||||
base_u = EdmondsBlossomAlgorithm.find_base(base,
|
||||
parent,
|
||||
current,
|
||||
y)
|
||||
base_u = EdmondsBlossomAlgorithm.find_base(
|
||||
base, parent, current, y
|
||||
)
|
||||
if base_u != EdmondsBlossomAlgorithm.UNMATCHED:
|
||||
EdmondsBlossomAlgorithm.contract_blossom(BlossomData(
|
||||
BlossomAuxData(queue, parent,
|
||||
base, in_blossom,
|
||||
match, in_queue),
|
||||
current, y, base_u))
|
||||
EdmondsBlossomAlgorithm.contract_blossom(
|
||||
BlossomData(
|
||||
BlossomAuxData(
|
||||
queue,
|
||||
parent,
|
||||
base,
|
||||
in_blossom,
|
||||
match,
|
||||
in_queue,
|
||||
),
|
||||
current,
|
||||
y,
|
||||
base_u,
|
||||
)
|
||||
)
|
||||
|
||||
# Create result list of matched pairs
|
||||
matching_result = []
|
||||
|
@ -181,16 +197,20 @@ class EdmondsBlossomAlgorithm:
|
|||
blossom_data: The data related to the blossom to be contracted.
|
||||
"""
|
||||
# Mark vertices in the blossom
|
||||
for x in range(blossom_data.u,
|
||||
blossom_data.aux_data.base[blossom_data.u] != blossom_data.lca):
|
||||
for x in range(
|
||||
blossom_data.u,
|
||||
blossom_data.aux_data.base[blossom_data.u] != blossom_data.lca,
|
||||
):
|
||||
base_x = blossom_data.aux_data.base[x]
|
||||
match_base_x = blossom_data.aux_data.base[blossom_data.aux_data.match[x]]
|
||||
# Mark the base as in a blossom
|
||||
blossom_data.aux_data.in_blossom[base_x] = True
|
||||
blossom_data.aux_data.in_blossom[match_base_x] = True
|
||||
|
||||
for x in range(blossom_data.v,
|
||||
blossom_data.aux_data.base[blossom_data.v] != blossom_data.lca):
|
||||
for x in range(
|
||||
blossom_data.v,
|
||||
blossom_data.aux_data.base[blossom_data.v] != blossom_data.lca,
|
||||
):
|
||||
base_x = blossom_data.aux_data.base[x]
|
||||
match_base_x = blossom_data.aux_data.base[blossom_data.aux_data.match[x]]
|
||||
# Mark the base as in a blossom
|
||||
|
|
Loading…
Reference in New Issue
Block a user