Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selfLoops flag to Python's ErdosRenyiGenerator #383

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions networkit/_NetworKit.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2220,14 +2220,14 @@ cdef class PubWebGenerator(StaticGraphGenerator):
cdef extern from "<networkit/generators/ErdosRenyiGenerator.hpp>":

cdef cppclass _ErdosRenyiGenerator "NetworKit::ErdosRenyiGenerator"(_StaticGraphGenerator):
_ErdosRenyiGenerator(count nNodes, double prob, bool_t directed) except +
_ErdosRenyiGenerator(count nNodes, double prob, bool_t directed, bool_t selfLoops) except +

cdef class ErdosRenyiGenerator(StaticGraphGenerator):
""" Creates random graphs in the G(n,p) model.
The generation follows Vladimir Batagelj and Ulrik Brandes: "Efficient
generation of large random networks", Phys Rev E 71, 036113 (2005).

ErdosRenyiGenerator(count, double)
ErdosRenyiGenerator(count nNodes, double prob, directed = False, selfLoops = False)

Creates G(nNodes, prob) graphs.

Expand All @@ -2239,10 +2239,12 @@ cdef class ErdosRenyiGenerator(StaticGraphGenerator):
Probability of existence for each edge p.
directed : bool
Generates a directed
selfLoops : bool
Allows self-loops to be generated (only for directed graphs)
"""

def __cinit__(self, nNodes, prob, directed=False):
self._this = new _ErdosRenyiGenerator(nNodes, prob, directed)
def __cinit__(self, nNodes, prob, directed = False, selfLoops = False):
self._this = new _ErdosRenyiGenerator(nNodes, prob, directed, selfLoops)

@classmethod
def fit(cls, Graph G, scale=1):
Expand Down
5 changes: 4 additions & 1 deletion networkit/cpp/generators/ErdosRenyiGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ namespace NetworKit {

ErdosRenyiGenerator::ErdosRenyiGenerator(count nNodes, double prob, bool directed, bool self_loops) :
nNodes{nNodes}, prob{prob}, directed{directed}, self_loops{self_loops}
{}
{
if (self_loops && !directed)
throw std::runtime_error("Self-loops are only supported for directed graphs");
}

Graph ErdosRenyiGenerator::generate() {
GraphBuilder builder(nNodes, false, directed);
Expand Down