def __init__(self, size, noOfEdges):
        """ Constructs an empty graph

            @param size Number of vertices to be considered for generation
            @param noOfEdges Number of edges to generate
        """
        NumberedEdgeUndirectedGraph.__init__(self)

        ## Number of vertices to be considered for generation
        self.graphSize = size

        ## Number of edges to generate
        self.noOfEdges = noOfEdges

        ## Parameters of the RMAT algorithm. Decide the probability with which quadrants in an adjacency matrix are chosen
        ## \todo Add description about choosing these probabilities

        ## Probability of choosing quadrant A
        self.probA = 0.45

        ## Probability of choosing quadrant B
        self.probB = 0.15

        ## Probability of choosing quadrant C
        self.probC = 0.15

        ## Probability of choosing quadrant D
        self.probD = 0.25

        ## Temporary storage of edges. Maintained for achieving performance
        self.serialEdgeList = []

        ## Debug flag
        self.debug = 0

        self.startVertX = 1
        self.endVertX = size

        self.startVertY = 1
        self.endVertY = size

        ## Logger instance
        self.logger = PyGelLogging().getLogger()
    def __init__(self, size, noOfEdges):
        """ Constructs an empty graph

            @param size Number of vertices to be considered for generation
            @param noOfEdges Number of edges to generate
        """
        NumberedEdgeUndirectedGraph.__init__(self)

        ## Number of vertices to be considered for generation
        self.graphSize = size

        ## Number of edges to generate
        self.noOfEdges = noOfEdges

        ## Parameters of the RMAT algorithm. Decide the probability with which quadrants in an adjacency matrix are chosen
        ## \todo Add description about choosing these probabilities

        ## Probability of choosing quadrant A
        self.probA = 0.45

        ## Probability of choosing quadrant B
        self.probB = 0.15

        ## Probability of choosing quadrant C
        self.probC = 0.15

        ## Probability of choosing quadrant D
        self.probD = 0.25

        ## Temporary storage of edges. Maintained for achieving performance
        self.serialEdgeList = []

        ## Debug flag
        self.debug = 0

        self.startVertX = 1
        self.endVertX = size

        self.startVertY = 1
        self.endVertY = size

        ## Logger instance
        self.logger = PyGelLogging().getLogger()
示例#3
0
    def __init__(self):
        """ Constructs a numbered edge graph
        """
        ## Dictionary of edges, indexed by edge number
        self.edgeIndex = {}

        ## Dictionary of vertices, indexed by vertex number
        self.vertexIndex = {}

        ## Dictionary of vertices, indexed by parent
        self.parentIndex = {}

        ## Dictionary of vertices and edge numbers, indexed by parent
        self.parentEdgeIndex = {}

        ## Last edge number assigned
        self.__lastEdgeNumber = -1

        ## Dictionary of degree counts. Used for efficiently computing degree distribution
        self.__degreeCount = {}

        ## Logger instance
        self.logger = PyGelLogging().getLogger()
class UndirectedPowerLawRandomGraph(NumberedEdgeUndirectedGraph):
    """ Generates a synthetic Web graph or Power Law graph using an RMAT algorithm
        \ingroup RandomGraphs
    """
    def __init__(self, size, noOfEdges):
        """ Constructs an empty graph

            @param size Number of vertices to be considered for generation
            @param noOfEdges Number of edges to generate
        """
        NumberedEdgeUndirectedGraph.__init__(self)

        ## Number of vertices to be considered for generation
        self.graphSize = size

        ## Number of edges to generate
        self.noOfEdges = noOfEdges

        ## Parameters of the RMAT algorithm. Decide the probability with which quadrants in an adjacency matrix are chosen
        ## \todo Add description about choosing these probabilities

        ## Probability of choosing quadrant A
        self.probA = 0.45

        ## Probability of choosing quadrant B
        self.probB = 0.15

        ## Probability of choosing quadrant C
        self.probC = 0.15

        ## Probability of choosing quadrant D
        self.probD = 0.25

        ## Temporary storage of edges. Maintained for achieving performance
        self.serialEdgeList = []

        ## Debug flag
        self.debug = 0

        self.startVertX = 1
        self.endVertX = size

        self.startVertY = 1
        self.endVertY = size

        ## Logger instance
        self.logger = PyGelLogging().getLogger()

    def setProbs(self, probA, probB, probC, probD):
        """ Sets the probability with which quadrants in an adjacency matrix are chosen

            @param probA Probability of choosing quadrant A
            @param probB Probability of choosing quadrant B
            @param probC Probability of choosing quadrant C
            @param probD Probability of choosing quadrant D
            @throws PackageExceptions::DistError
        """
        if probA + probB + probC + probD != 1:
            raise DistError(ErrorMessages.distAddOne)

        self.probA = probA
        self.probB = probB
        self.probC = probC
        self.probD = probD
        return

    def generate(self, noOfThreads, noSelfLoops):
        """ Generates a the graph. Heart of web graph generation algorithm. Each thread gets an equal number of nodes to generate.

            @param noOfThreads Number of threads to spawn for the graph generation. More threads does not correspond to fast generation  
            @param noSelfLoops If true (set to 1) self loops are discarded in the resulting graph.
        """
        chooserThreads = []
        for i in range(noOfThreads):
            chooser = ChooseEdges(self.noOfEdges / noOfThreads, noSelfLoops,
                                  self.startVertX, self.endVertX,
                                  self.startVertY, self.endVertY, self.probA,
                                  self.probB, self.probC, self.probD)

            chooserThreads.append(chooser)
            chooser.start()

        for t in chooserThreads:
            t.join()

        self.serialEdgeList = ChooseEdges.serialEdgeList

        del chooserThreads
        del ChooseEdges.serialEdgeList
        return

    def populate(self):
        """ Populate graph with edges generated after a call to DirectedPowerLawRandomGraph::generate. You should call this method before you can use any of the non-overridden method in Graph::NumberedEdgeDirectedGraph
        
        """
        serialEdgeList = self.serialEdgeList

        for i in xrange(0, len(serialEdgeList) - 1, 2):
            newEdge = Edge(Vertex(serialEdgeList[i]),
                           Vertex(serialEdgeList[i + 1]))
            try:
                ## In an NumberedEdgeUndirectedGraph you cannot have two edges between a pair of vertices. Thus, here we just log this error
                ## and move on to the next iteration. Perhaps this is the only difference between the undirected and the directed Power Law random
                ## graph.
                self.addEdge(newEdge)
            except EdgeError, e:
                self.logger.info(e.message)
