Class ErdosRenyiGraph
- java.lang.Object
-
- it.unimi.dsi.webgraph.ImmutableGraph
-
- it.unimi.dsi.webgraph.ImmutableSequentialGraph
-
- it.unimi.dsi.webgraph.examples.ErdosRenyiGraph
-
- All Implemented Interfaces:
it.unimi.dsi.lang.FlyweightPrototype<ImmutableGraph>
public class ErdosRenyiGraph extends ImmutableSequentialGraph
An Erdős–Rényi random graph: the number of nodes is fixed, and there is a fixed probability that an arc is put between any two nodes (independently for every pair).Note that an instance of this class is not random-access: you can, however, make a mutable copy of the returned graph and then take its immutable view.
Warning: From version 3.5.2, this classes uses
BinomialDistribution
instead of the previous COLT-basedBinomial
class. As a side-effect, the graphs generated with the same parameters will be different.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class it.unimi.dsi.webgraph.ImmutableGraph
ImmutableGraph.LoadMethod
-
-
Field Summary
-
Fields inherited from class it.unimi.dsi.webgraph.ImmutableGraph
GRAPHCLASS_PROPERTY_KEY, NUMBER_OF_THREADS_PROPERTY, PROPERTIES_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description ErdosRenyiGraph(int n, double p)
Creates an Erdős–Rényi graph with given parameters and no loops.ErdosRenyiGraph(int n, double p, boolean loops)
Creates an Erdős–Rényi graph with given parameters.ErdosRenyiGraph(int n, double p, long seed, boolean loops)
Creates an Erdős–Rényi graph with given parameters and random seed.ErdosRenyiGraph(int n, long m, boolean loops)
Creates an Erdős–Rényi graph with given parameters and random seed.ErdosRenyiGraph(int n, long m, long seed, boolean loops)
Creates an Erdős–Rényi graph with given parameters and random seed.ErdosRenyiGraph(java.lang.String n, java.lang.String p)
Creates an Erdős–Rényi graph with given parameters and no loops.ErdosRenyiGraph(java.lang.String n, java.lang.String p, java.lang.String loops)
Creates an Erdős–Rényi graph with given parameters.ErdosRenyiGraph(java.lang.String n, java.lang.String p, java.lang.String seed, java.lang.String loops)
Creates an Erdős–Rényi graph with given parameters and random seed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ErdosRenyiGraph
copy()
Throws anUnsupportedOperationException
.ImmutableGraph
generate()
Deprecated.An instance of this class is already anImmutableSequentialGraph
.ImmutableSequentialGraph
generate(long seed)
Deprecated.An instance of this class is already anImmutableSequentialGraph
.static void
main(java.lang.String[] arg)
NodeIterator
nodeIterator()
Returns a node iterator for scanning the graph sequentially, starting from the first node.int
numNodes()
Returns the number of nodes of this graph.-
Methods inherited from class it.unimi.dsi.webgraph.ImmutableSequentialGraph
nodeIterator, outdegree, randomAccess, successorArray
-
Methods inherited from class it.unimi.dsi.webgraph.ImmutableGraph
basename, equals, hasCopiableIterators, hashCode, load, load, load, loadMapped, loadMapped, loadOffline, loadOffline, loadOnce, loadSequential, loadSequential, numArcs, outdegrees, splitNodeIterators, store, store, successors, toString
-
-
-
-
Constructor Detail
-
ErdosRenyiGraph
public ErdosRenyiGraph(int n, double p, long seed, boolean loops)
Creates an Erdős–Rényi graph with given parameters and random seed.- Parameters:
n
- the number of nodes.p
- the probability of generating an arc.seed
- a seed for pseudorandom number generation.loops
- whether loops are allowed or not.
-
ErdosRenyiGraph
public ErdosRenyiGraph(int n, double p, boolean loops)
Creates an Erdős–Rényi graph with given parameters.- Parameters:
n
- the number of nodes.p
- the probability of generating an arc.loops
- whether loops are allowed or not.
-
ErdosRenyiGraph
public ErdosRenyiGraph(int n, double p)
Creates an Erdős–Rényi graph with given parameters and no loops.- Parameters:
n
- the number of nodes.p
- the probability of generating an arc.
-
ErdosRenyiGraph
public ErdosRenyiGraph(java.lang.String n, java.lang.String p, java.lang.String seed, java.lang.String loops)
Creates an Erdős–Rényi graph with given parameters and random seed.This constructor can be used with an
ObjectParser
.- Parameters:
n
- the number of nodes.p
- the probability of generating an arc.seed
- a seed for pseudorandom number generation.loops
- whether loops are allowed or not.
-
ErdosRenyiGraph
public ErdosRenyiGraph(java.lang.String n, java.lang.String p)
Creates an Erdős–Rényi graph with given parameters and no loops.This constructor can be used with an
ObjectParser
.- Parameters:
n
- the number of nodes.p
- the probability of generating an arc.
-
ErdosRenyiGraph
public ErdosRenyiGraph(java.lang.String n, java.lang.String p, java.lang.String loops)
Creates an Erdős–Rényi graph with given parameters.This constructor can be used with an
ObjectParser
.- Parameters:
n
- the number of nodes.p
- the probability of generating an arc.loops
- whether loops are allowed or not.
-
ErdosRenyiGraph
public ErdosRenyiGraph(int n, long m, long seed, boolean loops)
Creates an Erdős–Rényi graph with given parameters and random seed.- Parameters:
n
- the number of nodes.m
- the expected number of arcs.seed
- a seed for pseudorandom number generation.loops
- whether loops are allowed or not.
-
ErdosRenyiGraph
public ErdosRenyiGraph(int n, long m, boolean loops)
Creates an Erdős–Rényi graph with given parameters and random seed.- Parameters:
n
- the number of nodes.m
- the expected number of arcs.loops
- whether loops are allowed or not.
-
-
Method Detail
-
numNodes
public int numNodes()
Description copied from class:ImmutableGraph
Returns the number of nodes of this graph.Albeit this method is not optional, it is allowed that this method throws an
UnsupportedOperationException
if this graph has never been entirely traversed using anode iterator
. This apparently bizarre behaviour is necessary to support implementations asArcListASCIIGraph
, which do not know the actual number of nodes until a traversal has been completed.- Specified by:
numNodes
in classImmutableGraph
- Returns:
- the number of nodes.
-
copy
public ErdosRenyiGraph copy()
Description copied from class:ImmutableSequentialGraph
Throws anUnsupportedOperationException
.- Specified by:
copy
in interfaceit.unimi.dsi.lang.FlyweightPrototype<ImmutableGraph>
- Overrides:
copy
in classImmutableSequentialGraph
- Returns:
- a flyweight copy of this immutable graph.
- See Also:
FlyweightPrototype
-
nodeIterator
public NodeIterator nodeIterator()
Description copied from class:ImmutableGraph
Returns a node iterator for scanning the graph sequentially, starting from the first node.- Overrides:
nodeIterator
in classImmutableGraph
- Returns:
- a
NodeIterator
for accessing nodes and successors sequentially.
-
generate
@Deprecated public ImmutableSequentialGraph generate(long seed)
Deprecated.An instance of this class is already anImmutableSequentialGraph
.Generates an Erdős–Rényi graph with the specified seed.This method exists only for backward compatibility.
- Parameters:
seed
- the seed for random generation.- Returns:
- the generated graph.
-
generate
@Deprecated public ImmutableGraph generate()
Deprecated.An instance of this class is already anImmutableSequentialGraph
.Generates an Erdős–Rényi graph.This method exists only for backward compatibility.
- Returns:
- the generated graph.
-
main
public static void main(java.lang.String[] arg) throws java.io.IOException, com.martiansoftware.jsap.JSAPException
- Throws:
java.io.IOException
com.martiansoftware.jsap.JSAPException
-
-