 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
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);
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.
static OptionsCont & getOptions()
Retrieves the options.
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.
#define DEFAULT_PASSING_TIME
~MSActuatedTrafficLightLogic()
Destructor.
The link has green light, may pass.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
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
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)
double getLength() const
Returns the lane's length.
A fixed traffic light logic.
std::vector< MSInductLoop * > myInductLoops
std::string time2string(SUMOTime t)
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.
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).
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.
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.
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.
Builds detectors for microsim.
#define DEFAULT_LENGTH_WITH_GAP
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.