 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
53 myConnections.push_back(c);
59 myPhases.push_back(
PhaseDef(time, color));
65 myTRedYellow = tRedYellow;
81 }
else if (forced && myTYellow < tyellow) {
91 std::vector<double> ret;
92 for (std::vector<PhaseDef>::const_iterator i = myPhases.begin(); i != myPhases.end(); i++) {
93 ret.push_back((
double)(*i).myTime);
97 for (std::vector<PhaseDef>::const_iterator i = myPhases.begin(); i != myPhases.end(); i++) {
100 if (time > cycleDuration) {
101 time = time - cycleDuration;
103 ret.push_back((
double) time);
113 return (
int) myConnections.size();
119 assert(myPhases.size() != 0);
120 for (std::vector<PhaseDef>::const_reverse_iterator i = myPhases.rbegin(); i != myPhases.rend(); i++) {
122 if (time >= nextTime) {
132 bool has_red_now = !mayDrive(time);
133 bool had_green = mayDrive(time - myTYellow);
134 return has_red_now && had_green;
140 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
141 if ((*i).getFrom() == from && (*i).getTo() == to) {
152 assert(pos < (
int)myConnections.size());
153 return myConnections[pos];
159 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
160 if ((*i).getFrom() == from) {
171 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
172 if ((*i).getFrom() == which) {
174 i = myConnections.erase(i);
175 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
178 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
180 newConns.push_back(curr);
186 copy(newConns.begin(), newConns.end(),
187 back_inserter(myConnections));
193 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
194 if ((*i).getTo() == to) {
205 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
206 if ((*i).getTo() == which) {
208 i = myConnections.erase(i);
209 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
212 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
214 newConns.push_back(curr);
220 copy(newConns.begin(), newConns.end(),
221 back_inserter(myConnections));
228 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end(); i++) {
229 if ((*i).getTo() == removed
231 ((*i).getToLane() == removedLane
233 (*i).getToLane() == -1)) {
234 (*i).replaceTo(removed, removedLane, by, byLane);
236 }
else if ((*i).getTo() == removed && removedLane == -1) {
237 (*i).replaceTo(removed, by);
240 if ((*i).getFrom() == removed
242 ((*i).getFromLane() == removedLane
244 (*i).getFromLane() == -1)) {
245 (*i).replaceFrom(removed, removedLane, by, byLane);
247 }
else if ((*i).getFrom() == removed && removedLane == -1) {
248 (*i).replaceFrom(removed, by);
286 NBLoadedTLDef::SignalGroupCont::const_iterator i;
288 std::set<double> tmpSwitchTimes;
299 for (std::vector<double>::const_iterator k = gtimes.begin(); k != gtimes.end(); k++) {
300 tmpSwitchTimes.insert(*k);
303 std::vector<double> switchTimes;
304 copy(tmpSwitchTimes.begin(), tmpSwitchTimes.end(), back_inserter(switchTimes));
305 sort(switchTimes.begin(), switchTimes.end());
310 noSignals += (*i).second->getLinkNo();
314 for (std::vector<double>::iterator l = switchTimes.begin(); l != switchTimes.end(); l++) {
317 if (l != switchTimes.end() - 1) {
319 duration = (int)((*(l + 1)) - (*l));
337 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = logic->
getPhases();
338 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
339 const std::string state = (*it).state;
351 && (state[i2] ==
'G' || state[i2] ==
'g')
390 bool mayDrive = group->
mayDrive(time);
399 for (
int j = 0; j < linkNo; j++) {
414 for (
int j = 0; j < linkNo; j++) {
419 if (state[pos] ==
'g') {
422 if (state[pos] ==
'y') {
436 const std::string& state,
439 if (state[strmpos] !=
'g' && state[strmpos] !=
'G') {
450 for (
int j = 0; j < linkNo; j++) {
461 if (state[pos] ==
'g' || state[pos] ==
'G') {
486 SignalGroupCont::const_iterator m;
490 for (
int j = 0; j < linkNo; j++) {
508 for (
int j = 0; j < noLanes; j++) {
510 for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) {
512 if (el.
toEdge !=
nullptr) {
524 for (
int j = 0; j < linkNo; j++) {
530 if (tst.getFrom()->mayBeTLSControlled(tst.getFromLane(), tst.getTo(), tst.getToLane())) {
534 && tst.getFrom() == c.
getFrom() && tst.getTo() == c.
getTo()
535 && (tst.getFromLane() < 0 || tst.getFromLane() == c.
getFromLane())
536 && (tst.getToLane() < 0 || tst.getToLane() == c.
getToLane())) {
554 if ((*i).second->containsConnection(from, to)) {
587 for (NBConnectionVector::const_iterator i = connections.begin(); i != connections.end(); i++) {
644 group->
remap(removed, removedLane, by, byLane);
653 throw ProcessError(
"myNeedsContRelation was not propperly initialized\n");
662 if (logic !=
nullptr) {
data structure for caching needsCont information
NBEdge * toEdge
The edge the connections yields in.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
#define WRITE_WARNING(msg)
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
Base class for objects which have an id.
Storage for edges, including some functionality operating on multiple edges.
void collectNodes()
Collects the nodes participating in this traffic light.
Used for sorting the cells by the begin time they describe.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
void addSignalGroup(const std::string &id)
Adds a signal group.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
A single signal group, may control several connections.
void patchTYellow(int tyellow, bool forced)
Sets the yellow time.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
NBConnectionVector myControlledLinks
The list of controlled links.
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
void closeBuilding(bool checkVarDurations=true)
closes the building process
NBEdge * getFrom() const
returns the from-edge (start of the connection)
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
SUMOTime myOffset
The offset in the program.
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
const static int InvalidTlIndex
NBEdge * getTo() const
returns the to-edge (end of the connection)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
SignalGroupCont mySignalGroups
Controlled signal groups.
TrafficLightType myType
The algorithm type for the traffic light.
virtual void collectEdges()
Build the list of participating edges.
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
The representation of a single edge during network building.
virtual void clear()
Clears information whether an error occurred previously.
void addStep(SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", int index=-1)
Adds a phase to the logic.
int toLane
The lane the connections yields in.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
NBNode * getToNode() const
Returns the destination node of the edge.
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
void setTLIndex(int tlIndex)
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
TLColor
An enumeration of possible tl-signal states.
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
int getNumLinks()
Returns the number of participating links.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
int getToLane() const
returns the to-lane
int getNumLanes() const
Returns the number of lanes.
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane, bool lefthand=false)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
NeedsContRelation myNeedsContRelation
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
int myCycleDuration
The duration of a single cycle.
void collectLinks()
Collects the links participating in this traffic light.
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
bool myNeedsContRelationReady
~SignalGroup()
Destructor.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
SignalGroup(const std::string &id)
Constructor.
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
Sorts phases by their begin time.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
static const std::string DefaultProgramID
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
const std::string & getProgramID() const
Returns the ProgramID.
Definition of a single, loaded phase.
void initNeedsContRelation() const
std::string buildPhaseState(int time) const
Builds the phase for a given time.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
~NBLoadedTLDef()
Destructor.
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
const NBEdgeCont * myEdgeCont
A SUMO-compliant built logic for a traffic light.
Represents a single node (junction) during network building.
EdgeVector myIncomingEdges
The list of incoming edges.
void sortPhases()
Sorts the phases.
bool containsConnection(NBEdge *from, NBEdge *to) const
Returns whether the given connection is controlled by this signal.
A structure which describes a connection between edges or lanes.
std::vector< double > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
const std::string & getID() const
Returns the id.
NBNode * getFromNode() const
Returns the origin node of the edge.
int getFromLane() const
returns the from-lane
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly=false) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
The base class for traffic light logic definitions.
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
const std::string & getID() const