 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
45 #define DEBUG_COND (getID()=="C")
50 #define DEFAULT_MAX_GAP "3.0"
51 #define DEFAULT_PASSING_TIME "1.9"
52 #define DEFAULT_DETECTOR_GAP "2.0"
53 #define DEFAULT_INACTIVE_THRESHOLD "180"
54 #define DEFAULT_CURRENT_PRIORITY 10
56 #define DEFAULT_LENGTH_WITH_GAP 7.5
63 const std::string&
id,
const std::string& programID,
66 const std::map<std::string, std::string>& parameter,
67 const std::string& basePath) :
87 const int numLinks = (int)
myLinks.size();
109 LaneVectorVector::const_iterator i2;
110 LaneVector::const_iterator i;
112 std::map<const MSLane*, MSInductLoop*> laneInductLoopMap;
113 std::map<MSInductLoop*, const MSLane*> inductLoopLaneMap;
114 double maxDetectorGap = 0;
117 for (i = lanes.begin(); i != lanes.end(); i++) {
123 if (laneInductLoopMap.find(lane) != laneInductLoopMap.end()) {
128 if (minDur == std::numeric_limits<SUMOTime>::max()) {
134 double inductLoopPosition =
MIN2(
139 double ilpos = length - inductLoopPosition;
140 MSLane* placementLane = lane;
141 while (ilpos < 0 && placementLane->getIncomingLanes().size() == 1) {
151 laneInductLoopMap[lane] = loop;
152 inductLoopLaneMap[loop] = lane;
155 maxDetectorGap =
MAX2(maxDetectorGap, length - ilpos);
179 std::map<int, std::set<MSInductLoop*> > linkToLoops;
180 std::set<int> actuatedLinks;
182 std::vector<bool> neverMajor(numLinks,
true);
184 const std::string& state = phase->getState();
185 for (
int i = 0; i < numLinks; i++) {
187 neverMajor[i] =
false;
191 std::vector<bool> oneLane(numLinks,
false);
192 for (
int i = 0; i < numLinks; i++) {
195 int numMotorized = 0;
197 if ((l->getPermissions() & motorized) != 0) {
201 if (numMotorized == 1) {
211 std::set<MSInductLoop*> loops;
212 if (phase->minDuration != phase->maxDuration) {
214 const std::string& state = phase->getState();
216 std::set<int> greenLinks;
218 std::map<MSInductLoop*, std::set<int> > loopLinks;
220 for (
int i = 0; i < numLinks; i++) {
227 greenLinks.insert(i);
228 actuatedLinks.insert(i);
230 #ifdef DEBUG_DETECTORS
243 if (laneInductLoopMap.count(lane) != 0) {
244 loopLinks[laneInductLoopMap[lane]].insert(i);
248 for (
auto& item : loopLinks) {
250 const MSLane* loopLane = inductLoopLaneMap[loop];
253 for (
int j : item.second) {
254 if (greenLinks.count(j) == 0) {
256 #ifdef DEBUG_DETECTORS
258 std::cout <<
" phase=" << phaseIndex <<
" check1: loopLane=" << loopLane->
getID() <<
" notGreen=" << j <<
" oneLane[j]=" << oneLane[j] <<
"\n";
267 const MSLane* next = link->getLane();
268 if (laneInductLoopMap.count(next) != 0) {
270 for (
int j : loopLinks[nextLoop]) {
271 if (greenLinks.count(j) == 0) {
273 #ifdef DEBUG_DETECTORS
274 if (
DEBUG_COND) std::cout <<
" phase=" << phaseIndex <<
" check2: loopLane=" << loopLane->
getID()
275 <<
" nextLane=" << next->
getID() <<
" nextLink=" << j <<
" nextState=" << state[j] <<
"\n";
285 loops.insert(item.first);
286 #ifdef DEBUG_DETECTORS
289 for (
int j : item.second) {
290 linkToLoops[j].insert(item.first);
294 if (loops.size() == 0) {
295 WRITE_WARNING(
"At actuated tlLogic '" +
getID() +
"', actuated phase " +
toString(phaseIndex) +
" has no controlling detector");
298 #ifdef DEBUG_DETECTORS
300 std::cout <<
" phase=" << phaseIndex <<
" loops=" <<
joinNamedToString(loops,
" ") <<
"\n";
309 std::vector<InductLoopInfo*> loopInfos;
313 if (loopInfo.loop == loop) {
315 loopInfo.servedPhase[phaseIndex] =
true;
320 #ifdef DEBUG_DETECTORS
328 for (
int i : actuatedLinks) {
329 if (linkToLoops[i].size() == 0 &&
myLinks[i].size() > 0
330 && (
myLinks[i].front()->getLaneBefore()->getPermissions() & motorized) != 0) {
339 SUMOTime result = std::numeric_limits<SUMOTime>::max();
341 const std::string& state = phase->getState();
342 for (
int i = 0; i < (int)state.size(); i++) {
346 if (phase->minDuration != phase->maxDuration) {
347 result =
MIN2(result, phase->minDuration);
359 for (
int i = 0; i < (int)state.size(); i++) {
362 for (
MSLane* lane : lanes) {
379 loopInfo.loop->setVisible(
true);
388 loopInfo.loop->setVisible(
false);
400 #ifdef DEBUG_PHASE_SELECTION
402 std::cout <<
SIMTIME <<
" p=" <<
myStep <<
" trySwitch dGap=" << detectionGap <<
" multi=" << multiTarget <<
"\n";
405 if (detectionGap < std::numeric_limits<double>::max() && !multiTarget) {
409 const int origStep =
myStep;
435 loopInfo->lastGreenTime = now;
454 if (newDuration % 1000 != 0) {
455 const SUMOTime totalDur = newDuration + actDuration;
456 newDuration = (totalDur / 1000 + 1) * 1000 - actDuration;
468 double result = std::numeric_limits<double>::max();
475 if (loopInfo.lastGreenTime < loopInfo.loop->getLastDetectionTime()) {
478 loopInfo.loop->setSpecialColor(
nullptr);
498 result =
MIN2(result, actualGap);
511 int result = cands.front();
519 #ifdef DEBUG_PHASE_SELECTION
522 if (currentPrio > maxPrio) {
524 maxPrio = currentPrio;
527 for (
int step : cands) {
530 #ifdef DEBUG_PHASE_SELECTION
535 if (prio > maxPrio) {
543 if (prio > maxPrio) {
544 result = cands.front();
547 +
"', starvation at e1Detector '" + loopInfo.loop->getID()
548 +
"' which cannot be reached from the default phase " +
toString(
myStep) +
".");
551 #ifdef DEBUG_PHASE_SELECTION
553 std::cout <<
SIMTIME <<
" p=" <<
myStep <<
" loop=" << loopInfo.loop->getID() <<
" prio=" << prio <<
" next=" << result <<
"\n";
567 while (!
myPhases[step]->isGreenPhase()) {
568 if (
myPhases[step]->nextPhases.size() > 0 &&
myPhases[step]->nextPhases.front() >= 0) {
569 if (
myPhases[step]->nextPhases.size() > 1) {
570 WRITE_WARNING(
"At actuated tlLogic '" +
getID() +
"', transition phase " +
toString(step) +
" should not have multiple next phases");
572 step =
myPhases[step]->nextPhases.front();
576 if (step == origStep) {
592 #ifdef DEBUG_PHASE_SELECTION
virtual void activateProgram()
called when switching programs
@ SVC_PEDESTRIAN
pedestrian
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
MSDetectorControl & getDetectorControl()
Returns the detector control.
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
#define WRITE_WARNING(msg)
Representation of a lane in the micro simulation.
virtual MSDetectorFileOutput * createInductLoop(const std::string &id, MSLane *lane, double pos, const std::string &vTypes, bool show=true)
Creates an instance of an e1 detector using the given values.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
@ SVC_BICYCLE
vehicle is a bicycle
static OptionsCont & getOptions()
Retrieves the options.
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
An unextended detector measuring at a fixed position on a fixed lane.
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessable from the current working directory.
std::vector< InductLoopInfo > myInductLoops
#define DEFAULT_PASSING_TIME
#define DEFAULT_INACTIVE_THRESHOLD
~MSActuatedTrafficLightLogic()
Destructor.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
SUMOTime maxDuration
The maximum duration of the phase.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
int decideNextPhase()
select am candidate phases based on detector states
SUMOTime trySwitch()
Switches to the next phase.
SUMOTime duration(const double detectionGap) const
Returns the minimum duration of the current phase.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
#define DEFAULT_DETECTOR_GAP
int getTarget(int step)
get the green phase following step
std::string myFile
The output file for generated detectors.
std::string myVehicleTypes
Whether detector output separates by vType.
SUMOTime getMinimumMinDuration(MSLane *lane) const
get the minimum min duration for all stretchable phases that affect the given lane
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
std::string joinNamedToString(const std::set< T *, C > &ns, const T_BETWEEN &between)
virtual void deactivateProgram()
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
double getLength() const
Returns the lane's length.
#define DEFAULT_CURRENT_PRIORITY
A fixed traffic light logic.
std::string time2string(SUMOTime t)
static const RGBColor RED
named colors
SUMOTime myFreq
The frequency for aggregating detector output.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
const std::string myProgramID
The id of the logic.
SUMOTime string2time(const std::string &r)
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
MSEdge & getEdge() const
Returns the lane's edge.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void setShowDetectors(bool show)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
int getDetectorPriority(const InductLoopInfo &loopInfo) const
std::vector< bool > servedPhase
SUMOTime myInactiveThreshold
The time threshold to avoid starved phases.
Phases myPhases
The list of phases this logic uses.
bool hasMajor(const std::string &state, const LaneVector &lanes) const
return whether there is a major link from the given lane in the given phase
double myDetectorGap
The detector distance in seconds.
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permission forbids vehicles.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
double gapControl()
Return the minimum detection gap of all detectors if the current phase should be extended and double:...
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime splInterval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
A class that stores and controls tls and switching of their programs.
InductLoopMap myInductLoopsForPhase
A map from phase to induction loops to be used for gap control.
static const RGBColor GREEN
MSActuatedTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const MSSimpleTrafficLightLogic::Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > ¶meter, const std::string &basePath)
Constructor.
The definition of a single phase of a tls logic.
double myPassingTime
The passing time used in seconds.
int myStep
The current step.
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
double myMaxGap
The maximum gap to check in seconds.
void activateProgram()
called when switching programs
Builds detectors for microsim.
#define DEFAULT_LENGTH_WITH_GAP
int getPhasePriority(int step) const
count the number of active detectors for the given step
SUMOTime minDuration
The minimum duration of the phase.
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.