SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSQueueExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
6 // Export the queueing length in front of a junction (very experimental!)
7 /****************************************************************************/
8 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
9 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
10 /****************************************************************************/
11 //
12 // This file is part of SUMO.
13 // SUMO is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <microsim/MSEdgeControl.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSLane.h>
33 #include <microsim/MSGlobals.h>
35 #include "MSQueueExport.h"
36 #include <microsim/MSNet.h>
37 #include <microsim/MSVehicle.h>
38 
39 #ifdef HAVE_MESOSIM
40 #include <mesosim/MELoop.h>
41 #include <mesosim/MESegment.h>
42 #endif
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 void
54  of.openTag("data").writeAttr("timestep", time2string(timestep));
55  writeEdge(of);
56  of.closeTag();
57 }
58 
59 
60 void
62  of.openTag("lanes");
64  const std::vector<MSEdge*>& edges = ec.getEdges();
65  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
66  MSEdge& edge = **e;
67  const std::vector<MSLane*>& lanes = edge.getLanes();
68  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
69  writeLane(of, **lane);
70  }
71  }
72  of.closeTag();
73 }
74 
75 
76 void
78  //Fahrzeug mit der höchsten Wartezeit
79  //Fahrzeug am Ende des Rückstaus
80  double queueing_time = 0.0;
81  double queueing_length = 0.0;
82  double queueing_length2 = 0.0;
83 
84  if (lane.getVehicleNumber() != 0) {
85  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin(); veh != lane.myVehBuffer.end(); ++veh) {
86  const MSVehicle& veh_tmp = **veh;
87  if (!veh_tmp.isOnRoad()) {
88  continue;
89  }
90  if (veh_tmp.getWaitingSeconds() > 0) {
91  if (veh_tmp.getWaitingSeconds() > queueing_time) {
92  queueing_time = veh_tmp.getWaitingSeconds();
93  }
94  double tmp_length = (lane.getLength() - veh_tmp.getPositionOnLane()) + veh_tmp.getVehicleType().getLengthWithGap();
95  if (tmp_length > queueing_length) {
96  queueing_length = tmp_length;
97  }
98  }
99  }
100 
101  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin(); veh != lane.myVehicles.end(); ++veh) {
102  const MSVehicle& veh_tmp = **veh;
103  if (!veh_tmp.isOnRoad()) {
104  continue;
105  }
106 
107  if (veh_tmp.getWaitingSeconds() > 0) {
108  if (veh_tmp.getWaitingSeconds() > queueing_time) {
109  queueing_time = veh_tmp.getWaitingSeconds();
110  }
111  double tmp_length = (lane.getLength() - veh_tmp.getPositionOnLane()) + veh_tmp.getVehicleType().getLengthWithGap();
112  if (tmp_length > queueing_length) {
113  queueing_length = tmp_length;
114  }
115  }
116  }
117 
118 
119  //Experimental
120  double tmp_length2 = 0.0;
121  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin(); veh != lane.myVehicles.end(); ++veh) {
122  //wenn Fahrzeug langsamer als 5 km/h fährt = Rückstau
123  double threshold_velocity = 5 / 3.6;
124  const MSVehicle& veh_tmp = **veh;
125  if (!veh_tmp.isOnRoad()) {
126  continue;
127  }
128 
129  if (veh_tmp.getSpeed() < (threshold_velocity) && (veh_tmp.getPositionOnLane() > (veh_tmp.getLane()->getLength()) * 0.25)) {
130  tmp_length2 = (lane.getLength() - veh_tmp.getPositionOnLane()) + veh_tmp.getVehicleType().getLengthWithGap();
131  }
132  if (tmp_length2 > queueing_length2) {
133  queueing_length2 = tmp_length2;
134  }
135  }
136  }
137 
138  //Output
139  if (queueing_length > 1 || queueing_length2 > 1) {
140  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
141  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
142  }
143 }
144 
145 
146 /****************************************************************************/
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:254
VehCont myVehicles
The lane&#39;s vehicles. The entering vehicles are inserted at the front of this container and the leavin...
Definition: MSLane.h:696
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
SUMOReal getLengthWithGap() const
Get vehicle&#39;s length including the minimum gap [m].
SUMOReal getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:360
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:284
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
static void writeLane(OutputDevice &of, const MSLane &lane)
Iterates through the lanes and check for available vehicle queues.
std::vector< MSVehicle * > myVehBuffer
Definition: MSLane.h:716
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
unsigned int getVehicleNumber() const
Returns the number of vehicles on this lane.
Definition: MSLane.h:280
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:94
SUMOReal getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:292
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:353
const std::vector< MSEdge * > & 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:269
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:331
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:323
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.