SUMO - Simulation of Urban MObility
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.dlr.de/
13 // Copyright (C) 2012-2017 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 
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 MSEdgeVector& edges = ec.getEdges();
65  for (MSEdgeVector::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  // maximum of all vehicle waiting times
79  double queueing_time = 0.0;
80  // back of last stopped vehicle (XXX does not check for continuous queue)
81  double queueing_length = 0.0;
82  // back of last slow vehicle (XXX does not check for continuous queue)
83  double queueing_length2 = 0.0;
84  const double threshold_velocity = 5 / 3.6; // slow
85 
86  if (!lane.empty()) {
87  for (MSLane::VehCont::const_iterator it_veh = lane.myVehicles.begin(); it_veh != lane.myVehicles.end(); ++it_veh) {
88  const MSVehicle& veh = **it_veh;
89  if (!veh.isOnRoad()) {
90  continue;
91  }
92 
93  if (veh.getWaitingSeconds() > 0) {
94  queueing_time = MAX2(veh.getWaitingSeconds(), queueing_time);
95  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
96  queueing_length = MAX2(veh_back_to_lane_end, queueing_length);
97  }
98 
99  //Experimental
100  if (veh.getSpeed() < (threshold_velocity) && (veh.getPositionOnLane() > (veh.getLane()->getLength()) * 0.25)) {
101  const double veh_back_to_lane_end = (lane.getLength() - veh.getPositionOnLane()) + veh.getVehicleType().getLength();
102  queueing_length2 = MAX2(veh_back_to_lane_end, queueing_length2);
103  }
104  }
105  }
106 
107  //Output
108  if (queueing_length > 1 || queueing_length2 > 1) {
109  of.openTag("lane").writeAttr("id", lane.getID()).writeAttr("queueing_time", queueing_time).writeAttr("queueing_length", queueing_length);
110  of.writeAttr("queueing_length_experimental", queueing_length2).closeTag();
111  }
112 }
113 
114 
115 /****************************************************************************/
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&#39;s vehicles. This container holds all vehicles that have their front (longitudinally) and the...
Definition: MSLane.h:1090
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:570
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:488
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:375
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
T MAX2(T a, T b)
Definition: StdDefs.h:70
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:484
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:510
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:74
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:71
bool closeTag()
Closes the most recently opened tag.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:353
long long int SUMOTime
Definition: TraCIDefs.h:52
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:442
bool empty() const
Returns true if there is not a single vehicle on the lane.
Definition: MSLane.h:564
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.