2

I'm doing a simulation program of a transport network. I want to simulate an arrival of passengers in a bus station that have a poison distribution of rate lambda.

In fact, in my conception of the program I need two lists of arrival dates: the first one is considered as the expected arrival dates for passengers and the second will be considered as the real effective arrival of passengers.

For generating time arrival I did use the following code using boost:

<blink>

  double lambda(Lambda1);  //mean of Poisson distr 
  boost::mt19937 rnd_gen;   //Mersenne Twister generator 

  typedef boost::variate_generator< 
      boost::mt19937, boost::poisson_distribution<> 
  > rnd_poisson_t; 

  rnd_poisson_t rnd_poisson( rnd_gen, 
    boost::poisson_distribution<>( lambda ) ); 

  rnd_poisson = rnd_poisson_t( rnd_gen, 
  boost::poisson_distribution<>( lambda ));      


  for(int i = 0; i <size;i++) 
  { 
      value=rnd_poisson();       
      tab[i]= rnd_poisson(); 
      i++;    
  } 

</blink>

The problem is if I use this code for different lists to generate the arrivals dates for the same Lambda and the same list size it will always generate the same numbers.

How do I to create a certain variation in this generation so that the two generated lists will be a little bit different?

4

1 回答 1

0

每当您使用它时,用当前时间重新播种随机生成器。大多数情况下,这将产生不同的序列。如您所见:

rnd_gen(static_cast<unsigned int>(std::time(0)));
于 2012-10-26T22:35:33.190 回答