Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSQueueExport.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// Export the queueing length in front of a junction (very experimental!)
22/****************************************************************************/
23#include <config.h>
24
26#include <microsim/MSEdge.h>
27#include <microsim/MSLane.h>
28#include <microsim/MSGlobals.h>
31#include "MSQueueExport.h"
32#include <microsim/MSNet.h>
33#include <microsim/MSVehicle.h>
34
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39void
41 const SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin"));
42 const SUMOTime period = string2time(OptionsCont::getOptions().getString("queue-output.period"));
43 if (period > 0 && (timestep - begin) % period != 0) {
44 return;
45 }
46 of.openTag("data").writeAttr("timestep", time2string(timestep));
47 writeEdge(of);
48 of.closeTag();
49}
50
51
52void
54 of.openTag("lanes");
56 const MSEdgeVector& edges = ec.getEdges();
57 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
58 MSEdge& edge = **e;
59 const std::vector<MSLane*>& lanes = edge.getLanes();
60 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
61 writeLane(of, **lane);
62 }
63 }
64 of.closeTag();
65}
66
67
68void
70 // maximum of all vehicle waiting times
71 double queueing_time = 0.0;
72 // back of last stopped vehicle (XXX does not check for continuous queue)
73 double queueing_length = 0.0;
74 // back of last slow vehicle (XXX does not check for continuous queue)
75 double queueing_length2 = 0.0;
76 const double threshold_velocity = 5 / 3.6; // slow
77
78 if (!lane.empty()) {
79 for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
80 const MSVehicle& veh = **it_veh;
81 if (!veh.isOnRoad()) {
82 continue;
83 }
84
85 if (veh.getWaitingSeconds() > 0) {
86 queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
87 const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
88 queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
89 }
90
91 //Experimental
92 if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
93 const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
94 queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
95 }
96 }
97 }
98
99 //Output
100 if (queueing_length > 1 || queueing_length2 > 1) {
101 of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
102 of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
103 }
104}
105
106
107/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
T MAX2(T a, T b)
Definition StdDefs.h:82
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.
Stores edges and lanes, performs moving of vehicle.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
Representation of a lane in the micro simulation.
Definition MSLane.h:84
bool empty() const
Returns true if there is not a single vehicle on the lane.
Definition MSLane.h:739
VehCont myVehicles
The lane's vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition MSLane.h:1458
double getLength() const
Returns the lane's length.
Definition MSLane.h:606
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:421
static void writeLane(OutputDevice &of, const MSLane &lane)
Iterates through the lanes and check for available vehicle queues.
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
static void writeEdge(OutputDevice &of)
Iterates through all the edges and extract the lanes.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition MSVehicle.h:605
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MSVehicle.h:374
double getLength() const
Get vehicle's length [m].
const std::string & getID() const
Returns the id.
Definition Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.