59 if (period > 0 && (timestep - begin) % period != 0) {
62 const double threshold = oc.
getFloat(
"queue-output.speed-threshold");
64 if (aggregation > 0) {
65 const SUMOTime intervalStart = begin + ((timestep - begin) / aggregation) * aggregation;
76 bool wrapperOpen =
false;
77 auto ensureOpen = [&]() {
84 if (!oc.
getBool(
"queue-output.skip-empty")) {
111 double segmentOffset = 0.;
112 for (
const MESegment* segment =
MSGlobals::gMesoNet->getSegmentForEdge(*edge); segment !=
nullptr; segment = segment->getNextSegment()) {
113 for (
int qIdx = 0; qIdx < segment->numQueues(); ++qIdx) {
114 writeMesoQueue(of, *edge, *segment, qIdx, segmentOffset, threshold, ensureOpen);
116 segmentOffset += segment->getLength();
119 for (
const MSLane*
const lane : edge->getLanes()) {
120 writeLane(of, *lane, threshold, ensureOpen);
130 double queueing_time = 0.0;
132 double queueing_length = 0.0;
134 double queueing_length2 = 0.0;
136 int queueing_count = 0;
139 for (MSLane::VehCont::const_iterator it_veh = lane.
myVehicles.begin(); it_veh != lane.
myVehicles.end(); ++it_veh) {
148 queueing_length =
MAX2(veh_back_to_lane_end, queueing_length);
154 queueing_length2 =
MAX2(veh_back_to_lane_end, queueing_length2);
162 if (queueing_length > 1 || queueing_length2 > 1) {
167 }
else if (queueing_count > 0) {
168 myEdgeSamples[&lane.
getEdge()].push_back(std::make_pair((
double)queueing_count, queueing_length2));
175 const std::vector<MEVehicle*>& queue = segment.
getQueue(qIdx);
176 const int queueSize = (int)queue.size();
178 double queueing_time = 0.0;
180 int queueing_count = 0;
182 double queueing_length = 0.0;
183 double occupancy = 0.0;
184 const double segLength = segment.
getLength();
185 const double segmentEnd = segmentOffset + segLength;
186 const double lanesCovered = segment.
numQueues() == 1 ? std::round(segment.
getCapacity() / segLength) : 1.;
190 SUMOTime conservativeExitTime = earliestExitTime;
191 double prevPos = std::numeric_limits<double>::max();
192 bool prevQueued =
false;
194 for (
int i = 0; i < queueSize; ++i) {
196 const MEVehicle*
const veh = queue[queueSize - 1 - i];
198 occupancy += lengthWithGap;
201 double maxPos = segmentEnd;
205 maxPos =
MIN2(maxPos, prevPos - lengthWithGap / lanesCovered);
209 const double linearPos =
MIN2(segmentEnd, segmentOffset + segLength * (now - entry) / travelTime);
212 const double interpolatedSpeed = segLength /
MAX2(
STEPS2TIME(conservativeExitTime) - entry,
TS);
215 const bool queued =
MIN2(veh->
getSpeed(), interpolatedSpeed) < threshold || (prevQueued && linearPos >= maxPos - POSITION_EPS);
217 queueing_count = i + 1;
222 queueing_length = occupancy / lanesCovered;
226 prevPos =
MIN2(linearPos, maxPos);
228 if (queueing_count == 0) {
236 myEdgeSamples[&edge].push_back(std::make_pair((
double)queueing_count, queueing_length));
246 bool intervalOpen =
false;
247 auto ensureOpen = [&]() {
254 if (!oc.
getBool(
"queue-output.skip-empty")) {
257 const double p = oc.
getFloat(
"queue-output.percentile") / 100.;
264 std::vector<double> counts;
265 std::vector<double> lengths;
266 for (
const auto& sample : it->second) {
267 counts.push_back(sample.first);
268 lengths.push_back(sample.second);
270 std::sort(counts.begin(), counts.end());
271 std::sort(lengths.begin(), lengths.end());
274 of.
writeAttr(
"maxQueueLengthInVehicles", counts.back());
277 of.
writeAttr(
"maxQueueLengthInMeters", lengths.back());
291 assert(!sorted.empty());
292 const double rank = p * (double)(sorted.size() - 1);
293 const int lower = (int)rank;
294 if (lower + 1 >= (
int)sorted.size()) {
295 return sorted.back();
297 const double frac = rank - (double)lower;
298 return sorted[lower] * (1. - frac) + sorted[lower + 1] * frac;
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
A single mesoscopic segment (cell)
SUMOTime getTauWithVehLength(int qIdx, double lengthWithGap, double vehicleTau) const
like getMinTauWithVehLength but using the jam-state dependent net time gap of the given queue (as in ...
double getLength() const
Returns the length of the segment in meters.
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
int numQueues() const
return the number of queues
double getCapacity() const
Returns the sum of the lengths of all usable lanes of the segment in meters.
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
SUMOTime getQueueBlockTime(int index) const
SUMOTime getMinTauWithVehLength(double lengthWithGap, double vehicleTau) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
A vehicle from the mesoscopic point of view.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
double getPositionOnLane() const
Get the vehicle's position along the lane.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Stores edges and lanes, performs moving of vehicle.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
static bool gMesoInterpolatePos
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Representation of a lane in the micro simulation.
bool empty() const
Returns true if there is not a single vehicle on the lane.
VehCont myVehicles
The lane's vehicles. This container holds all vehicles that have their front (longitudinally) and the...
double getLength() const
Returns the lane's length.
MSEdge & getEdge() const
Returns the lane's edge.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEdgeControl & getEdgeControl()
Returns the edge control.
static SUMOTime myIntervalStart
The begin of the current aggregation interval.
static void writeMesoQueue(OutputDevice *of, const MSEdge &edge, const MESegment &segment, int qIdx, double segmentOffset, double threshold, const std::function< void()> &ensureOpen)
Checks a single segment queue (meso)
static double percentile(const std::vector< double > &sorted, double p)
Returns the given percentile (with linear interpolation) of a sorted sample vector.
static void finish(OutputDevice &of, SUMOTime timestep)
Writes the last (possibly incomplete) aggregation interval and clears the collected samples.
static void writeLane(OutputDevice *of, const MSLane &lane, double threshold, const std::function< void()> &ensureOpen)
Checks a single lane for a vehicle queue (micro)
static void writeInterval(OutputDevice &of, SUMOTime begin, SUMOTime end)
Writes aggregated per-edge queue length statistics for the given interval.
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
static std::map< const MSEdge *, std::vector< std::pair< double, double > > > myEdgeSamples
Queue length samples (in vehicles, in meters) per edge, collected during the current aggregation inte...
static void writeEdge(OutputDevice *of, double threshold, const std::function< void()> &ensureOpen)
Iterates through the edges and their lanes (micro) or segment queues (meso). If of is nullptr,...
Representation of a vehicle in the micro simulation.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const MSLane * getLane() const
Returns the lane the vehicle is on.
double getSpeed() const
Returns the vehicle's current speed.
double getPositionOnLane() const
Get the vehicle's position along the lane.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
double getLength() const
Get vehicle's length [m].
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.