Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
C++ Boost erdos_renyi_iterator
template<typename RandomGenerator, typename Graph>
class erdos_renyi_iterator
  typedef std::input_iterator_tag iterator_category;
  typedef std::pair<vertices_size_type, vertices_size_type> value_type;
  typedef const value_type& reference;
  typedef const value_type* pointer;
  typedef void difference_type;

  erdos_renyi_iterator(RandomGenerator& gen, vertices_size_type n,
                       double probability = 0.0, bool allow_self_loops = false);
  // Iterator operations
  reference operator*() const;
  pointer operator->() const;
  erdos_renyi_iterator& operator++();
  erdos_renyi_iterator operator++(int);
  bool operator==(const erdos_renyi_iterator& other) const;
  bool operator!=(const erdos_renyi_iterator& other) const;

This class template implements a generator for Erdöos-Renyi graphs, suitable for initializing an adjacency_list or other graph structure with iterator-based initialization. An Erdöos-Renyi graph G = (n, p) is a graph with n vertices that. The probability of having an edge (u, v) in G is p for any vertices u and v. Typically, there are no self-loops, but the generator can optionally introduce self-loops with probability p.

Erdös-Renyi graphs typically exhibit very little structure. For this reason, they are rarely useful in modeling real-world problems. However, they are often used when determining the theoretical complexity of complex graph algorithms.

Where Defined



Constructs a past-the-end iterator.
erdos_renyi_iterator(RandomGenerator& gen, vertices_size_type n,
                     double probability = 0.0, bool allow_self_loops =
Constructs an Erdös-Renyi generator iterator that creates a graph with n vertices and edges with probability probability. Probabilities are drawn from the random number generator gen. Self-loops are permitted only when allow_self_loops is true.


#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/erdos_renyi_generator.hpp>
#include <boost/random/linear_congruential.hpp>

typedef boost::adjacency_list<> Graph;
typedef boost::erdos_renyi_iterator<boost::minstd_rand, Graph> ERGen;

int main()
  boost::minstd_rand gen;
  // Create graph with 100 nodes and edges with probability 0.05
  Graph g(ERGen(gen, 100, 0.05), ERGen(), 100);
  return 0;

Copyright © 2005 Doug Gregor, Indiana University ()
Andrew Lumsdaine, Indiana University ()