@@ -3001,7 +3001,7 @@ def is_chordal_bipartite(self, certificate=False):
3001
3001
sage: len(cycle) == 6
3002
3002
True
3003
3003
3004
- A 2 x ` n` grid graph is chordal bipartite::
3004
+ A `2 \times n` grid graph is chordal bipartite::
3005
3005
3006
3006
sage: g = graphs.Grid2dGraph(2, 6)
3007
3007
sage: result, pewveo = g.is_chordal_bipartite(certificate=True)
@@ -3073,12 +3073,10 @@ def is_chordal_bipartite(self, certificate=False):
3073
3073
b , certif = gg .is_chordal_bipartite (certificate = True )
3074
3074
if not b :
3075
3075
return False , certif
3076
- else :
3077
- pewveo .extend (certif )
3076
+ pewveo .extend (certif )
3078
3077
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 ())
3082
3080
3083
3081
left = [v for v , c in bipartite_certificate .items () if c == 0 ]
3084
3082
right = [v for v , c in bipartite_certificate .items () if c == 1 ]
@@ -3113,27 +3111,25 @@ def is_chordal_bipartite(self, certificate=False):
3113
3111
if is_Gamma_free :
3114
3112
pewveo = dict ()
3115
3113
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
3123
3119
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 ]])
3125
3121
return True , edges
3126
3122
3127
3123
# Find a chordless cycle of length at least 6
3128
3124
r1 , c1 , r2 , c2 = Gamma_submatrix_indices
3129
3125
row_indices = [r1 , r2 ]
3130
3126
col_indices = [c1 , c2 ]
3131
- while B [row_indices [- 1 ]][ col_indices [- 1 ]] == 0 :
3127
+ while not B [row_indices [- 1 ], col_indices [- 1 ]]:
3132
3128
# find the rightmost column with different value
3133
3129
# in row_indices[-2] and row_indices[-1]
3134
3130
col = order_right - 1
3135
3131
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 ]:
3137
3133
break
3138
3134
col -= 1
3139
3135
assert col > col_indices [- 1 ]
@@ -3142,7 +3138,7 @@ def is_chordal_bipartite(self, certificate=False):
3142
3138
# in col_indices[-2] and col_indices[-1]
3143
3139
row = order_left - 1
3144
3140
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 ]]:
3146
3142
break
3147
3143
row -= 1
3148
3144
assert row > row_indices [- 1 ]
0 commit comments