@@ -3001,7 +3001,7 @@ def is_chordal_bipartite(self, certificate=False):
30013001 sage: len(cycle) == 6
30023002 True
30033003
3004- A 2 x ` n` grid graph is chordal bipartite::
3004+ A `2 \times n` grid graph is chordal bipartite::
30053005
30063006 sage: g = graphs.Grid2dGraph(2, 6)
30073007 sage: result, pewveo = g.is_chordal_bipartite(certificate=True)
@@ -3073,12 +3073,10 @@ def is_chordal_bipartite(self, certificate=False):
30733073 b , certif = gg .is_chordal_bipartite (certificate = True )
30743074 if not b :
30753075 return False , certif
3076- else :
3077- pewveo .extend (certif )
3076+ pewveo .extend (certif )
30783077 return True , pewveo
3079- else :
3080- return all (gg .is_chordal_bipartite () for gg in
3081- self .connected_components_subgraphs ())
3078+ return all (gg .is_chordal_bipartite () for gg in
3079+ self .connected_components_subgraphs ())
30823080
30833081 left = [v for v , c in bipartite_certificate .items () if c == 0 ]
30843082 right = [v for v , c in bipartite_certificate .items () if c == 1 ]
@@ -3113,27 +3111,25 @@ def is_chordal_bipartite(self, certificate=False):
31133111 if is_Gamma_free :
31143112 pewveo = dict ()
31153113 order = 0
3116- for i in range (B .nrows ()):
3117- for j in range (B .ncols ()):
3118- if B [i ][j ] == 1 :
3119- v_i = row_vertices [i ]
3120- v_j = col_vertices [j ]
3121- pewveo [(v_i , v_j )] = order
3122- pewveo [(v_j , v_i )] = order
3114+ for i , vi in enumerate (row_vertices ):
3115+ for j , vj in enumerate (col_vertices ):
3116+ if B [i , j ] == 1 :
3117+ pewveo [vi , vj ] = order
3118+ pewveo [vj , vi ] = order
31233119 order += 1
3124- edges = self .edges (sort = True , key = lambda x : pewveo [( x [0 ], x [1 ]) ])
3120+ edges = self .edges (sort = True , key = lambda x : pewveo [x [0 ], x [1 ]])
31253121 return True , edges
31263122
31273123 # Find a chordless cycle of length at least 6
31283124 r1 , c1 , r2 , c2 = Gamma_submatrix_indices
31293125 row_indices = [r1 , r2 ]
31303126 col_indices = [c1 , c2 ]
3131- while B [row_indices [- 1 ]][ col_indices [- 1 ]] == 0 :
3127+ while not B [row_indices [- 1 ], col_indices [- 1 ]]:
31323128 # find the rightmost column with different value
31333129 # in row_indices[-2] and row_indices[-1]
31343130 col = order_right - 1
31353131 while col > col_indices [- 1 ]:
3136- if B [row_indices [- 2 ]][ col ] == 0 and B [row_indices [- 1 ]][ col ] == 1 :
3132+ if not B [row_indices [- 2 ], col ] and B [row_indices [- 1 ], col ]:
31373133 break
31383134 col -= 1
31393135 assert col > col_indices [- 1 ]
@@ -3142,7 +3138,7 @@ def is_chordal_bipartite(self, certificate=False):
31423138 # in col_indices[-2] and col_indices[-1]
31433139 row = order_left - 1
31443140 while row > row_indices [- 1 ]:
3145- if B [row ][ col_indices [- 2 ]] == 0 and B [row ][ col_indices [- 1 ]] == 1 :
3141+ if not B [row , col_indices [- 2 ]] and B [row , col_indices [- 1 ]]:
31463142 break
31473143 row -= 1
31483144 assert row > row_indices [- 1 ]
0 commit comments