def generate(self, graph):
        Parameter.checkClass(graph, AbstractMatrixGraph)
        
        if graph.getNumEdges()!= 0: 
            raise ValueError("Graph must have no edges")

        if not graph.isUndirected():
            raise ValueError("Graph must be undirected")
        

        numVertices = graph.getNumVertices()
        
        #First, create a lattice with k neighbours
        #For each vertex, create an edge to the next k vertices
        for i in range(0, numVertices): 
            for j in range(0, self.k):
                graph.addEdge(i, (i+j+1)%numVertices)
        
        #Now, let's get re-wiring, but only for forward links and no self-edges
        for i in range(0, numVertices): 
            v = numpy.random.rand(self.k, 1)
            for j in range(0, self.k):
                if (v[j] < self.p):
                    ind = numpy.random.randint(0, numVertices)

                    if graph.getEdge(i, ind)==None and ind!=i:
                        graph.addEdge(i, ind)
                        graph.removeEdge(i, (i+j+1)%numVertices)
                    
        return graph
Create a small-world graph using the given input graph.
dataset/ETHPy150Open charanpald/APGL/apgl/generator/SmallWorldGenerator.py/SmallWorldGenerator.generate