#NEWLINE# def generate2( self , graph , requireEmpty = True ) : #NEWLINE# #INDENT# '\n        An alternative way of generating random edges which might work better \n        than generate. \n        ' #NEWLINE# Parameter . checkClass ( graph , AbstractMatrixGraph ) #NEWLINE# if ( requireEmpty and ( graph . getNumEdges ( ) != 0 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Graph must have no edges' ) #NEWLINE# #UNINDENT# numVertices = graph . getNumVertices ( ) #NEWLINE# W = ( numpy . random . rand ( numVertices , numVertices ) < self . p ) #NEWLINE# W = numpy . array ( W , numpy . int ) #NEWLINE# if graph . isUndirected ( ) : #NEWLINE# #INDENT# diagW = numpy . diag ( W ) #NEWLINE# W = numpy . triu ( W , 1 ) #NEWLINE# W = ( W + W . T ) #NEWLINE# #UNINDENT# graph . setWeightMatrix ( scipy . sparse . csr_matrix ( W , dtype = numpy . float ) ) #NEWLINE# return graph