#include <MSEventControl.h>

Definition at line 53 of file MSEventControl.h.
Public Types | |
| enum | AdaptType { ADAPT_AFTER_EXECUTION = 1, NO_CHANGE = 2 } |
| Defines what to do if the insertion time lies before the current simulation time. More... | |
| typedef std::pair< Command *, SUMOTime > | Event |
| Combination of an event and the time it shall be executed at. | |
Public Member Functions | |
| virtual SUMOTime | addEvent (Command *operation, SUMOTime execTimeStep, AdaptType type) throw () |
| Adds an Event. | |
| virtual void | execute (SUMOTime time) throw (ProcessError) |
| Executes time-dependant commands. | |
| bool | isEmpty () throw () |
| Returns whether events are in the que. | |
| MSEventControl () throw () | |
| Default constructor. | |
| void | setCurrentTimeStep (SUMOTime time) |
| Set the current Time. | |
| virtual | ~MSEventControl () throw () |
| Destructor. | |
Private Types | |
| typedef std::priority_queue < Event, std::vector< Event > , EventSortCrit > | EventCont |
| Container for time-dependant events, e.g. traffic-light-change. | |
Private Member Functions | |
| SUMOTime | getCurrentTimeStep () throw () |
| get the Current TimeStep used in addEvent. | |
| MSEventControl (const MSEventControl &) | |
| invalid copy constructor. | |
| MSEventControl & | operator= (const MSEventControl &) |
| invalid assignment operator. | |
Private Attributes | |
| SUMOTime | currentTimeStep |
| The Current TimeStep. | |
| EventCont | myEvents |
| Event-container, holds executable events. | |
Data Structures | |
| class | EventSortCrit |
| Sort-criterion for events. More... | |
| typedef std::pair< Command*, SUMOTime > MSEventControl::Event |
Combination of an event and the time it shall be executed at.
Definition at line 56 of file MSEventControl.h.
typedef std::priority_queue< Event, std::vector< Event >, EventSortCrit > MSEventControl::EventCont [private] |
Container for time-dependant events, e.g. traffic-light-change.
Definition at line 150 of file MSEventControl.h.
Defines what to do if the insertion time lies before the current simulation time.
| ADAPT_AFTER_EXECUTION | Patch the time in a way that it is at least as high as the simulation begin time. |
| NO_CHANGE | Do nothing. |
Definition at line 63 of file MSEventControl.h.
00063 { 00065 ADAPT_AFTER_EXECUTION = 1, 00067 NO_CHANGE = 2 00068 };
| MSEventControl::MSEventControl | ( | ) | throw () |
Default constructor.
Definition at line 44 of file MSEventControl.cpp.
00045 : myEvents(), currentTimeStep(-1) {}
| MSEventControl::~MSEventControl | ( | ) | throw () [virtual] |
| MSEventControl::MSEventControl | ( | const MSEventControl & | ) | [private] |
invalid copy constructor.
| SUMOTime MSEventControl::addEvent | ( | Command * | operation, | |
| SUMOTime | execTimeStep, | |||
| AdaptType | type | |||
| ) | throw () [virtual] |
Adds an Event.
If the given execution time step lies before the current and ADAPT_AFTER_EXECUTION is passed for adaptation type, the execution time step will be set to the current time step.
Returns the time the event will be executed, really.
| [in] | operation | The event to add |
| [in] | execTimeStep | The time the event shall be executed at |
| [in] | type | The adaptation type |
Reimplemented in GUIEventControl.
Definition at line 59 of file MSEventControl.cpp.
References ADAPT_AFTER_EXECUTION, getCurrentTimeStep(), and myEvents.
Referenced by GUIEventControl::addEvent(), NLTriggerBuilder::buildVaporizer(), MSDevice_Routing::buildVehicleDevices(), MSSimpleTrafficLightLogic::changeStepAndDuration(), MSTLLogicControl::closeWAUT(), Command_SaveTLSState::Command_SaveTLSState(), Command_SaveTLSSwitches::Command_SaveTLSSwitches(), Command_SaveTLSSwitchStates::Command_SaveTLSSwitchStates(), MSDevice_Routing::enterLaneAtEmit(), MSDevice_HBEFA::enterLaneAtEmit(), FXIMPLEMENT(), MSLaneSpeedTrigger::init(), MSEmitter::MSEmitter_FileTriggeredChild::inputEndReached(), MSCalibrator::MSCalibrator_FileTriggeredChild::inputEndReached(), MSCalibrator::MSCalibrator(), MSTrafficLightLogic::MSTrafficLightLogic(), MSTriggeredXMLReader::MSTriggeredXMLReader(), MSVTypeProbe::MSVTypeProbe(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), and TEST().
00061 { 00062 SUMOTime currTimeStep = getCurrentTimeStep(); 00063 if (type == ADAPT_AFTER_EXECUTION && execTimeStep <= currTimeStep) { 00064 execTimeStep = currTimeStep; 00065 } 00066 Event newEvent = Event(operation, execTimeStep); 00067 myEvents.push(newEvent); 00068 return execTimeStep; 00069 }
| void MSEventControl::execute | ( | SUMOTime | time | ) | throw (ProcessError) [virtual] |
Executes time-dependant commands.
Loops over all stored events, continuing until the first event which execution time lies beyond the given time + deltaT. If the event had to be executed before the given time, a warning is generated and the event deleted. Otherwise (the event is valid), the event is executed.
Each executed event must return the time that has to pass until it shall be executed again. If the returned time is 0, the event is deleted. Otherwise it is readded, after the new execution time (returned + current) is computed.
ProcessErrors thrown by executed commands are rethrown.
| [in] | time | The current simulation time |
| ProcessError | From an executed Command |
Reimplemented in GUIEventControl.
Definition at line 73 of file MSEventControl.cpp.
References DELTA_T, Command::execute(), myEvents, and WRITE_WARNING.
Referenced by GUIEventControl::execute(), MSNet::simulationStep(), and TEST().
00073 { 00074 // Execute all events that are scheduled for execTime. 00075 for (; !myEvents.empty();) { 00076 Event currEvent = myEvents.top(); 00077 if (currEvent.second == execTime || currEvent.second<execTime+DELTA_T) { 00078 Command *command = currEvent.first; 00079 myEvents.pop(); 00080 SUMOTime time = 0; 00081 try { 00082 time = command->execute(execTime); 00083 } catch (...) { 00084 delete command; 00085 throw; 00086 } 00087 00088 // Delete nonrecurring events, reinsert recurring ones 00089 // with new execution time = execTime + returned offset. 00090 if (time <= 0) { 00091 if (time<0) { 00092 WRITE_WARNING("Command returned negative repeat number; will be deleted."); 00093 } 00094 delete currEvent.first; 00095 } else { 00096 currEvent.second = execTime + time; 00097 myEvents.push(currEvent); 00098 } 00099 } else { 00100 if (currEvent.second < execTime) { 00101 // !!! more verbose information 00102 WRITE_WARNING("Could not execute scheduled event."); 00103 delete currEvent.first; 00104 myEvents.pop(); 00105 } else { 00106 break; 00107 } 00108 } 00109 } 00110 }
| SUMOTime MSEventControl::getCurrentTimeStep | ( | ) | throw () [private] |
get the Current TimeStep used in addEvent.
Definition at line 124 of file MSEventControl.cpp.
References currentTimeStep, MSNet::getCurrentTimeStep(), and MSNet::getInstance().
Referenced by addEvent().
00124 { 00125 if (currentTimeStep < 0) { 00126 return MSNet::getInstance()->getCurrentTimeStep(); 00127 } 00128 return currentTimeStep; 00129 }
| bool MSEventControl::isEmpty | ( | ) | throw () |
Returns whether events are in the que.
Definition at line 114 of file MSEventControl.cpp.
References myEvents.
Referenced by MSNet::simulationState().
00114 { 00115 return myEvents.empty(); 00116 }
| MSEventControl& MSEventControl::operator= | ( | const MSEventControl & | ) | [private] |
invalid assignment operator.
| void MSEventControl::setCurrentTimeStep | ( | SUMOTime | time | ) |
Set the current Time.
This method is only for Unit Testing. Set the current TimeStep used in addEvent. Normally the time is set automatically from an instance of MSNet.
Definition at line 119 of file MSEventControl.cpp.
References currentTimeStep.
Referenced by TEST().
00119 { 00120 currentTimeStep = time; 00121 }
SUMOTime MSEventControl::currentTimeStep [private] |
The Current TimeStep.
Definition at line 153 of file MSEventControl.h.
Referenced by getCurrentTimeStep(), and setCurrentTimeStep().
EventCont MSEventControl::myEvents [private] |
Event-container, holds executable events.
Definition at line 156 of file MSEventControl.h.
Referenced by addEvent(), execute(), isEmpty(), and ~MSEventControl().
1.5.6