Skip to content

Commit d747def

Browse files
author
Release Manager
committed
sagemathgh-39065: Implemented methods concerning bricks and braces of a matching covered graph <!-- ^ Please provide a concise and informative title. --> The objective of this issue is to implement the methods pertaining to the bricks and brace of a matching covered graph. <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> More specifically, this PR aims to implement the following two methods: <!-- - [ ] `bricks_and_braces()` | Return the list of (underlying simple graph of) the bricks and braces of the (matching covered) graph. --> - [x] `is_brace()` | Check if the (matching covered) graph is a brace - [x] `is_brick()` | Check if the (matching covered) graph is a brick. <!-- - [ ] `number_of_braces()` | Return the number of braces. --> <!-- - [ ] `number_of_bricks()` | Return the number of bricks. --> <!-- - [ ] `number_of_petersen_bricks()` | Return the number of Petersen bricks. --> <!-- - [ ] `tight_cut_decomposition()` | Return a tight cut decomposition. --> <!-- v Why is this change required? What problem does it solve? --> This PR shall address the methods related to bricks, braces and tight cut decomposition of matching covered graphs. <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Fixes sagemath#38216. Note that this issue fixes a small part of the mentioned issue. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies This PR depends on the PR sagemath#38742 and sagemath#38892. <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> cc: @dcoudert. URL: sagemath#39065 Reported by: Janmenjaya Panda Reviewer(s): David Coudert, Janmenjaya Panda, user202729
2 parents 3f14bcf + e12674a commit d747def

File tree

2 files changed

+883
-81
lines changed

2 files changed

+883
-81
lines changed

src/sage/graphs/matching.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ def is_matching_covered(G, matching=None, algorithm='Edmonds', coNP_certificate=
877877
sage: H = graphs.PathGraph(20)
878878
sage: M = H.matching()
879879
sage: H.is_matching_covered(matching=M, coNP_certificate=True)
880-
(False, (1, 2, None))
880+
(False, (2, 1, None))
881881
882882
TESTS:
883883
@@ -1019,44 +1019,33 @@ def is_matching_covered(G, matching=None, algorithm='Edmonds', coNP_certificate=
10191019
if color[u]:
10201020
u, v = v, u
10211021

1022-
if M.has_edge(u, v):
1023-
H.add_edge(u, v)
1024-
else:
1025-
H.add_edge(v, u)
1022+
H.add_edge((u, v))
1023+
if next(M.neighbor_iterator(u)) == v:
1024+
H.add_edge((v, u))
10261025

10271026
# Check if H is strongly connected using Kosaraju's algorithm
1028-
def dfs(J, v, visited, orientation):
1027+
def dfs(v, visited, neighbor_iterator):
10291028
stack = [v] # a stack of vertices
10301029

10311030
while stack:
10321031
v = stack.pop()
1032+
visited.add(v)
10331033

1034-
if v not in visited:
1035-
visited[v] = True
1036-
1037-
if orientation == 'in':
1038-
for u in J.neighbors_out(v):
1039-
if u not in visited:
1040-
stack.append(u)
1041-
1042-
elif orientation == 'out':
1043-
for u in J.neighbors_in(v):
1044-
if u not in visited:
1045-
stack.append(u)
1046-
else:
1047-
raise ValueError('Unknown orientation')
1034+
for u in neighbor_iterator(v):
1035+
if u not in visited:
1036+
stack.append(u)
10481037

10491038
root = next(H.vertex_iterator())
10501039

1051-
visited_in = {}
1052-
dfs(H, root, visited_in, 'in')
1040+
visited_in = set()
1041+
dfs(root, visited_in, H.neighbor_in_iterator)
10531042

1054-
visited_out = {}
1055-
dfs(H, root, visited_out, 'out')
1043+
visited_out = set()
1044+
dfs(root, visited_out, H.neighbor_out_iterator)
10561045

10571046
for edge in H.edge_iterator():
10581047
u, v, _ = edge
1059-
if (u not in visited_in) or (v not in visited_out):
1048+
if (u not in visited_out) or (v not in visited_in):
10601049
if not M.has_edge(edge):
10611050
return (False, edge) if coNP_certificate else False
10621051

0 commit comments

Comments
 (0)