Expose RNG seed/run # to attributes; bindings update

This commit is contained in:
Raj Bhattacharjea
2009-01-20 14:00:05 -05:00
parent 2e2fd41d48
commit cdde863642
3 changed files with 108 additions and 2 deletions

View File

@@ -55,6 +55,8 @@ def register_types(module):
module.add_class('ListScheduler', parent=root_module['ns3::Scheduler'])
## map-scheduler.h: ns3::MapScheduler [class]
module.add_class('MapScheduler', parent=root_module['ns3::Scheduler'])
## ns2-calendar-scheduler.h: ns3::Ns2CalendarScheduler [class]
module.add_class('Ns2CalendarScheduler', parent=root_module['ns3::Scheduler'])
## realtime-simulator-impl.h: ns3::RealtimeSimulatorImpl [class]
module.add_class('RealtimeSimulatorImpl', parent=root_module['ns3::SimulatorImpl'])
## realtime-simulator-impl.h: ns3::RealtimeSimulatorImpl::SynchronizationMode [enumeration]
@@ -127,6 +129,7 @@ def register_methods(root_module):
register_Ns3HeapScheduler_methods(root_module, root_module['ns3::HeapScheduler'])
register_Ns3ListScheduler_methods(root_module, root_module['ns3::ListScheduler'])
register_Ns3MapScheduler_methods(root_module, root_module['ns3::MapScheduler'])
register_Ns3Ns2CalendarScheduler_methods(root_module, root_module['ns3::Ns2CalendarScheduler'])
register_Ns3RealtimeSimulatorImpl_methods(root_module, root_module['ns3::RealtimeSimulatorImpl'])
return
@@ -718,7 +721,9 @@ def register_Ns3SchedulerEvent_methods(root_module, cls):
return
def register_Ns3SchedulerEventKey_methods(root_module, cls):
cls.add_binary_comparison_operator('!=')
cls.add_binary_comparison_operator('<')
cls.add_binary_comparison_operator('>')
## scheduler.h: ns3::Scheduler::EventKey::EventKey() [constructor]
cls.add_constructor([])
## scheduler.h: ns3::Scheduler::EventKey::EventKey(ns3::Scheduler::EventKey const & arg0) [copy constructor]
@@ -1289,6 +1294,42 @@ def register_Ns3MapScheduler_methods(root_module, cls):
cls.add_copy_constructor()
return
def register_Ns3Ns2CalendarScheduler_methods(root_module, cls):
## ns2-calendar-scheduler.h: static ns3::TypeId ns3::Ns2CalendarScheduler::GetTypeId() [member function]
cls.add_method('GetTypeId',
'ns3::TypeId',
[],
is_static=True)
## ns2-calendar-scheduler.h: ns3::Ns2CalendarScheduler::Ns2CalendarScheduler() [constructor]
cls.add_constructor([])
## ns2-calendar-scheduler.h: void ns3::Ns2CalendarScheduler::Insert(ns3::Scheduler::Event const & ev) [member function]
cls.add_method('Insert',
'void',
[param('ns3::Scheduler::Event const &', 'ev')],
is_virtual=True)
## ns2-calendar-scheduler.h: bool ns3::Ns2CalendarScheduler::IsEmpty() const [member function]
cls.add_method('IsEmpty',
'bool',
[],
is_const=True, is_virtual=True)
## ns2-calendar-scheduler.h: ns3::Scheduler::Event ns3::Ns2CalendarScheduler::PeekNext() const [member function]
cls.add_method('PeekNext',
'ns3::Scheduler::Event',
[],
is_const=True, is_virtual=True)
## ns2-calendar-scheduler.h: ns3::Scheduler::Event ns3::Ns2CalendarScheduler::RemoveNext() [member function]
cls.add_method('RemoveNext',
'ns3::Scheduler::Event',
[],
is_virtual=True)
## ns2-calendar-scheduler.h: void ns3::Ns2CalendarScheduler::Remove(ns3::Scheduler::Event const & ev) [member function]
cls.add_method('Remove',
'void',
[param('ns3::Scheduler::Event const &', 'ev')],
is_virtual=True)
cls.add_copy_constructor()
return
def register_Ns3RealtimeSimulatorImpl_methods(root_module, cls):
## realtime-simulator-impl.h: static ns3::TypeId ns3::RealtimeSimulatorImpl::GetTypeId() [member function]
cls.add_method('GetTypeId',

View File

@@ -21,6 +21,8 @@
#include <cstdlib>
#include <iostream>
#include "rng-stream.h"
#include "global-value.h"
#include "integer.h"
using namespace std;
namespace
@@ -199,7 +201,14 @@ void MatPowModM (const double A[3][3], double B[3][3], double m, int32_t n)
}
}
static ns3::GlobalValue g_rngSeed ("RngSeed",
"The global seed of all rng streams",
ns3::IntegerValue (1),
ns3::MakeIntegerChecker<uint32_t> ());
static ns3::GlobalValue g_rngRun ("RngRun",
"The run number used to modify the global seed",
ns3::IntegerValue (1),
ns3::MakeIntegerChecker<uint32_t> ());
} // end of anonymous namespace
@@ -291,7 +300,61 @@ bool RngStream::CheckSeed (const uint32_t seed[6])
return true;
}
void
RngStream::EnsureGlobalInitialized (void)
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
uint32_t seed;
uint32_t run;
// First, initialize ourselves from the global value.
{
IntegerValue value;
g_rngSeed.GetValue (value);
seed = value.Get ();
g_rngRun.GetValue (value);
run = value.Get ();
}
// then, in case we have NS_RNG set, override the global
// value from the env var.
char *tmp = getenv ("NS_RNG");
if (tmp != 0)
{
std::string var = std::string (getenv ("NS_RNG"));
std::string::size_type colon = var.find (":");
if (colon != std::string::npos)
{
{
std::string seedString = var.substr (0, colon);
std::istringstream iss;
iss.str (seedString);
iss >> seed;
}
{
std::string runString = var.substr (colon+1,var.size ()-colon-1);
std::istringstream iss;
iss.str (runString);
iss >> run;
}
}
else
{
{
std::istringstream iss;
iss.str (var);
iss >> seed;
}
}
}
// finally, actually use these values to do something.
uint32_t seedArray [] = {seed, seed, seed, seed, seed, seed};
SetPackageSeed (seedArray);
// set to the chosen substream (run)
ResetNthSubstream (run);
}
}
//*************************************************************************
// Public members of the class start here
@@ -311,6 +374,7 @@ double RngStream::nextSeed[6] =
//
RngStream::RngStream ()
{
EnsureGlobalInitialized ();
anti = false;
incPrec = false;
// Stream initialization moved to separate method.

View File

@@ -60,6 +60,7 @@ private: //members
bool anti, incPrec;
double U01 ();
double U01d ();
static void EnsureGlobalInitialized (void);
private: //static data
static double nextSeed[6];
};