如何在ns3中为RandomPropagatoinModel指定某个RadomVariableStream

时间:2018-04-01 16:20:50

标签: ns-3

我将使用ns3的传播损耗模型来查看损失和距离之间的关系。但是,我注意到在RandomPropagationModel中,默认的RandomVariableStream是ConstantRandomVariable。

这导致无法看到损失。

我搜索了官方文档,发现RandomPropagationModel类没有指定某个RadomVariableStream的函数。

顺便说一句,有一个名为'AssignStream'的函数提到RandomVariableStream。虽然我试图使用它,但模型得到的值是常数。

我想知道如何将RandomPropagationModel与某个RandomVariableStream相关联,例如ExponentialRandomVariable?

1 个答案:

答案 0 :(得分:1)

我解决了这个问题。类RandomPropagationModel提供了一个属性'Variable',它与私有成员m_variable绑定。我们可以用函数Config::SetDefault或值1更改默认值具有函数pointer->SetAttribute的对象。

要查找与某个memeber绑定的属性,请查看它的官方文档。将始终有一个名为“Attribute”的部分来介绍它。

至于这个问题,我们可以改变m_variable指向使用代码的类:

Ptr<RandomPropagationModel>random=CreateObject<RandomPropagationModel>();
//now the m_variable points to ConstantRandomVariable[constant=1.0]
Ptr<ExponentialRandomVariable>exponential=CreateObject<ExponentialRandomVariable>();
//set attribute for exponential
//Bound and Mean are m_bound and m_mean separately
exponential->SetAttribute("Bound",0);
exponential->SetAttribute("Mean",100);
//change the m_varibule
random->SetAttribute("Variable",PointValue(exponential));//PointValue is used because exponential is a pointer.
//we can get the info which function shall be used for different attributes also in the section 'Attribute'
//done

顺便说一下,应该包含一些.h文件。

昨天我忽略了从Object类继承的函数,这导致了我的困惑。