45 #define DEBUG_COND (getID()=="26121229") 50 #define DEFAULT_MAX_GAP "3.0" 51 #define DEFAULT_PASSING_TIME "1.9" 52 #define DEFAULT_DETECTOR_GAP "2.0" 54 #define DEFAULT_LENGTH_WITH_GAP 7.5 61 const std::string&
id,
const std::string& programID,
64 const std::map<std::string, std::string>& parameter,
65 const std::string& basePath) :
84 const int numLinks = (int)
myLinks.size();
106 LaneVectorVector::const_iterator i2;
107 LaneVector::const_iterator i;
109 std::map<const MSLane*, MSInductLoop*> laneInductLoopMap;
110 std::map<MSInductLoop*, const MSLane*> inductLoopLaneMap;
111 double maxDetectorGap = 0;
114 for (i = lanes.begin(); i != lanes.end(); i++) {
120 if (laneInductLoopMap.find(lane) != laneInductLoopMap.end()) {
125 if (minDur == std::numeric_limits<SUMOTime>::max()) {
131 double inductLoopPosition =
MIN2(
136 double ilpos = length - inductLoopPosition;
137 MSLane* placementLane = lane;
138 while (ilpos < 0 && placementLane->getIncomingLanes().size() == 1) {
148 laneInductLoopMap[lane] = loop;
149 inductLoopLaneMap[loop] = lane;
152 maxDetectorGap =
MAX2(maxDetectorGap, length - ilpos);
176 std::map<int, std::set<MSInductLoop*> > linkToLoops;
177 std::set<int> actuatedLinks;
179 std::vector<bool> neverMajor(numLinks,
true);
181 const std::string& state = phase->getState();
182 for (
int i = 0; i < numLinks; i++) {
184 neverMajor[i] =
false;
188 std::vector<bool> oneLane(numLinks,
false);
189 for (
int i = 0; i < numLinks; i++) {
192 int numMotorized = 0;
194 if ((l->getPermissions() & motorized) != 0) {
198 if (numMotorized == 1) {
207 std::set<MSInductLoop*> loops;
208 if (phase->minDuration != phase->maxDuration) {
210 const std::string& state = phase->getState();
212 std::set<int> greenLinks;
214 std::map<MSInductLoop*, std::set<int> > loopLinks;
216 for (
int i = 0; i < numLinks; i++) {
223 greenLinks.insert(i);
224 actuatedLinks.insert(i);
226 #ifdef DEBUG_DETECTORS 239 if (laneInductLoopMap.count(lane) != 0) {
240 loopLinks[laneInductLoopMap[lane]].insert(i);
244 for (
auto& item : loopLinks) {
246 const MSLane* loopLane = inductLoopLaneMap[loop];
249 for (
int j : item.second) {
250 if (greenLinks.count(j) == 0) {
252 #ifdef DEBUG_DETECTORS 254 std::cout <<
" phase=" <<
myInductLoopsForPhase.size() <<
" check1: loopLane=" << loopLane->
getID() <<
" notGreen=" << j <<
" oneLane[j]=" << oneLane[j] <<
"\n";
263 const MSLane* next = link->getLane();
264 if (laneInductLoopMap.count(next) != 0) {
266 for (
int j : loopLinks[nextLoop]) {
267 if (greenLinks.count(j) == 0) {
269 #ifdef DEBUG_DETECTORS 271 <<
" nextLane=" << next->
getID() <<
" nextLink=" << j <<
" nextState=" << state[j] <<
"\n";
281 loops.insert(item.first);
282 #ifdef DEBUG_DETECTORS 285 for (
int j : item.second) {
286 linkToLoops[j].insert(item.first);
290 if (loops.size() == 0) {
294 #ifdef DEBUG_DETECTORS 307 #ifdef DEBUG_DETECTORS 315 for (
int i : actuatedLinks) {
316 if (linkToLoops[i].size() == 0 &&
myLinks[i].size() > 0
317 && (
myLinks[i].front()->getLaneBefore()->getPermissions() & motorized) != 0) {
326 SUMOTime result = std::numeric_limits<SUMOTime>::max();
328 const std::string& state = phase->getState();
329 for (
int i = 0; i < (int)state.size(); i++) {
333 if (phase->minDuration != phase->maxDuration) {
334 result =
MIN2(result, phase->minDuration);
346 for (
int i = 0; i < (int)state.size(); i++) {
349 for (
MSLane* lane : lanes) {
368 if (detectionGap < std::numeric_limits<double>::max()) {
402 if (newDuration % 1000 != 0) {
403 const SUMOTime totalDur = newDuration + actDuration;
404 newDuration = (totalDur / 1000 + 1) * 1000 - actDuration;
416 double result = std::numeric_limits<double>::max();
423 loop->setSpecialColor(
nullptr);
439 const double actualGap = loop->getTimeSinceLastDetection();
441 result =
MIN2(result, actualGap);
The link has green light, may pass.
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Builds detectors for microsim.
MSEdge & getEdge() const
Returns the lane's edge.
alternative tag for e1 detector
std::string joinNamedToString(const std::set< T *, C > &ns, const T_BETWEEN &between)
The link has green light, has to brake.
void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Phases myPhases
The list of phases this logic uses.
std::string time2string(SUMOTime t)
int myStep
The current step.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
std::string myFile
The output file for generated detectors.
double getLength() const
Returns the lane's length.
#define DEFAULT_DETECTOR_GAP
const std::string & getID() const
Returns the id.
void setShowDetectors(bool show)
#define WRITE_WARNING(msg)
SUMOTime duration(const double detectionGap) const
Returns the minimum duration of the current phase.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
A fixed traffic light logic.
static OptionsCont & getOptions()
Retrieves the options.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index...
InductLoopMap myInductLoopsForPhase
A map from phase to induction loops to be used for gap control.
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter ...
A class that stores and controls tls and switching of their programs.
std::string myVehicleTypes
Whether detector output separates by vType.
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 const RGBColor GREEN
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
SUMOTime getMinimumMinDuration(MSLane *lane) const
get the minimum min duration for all stretchable phases that affect the given lane ...
~MSActuatedTrafficLightLogic()
Destructor.
#define DEFAULT_PASSING_TIME
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
double myMaxGap
The maximum gap to check in seconds.
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime splInterval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
MSDetectorControl & getDetectorControl()
Returns the detector control.
#define DEFAULT_LENGTH_WITH_GAP
const std::string myProgramID
The id of the logic.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index...
std::string myID
The name of the object.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
double gapControl()
Return the minimum detection gap of all detectors if the current phase should be extended and double:...
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...
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permission forbids vehicles.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
SUMOTime minDuration
The minimum duration of the phase.
double myDetectorGap
The detector distance in seconds.
double myPassingTime
The passing time used in seconds.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
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.
std::vector< MSInductLoop * > myInductLoops
SUMOTime myFreq
The frequency for aggregating detector output.
The definition of a single phase of a tls logic.
Representation of a lane in the micro simulation.
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
SUMOTime trySwitch()
Switches to the next phase.
An unextended detector measuring at a fixed position on a fixed lane.