#NEWLINE# def generate( self , graph ) : #NEWLINE# #INDENT# '\n        Create a random graph using the input graph according to the Barabasi-Albert\n        model. Note that the input graph is modified.\n\n        :param graph: the empty input graph.\n        :type graph: :class:`apgl.graph.AbstractMatrixGraph`\n\n        :returns: The modified input graph. \n        ' #NEWLINE# Parameter . checkClass ( graph , AbstractMatrixGraph ) #NEWLINE# if ( graph . getNumEdges ( ) != 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'Graph must have no edges' ) #NEWLINE# #UNINDENT# vertexList = list ( range ( 0 , self . ell ) ) #NEWLINE# for i in range ( self . ell , graph . getNumVertices ( ) ) : #NEWLINE# #INDENT# perm = numpy . random . permutation ( len ( vertexList ) ) #NEWLINE# numEdgesAdded = 0 #NEWLINE# j = 0 #NEWLINE# while ( numEdgesAdded != self . m ) : #NEWLINE# #INDENT# ind = perm [ j ] #NEWLINE# vertexIndex = vertexList [ ind ] #NEWLINE# if ( graph . getEdge ( graph , vertexIndex ) == None ) : #NEWLINE# #INDENT# graph . addEdge ( i , vertexIndex ) #NEWLINE# vertexList . append ( i ) #NEWLINE# vertexList . append ( vertexIndex ) #NEWLINE# numEdgesAdded += 1 #NEWLINE# #UNINDENT# j = ( j + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# return graph