class UndirectedPowerLawRandomGraph(NumberedEdgeUndirectedGraph):

    """ Generates a synthetic Web graph or Power Law graph using an RMAT algorithm
        \ingroup RandomGraphs
    """

    def __init__(self, size, noOfEdges):
        """ Constructs an empty graph

            @param size Number of vertices to be considered for generation
            @param noOfEdges Number of edges to generate
        """
        NumberedEdgeUndirectedGraph.__init__(self)

        ## Number of vertices to be considered for generation
        self.graphSize = size

        ## Number of edges to generate
        self.noOfEdges = noOfEdges

        ## Parameters of the RMAT algorithm. Decide the probability with which quadrants in an adjacency matrix are chosen
        ## \todo Add description about choosing these probabilities

        ## Probability of choosing quadrant A
        self.probA = 0.45

        ## Probability of choosing quadrant B
        self.probB = 0.15

        ## Probability of choosing quadrant C
        self.probC = 0.15

        ## Probability of choosing quadrant D
        self.probD = 0.25

        ## Temporary storage of edges. Maintained for achieving performance
        self.serialEdgeList = []

        ## Debug flag
        self.debug = 0

        self.startVertX = 1
        self.endVertX = size

        self.startVertY = 1
        self.endVertY = size

        ## Logger instance
        self.logger = PyGelLogging().getLogger()

    def setProbs(self, probA, probB, probC, probD):
        """ Sets the probability with which quadrants in an adjacency matrix are chosen

            @param probA Probability of choosing quadrant A
            @param probB Probability of choosing quadrant B
            @param probC Probability of choosing quadrant C
            @param probD Probability of choosing quadrant D
            @throws PackageExceptions::DistError
        """
        if probA + probB + probC + probD != 1:
            raise DistError(ErrorMessages.distAddOne)

        self.probA = probA
        self.probB = probB
        self.probC = probC
        self.probD = probD
        return

    def generate(self, noOfThreads, noSelfLoops):
        """ Generates a the graph. Heart of web graph generation algorithm. Each thread gets an equal number of nodes to generate.

            @param noOfThreads Number of threads to spawn for the graph generation. More threads does not correspond to fast generation  
            @param noSelfLoops If true (set to 1) self loops are discarded in the resulting graph.
        """
        chooserThreads = []
        for i in range(noOfThreads):
            chooser = ChooseEdges(
                self.noOfEdges / noOfThreads,
                noSelfLoops,
                self.startVertX,
                self.endVertX,
                self.startVertY,
                self.endVertY,
                self.probA,
                self.probB,
                self.probC,
                self.probD,
            )

            chooserThreads.append(chooser)
            chooser.start()

        for t in chooserThreads:
            t.join()

        self.serialEdgeList = ChooseEdges.serialEdgeList

        del chooserThreads
        del ChooseEdges.serialEdgeList
        return

    def populate(self):
        """ Populate graph with edges generated after a call to DirectedPowerLawRandomGraph::generate. You should call this method before you can use any of the non-overridden method in Graph::NumberedEdgeDirectedGraph
        
        """
        serialEdgeList = self.serialEdgeList

        for i in xrange(0, len(serialEdgeList) - 1, 2):
            newEdge = Edge(Vertex(serialEdgeList[i]), Vertex(serialEdgeList[i + 1]))
            try:
                ## In an NumberedEdgeUndirectedGraph you cannot have two edges between a pair of vertices. Thus, here we just log this error
                ## and move on to the next iteration. Perhaps this is the only difference between the undirected and the directed Power Law random
                ## graph.
                self.addEdge(newEdge)
            except EdgeError, e:
                self.logger.info(e.message)