46 #ifdef CHECK_MEMORY_LEAKS
48 #endif // CHECK_MEMORY_LEAKS
56 const std::string&
id,
const std::string& programID,
60 tSinceLastDecision(0), stepOfLastDecision(0) {
63 if (parameter.find(
"decision-horizon") != parameter.end()) {
67 if (parameter.find(
"learn-horizon") != parameter.end()) {
71 if (parameter.find(
"tcycle") != parameter.end()) {
75 if (parameter.find(
"min-diff") != parameter.end()) {
84 LaneVectorVector::const_iterator i2;
85 LaneVector::const_iterator i;
89 for (i = lanes.begin(); i != lanes.end(); i++) {
92 std::string
id =
"TL_" +
myID +
"_" +
myProgramID +
"_E2OverLanesDetectorStartingAt_" + lane->
getID();
108 unsigned int tCycleIst = 0;
109 unsigned int tCycleMin = 0;
110 unsigned int tDeltaGreen = 0;
113 for (
unsigned int actStep = 0; actStep !=
myPhases.size(); actStep++) {
114 unsigned int dur = (
unsigned int)
myPhases[actStep]->duration;
115 tCycleIst = tCycleIst + dur;
116 if (
myPhases[actStep]->isGreenPhase()) {
117 unsigned int mindur = (
unsigned int)
myPhases[actStep]->minDuration;
118 tCycleMin = tCycleMin + mindur;
120 tCycleMin = tCycleMin + dur;
127 tDeltaGreen =
tCycle - tCycleIst;
131 tDeltaGreen = tCycleIst -
tCycle;
186 for (
unsigned int i = 0; i < (
unsigned int) state.size(); i++) {
189 const std::vector<MSLane*>& lanes =
getLanesAt(i);
194 for (LaneVector::const_iterator j = lanes.begin(); j != lanes.end(); j++) {
207 if (maxPerPhase < maxPerBit) {
208 maxPerPhase = maxPerBit;
245 if (stepOfMaxValue ==
myPhases.size()) {
249 if (stepOfMinValue ==
myPhases.size()) {
252 if (stepOfMinValue == stepOfMaxValue) {
258 myPhases[stepOfMaxValue]->duration =
myPhases[stepOfMaxValue]->duration + 1;
259 myPhases[stepOfMinValue]->duration =
myPhases[stepOfMinValue]->duration - 1;
268 typedef std::pair <unsigned int, unsigned int> contentType;
269 typedef std::vector< std::pair <unsigned int, unsigned int> > GreenPhasesVector;
270 GreenPhasesVector tmp_phases(
myPhases.size());
272 unsigned int maxLengthen = 0;
278 for (
unsigned int i_Step = 0; i_Step !=
myPhases.size(); i_Step++) {
279 if (
myPhases[i_Step]->isGreenPhase()) {
280 unsigned int dur = (
unsigned int)
myPhases[i_Step]->duration;
281 unsigned int maxdur = (
unsigned int)
myPhases[i_Step]->maxDuration;
285 tmp.first = maxdur - dur;
286 tmp_phases.push_back(tmp);
287 maxLengthen = maxLengthen + tmp.first;
291 sort(tmp_phases.begin(), tmp_phases.end());
293 for (GreenPhasesVector::iterator i = tmp_phases.begin(); i != tmp_phases.end(); i++) {
296 toLengthenPerPhase =
static_cast<SUMOTime>(tmpdb);
297 toLengthen = toLengthen - (
unsigned int) toLengthenPerPhase;
298 maxLengthen = maxLengthen - (*i).first;
300 myPhases[(*i).second]->duration = newDur;
307 typedef std::pair <unsigned int, unsigned int> contentType;
308 typedef std::vector< std::pair <unsigned int, unsigned int> > GreenPhasesVector;
309 GreenPhasesVector tmp_phases(
myPhases.size());
317 for (
unsigned i_Step = 0; i_Step !=
myPhases.size(); i_Step++) {
318 if (
myPhases[i_Step]->isGreenPhase()) {
319 unsigned int dur = (
unsigned int)
myPhases[i_Step]->duration;
320 unsigned int mindur = (
unsigned int)
myPhases[i_Step]->minDuration;
324 tmp.first = dur - mindur;
325 tmp_phases.push_back(tmp);
326 maxCut = maxCut + tmp.first;
330 std::sort(tmp_phases.begin(), tmp_phases.end());
332 for (GreenPhasesVector::iterator i = tmp_phases.begin(); i != tmp_phases.end(); i++) {
335 toCutPerPhase =
static_cast<SUMOTime>(tmpdb);
336 toCut = toCut - (
unsigned int) toCutPerPhase;
337 maxCut = maxCut - (*i).first;
339 myPhases[(*i).second]->duration = newDur;
346 unsigned int StepOfMaxValue = (
unsigned int)
myPhases.size();
351 unsigned int maxDur = (
unsigned int)
myPhases[(*it).first]->maxDuration;
352 unsigned int actDur = (
unsigned int)
myPhases[(*it).first]->duration;
353 if (actDur >= maxDur) {
356 if ((*it).second > MaxValue) {
357 MaxValue = (*it).second;
358 StepOfMaxValue = (*it).first;
361 return StepOfMaxValue;
367 unsigned int StepOfMinValue = (
unsigned int)
myPhases.size();
372 unsigned int minDur = (
unsigned int)
myPhases[(*it).first]->minDuration;
373 unsigned int actDur = (
unsigned int)
myPhases[(*it).first]->duration;
374 if (actDur <= minDur) {
377 if ((*it).second < MinValue) {
378 MinValue = (*it).second;
379 StepOfMinValue = (*it).first;
382 return StepOfMinValue;