Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The following deletes one arc from each of the cycles of length 2. If you are interested in preserving any particular arc you should adapt this to suit your needs.

LG.delete_edges( [ ((x,y,None),(y,x,None)) for x,y in G.edges(labels=False) ] )
click to hide/show revision 2
Updated to answer new version of question.

The following deletes one arc from each of the line graph you obtain contains cycles of length 2. 2 because the digraph that to_directed() returns contains arcs (x,y) and (x,y) for each edge xy in the original graph.

If you are interested want to avoid these kind of cycles in preserving any particular arc the line graph you should adapt just need to get an arbitrary orientation of the original graph. You can achieve this to suit your needs.with

LG.delete_edges( [ ((x,y,None),(y,x,None)) D=DiGraph()
for x,y in G.edges(labels=False) ] )
graphs.CompleteGraph(4).edges(labels=None):
    if random()>= 0.5:
        D.add_edge(y,x)
    else:
        D.add_edge(x,y)
click to hide/show revision 3
Adapted to new version of question.

The line graph you obtain contains cycles of length 2 because the digraph D that to_directed() returns contains arcs (x,y) and (x,y) for each edge xy in the original graph.graph G.

If From what you show in your diagram you want to avoid these kind of cycles in the line graph you just need to get an arbitrary orientation of of D minus all the original graph. You can achieve arcs connecting vertices that came from the same edge in G. Maybe this withwill do the job

D=DiGraph()
G=graphs.CompleteGraph(4)
D=G.to_directed()
L=D.line_graph()
L.delete_edges([((x,y,None), (y,x,None)) for x,y in graphs.CompleteGraph(4).edges(labels=None):
    if random()>= 0.5:
        D.add_edge(y,x)
    else:
        D.add_edge(x,y)
G.edges( labels=None ) ])
L.delete_edges([((x,y,None), (y,x,None)) for y,x in G.edges( labels=None ) ])

Here is what L looks like using this code.

Line graph minus some arcs.