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 /****************************************************************************/
7 // Export the queueing length in front of a junction (very experimental!)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <microsim/MSEdgeControl.h>
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSGlobals.h>
36 #include "MSQueueExport.h"
37 #include <microsim/MSNet.h>
38 #include <microsim/MSVehicle.h>
39 
40 #ifdef HAVE_MESOSIM
41 #include <mesosim/MELoop.h>
42 #include <mesosim/MESegment.h>
43 #endif
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 void
55  of.openTag("data").writeAttr("timestep", time2string(timestep));
56  writeEdge(of);
57  of.closeTag();
58 }
59 
60 
61 void
63  of.openTag("lanes");
65  const std::vector<MSEdge*>& edges = ec.getEdges();
66  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
67  MSEdge& edge = **e;
68  const std::vector<MSLane*>& lanes = edge.getLanes();
69  for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
70  writeLane(of, **lane);
71  }
72  }
73  of.closeTag();
74 }
75 
76 
77 void
79  // maximum of all vehicle waiting times
80  SUMOReal queueing_time = 0.0;
81  // back of last stopped vehicle (XXX does not check for continuous queue)
82  SUMOReal queueing_length = 0.0;
83  // back of last slow vehicle (XXX does not check for continuous queue)
84  SUMOReal queueing_length2 = 0.0;
85  const SUMOReal threshold_velocity = 5 / 3.6; // slow
86 
87  if (!lane.empty()) {
88  for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
89  const MSVehicle& veh = **it_veh;
90  if (!veh.isOnRoad()) {
91  continue;
92  }
93 
94  if (veh.getWaitingSeconds() > 0) {
95  queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
96  const SUMOReal veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
97  queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
98  }
99 
100  //Experimental
101  if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
102  const SUMOReal veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
103  queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
104  }
105  }
106  }
107 
108  //Output
109  if (queueing_length > 1 || queueing_length2 > 1) {
110  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
111  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
112  }
113 }
114 
115 
116 /****************************************************************************/
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:256
VehCont myVehicles
The lane's vehicles. The entering vehicles are inserted at the front of this container and the leavin...
Definition: MSLane.h:773
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
SUMOReal getLength() const
Returns the lane's length.
Definition: MSLane.h:370
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOReal getLength() const
Get vehicle's length [m].
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
T MAX2(T a, T b)
Definition: StdDefs.h:71
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:283
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.
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
bool empty() const
Returns true if there is not a single vehicle on the lane.
Definition: MSLane.h:435
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:94
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:373
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.
#define SUMOReal
Definition: config.h:215
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:284
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:336
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:328
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.