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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Export the queueing length in front of a junction (very experimental!)
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <microsim/MSEdgeControl.h>
27 #include <microsim/MSEdge.h>
28 #include <microsim/MSLane.h>
29 #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 // ===========================================================================
39 void
41  of.openTag("data").writeAttr("timestep", time2string(timestep));
42  writeEdge(of);
43  of.closeTag();
44 }
45 
46 
47 void
49  of.openTag("lanes");
51  const MSEdgeVector& edges = ec.getEdges();
52  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
53  MSEdge& edge = **e;
54  const std::vector<MSLane*>& lanes = edge.getLanes();
55  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
56  writeLane(of, **lane);
57  }
58  }
59  of.closeTag();
60 }
61 
62 
63 void
65  // maximum of all vehicle waiting times
66  double queueing_time = 0.0;
67  // back of last stopped vehicle (XXX does not check for continuous queue)
68  double queueing_length = 0.0;
69  // back of last slow vehicle (XXX does not check for continuous queue)
70  double queueing_length2 = 0.0;
71  const double threshold_velocity = 5 / 3.6; // slow
72 
73  if (!lane.empty()) {
74  for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
75  const MSVehicle& veh = **it_veh;
76  if (!veh.isOnRoad()) {
77  continue;
78  }
79 
80  if (veh.getWaitingSeconds() > 0) {
81  queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
82  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
83  queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
84  }
85 
86  //Experimental
87  if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
88  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
89  queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
90  }
91  }
92  }
93 
94  //Output
95  if (queueing_length > 1 || queueing_length2 > 1) {
96  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
97  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
98  }
99 }
100 
101 
102 /****************************************************************************/
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSVehicle::isOnRoad
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:582
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSEdge.h
MSQueueExport::write
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
Definition: MSQueueExport.cpp:40
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
MSQueueExport::writeLane
static void writeLane(OutputDevice &of, const MSLane &lane)
Iterates through the lanes and check for available vehicle queues.
Definition: MSQueueExport.cpp:64
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:392
MSLane::getLength
double getLength() const
Returns the lane's length.
Definition: MSLane.h:540
OutputDevice.h
MSLane::empty
bool empty() const
Returns true if there is not a single vehicle on the lane.
Definition: MSLane.h:651
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSGlobals.h
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSQueueExport.h
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:123
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSVehicleType::getLength
double getLength() const
Get vehicle's length [m].
Definition: MSVehicleType.h:109
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
config.h
MSEdgeControl
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
MSVehicle::getSpeed
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:476
MSQueueExport::writeEdge
static void writeEdge(OutputDevice &of)
Iterates through all the edges and extract the lanes.
Definition: MSQueueExport.cpp:48
MSLane.h
MSNet::getEdgeControl
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:379
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSLane::myVehicles
VehCont myVehicles
The lane's vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1285
MSEdgeControl::getEdges
const MSEdgeVector & getEdges() const
Returns loaded edges.
Definition: MSEdgeControl.h:169
MSVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:656
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79