org.graphstream.algorithm.generator
Class BarabasiAlbertGenerator

java.lang.Object
  extended by org.graphstream.stream.SourceBase
      extended by org.graphstream.algorithm.generator.BaseGenerator
          extended by org.graphstream.algorithm.generator.BarabasiAlbertGenerator
All Implemented Interfaces:
Generator, org.graphstream.stream.Source

public class BarabasiAlbertGenerator
extends BaseGenerator

Scale-free graph generator using the preferential attachment rule as defined in the Barabási-Albert model.

This is a very simple graph generator that generates a graph using the preferential attachment rule defined in the Barabási-Albert model: nodes are generated one by one, and each time attached by one or more edges other nodes. The other nodes are chosen using a biased random selection giving more chance to a node if it has a high degree.

Usage

The more this generator is iterated, the more nodes are generated. It can therefore generate graphs of any size. One node is generated at each call to nextEvents(). At each node added at least one new edge is added. The number of edges added at each step is given by the getMaxLinksPerStep(). However by default the generator creates a number of edges per new node chosen randomly between 1 and getMaxLinksPerStep(). To have exactly this number of edges at each new node, use setExactlyMaxLinksPerStep(boolean).

Complexity

For each new step, the algorithm act in O(n) with n the number of nodes if 1 max edge per new node is created, else the complexity is O(nm) if m max edge per new node is created.

Example

 Graph graph = new SingleGraph("Barabàsi-Albert");
 // Between 1 and 3 new links per node added.
 Generator gen = new BarabasiAlbertGenerator(3);
 // Generate 100 nodes:
 gen.addSink(graph); 
 gen.begin();
 for(int i=0; i<100; i++) {
                gen.nextEvents();
 }
 gen.end();
 graph.display();
 

Scientific Reference :
Albert-László Barabási & Réka Albert "Emergence of scaling in random networks", Science 286: 509–512. October 1999. doi:10.1126/science.286.5439.509.

Nested Class Summary
 
Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase
org.graphstream.stream.SourceBase.ElementType
 
Constructor Summary
BarabasiAlbertGenerator()
          New generator.
BarabasiAlbertGenerator(int maxLinksPerStep)
           
BarabasiAlbertGenerator(int maxLinksPerStep, boolean exactlyMaxLinksPerStep)
           
 
Method Summary
 void begin()
          Start the generator.
 void end()
          Clean degrees.
 int getMaxLinksPerStep()
          Maximum number of edges created when a new node is added.
 boolean nextEvents()
          Step of the generator.
 boolean produceExactlyMaxLinkPerStep()
          True if the generator produce exactly getMaxLinksPerStep(), else it produce a random number of links ranging between 1 and getMaxLinksPerStep().
 void setExactlyMaxLinksPerStep(boolean on)
          Set if the generator produce exactly getMaxLinksPerStep() (true), else it produce a random number of links ranging between 1 and getMaxLinksPerStep() (false).
 void setMaxLinksPerStep(int max)
          Set how many edge (maximum) to create for each new node added.
 
Methods inherited from class org.graphstream.algorithm.generator.BaseGenerator
addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setEdgeAttributesRange, setNodeAttributesRange, setRandomSeed, setUseInternalGraph
 
Methods inherited from class org.graphstream.stream.SourceBase
addAttributeSink, addElementSink, addSink, attributeSinks, clearAttributeSinks, clearElementSinks, clearSinks, elementSinks, removeAttributeSink, removeElementSink, removeSink, sendAttributeChangedEvent, sendAttributeChangedEvent, sendEdgeAdded, sendEdgeAdded, sendEdgeRemoved, sendEdgeRemoved, sendGraphCleared, sendGraphCleared, sendNodeAdded, sendNodeAdded, sendNodeRemoved, sendNodeRemoved, sendStepBegins, sendStepBegins
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graphstream.stream.Source
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
 

Constructor Detail

BarabasiAlbertGenerator

public BarabasiAlbertGenerator()
New generator.


BarabasiAlbertGenerator

public BarabasiAlbertGenerator(int maxLinksPerStep)

BarabasiAlbertGenerator

public BarabasiAlbertGenerator(int maxLinksPerStep,
                               boolean exactlyMaxLinksPerStep)
Method Detail

getMaxLinksPerStep

public int getMaxLinksPerStep()
Maximum number of edges created when a new node is added.

Returns:
The maximum number of links per step.

produceExactlyMaxLinkPerStep

public boolean produceExactlyMaxLinkPerStep()
True if the generator produce exactly getMaxLinksPerStep(), else it produce a random number of links ranging between 1 and getMaxLinksPerStep().

Returns:
Does the generator generates exactly getMaxLinksPerStep().

setMaxLinksPerStep

public void setMaxLinksPerStep(int max)
Set how many edge (maximum) to create for each new node added.

Parameters:
max - The new maximum, it must be strictly greater than zero.

setExactlyMaxLinksPerStep

public void setExactlyMaxLinksPerStep(boolean on)
Set if the generator produce exactly getMaxLinksPerStep() (true), else it produce a random number of links ranging between 1 and getMaxLinksPerStep() (false).

Parameters:
on - Does the generator generates exactly getMaxLinksPerStep().

begin

public void begin()
Start the generator. A single node is added.

See Also:
Generator.begin()

nextEvents

public boolean nextEvents()
Step of the generator. Add a node and try to connect it with some others. The number of links is randomly chosen between 1 and the maximum number of links per step specified in setMaxLinksPerStep(int). The complexity of this method is O(n) with n the number of nodes if the number of edges created per new node is 1, else it is O(nm) with m the number of edges generated per node.

Returns:
true while there are elements to add to the graph.
See Also:
Generator.nextEvents()

end

public void end()
Clean degrees.

Specified by:
end in interface Generator
Overrides:
end in class BaseGenerator
See Also:
Generator.end()


Copyright © 2011. All Rights Reserved.