From 300f3b58a544d242f6cb3264bd4c6fe93307bab4 Mon Sep 17 00:00:00 2001 From: Nicco Date: Sat, 5 Oct 2024 11:30:37 -0400 Subject: [PATCH] Removed unnecessary graph duplication, fixed 3-connectivity check, optimized unnecessary call to .index() --- src/sage/graphs/generic_graph.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index b87dcaeaf89..ccbb125b4f4 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -21058,16 +21058,16 @@ def layout_tutte(self, external_face, external_face_pos=None, **options): if (len(external_face) < 3): raise ValueError("External face must have at least 3 vertices") - G = Graph(self) - if (not G.is_planar()): + if (not self.is_planar()): raise ValueError("Graph must be planar") - C = G.subgraph(vertices=external_face) - if (not C.is_cycle()): + + C = self.subgraph(vertices=external_face) + if (not C.is_cycle(directed_cycle=False)): raise ValueError("External face must be a cycle") - external_face_ordered = C.depth_first_search(start=external_face[0]) + external_face_ordered = C.depth_first_search(start=external_face[0], ignore_direction=False) from sage.graphs.connectivity import vertex_connectivity - if (vertex_connectivity(G, k=4)): + if (not vertex_connectivity(self, k=3)): raise ValueError("Graph must be 3-connected") from math import sin, cos, pi @@ -21088,6 +21088,7 @@ def layout_tutte(self, external_face, external_face_pos=None, **options): M = zero_matrix(RR,n,n) b = zero_matrix(RR,n,2) + vertices_to_indices = {v:i for i,v in enumerate(V)} for i in range(n): v = V[i] if v in pos: @@ -21095,9 +21096,9 @@ def layout_tutte(self, external_face, external_face_pos=None, **options): b[i,0] = pos[v][0] b[i,1] = pos[v][1] else: - nv = G.neighbors(v) + nv = self.neighbors(v) for u in nv: - j = V.index(u) + j = vertices_to_indices[u] M[i,j] = -1 M[i,i] = len(nv) @@ -21425,7 +21426,7 @@ def plot(self, **options): depending on minimum distance for the root. - ``'tutte'`` -- uses the Tutte embedding algorithm. The graph must be - a 3-connected, planar graph. + a 3-connected, planar graph. - ``vertex_labels`` -- boolean (default: ``True``); whether to print vertex labels