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.sourceforge.net/
9 // Copyright (C) 2001-2012 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 
55  of.openTag("data") << " timestep=\"" << time2string(timestep) << "\">\n";
56 
57  writeEdge(of);
58 
59  of.closeTag();
60 }
61 
62 void
64 
65  of.openTag("lanes") << ">\n";
66 
68 
69  const std::vector<MSEdge*>& edges = ec.getEdges();
70  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
71 
72  MSEdge& edge = **e;
73 
74  const std::vector<MSLane*>& lanes = edge.getLanes();
75  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
76 
77  writeLane(of, **lane);
78 
79  }
80 
81  }
82 
83  of.closeTag();
84 
85 }
86 
87 
88 void
90 
91  //Fahrzeug mit der höchsten Wartezeit
92  //Fahrzeug am Ende des Rückstaus
93 
94  double queueing_time = 0.0;
95  double queueing_length = 0.0;
96  double queueing_length2 = 0.0;
97 
98 
99  if (lane.getVehicleNumber() != 0) {
100 
101  for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin(); veh != lane.myVehBuffer.end(); ++veh) {
102 
103  const MSVehicle& veh_tmp = **veh;
104  if (veh_tmp.isOnRoad()) {
105 
106  if (veh_tmp.getWaitingSeconds() > 0) {
107 
108  if (veh_tmp.getWaitingSeconds() > queueing_time) {
109  queueing_time = veh_tmp.getWaitingSeconds();
110  }
111 
112  double tmp_length = (lane.getLength() - veh_tmp.getPositionOnLane()) + veh_tmp.getVehicleType().getLengthWithGap();
113 
114  if (tmp_length > queueing_length) {
115  queueing_length = tmp_length;
116  }
117 
118 
119  }
120 
121  }
122 
123  }
124 
125 
126  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin(); veh != lane.myVehicles.end(); ++veh) {
127 
128  const MSVehicle& veh_tmp = **veh;
129  if (veh_tmp.isOnRoad()) {
130 
131  if (veh_tmp.getWaitingSeconds() > 0) {
132 
133  if (veh_tmp.getWaitingSeconds() > queueing_time) {
134  queueing_time = veh_tmp.getWaitingSeconds();
135  }
136 
137  double tmp_length = (lane.getLength() - veh_tmp.getPositionOnLane()) + veh_tmp.getVehicleType().getLengthWithGap();
138 
139  if (tmp_length > queueing_length) {
140  queueing_length = tmp_length;
141  }
142 
143 
144  }
145 
146  }
147  }
148 
149 
150  //Experimental
151  double tmp_length2 = 0.0;
152 
153  for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin(); veh != lane.myVehicles.end(); ++veh) {
154 
155  //wenn Fahrzeug langsamer als 5 km/h fährt = Rückstau
156  double threshold_velocity = 5 / 3.6;
157  const MSVehicle& veh_tmp = **veh;
158  if (veh_tmp.isOnRoad()) {
159 
160  if (veh_tmp.getSpeed() < (threshold_velocity) && (veh_tmp.getPositionOnLane() > (veh_tmp.getLane()->getLength()) * 0.25))
161 
162  {
163  tmp_length2 = (lane.getLength() - veh_tmp.getPositionOnLane()) + veh_tmp.getVehicleType().getLengthWithGap();
164  }
165  if (tmp_length2 > queueing_length2) {
166  queueing_length2 = tmp_length2;
167  }
168 
169  }
170  }
171 
172  }
173 
174  //Output
175  if (queueing_length > 1 || queueing_length2 > 1) {
176  of.openTag("lane") << " id=\"" << lane.getID() << "\"";
177  of << " queueing_time=\"" << queueing_time << "\" queueing_length=\"" << queueing_length << "\" queueing_length_experimental=\"" << queueing_length2 << "\"";
178  of.closeTag(true);
179  }
180 
181 }
182 
183 /****************************************************************************/