Package org.jgrapht.generate
Class GnpRandomGraphGenerator<V,E>
- java.lang.Object
-
- org.jgrapht.generate.GnpRandomGraphGenerator<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
GraphGenerator<V,E,V>
public class GnpRandomGraphGenerator<V,E> extends java.lang.Object implements GraphGenerator<V,E,V>
Create a random graph based on the G(n, p) Erdős–Rényi model. See the Wikipedia article for details and references about Random Graphs and the Erdős–Rényi model .In the G(n, p) model, a graph is constructed by connecting nodes randomly. Each edge is included in the graph with probability p independent from every other edge. The complexity of the generator is O(n^2) where n is the number of vertices.
For the G(n, M) model please see
GnmRandomGraphGenerator
.- Since:
- September 2016
- See Also:
GnmRandomGraphGenerator
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
DEFAULT_ALLOW_LOOPS
private boolean
loops
private int
n
private double
p
private java.util.Random
rng
-
Constructor Summary
Constructors Constructor Description GnpRandomGraphGenerator(int n, double p)
Create a new G(n, p) random graph generator.GnpRandomGraphGenerator(int n, double p, long seed)
Create a new G(n, p) random graph generator.GnpRandomGraphGenerator(int n, double p, long seed, boolean loops)
Create a new G(n, p) random graph generator.GnpRandomGraphGenerator(int n, double p, java.util.Random rng, boolean loops)
Create a new G(n, p) random graph generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
generateGraph(Graph<V,E> target, VertexFactory<V> vertexFactory, java.util.Map<java.lang.String,V> resultMap)
Generates a random graph based on the G(n, p) model.
-
-
-
Field Detail
-
DEFAULT_ALLOW_LOOPS
private static final boolean DEFAULT_ALLOW_LOOPS
- See Also:
- Constant Field Values
-
rng
private final java.util.Random rng
-
n
private final int n
-
p
private final double p
-
loops
private final boolean loops
-
-
Constructor Detail
-
GnpRandomGraphGenerator
public GnpRandomGraphGenerator(int n, double p)
Create a new G(n, p) random graph generator. The generator does not create self-loops.- Parameters:
n
- the number of nodesp
- the edge probability
-
GnpRandomGraphGenerator
public GnpRandomGraphGenerator(int n, double p, long seed)
Create a new G(n, p) random graph generator. The generator does not create self-loops.- Parameters:
n
- the number of nodesp
- the edge probabilityseed
- seed for the random number generator
-
GnpRandomGraphGenerator
public GnpRandomGraphGenerator(int n, double p, long seed, boolean loops)
Create a new G(n, p) random graph generator.- Parameters:
n
- the number of nodesp
- the edge probabilityseed
- seed for the random number generatorloops
- whether the generated graph may create loops
-
GnpRandomGraphGenerator
public GnpRandomGraphGenerator(int n, double p, java.util.Random rng, boolean loops)
Create a new G(n, p) random graph generator.- Parameters:
n
- the number of nodesp
- the edge probabilityrng
- the random number generator to useloops
- whether the generated graph may create loops
-
-
Method Detail
-
generateGraph
public void generateGraph(Graph<V,E> target, VertexFactory<V> vertexFactory, java.util.Map<java.lang.String,V> resultMap)
Generates a random graph based on the G(n, p) model.- Specified by:
generateGraph
in interfaceGraphGenerator<V,E,V>
- Parameters:
target
- the target graphvertexFactory
- the vertex factoryresultMap
- not used by this generator, can be null
-
-