00001
00002 #include "simulator.hpp"
00003 #include "rand_num_generator.hpp"
00004
00005 SimulatorPtr Simulator::m_instance;
00006 const double Simulator::m_SIM_START_TIME = 0.0;
00007
00008 Simulator::Simulator()
00009 {
00010 m_clock.setTime(m_SIM_START_TIME);
00011 m_randNumGeneratorPtr = RandNumGenerator::create();
00012 }
00013
00014 Simulator::~Simulator()
00015 {
00016
00017 }
00018
00019 void Simulator::runSimulation(const SimTime& stopTime)
00020 {
00021 while(!m_eventPtrQueue.empty()) {
00022 EventPtr nextEvent = getNextEvent();
00023 if(nextEvent->getFireTime() > stopTime) {
00024 break;
00025 }
00026 dispatchEvent(nextEvent);
00027 }
00028 m_clock = stopTime;
00029
00030 for(t_uint i = 0; i < m_simulationEndListeners.size(); i++)
00031 m_simulationEndListeners[i]->simulationEndHandler();
00032 }
00033
00034 void Simulator::seedRandNumGenerator(const t_uint seed) const
00035 {
00036 assert(m_randNumGeneratorPtr != 0);
00037 m_randNumGeneratorPtr->setSeed(seed);
00038 }
00039
00040 void Simulator::reset()
00041 {
00042
00043
00044
00045 m_eventPtrQueue.clear();
00046 m_clock.setTime(m_SIM_START_TIME);
00047 }
00048