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