Eclipse SUMO - Simulation of Urban MObility
MSQueueExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2020 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 
25 #include <microsim/MSEdgeControl.h>
26 #include <microsim/MSEdge.h>
27 #include <microsim/MSLane.h>
28 #include <microsim/MSGlobals.h>
30 #include "MSQueueExport.h"
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.h>
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 void
40  of.openTag("data").writeAttr("timestep", time2string(timestep));
41  writeEdge(of);
42  of.closeTag();
43 }
44 
45 
46 void
48  of.openTag("lanes");
50  const MSEdgeVector& edges = ec.getEdges();
51  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
52  MSEdge& edge = **e;
53  const std::vector<MSLane*>& lanes = edge.getLanes();
54  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
55  writeLane(of, **lane);
56  }
57  }
58  of.closeTag();
59 }
60 
61 
62 void
64  // maximum of all vehicle waiting times
65  double queueing_time = 0.0;
66  // back of last stopped vehicle (XXX does not check for continuous queue)
67  double queueing_length = 0.0;
68  // back of last slow vehicle (XXX does not check for continuous queue)
69  double queueing_length2 = 0.0;
70  const double threshold_velocity = 5 / 3.6; // slow
71 
72  if (!lane.empty()) {
73  for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
74  const MSVehicle& veh = **it_veh;
75  if (!veh.isOnRoad()) {
76  continue;
77  }
78 
79  if (veh.getWaitingSeconds() > 0) {
80  queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
81  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
82  queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
83  }
84 
85  //Experimental
86  if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
87  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
88  queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
89  }
90  }
91  }
92 
93  //Output
94  if (queueing_length > 1 || queueing_length2 > 1) {
95  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
96  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
97  }
98 }
99 
100 
101 /****************************************************************************/
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
T MAX2(T a, T b)
Definition: StdDefs.h:79
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:81
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:166
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
bool empty() const
Returns true if there is not a single vehicle on the lane.
Definition: MSLane.h:655
VehCont myVehicles
The lane's vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1322
double getLength() const
Returns the lane's length.
Definition: MSLane.h:539
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:414
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:580
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:669
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:458
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:374
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:550
double getLength() const
Get vehicle's length [m].
const std::string & getID() const
Returns the id.
Definition: Named.h:73
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.