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 /****************************************************************************/
18 // Export the queueing length in front of a junction (very experimental!)
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <microsim/MSEdgeControl.h>
28 #include <microsim/MSEdge.h>
29 #include <microsim/MSLane.h>
30 #include <microsim/MSGlobals.h>
32 #include "MSQueueExport.h"
33 #include <microsim/MSNet.h>
34 #include <microsim/MSVehicle.h>
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 void
42  of.openTag("data").writeAttr("timestep", time2string(timestep));
43  writeEdge(of);
44  of.closeTag();
45 }
46 
47 
48 void
50  of.openTag("lanes");
52  const MSEdgeVector& edges = ec.getEdges();
53  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
54  MSEdge& edge = **e;
55  const std::vector<MSLane*>& lanes = edge.getLanes();
56  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
57  writeLane(of, **lane);
58  }
59  }
60  of.closeTag();
61 }
62 
63 
64 void
66  // maximum of all vehicle waiting times
67  double queueing_time = 0.0;
68  // back of last stopped vehicle (XXX does not check for continuous queue)
69  double queueing_length = 0.0;
70  // back of last slow vehicle (XXX does not check for continuous queue)
71  double queueing_length2 = 0.0;
72  const double threshold_velocity = 5 / 3.6; // slow
73 
74  if (!lane.empty()) {
75  for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
76  const MSVehicle& veh = **it_veh;
77  if (!veh.isOnRoad()) {
78  continue;
79  }
80 
81  if (veh.getWaitingSeconds() > 0) {
82  queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
83  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
84  queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
85  }
86 
87  //Experimental
88  if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
89  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
90  queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
91  }
92  }
93  }
94 
95  //Output
96  if (queueing_length > 1 || queueing_length2 > 1) {
97  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
98  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
99  }
100 }
101 
102 
103 /****************************************************************************/
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSVehicle::isOnRoad
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:583
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
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:41
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:80
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
MSQueueExport::writeLane
static void writeLane(OutputDevice &of, const MSLane &lane)
Iterates through the lanes and check for available vehicle queues.
Definition: MSQueueExport.cpp:65
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:397
MSLane::getLength
double getLength() const
Returns the lane's length.
Definition: MSLane.h:541
OutputDevice.h
MSLane::empty
bool empty() const
Returns true if there is not a single vehicle on the lane.
Definition: MSLane.h:652
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSGlobals.h
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
MSQueueExport.h
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:118
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
MSVehicleType::getLength
double getLength() const
Get vehicle's length [m].
Definition: MSVehicleType.h:110
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:165
config.h
MSEdgeControl
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
MSVehicle::getSpeed
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:477
MSQueueExport::writeEdge
static void writeEdge(OutputDevice &of)
Iterates through all the edges and extract the lanes.
Definition: MSQueueExport.cpp:49
MSLane.h
MSNet::getEdgeControl
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:380
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
MSLane::myVehicles
VehCont myVehicles
The lane's vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1286
MSEdgeControl::getEdges
const MSEdgeVector & getEdges() const
Returns loaded edges.
Definition: MSEdgeControl.h:168
MSVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:657
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80