46 #ifdef CHECK_MEMORY_LEAKS
48 #endif // CHECK_MEMORY_LEAKS
54 #define DEFAULT_T_DECIDE "1"
55 #define DEFAULT_LEARN_HORIZON "3"
56 #define DEFAULT_CYCLE_TIME "90"
57 #define DEFAULT_MIN_DIFF "1"
58 #define DEFAULT_DETECTOR_OFFSET "0"
66 const std::string&
id,
const std::string& programID,
68 const std::map<std::string, std::string>& parameter) :
70 tSinceLastDecision(0), stepOfLastDecision(0) {
83 LaneVectorVector::const_iterator i2;
84 LaneVector::const_iterator i;
88 for (i = lanes.begin(); i != lanes.end(); i++) {
91 std::string
id =
"TL_" +
myID +
"_" +
myProgramID +
"_E2OverLanesDetectorStartingAt_" + lane->
getID();
107 unsigned int tCycleIst = 0;
108 unsigned int tCycleMin = 0;
109 unsigned int tDeltaGreen = 0;
112 for (
unsigned int actStep = 0; actStep !=
myPhases.size(); actStep++) {
113 unsigned int dur = (
unsigned int)
myPhases[actStep]->duration;
114 tCycleIst = tCycleIst + dur;
115 if (
myPhases[actStep]->isGreenPhase()) {
116 unsigned int mindur = (
unsigned int)
myPhases[actStep]->minDuration;
117 tCycleMin = tCycleMin + mindur;
119 tCycleMin = tCycleMin + dur;
126 tDeltaGreen =
tCycle - tCycleIst;
130 tDeltaGreen = tCycleIst -
tCycle;
185 for (
unsigned int i = 0; i < (
unsigned int) state.size(); i++) {
188 const std::vector<MSLane*>& lanes =
getLanesAt(i);
193 for (LaneVector::const_iterator j = lanes.begin(); j != lanes.end(); j++) {
206 if (maxPerPhase < maxPerBit) {
207 maxPerPhase = maxPerBit;
244 if (stepOfMaxValue ==
myPhases.size()) {
248 if (stepOfMinValue ==
myPhases.size()) {
251 if (stepOfMinValue == stepOfMaxValue) {
257 myPhases[stepOfMaxValue]->duration =
myPhases[stepOfMaxValue]->duration + 1;
258 myPhases[stepOfMinValue]->duration =
myPhases[stepOfMinValue]->duration - 1;
267 typedef std::pair <unsigned int, unsigned int> contentType;
268 typedef std::vector< std::pair <unsigned int, unsigned int> > GreenPhasesVector;
269 GreenPhasesVector tmp_phases(
myPhases.size());
271 unsigned int maxLengthen = 0;
277 for (
unsigned int i_Step = 0; i_Step !=
myPhases.size(); i_Step++) {
278 if (
myPhases[i_Step]->isGreenPhase()) {
279 unsigned int dur = (
unsigned int)
myPhases[i_Step]->duration;
280 unsigned int maxdur = (
unsigned int)
myPhases[i_Step]->maxDuration;
284 tmp.first = maxdur - dur;
285 tmp_phases.push_back(tmp);
286 maxLengthen = maxLengthen + tmp.first;
290 sort(tmp_phases.begin(), tmp_phases.end());
292 for (GreenPhasesVector::iterator i = tmp_phases.begin(); i != tmp_phases.end(); i++) {
295 toLengthenPerPhase =
static_cast<SUMOTime>(tmpdb);
296 toLengthen = toLengthen - (
unsigned int) toLengthenPerPhase;
297 maxLengthen = maxLengthen - (*i).first;
299 myPhases[(*i).second]->duration = newDur;
306 typedef std::pair <unsigned int, unsigned int> contentType;
307 typedef std::vector< std::pair <unsigned int, unsigned int> > GreenPhasesVector;
308 GreenPhasesVector tmp_phases(
myPhases.size());
316 for (
unsigned i_Step = 0; i_Step !=
myPhases.size(); i_Step++) {
317 if (
myPhases[i_Step]->isGreenPhase()) {
318 unsigned int dur = (
unsigned int)
myPhases[i_Step]->duration;
319 unsigned int mindur = (
unsigned int)
myPhases[i_Step]->minDuration;
323 tmp.first = dur - mindur;
324 tmp_phases.push_back(tmp);
325 maxCut = maxCut + tmp.first;
329 std::sort(tmp_phases.begin(), tmp_phases.end());
331 for (GreenPhasesVector::iterator i = tmp_phases.begin(); i != tmp_phases.end(); i++) {
334 toCutPerPhase =
static_cast<SUMOTime>(tmpdb);
335 toCut = toCut - (
unsigned int) toCutPerPhase;
336 maxCut = maxCut - (*i).first;
338 myPhases[(*i).second]->duration = newDur;
345 unsigned int StepOfMaxValue = (
unsigned int)
myPhases.size();
350 unsigned int maxDur = (
unsigned int)
myPhases[(*it).first]->maxDuration;
351 unsigned int actDur = (
unsigned int)
myPhases[(*it).first]->duration;
352 if (actDur >= maxDur) {
355 if ((*it).second > MaxValue) {
356 MaxValue = (*it).second;
357 StepOfMaxValue = (*it).first;
360 return StepOfMaxValue;
366 unsigned int StepOfMinValue = (
unsigned int)
myPhases.size();
371 unsigned int minDur = (
unsigned int)
myPhases[(*it).first]->minDuration;
372 unsigned int actDur = (
unsigned int)
myPhases[(*it).first]->duration;
373 if (actDur <= minDur) {
376 if ((*it).second < MinValue) {
377 MinValue = (*it).second;
378 StepOfMinValue = (*it).first;
381 return StepOfMinValue;
void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
PhaseValueMap myRawDetectorData
A map of the step of the greenphases and their detectorvalues for several (mumberofValues) cycles...
unsigned int numberOfValues
The number of detector values whivh is considered to make a decision.
The link has green light, may pass.
#define DEFAULT_DETECTOR_OFFSET
Builds detectors for microsim.
const std::string & getState() const
Returns the state within this phase.
unsigned int myStep
The current step.
std::string myProgramID
The id of the logic.
static SUMOReal _2SUMOReal(const E *const data)
A detector which joins E2Collectors over consecutive lanes (backward)
The link has green light, has to brake.
void lengthenCycleTime(unsigned int toLenghten)
lenghtens the actual cycle by an given value
Phases myPhases
The list of phases this logic uses.
void calculateDuration()
Calculates the duration for all real phases except intergreen phases.
MSDetectorFileOutput * buildMultiLaneE2Det(const std::string &id, DetectorUsage usage, MSLane *lane, SUMOReal pos, SUMOReal length, SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold, SUMOReal jamDistThreshold)
Builds an e2 detector that continues on preceeding lanes.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
std::deque< SUMOReal > ValueType
Definition of a map which stores the detector values of one single phase.
unsigned int nextStep()
Returns the index of the phase next to the given phase.
MSAgentbasedTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const MSSimpleTrafficLightLogic::Phases &phases, unsigned int step, SUMOTime delay, const std::map< std::string, std::string > ¶meter)
Constructor.
~MSAgentbasedTrafficLightLogic()
Destructor.
A fixed traffic light logic.
LaneVectorVector myLanes
The list of links which do participate in this traffic light.
A class that stores and controls tls and switching of their programs.
unsigned int findStepOfMaxValue() const
Returns the step of the phase with the longest Queue_Lengt_Ahead_Of_Traffic_Lights.
const std::string & getID() const
Returns the id.
SUMOTime duration
The duration of the phase.
unsigned int tCycle
The cycletime of the trafficlight.
void aggregateRawData()
Aggregates the data of one phase, collected during different cycles.
MeanDataMap myMeanDetectorData
A map of the step of the greenphases and their aggregated detectordata.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
#define DEFAULT_LEARN_HORIZON
const LaneVector & getLanesAt(unsigned int i) const
Returns the list of lanes that are controlled by the signals at the given position.
unsigned int tDecide
the interval in which the traffic light can make a decision
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
SUMOTime trySwitch(bool isActive)
Switches to the next phase.
void collectData()
Collects the traffic data.
unsigned int tSinceLastDecision
The number of cycles, before the last decision was made.
E2DetectorMap myE2Detectors
A map from lanes to E2 detectors lying on them.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
static int _2int(const E *const data)
std::string myID
The name of the object.
std::vector< MSLane * > LaneVector
Definition of the list of links that participate in this tl-light.
void cutCycleTime(unsigned int toCut)
cuts the actual cycle by an given value
The edge is an internal edge.
unsigned int findStepOfMinValue() const
Returns the step of the phase with the shortest Queue_Lengt_Ahead_Of_Traffic_Lights.
Representation of a lane in the micro simulation.
#define DEFAULT_CYCLE_TIME
unsigned int stepOfLastDecision
Stores the step of the phase, when the last decision was made.
Base of value-generating classes (detectors)