#NEWLINE# def complement( G , name = None ) : #NEWLINE# #INDENT# 'Return the graph complement of G.\n\n    Parameters\n    ----------\n    G : graph\n       A NetworkX graph\n\n    name : string\n       Specify name for new graph\n\n    Returns\n    -------\n    GC : A new graph.\n\n    Notes\n    ------\n    Note that complement() does not create self-loops and also\n    does not produce parallel edges for MultiGraphs.\n\n    Graph, node, and edge data are not propagated to the new graph.\n    ' #NEWLINE# if ( name is None ) : #NEWLINE# #INDENT# name = ( 'complement(%s)' % G . name ) #NEWLINE# #UNINDENT# R = G . __class__ ( ) #NEWLINE# R . name = name #NEWLINE# R . add_nodes_from ( G ) #NEWLINE# R . add_edges_from ( ( ( n , n2 ) for ( n , nbrs ) in G . adjacency ( ) for n2 in G if ( n2 not in nbrs ) if ( n != n2 ) ) ) #NEWLINE# return R