double MSActuatedTrafficLightLogic::gapControl() { //intergreen times should not be lenghtend assert((int)myPhases.size() > myStep); double result = std::numeric_limits<double>::max(); if (!getCurrentPhaseDef().isGreenPhase()) { return result; // end current phase } // Checks, if the maxDuration is kept. No phase should longer send than maxDuration. SUMOTime actDuration = MSNet::getInstance()->getCurrentTimeStep() - myPhases[myStep]->myLastSwitch; if (actDuration >= getCurrentPhaseDef().maxDuration) { return result; // end current phase } // now the gapcontrol starts const std::string& state = getCurrentPhaseDef().getState(); for (int i = 0; i < (int) state.size(); i++) { if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) { const std::vector<MSLane*>& lanes = getLanesAt(i); for (LaneVector::const_iterator j = lanes.begin(); j != lanes.end(); j++) { if (myInductLoops.find(*j) == myInductLoops.end()) { continue; } if (!MSGlobals::gUseMesoSim) { // why not check outside the loop? (Leo) const double actualGap = static_cast<MSInductLoop*>(myInductLoops.find(*j)->second)->getTimeSinceLastDetection(); if (actualGap < myMaxGap) { result = MIN2(result, actualGap); } } } } } return result; }
void MSAgentbasedTrafficLightLogic::collectData() throw() { //collects the traffic data // gets a copy of the driveMask const std::string &state = getCurrentPhaseDef().getState(); // finds the maximum QUEUE_LENGTH_AHEAD_OF_TRAFFIC_LIGHTS_IN_VEHICLES of one phase SUMOReal maxPerPhase = 0; for (unsigned int i=0; i<(unsigned int) state.size(); i++) { /* finds the maximum QUEUE_LENGTH_AHEAD_OF_TRAFFIC_LIGHTS_IN_VEHICLES of all lanes of a bit of the drivemask, that shows green */ if (state[i]==MSLink::LINKSTATE_TL_GREEN_MAJOR||state[i]==MSLink::LINKSTATE_TL_GREEN_MINOR) { const std::vector<MSLane*> &lanes = getLanesAt(i); if (lanes.empty()) { break; } SUMOReal maxPerBit = 0; for (LaneVector::const_iterator j=lanes.begin(); j!=lanes.end(); j++) { if ((*j)->getEdge().getPurpose()==MSEdge::EDGEFUNCTION_INTERNAL) { continue; } /*!!! SUMOReal tmp = currentForLane(E2::QUEUE_LENGTH_AHEAD_OF_TRAFFIC_LIGHTS_IN_VEHICLES, *j); if (maxPerBit < tmp) { maxPerBit = tmp; } E2DetectorMap::const_iterator it=myE2Detectors.find(*j); (*it).second->resetQueueLengthAheadOfTrafficLights(); */ } if (maxPerPhase < maxPerBit) { maxPerPhase = maxPerBit; } } } // if still no entry for the phase exists a new entry with an empty value is created if (myRawDetectorData.find(myStep) == myRawDetectorData.end()) { ValueType firstData; myRawDetectorData[myStep] = firstData; } /* checks whether the number of values that are already in the dataqueue is the same number of values taht shall be consideres in the traffic control if both numbers are the same, the oldest value is deleted */ if (myRawDetectorData[myStep].size()== numberOfValues) { myRawDetectorData[myStep].pop_back(); } // adds the detectorvalue of the considered phase myRawDetectorData[myStep].push_front(maxPerPhase); }