33#define INVALID_POSITION std::numeric_limits<double>::max()
45 const std::string&
id,
const std::string& programID,
50 const std::string& basePath) :
52#ifdef DEBUG_TIMELOSS_CONTROL
53 std::cout <<
"Building delay based tls logic '" <<
id <<
"'" << std::endl;
61#ifdef DEBUG_TIMELOSS_CONTROL
77 LaneVectorVector::const_iterator i2;
78 LaneVector::const_iterator i;
82 for (i = lanes.begin(); i != lanes.end(); i++) {
95 WRITE_ERROR(
"Unknown laneAreaDetector '" + customID +
"' given as custom detector for delay_based tlLogic '" +
getID() +
"', program '" +
getProgramID() +
".");
101 det = nb.
createE2Detector(
id,
DU_TL_CONTROL, lane,
INVALID_POSITION, lane->
getLength(),
myDetectionRange, 0, 0, 0,
myVehicleTypes,
"",
"", (
int)
PersonMode::NONE,
myShowDetectors);
119#ifdef DEBUG_TIMELOSS_CONTROL
120 std::cout <<
"\n" <<
SIMTIME <<
" MSDelayBasedTrafficLightLogic::proposeProlongation() for TLS '" << this->
getID() <<
"' (current phase = " <<
myStep <<
")" << std::endl;
125 for (
int i = 0; i < (int) state.size(); i++) {
129 std::map<const MSLane*, MSE2Collector*>::iterator it =
myLaneDetectors.find(lane);
131#ifdef DEBUG_TIMELOSS_CONTROL
133 std::cout <<
"no detector on lane '" << lane->getID() << std::endl;
137 const std::vector<MSE2Collector::VehicleInfo*> vehInfos = it->second->getCurrentVehicles();
138#ifdef DEBUG_TIMELOSS_CONTROL
145 const SUMOTime estimatedTimeToJunction =
TIME2STEPS((iv->distToDetectorEnd) / lane->getSpeedLimit());
146 if (actDuration + estimatedTimeToJunction <= maxDuration &&
getLatest() > 0) {
148 prolongation =
MAX2(prolongation, estimatedTimeToJunction);
150#ifdef DEBUG_TIMELOSS_CONTROL
154#ifdef DEBUG_TIMELOSS_CONTROL
155 std::cout <<
"vehicle '" << iv->id <<
"' with accumulated timeloss: " << iv->accumulatedTimeLoss
156 <<
"\nestimated passing time: " << estimatedTimeToJunction << std::endl;
158 std::string reason = iv->accumulatedTimeLoss <=
myTimeLossThreshold ?
" (time loss below threshold)" :
" (front already left detector)";
159 std::cout <<
"disregarded: (vehicle '" << iv->id <<
"' with accumulated timeloss " << iv->accumulatedTimeLoss <<
")" << reason << std::endl;
165 if (vehInfos.size() > 0) {
169#ifdef DEBUG_TIMELOSS_CONTROL
170 std::cout <<
"Actual duration exceeds maxDuration and a vehicle is on concurrent approach: " << nrVehs << std::endl;
177#ifdef DEBUG_TIMELOSS_CONTROL
178 std::cout <<
"Number of current vehicles on detector: " << nrVehs << std::endl;
183#ifdef DEBUG_TIMELOSS_CONTROL
184 std::cout <<
"Proposed prolongation (maximal estimated passing time): " << prolongation << std::endl;
197#ifdef DEBUG_TIMELOSS_CONTROL
198 std::cout <<
"last switch = " << currentPhase.
myLastSwitch
199 <<
"\nactDuration = " << actDuration
206 bool othersEmpty =
true;
209#ifdef DEBUG_TIMELOSS_CONTROL
210 std::cout <<
"othersEmpty = " << othersEmpty
215 bool prolong = othersEmpty || actDuration < currentPhase.
maxDuration;
220 proposedProlongation =
MAX2(proposedProlongation,
TIME2STEPS(1.));
226#ifdef DEBUG_TIMELOSS_CONTROL
227 std::cout <<
"Proposed prolongation = " << proposedProlongation << std::endl;
230 prolong = proposedProlongation > 0;
234 return proposedProlongation;
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permission forbids vehicles.
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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.
double myDetectionRange
Range of the connected detector, which provides the information on approaching vehicles.
void setShowDetectors(bool show)
std::string myVehicleTypes
Whether detector output separates by vType.
void init(NLDetectorBuilder &nb)
Initializes the tls with information about incoming lanes.
SUMOTime myFreq
The frequency for aggregating detector output.
std::map< const MSLane *, MSE2Collector * > myLaneDetectors
A map from lanes to the corresponding lane detectors.
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
double myTimeLossThreshold
std::string myFile
The output file for generated detectors.
MSDelayBasedTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const MSSimpleTrafficLightLogic::Phases &phases, int step, SUMOTime delay, const Parameterised::Map ¶meter, const std::string &basePath)
Constructor.
SUMOTime proposeProlongation(const SUMOTime actDuration, const SUMOTime maxDuration, bool &othersEmpty)
The returned, proposed prolongation for the green phase is oriented on the largest estimated passing ...
~MSDelayBasedTrafficLightLogic()
Destructor.
SUMOTime trySwitch()
Switches to the next phase, if possible.
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime interval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
An areal detector corresponding to a sequence of consecutive lanes.
virtual void setVisible(bool)
Representation of a lane in the micro simulation.
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
double getLength() const
Returns the lane's length.
MSDetectorControl & getDetectorControl()
Returns the detector control.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The definition of a single phase of a tls logic.
SUMOTime maxDuration
The maximum duration of the phase.
SUMOTime minDuration
The minimum duration of the phase.
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
const std::string & getState() const
Returns the state within this phase.
bool isGreenPhase() const
Returns whether this phase is a pure "green" phase.
A fixed traffic light logic.
SUMOTime getLatest() const
the maximum duration for keeping the current phase when considering 'latestEnd'
Phases myPhases
The list of phases this logic uses.
SUMOTime getEarliest(SUMOTime prevStart) const
the minimum duration for keeping the current phase when considering 'earliestEnd'
int myStep
The current step.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
gets a parameter
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
A class that stores and controls tls and switching of their programs.
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
const std::string & getProgramID() const
Returns this tl-logic's id.
const std::string myProgramID
The id of the logic.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
Builds detectors for microsim.
virtual MSE2Collector * createE2Detector(const std::string &id, DetectorUsage usage, MSLane *lane, double pos, double endPos, double length, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool showDetector)
Creates a MSE2Collector instance, overridden by GUIE2Collector::createE2Detector()
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
T get(const std::string &id) const
Retrieves an item.
static OptionsCont & getOptions()
Retrieves the options.
std::map< std::string, std::string > Map
parameters map
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
A VehicleInfo stores values that are tracked for the individual vehicles on the detector,...