Opened 5 years ago

#13209 new Bugs

erdos_renyi_iterator hangs when n is 1

Reported by: grievejia@… Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

Running the following program would result in an infinite loop:

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

using Graph = boost::adjacency_list<>;
using ERGen = boost::erdos_renyi_iterator<std::mt19937, Graph>;

int main() {
  std::mt19937 gen;
  int n = 1;
  Graph g(ERGen(gen, n, 0.5), ERGen(), n);
}

This is caused by the while loop inside erdos_renyi_iterator::next(). If n is 1 and allow_self_loops is false, the loop condition will be true forever. A simple change that makes an early exit for the n=1 case would fix the problem.

Change History (0)

Note: See TracTickets for help on using tickets.