55 : myTLControl(tlcontrol), myTLLogic(tlLogic),
56 myAssumedNextSwitch(nextSwitch), myAmValid(true) {}
103 const std::map<std::string, std::string>& parameters) :
120 if (phases.size() > 1) {
121 bool haveWarnedAboutUnusedStates =
false;
122 std::vector<bool> foundGreen(phases.front()->getState().size(),
false);
123 for (
int i = 0; i < (int)phases.size(); ++i) {
125 const int iNext = phases[i]->nextPhase < 0 ? (i + 1) % phases.size() : phases[i]->nextPhase;
126 if (iNext < 0 || iNext >= (
int)phases.size()) {
130 const std::string optionalFrom = phases[i]->nextPhase < 0 ?
"" :
" from phase " +
toString(i);
131 const std::string& state1 = phases[i]->getState();
132 const std::string& state2 = phases[iNext]->getState();
133 assert(state1.size() == state2.size());
138 haveWarnedAboutUnusedStates =
true;
142 if (std::string::npos != illegal) {
147 for (
int j = 0; j < (int)
MIN3(state1.size(), state2.size(),
myLanes.size()); ++j) {
151 for (LaneVector::const_iterator it =
myLanes[j].begin(); it !=
myLanes[j].end(); ++it) {
155 +
" when switching" + optionalFrom +
" to phase " +
toString(iNext));
162 for (
int j = 0; j < (int)state1.size(); ++j) {
165 foundGreen[j] =
true;
169 for (
int j = 0; j < (int)foundGreen.size(); ++j) {
170 if (!foundGreen[j]) {
191 while ((
int)
myLinks.size() <= pos) {
197 while ((
int)
myLanes.size() <= pos) {
213 std::map<MSLink*, LinkState>
215 std::map<MSLink*, LinkState> ret;
216 for (LinkVectorVector::const_iterator i1 =
myLinks.begin(); i1 !=
myLinks.end(); ++i1) {
218 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
219 ret[*i2] = (*i2)->getState();
231 for (
int i = 0; i < (int)
myLinks.size(); i++) {
234 for (LinkVector::const_iterator j = currGroup.begin(); j != currGroup.end(); j++) {
235 (*j)->setTLState(ls, t);
244 for (LinkVectorVector::const_iterator i1 =
myLinks.begin(); i1 !=
myLinks.end(); ++i1) {
246 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
247 assert(vals.find(*i2) != vals.end());
258 for (LinkVectorVector::const_iterator i1 =
myLinks.begin(); i1 !=
myLinks.end(); ++i1, ++index) {
260 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
281 if (nextSwitch == -1) {
306 const int numLinks = (int)
myLinks.size();
308 assert(numLinks <= (
int)phases.front()->getState().size());
310 std::vector<double> redDuration(numLinks, 0);
311 std::vector<double> totalRedDuration(numLinks, 0);
312 std::vector<double> penalty(numLinks, 0);
313 for (
int i = 0; i < (int)phases.size(); ++i) {
314 const std::string& state = phases[i]->getState();
315 duration += phases[i]->duration;
317 for (
int j = 0; j < numLinks; ++j) {
320 redDuration[j] +=
STEPS2TIME(phases[i]->duration);
321 totalRedDuration[j] +=
STEPS2TIME(phases[i]->duration);
322 }
else if (redDuration[j] > 0) {
323 penalty[j] += 0.5 * (redDuration[j] * redDuration[j] + redDuration[j]);
329 for (
int j = 0; j < numLinks; ++j) {
330 if (redDuration[j] > 0) {
331 penalty[j] += 0.5 * (redDuration[j] * redDuration[j] + redDuration[j]);
335 const double durationSeconds =
STEPS2TIME(duration);
336 std::set<const MSJunction*> controlledJunctions;
337 for (
int j = 0; j < numLinks; ++j) {
338 for (
int k = 0; k < (int)
myLinks[j].size(); ++k) {
341 controlledJunctions.insert(
myLinks[j][k]->getLane()->getEdge().getFromJunction());
347 for (std::set<const MSJunction*>::iterator it = controlledJunctions.begin(); it != controlledJunctions.end(); ++it) {
349 for (ConstMSEdgeVector::const_iterator it_e = incoming.begin(); it_e != incoming.end(); ++it_e) {
SUMOTime myCurrentDurationIncrement
A value for enlarge the current duration.
The link has green light, may pass.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
const std::string & getState() const
Returns the state within this phase.
Builds detectors for microsim.
void initMesoTLSPenalties()
initialize optional meso penalties
void executeOnSwitchActions() const
Storage for all programs of a single tls.
MSTLLogicControl & myTLControl
The responsible traffic lights control.
static double gMesoTLSPenalty
std::vector< SUMOTime > myOverridingTimes
A list of duration overrides.
SwitchCommand(MSTLLogicControl &tlcontrol, MSTrafficLightLogic *tlLogic, SUMOTime nextSwitch)
Constructor.
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state
SUMOTime myAssumedNextSwitch
Assumed switch time (may change in case of adaptive traffic lights)
The link has green light, has to brake.
void recalcCache()
Recalculates the cached values.
static const LaneVector myEmptyLaneVector
An empty lane vector.
void setTLState(LinkState state, SUMOTime t)
Sets the current tl-state.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
std::vector< const MSEdge * > ConstMSEdgeVector
const std::string & getID() const
Returns the id.
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
const TrafficLightType myLogicType
The type of the logic.
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
void resetLinkStates(const std::map< MSLink *, LinkState > &vals) const
Resets the states of controlled links.
int getLinkIndex(const MSLink *const link) const
Returns the index of the given link.
std::set< int > myIgnoredIndices
list of indices that are ignored in mesoscopic simulatino
#define WRITE_WARNING(msg)
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index...
virtual ~MSTrafficLightLogic()
Destructor.
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
SUMOTime duration
The duration of the phase.
void deschedule(MSTrafficLightLogic *tlLogic)
Marks this swicth as invalid (if the phase duration has changed, f.e.)
Class realising the switch between the traffic light phases.
MSTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const TrafficLightType logicType, const SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor.
~SwitchCommand()
Destructor.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
SUMOTime myDefaultCycleTime
The cycle time (without changes)
const std::string & getProgramID() const
Returns this tl-logic's id.
MSTrafficLightLogic * myTLLogic
The logic to be executed on a switch.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
std::map< MSLink *, LinkState > collectLinkStates() const
Returns the (uncontrolled) states of the controlled links.
An upper class for objects with additional parameters.
void setCurrentDurationIncrement(SUMOTime delay)
Delays current phase by the given delay.
Base class for objects which have an id.
const std::string myProgramID
The id of the logic.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
virtual const Phases & getPhases() const =0
Returns the phases of this tls program.
void addOverridingDuration(SUMOTime duration)
Changes the duration of the next phase.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index...
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
void ignoreLinkIndex(int pos)
ignore pedestrian crossing index in mesosim
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
The link has red light (must brake)
virtual void addLink(MSLink *link, MSLane *lane, int pos)
Adds a link on building.
SwitchCommand * mySwitchCommand
The current switch command.
The parent class for traffic light logics.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
SUMOTime getSpentDuration() const
Returns the duration spent in the current phase.
bool myAmValid
Information whether this switch command is still valid.
virtual SUMOTime trySwitch()=0
Switches to the next phase.
Representation of a lane in the micro simulation.
The link has red light (must brake) but indicates upcoming green.
SUMOTime execute(SUMOTime currentTime)
Executes the regarded junction's "trySwitch"- method.