【问题标题】:Generate poisson Arrival date using C++ and boost使用 C++ 生成泊松到达日期并提升
【发布时间】:2012-10-17 03:02:46
【问题描述】:

我正在做一个传输网络的模拟程序。我想模拟乘客到达公交车站时,其毒物分布为 lambda。

事实上,在我的计划概念中,我需要两个到达日期列表:第一个被视为乘客的预计到达日期,第二个将被视为乘客的实际有效到达日期。

为了生成到达时间,我使用 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>

问题是,如果我为不同的列表使用此代码来为相同的 Lambda 和相同的列表大小生成到达日期,它总是会生成相同的数字。

如何在这一代中创建某种变化,以便生成的两个列表会有些不同?

【问题讨论】:

  • 每次在创建列表之前重新播种随机生成器 (rnd_gen) 怎么样?这不会导致它给出不同的序列吗?
  • 感谢您的提示。我实际上在声明中添加了这行代码: boost::mt19937 rnd_gen(static_cast(std::time(0)));每次我调用这个函数时它都运行得很好。再次感谢。
  • 为了完整起见,我将您的结论作为回答发布。

标签: c++ boost poisson


【解决方案1】:

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

rnd_gen(static_cast<unsigned int>(std::time(0)));

【讨论】:

    猜你喜欢
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    相关资源
    最近更新 更多