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;
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.
#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)