From 837a2869b04e6dbdccd77440b5424d2e5101de3f Mon Sep 17 00:00:00 2001 From: Mitch Watrous Date: Tue, 14 Aug 2012 11:29:57 -0700 Subject: [PATCH] Replace src/netanim usage of RandomVariable with RandomVariableStream --- src/netanim/model/animation-interface.cc | 12 ++++++++++-- src/netanim/model/animation-interface.h | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/netanim/model/animation-interface.cc b/src/netanim/model/animation-interface.cc index 2ddd33466..17bda4533 100644 --- a/src/netanim/model/animation-interface.cc +++ b/src/netanim/model/animation-interface.cc @@ -25,7 +25,6 @@ #include "ns3/channel.h" #include "ns3/config.h" #include "ns3/node.h" -#include "ns3/random-variable.h" #include "ns3/mobility-model.h" #include "ns3/packet.h" #include "ns3/simulator.h" @@ -68,6 +67,8 @@ AnimationInterface::AnimationInterface (const std::string fn, uint64_t maxPktsPe m_enablePacketMetadata (false), m_startTime (Seconds(0)), m_stopTime (Seconds(3600 * 1000)), m_maxPktsPerFile (maxPktsPerFile), m_originalFileName (fn) { + m_uniformRandomVariable = CreateObject (); + initialized = true; StartAnimation (); } @@ -212,7 +213,7 @@ Vector AnimationInterface::UpdatePosition (Ptr n) { NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary"); Vector deterministicVector (100,100,0); - Vector randomVector (UniformVariable (0, m_topoMaxX - m_topoMinX).GetValue (), UniformVariable (0, m_topoMaxY - m_topoMinY).GetValue (), 0); + Vector randomVector (m_uniformRandomVariable->GetValue (0, m_topoMaxX - m_topoMinX), m_uniformRandomVariable->GetValue (0, m_topoMaxY - m_topoMinY), 0); if (m_randomPosition) { m_nodeLocation[n->GetId ()] = randomVector; @@ -1307,6 +1308,13 @@ uint64_t AnimationInterface::GetTracePktCount () return m_currentPktCount; } +int64_t +AnimationInterface::AssignStreams (int64_t stream) +{ + NS_LOG_FUNCTION (this << stream); + m_uniformRandomVariable->SetStream (stream); + return 1; +} // Helper to output a wireless packet. // For now, only the XML interface is supported diff --git a/src/netanim/model/animation-interface.h b/src/netanim/model/animation-interface.h index 4f7c35859..8d9f3b3e4 100644 --- a/src/netanim/model/animation-interface.h +++ b/src/netanim/model/animation-interface.h @@ -30,6 +30,7 @@ #include "ns3/nstime.h" #include "ns3/log.h" #include "ns3/node-list.h" +#include "ns3/random-variable-stream.h" #include "ns3/simulator.h" #include "ns3/config.h" #include "ns3/animation-interface-helper.h" @@ -401,6 +402,15 @@ public: */ uint64_t GetTracePktCount (); + /** + * Assign a fixed random variable stream number to the random variables + * used by this model. Return the number of streams (possibly zero) that + * have been assigned. + * + * \param stream first stream index to use + * \return the number of stream indices assigned by this model + */ + int64_t AssignStreams (int64_t stream); private: FILE * m_f; // File handle for output (-1 if none) @@ -567,6 +577,8 @@ private: std::string GetXMLClose (std::string name) {return "\n"; } std::string GetXMLOpenClose_meta (std::string metaInfo); + /// Provides uniform random variables. + Ptr m_uniformRandomVariable; }; /**