@@ -232,15 +232,13 @@ def is_line_graph(g, certificate=False):
232
232
R, isom = root_graph(g)
233
233
if certificate:
234
234
return True, R, isom
235
- else:
236
- return True
235
+ return True
237
236
except ValueError as VE:
238
237
if str(VE) == "this graph is not a line graph !":
239
238
# g is not a line graph
240
239
if certificate:
241
240
return False, get_certificate(g)
242
- else:
243
- return False
241
+ return False
244
242
raise VE
245
243
246
244
# g is not connected, so we apply the above procedure to each connected
@@ -256,15 +254,13 @@ def is_line_graph(g, certificate=False):
256
254
# gg is not a line graph
257
255
if certificate:
258
256
return False, get_certificate(gg)
259
- else:
260
- return False
257
+ return False
261
258
raise VE
262
259
263
260
if certificate:
264
261
_, isom = g.is_isomorphic(R.line_graph(labels=False), certificate=True)
265
262
return True, R, isom
266
- else:
267
- return True
263
+ return True
268
264
269
265
270
266
def line_graph(g, labels=True):
@@ -366,54 +362,52 @@ def line_graph(g, labels=True):
366
362
G. add_edges(( e, f) for e in g. incoming_edge_iterator( v, labels=labels)
367
363
for f in g. outgoing_edge_iterator( v, labels=labels))
368
364
return G
369
- else:
370
- from sage. graphs. graph import Graph
371
- G = Graph( )
372
-
373
- # We must sort the edges' endpoints so that ( 1,2,None) is seen as the
374
- # same edge as ( 2,1,None) .
375
- #
376
- # We do so by comparing hashes, just in case all the natural order ( <)
377
- # on vertices would not be a total order ( for instance when vertices are
378
- # sets) . If two adjacent vertices have the same hash, then we store the
379
- # pair in the dictionary of conflicts
380
365
381
- # 1) List of vertices in the line graph
382
-
383
- for e in g. edge_iterator( labels=labels) :
366
+ from sage. graphs. graph import Graph
367
+ G = Graph( )
368
+
369
+ # We must sort the edges' endpoints so that ( 1,2,None) is seen as the
370
+ # same edge as ( 2,1,None) .
371
+ #
372
+ # We do so by comparing hashes, just in case all the natural order ( <)
373
+ # on vertices would not be a total order ( for instance when vertices are
374
+ # sets) . If two adjacent vertices have the same hash, then we store the
375
+ # pair in the dictionary of conflicts
376
+
377
+ # 1) List of vertices in the line graph
378
+ for e in g. edge_iterator( labels=labels) :
379
+ if hash( e[0 ]) < hash( e[1 ]) :
380
+ elist. append( e)
381
+ elif hash( e[0 ]) > hash( e[1 ]) :
382
+ elist. append(( e[1 ], e[0 ]) + e[2: ])
383
+ else:
384
+ # Settle the conflict arbitrarily
385
+ conflicts[e ] = e
386
+ conflicts[(e[1 ], e[0 ]) + e[2: ]] = e
387
+ elist. append( e)
388
+
389
+ G. add_vertices( elist)
390
+
391
+ # 2) adjacencies in the line graph
392
+ for v in g:
393
+ elist = []
394
+
395
+ # Add the edge to the list, according to hashes, as previously
396
+ for e in g. edge_iterator( v, labels=labels) :
384
397
if hash( e[0 ]) < hash( e[1 ]) :
385
398
elist. append( e)
386
399
elif hash( e[0 ]) > hash( e[1 ]) :
387
400
elist. append(( e[1 ], e[0 ]) + e[2: ])
388
401
else:
389
- # Settle the conflict arbitrarily
390
- conflicts[e ] = e
391
- conflicts[(e[1 ], e[0 ]) + e[2: ]] = e
392
- elist. append( e)
393
-
394
- G. add_vertices( elist)
402
+ elist. append( conflicts[e ])
395
403
396
- # 2) adjacencies in the line graph
397
- for v in g:
398
- elist = []
399
-
400
- # Add the edge to the list, according to hashes, as previously
401
- for e in g. edge_iterator( v, labels=labels) :
402
- if hash( e[0 ]) < hash( e[1 ]) :
403
- elist. append( e)
404
- elif hash( e[0 ]) > hash( e[1 ]) :
405
- elist. append(( e[1 ], e[0 ]) + e[2: ])
406
- else:
407
- elist. append( conflicts[e ])
408
-
409
- # All pairs of elements in elist are edges of the
410
- # line graph
411
- while elist:
412
- x = elist. pop( )
413
- for y in elist:
414
- G. add_edge( x, y)
404
+ # All pairs of elements in elist are edges of the line graph
405
+ while elist:
406
+ x = elist. pop( )
407
+ for y in elist:
408
+ G. add_edge( x, y)
415
409
416
- return G
410
+ return G
417
411
418
412
419
413
def root_graph( g, verbose=False) :
@@ -629,5 +623,4 @@ def root_graph(g, verbose=False):
629
623
is_isom, isom = g.is_isomorphic(R.line_graph(labels=False), certificate=True)
630
624
if is_isom:
631
625
return R, isom
632
- else:
633
- raise ValueError(not_line_graph)
626
+ raise ValueError(not_line_graph)
0 commit comments