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) {
82 LaneVectorVector::const_iterator i2;
83 LaneVector::const_iterator i;
87 for (i = lanes.begin(); i != lanes.end(); i++) {
90 std::string
id =
"TL_" +
myID +
"_" +
myProgramID +
"_E2OverLanesDetectorStartingAt_" + lane->
getID();
106 unsigned int tCycleIst = 0;
107 unsigned int tCycleMin = 0;
108 unsigned int tDeltaGreen = 0;
111 for (
unsigned int actStep = 0; actStep !=
myPhases.size(); actStep++) {
112 unsigned int dur = (
unsigned int)
myPhases[actStep]->duration;
113 tCycleIst = tCycleIst + dur;
114 if (
myPhases[actStep]->isGreenPhase()) {
115 unsigned int mindur = (
unsigned int)
myPhases[actStep]->minDuration;
116 tCycleMin = tCycleMin + mindur;
118 tCycleMin = tCycleMin + dur;
125 tDeltaGreen =
tCycle - tCycleIst;
129 tDeltaGreen = tCycleIst -
tCycle;
184 for (
unsigned int i = 0; i < (
unsigned int) state.size(); i++) {
187 const std::vector<MSLane*>& lanes =
getLanesAt(i);
192 for (LaneVector::const_iterator j = lanes.begin(); j != lanes.end(); j++) {
205 if (maxPerPhase < maxPerBit) {
206 maxPerPhase = maxPerBit;
243 if (stepOfMaxValue ==
myPhases.size()) {
247 if (stepOfMinValue ==
myPhases.size()) {
250 if (stepOfMinValue == stepOfMaxValue) {
256 myPhases[stepOfMaxValue]->duration =
myPhases[stepOfMaxValue]->duration + 1;
257 myPhases[stepOfMinValue]->duration =
myPhases[stepOfMinValue]->duration - 1;
266 typedef std::pair <unsigned int, unsigned int> contentType;
267 typedef std::vector< std::pair <unsigned int, unsigned int> > GreenPhasesVector;
268 GreenPhasesVector tmp_phases(
myPhases.size());
270 unsigned int maxLengthen = 0;
276 for (
unsigned int i_Step = 0; i_Step !=
myPhases.size(); i_Step++) {
277 if (
myPhases[i_Step]->isGreenPhase()) {
278 unsigned int dur = (
unsigned int)
myPhases[i_Step]->duration;
279 unsigned int maxdur = (
unsigned int)
myPhases[i_Step]->maxDuration;
283 tmp.first = maxdur - dur;
284 tmp_phases.push_back(tmp);
285 maxLengthen = maxLengthen + tmp.first;
289 sort(tmp_phases.begin(), tmp_phases.end());
291 for (GreenPhasesVector::iterator i = tmp_phases.begin(); i != tmp_phases.end(); i++) {
294 toLengthenPerPhase =
static_cast<SUMOTime>(tmpdb);
295 toLengthen = toLengthen - (
unsigned int) toLengthenPerPhase;
296 maxLengthen = maxLengthen - (*i).first;
298 myPhases[(*i).second]->duration = newDur;
305 typedef std::pair <unsigned int, unsigned int> contentType;
306 typedef std::vector< std::pair <unsigned int, unsigned int> > GreenPhasesVector;
307 GreenPhasesVector tmp_phases(
myPhases.size());
315 for (
unsigned i_Step = 0; i_Step !=
myPhases.size(); i_Step++) {
316 if (
myPhases[i_Step]->isGreenPhase()) {
317 unsigned int dur = (
unsigned int)
myPhases[i_Step]->duration;
318 unsigned int mindur = (
unsigned int)
myPhases[i_Step]->minDuration;
322 tmp.first = dur - mindur;
323 tmp_phases.push_back(tmp);
324 maxCut = maxCut + tmp.first;
328 std::sort(tmp_phases.begin(), tmp_phases.end());
330 for (GreenPhasesVector::iterator i = tmp_phases.begin(); i != tmp_phases.end(); i++) {
333 toCutPerPhase =
static_cast<SUMOTime>(tmpdb);
334 toCut = toCut - (
unsigned int) toCutPerPhase;
335 maxCut = maxCut - (*i).first;
337 myPhases[(*i).second]->duration = newDur;
344 unsigned int StepOfMaxValue = (
unsigned int)
myPhases.size();
349 unsigned int maxDur = (
unsigned int)
myPhases[(*it).first]->maxDuration;
350 unsigned int actDur = (
unsigned int)
myPhases[(*it).first]->duration;
351 if (actDur >= maxDur) {
354 if ((*it).second > MaxValue) {
355 MaxValue = (*it).second;
356 StepOfMaxValue = (*it).first;
359 return StepOfMaxValue;
365 unsigned int StepOfMinValue = (
unsigned int)
myPhases.size();
370 unsigned int minDur = (
unsigned int)
myPhases[(*it).first]->minDuration;
371 unsigned int actDur = (
unsigned int)
myPhases[(*it).first]->duration;
372 if (actDur <= minDur) {
375 if ((*it).second < MinValue) {
376 MinValue = (*it).second;
377 StepOfMinValue = (*it).first;
380 return StepOfMinValue;