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 /****************************************************************************/
10 // Export the queueing length in front of a junction (very experimental!)
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2012-2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <microsim/MSEdgeControl.h>
35 #include <microsim/MSEdge.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSGlobals.h>
39 #include "MSQueueExport.h"
40 #include <microsim/MSNet.h>
41 #include <microsim/MSVehicle.h>
42 
43 #ifdef HAVE_MESOSIM
44 #include <mesosim/MELoop.h>
45 #include <mesosim/MESegment.h>
46 #endif
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 void
58  of.openTag("data").writeAttr("timestep", time2string(timestep));
59  writeEdge(of);
60  of.closeTag();
61 }
62 
63 
64 void
66  of.openTag("lanes");
68  const std::vector<MSEdge*>& edges = ec.getEdges();
69  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
70  MSEdge& edge = **e;
71  const std::vector<MSLane*>& lanes = edge.getLanes();
72  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
73  writeLane(of, **lane);
74  }
75  }
76  of.closeTag();
77 }
78 
79 
80 void
82  // maximum of all vehicle waiting times
83  SUMOReal queueing_time = 0.0;
84  // back of last stopped vehicle (XXX does not check for continuous queue)
85  SUMOReal queueing_length = 0.0;
86  // back of last slow vehicle (XXX does not check for continuous queue)
87  SUMOReal queueing_length2 = 0.0;
88  const SUMOReal threshold_velocity = 5 / 3.6; // slow
89 
90  if (!lane.empty()) {
91  for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
92  const MSVehicle& veh = **it_veh;
93  if (!veh.isOnRoad()) {
94  continue;
95  }
96 
97  if (veh.getWaitingSeconds() > 0) {
98  queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
99  const SUMOReal veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
100  queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
101  }
102 
103  //Experimental
104  if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
105  const SUMOReal veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
106  queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
107  }
108  }
109  }
110 
111  //Output
112  if (queueing_length > 1 || queueing_length2 > 1) {
113  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
114  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
115  }
116 }
117 
118 
119 /****************************************************************************/