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;