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;
62#ifdef DEBUG_TIMELOSS_CONTROL
78 LaneVectorVector::const_iterator i2;
79 LaneVector::const_iterator i;
83 for (i = lanes.begin(); i != lanes.end(); i++) {
104 while (length < myDetectionRange && firstLane->getIncomingLanes().size() == 1
105 && firstLane->
getIncomingLanes().front().viaLink->getCorrespondingEntryLink()->getTLLogic() ==
nullptr) {
115 det = nb.
createE2Detector(
id,
DU_TL_CONTROL, lane,
INVALID_POSITION, lane->
getLength(), length,
TIME2STEPS(1.0), 5.0 / 3.6, 10.0,
"",
myVehicleTypes,
"", (
int)
PersonMode::NONE,
myShowDetectors);
133#ifdef DEBUG_TIMELOSS_CONTROL
134 std::cout <<
"\n" <<
SIMTIME <<
" MSDelayBasedTrafficLightLogic::proposeProlongation() for TLS '" << this->
getID() <<
"' (current phase = " <<
myStep <<
")" << std::endl;
139 for (
int i = 0; i < (int) state.size(); i++) {
143 std::map<const MSLane*, MSE2Collector*>::iterator it =
myLaneDetectors.find(lane);
145#ifdef DEBUG_TIMELOSS_CONTROL
147 std::cout <<
"no detector on lane '" << lane->getID() << std::endl;
151 const std::vector<MSE2Collector::VehicleInfo*> vehInfos = it->second->getCurrentVehicles();
152#ifdef DEBUG_TIMELOSS_CONTROL
159 const SUMOTime estimatedTimeToJunction =
TIME2STEPS((iv->distToDetectorEnd) / lane->getSpeedLimit());
160 if (actDuration + estimatedTimeToJunction <= maxDuration &&
getLatest() > 0) {
162 prolongation =
MAX2(prolongation, estimatedTimeToJunction);
164#ifdef DEBUG_TIMELOSS_CONTROL
168#ifdef DEBUG_TIMELOSS_CONTROL
169 std::cout <<
"vehicle '" << iv->id <<
"' with accumulated timeloss: " << iv->accumulatedTimeLoss
170 <<
"\nestimated passing time: " << estimatedTimeToJunction << std::endl;
172 std::string reason = iv->accumulatedTimeLoss <=
myTimeLossThreshold ?
" (time loss below threshold)" :
" (front already left detector)";
173 std::cout <<
"disregarded: (vehicle '" << iv->id <<
"' with accumulated timeloss " << iv->accumulatedTimeLoss <<
")" << reason << std::endl;
179 if (vehInfos.size() > 0) {
183#ifdef DEBUG_TIMELOSS_CONTROL
184 std::cout <<
"Actual duration exceeds maxDuration and a vehicle is on concurrent approach: " << nrVehs << std::endl;
191#ifdef DEBUG_TIMELOSS_CONTROL
192 std::cout <<
"Number of current vehicles on detector: " << nrVehs << std::endl;
197#ifdef DEBUG_TIMELOSS_CONTROL
198 std::cout <<
"Proposed prolongation (maximal estimated passing time): " << prolongation << std::endl;
211#ifdef DEBUG_TIMELOSS_CONTROL
212 std::cout <<
"last switch = " << currentPhase.
myLastSwitch
213 <<
"\nactDuration = " << actDuration
220 bool othersEmpty =
true;
223#ifdef DEBUG_TIMELOSS_CONTROL
224 std::cout <<
"othersEmpty = " << othersEmpty
232 proposedProlongation =
MAX2(proposedProlongation,
TIME2STEPS(1.));
241#ifdef DEBUG_TIMELOSS_CONTROL
242 std::cout <<
"Proposed prolongation = " << proposedProlongation << std::endl;
245 if (proposedProlongation > 0) {
248 return proposedProlongation;
270std::map<std::string, double>
272 std::map<std::string, double> result;
274 result[item.second->getID()] = item.second->getCurrentVehicleNumber();
283 if (item.first->getID() == laneID) {
284 result = item.second->getCurrentVehicleNumber();
295 if (item.first->getID() == laneID) {
296 result = item.second->getEstimateQueueLength();
#define WRITE_ERRORF(...)
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permissions 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.
double getDetectorState(const std::string laneID) const override
retrieve a specific detector used by this program
bool myExtendMaxDur
Whether phases may be extended beyond maxDur in the absence of traffic.
void setShowDetectors(bool show)
std::string myVehicleTypes
Whether detector output separates by vType.
SUMOTime myFreq
The frequency for aggregating detector output.
std::map< std::string, double > getDetectorStates() const override
retrieve all detectors used by this program
std::map< const MSLane *, MSE2Collector * > myLaneDetectors
A map from lanes to the corresponding lane detectors.
void init(NLDetectorBuilder &nb) override
Initializes the tls with information about incoming lanes.
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() override
Switches to the next phase, if possible.
double getTLQueueLength(const std::string laneID) const override
return the estimated queue length at the upcoming traffic light
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.
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
double getLength() const
Returns the lane's length.
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
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,...